Commit bc19f61c authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Fix for Bug 527505: Make t/001compile.t work even after Bugzilla::Install::CPAN…

Fix for Bug 527505: Make t/001compile.t work even after Bugzilla::Install::CPAN messes with @INC, and make Bugzilla->feature work during mod_perl.pl. Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=mkanat
parent 900f8b1d
...@@ -555,7 +555,11 @@ sub local_timezone { ...@@ -555,7 +555,11 @@ sub local_timezone {
sub request_cache { sub request_cache {
if ($ENV{MOD_PERL}) { if ($ENV{MOD_PERL}) {
require Apache2::RequestUtil; require Apache2::RequestUtil;
return Apache2::RequestUtil->request->pnotes(); # Sometimes (for example, during mod_perl.pl), the request
# object isn't available, and we should use $_request_cache instead.
my $request = eval { Apache2::RequestUtil->request };
return $_request_cache if !$request;
return $request->pnotes();
} }
return $_request_cache; return $_request_cache;
} }
......
...@@ -35,11 +35,13 @@ use base qw(Exporter); ...@@ -35,11 +35,13 @@ use base qw(Exporter);
our @EXPORT = qw( our @EXPORT = qw(
REQUIRED_MODULES REQUIRED_MODULES
OPTIONAL_MODULES OPTIONAL_MODULES
FEATURE_FILES
check_requirements check_requirements
check_graphviz check_graphviz
have_vers have_vers
install_command install_command
map_files_to_features
); );
# This is how many *'s are in the top of each "box" message printed # This is how many *'s are in the top of each "box" message printed
...@@ -294,6 +296,22 @@ sub OPTIONAL_MODULES { ...@@ -294,6 +296,22 @@ sub OPTIONAL_MODULES {
return $all_modules; return $all_modules;
}; };
# This maps features to the files that require that feature in order
# to compile. It is used by t/001compile.t and mod_perl.pl.
use constant FEATURE_FILES => (
jsonrpc => ['Bugzilla/WebService/Server/JSONRPC.pm', 'jsonrpc.cgi'],
xmlrpc => ['Bugzilla/WebService/Server/XMLRPC.pm', 'xmlrpc.cgi',
'Bugzilla/WebService.pm', 'Bugzilla/WebService/*.pm'],
moving => ['importxml.pl'],
auth_ldap => ['Bugzilla/Auth/Verify/LDAP.pm'],
auth_radius => ['Bugzilla/Auth/Verify/RADIUS.pm'],
inbound_email => ['email_in.pl'],
jobqueue => ['Bugzilla/Job/*', 'Bugzilla/JobQueue.pm',
'Bugzilla/JobQueue/*', 'jobqueue.pl'],
patch_viewer => ['Bugzilla/Attachment/PatchReader.pm'],
updates => ['Bugzilla/Update.pm'],
);
# This implements the install-requirements hook described in Bugzilla::Hook. # This implements the install-requirements hook described in Bugzilla::Hook.
sub _get_extension_requirements { sub _get_extension_requirements {
my ($function, $base_modules) = @_; my ($function, $base_modules) = @_;
...@@ -590,6 +608,21 @@ sub install_command { ...@@ -590,6 +608,21 @@ sub install_command {
return sprintf $command, $package; return sprintf $command, $package;
} }
# This does a reverse mapping for FEATURE_FILES.
sub map_files_to_features {
my %features = FEATURE_FILES;
my %files;
foreach my $feature (keys %features) {
my @my_files = @{ $features{$feature} };
foreach my $pattern (@my_files) {
foreach my $file (glob $pattern) {
$files{$file} = $feature;
}
}
}
return \%files;
}
1; 1;
__END__ __END__
...@@ -607,16 +640,42 @@ perl modules it requires.) ...@@ -607,16 +640,42 @@ perl modules it requires.)
=head1 CONSTANTS =head1 CONSTANTS
=over 4 =over
=item C<REQUIRED_MODULES> =item C<REQUIRED_MODULES>
An arrayref of hashrefs that describes the perl modules required by An arrayref of hashrefs that describes the perl modules required by
Bugzilla. The hashes have two keys, C<name> and C<version>, which Bugzilla. The hashes have three keys:
represent the name of the module and the version that we require.
=over
=item C<package> - The name of the Perl package that you'd find on
CPAN for this requirement.
=item C<module> - The name of a module that can be passed to the
C<install> command in C<CPAN.pm> to install this module.
=item C<version> - The version of this module that we require, or C<0>
if any version is acceptable.
=back =back
=item C<OPTIONAL_MODULES>
An arrayref of hashrefs that describes the perl modules that add
additional features to Bugzilla if installed. Its hashes have all
the fields of L</REQUIRED_MODULES>, plus a C<feature> item--an arrayref
of strings that describe what features require this module.
=item C<FEATURE_FILES>
A hashref that describes what files should only be compiled if a certain
feature is enabled. The feature is the key, and the values are arrayrefs
of file names (which are passed to C<glob>, so shell patterns work).
=back
=head1 SUBROUTINES =head1 SUBROUTINES
=over 4 =over 4
...@@ -699,4 +758,9 @@ Returns: C<1> if the check was successful, C<0> otherwise. ...@@ -699,4 +758,9 @@ Returns: C<1> if the check was successful, C<0> otherwise.
Returns: nothing Returns: nothing
=item C<map_files_to_features>
Returns a hashref where file names are the keys and the value is the feature
that must be enabled in order to compile that file.
=back =back
...@@ -34,12 +34,14 @@ use ModPerl::RegistryLoader (); ...@@ -34,12 +34,14 @@ use ModPerl::RegistryLoader ();
use CGI (); use CGI ();
CGI->compile(qw(:cgi -no_xhtml -oldstyle_urls :private_tempfiles CGI->compile(qw(:cgi -no_xhtml -oldstyle_urls :private_tempfiles
:unique_headers SERVER_PUSH :push)); :unique_headers SERVER_PUSH :push));
use File::Basename ();
use Template::Config (); use Template::Config ();
Template::Config->preload(); Template::Config->preload();
use Bugzilla (); use Bugzilla ();
use Bugzilla::Constants (); use Bugzilla::Constants ();
use Bugzilla::CGI (); use Bugzilla::CGI ();
use Bugzilla::Install::Requirements ();
use Bugzilla::Mailer (); use Bugzilla::Mailer ();
use Bugzilla::Template (); use Bugzilla::Template ();
use Bugzilla::Util (); use Bugzilla::Util ();
...@@ -75,9 +77,12 @@ my $rl = new ModPerl::RegistryLoader(); ...@@ -75,9 +77,12 @@ my $rl = new ModPerl::RegistryLoader();
# If we try to do this in "new" it fails because it looks for a # If we try to do this in "new" it fails because it looks for a
# Bugzilla/ModPerl/ResponseHandler.pm # Bugzilla/ModPerl/ResponseHandler.pm
$rl->{package} = 'Bugzilla::ModPerl::ResponseHandler'; $rl->{package} = 'Bugzilla::ModPerl::ResponseHandler';
# Note that $cgi_path will be wrong if somebody puts the libraries my $feature_files = Bugzilla::Install::Requirements::map_files_to_features();
# in a different place than the CGIs.
foreach my $file (glob "$cgi_path/*.cgi") { foreach my $file (glob "$cgi_path/*.cgi") {
my $base_filename = File::Basename::basename($file);
if (my $feature = $feature_files->{$base_filename}) {
next if !Bugzilla->feature($feature);
}
Bugzilla::Util::trick_taint($file); Bugzilla::Util::trick_taint($file);
$rl->handler($file, $file); $rl->handler($file, $file);
} }
......
...@@ -32,40 +32,18 @@ use Test::More tests => scalar(@Support::Files::testitems); ...@@ -32,40 +32,18 @@ use Test::More tests => scalar(@Support::Files::testitems);
BEGIN { BEGIN {
use_ok('Bugzilla::Constants'); use_ok('Bugzilla::Constants');
use_ok('Bugzilla::Install::Requirements');
use_ok('Bugzilla'); use_ok('Bugzilla');
} }
use constant FEATURE_FILES => (
jsonrpc => ['Bugzilla/WebService/Server/JSONRPC.pm', 'jsonrpc.cgi'],
xmlrpc => ['Bugzilla/WebService/Server/XMLRPC.pm', 'xmlrpc.cgi',
'Bugzilla/WebService.pm', 'Bugzilla/WebService/*.pm'],
moving => ['importxml.pl'],
auth_ldap => ['Bugzilla/Auth/Verify/LDAP.pm'],
auth_radius => ['Bugzilla/Auth/Verify/RADIUS.pm'],
inbound_email => ['email_in.pl'],
jobqueue => ['Bugzilla/Job/*', 'Bugzilla/JobQueue.pm',
'Bugzilla/JobQueue/*', 'jobqueue.pl'],
patch_viewer => ['Bugzilla/Attachment/PatchReader.pm'],
updates => ['Bugzilla/Update.pm'],
);
sub map_files_to_feature {
my %features = FEATURE_FILES;
my %files;
foreach my $feature (keys %features) {
my @my_files = @{ $features{$feature} };
foreach my $pattern (@my_files) {
foreach my $file (glob $pattern) {
$files{$file} = $feature;
}
}
}
return \%files;
}
sub compile_file { sub compile_file {
my ($file) = @_; my ($file) = @_;
# Don't allow CPAN.pm to modify the global @INC, which the version
# shipped with Perl 5.8.8 does. (It gets loaded by
# Bugzilla::Install::CPAN.)
local @INC = @INC;
if ($file =~ s/\.pm$//) { if ($file =~ s/\.pm$//) {
$file =~ s{/}{::}g; $file =~ s{/}{::}g;
use_ok($file); use_ok($file);
...@@ -91,12 +69,14 @@ sub compile_file { ...@@ -91,12 +69,14 @@ sub compile_file {
} }
my @testitems = @Support::Files::testitems; my @testitems = @Support::Files::testitems;
my $file_features = map_files_to_feature(); my $file_features = map_files_to_features();
# Test the scripts by compiling them # Test the scripts by compiling them
foreach my $file (@testitems) { foreach my $file (@testitems) {
# These were already compiled, above. # These were already compiled, above.
next if ($file eq 'Bugzilla.pm' or $file eq 'Bugzilla/Constants.pm'); next if ($file eq 'Bugzilla.pm'
or $file eq 'Bugzilla/Constants.pm'
or $file eq 'Bugzilla/Install/Requirements.pm');
SKIP: { SKIP: {
if ($file eq 'mod_perl.pl') { if ($file eq 'mod_perl.pl') {
skip 'mod_perl.pl cannot be compiled from the command line', 1; skip 'mod_perl.pl cannot be compiled from the command line', 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment