Commit 00d71f7c authored by Max Kanat-Alexander's avatar Max Kanat-Alexander

Bug 560330: Make sure that we always have a modern version of CPAN

installed when running install-module.pl. Otherwise, certain modules (like DateTime) weren't getting their XS compiled or their dependencies installed with Perl 5.8.8 and earlier. This also updates the urllist to remove perl.secsup.org (which was hanging when used with curl) and add a few more mirrors (including some in Europe). r=mkanat, a=mkanat (module owner)
parent b2b1427a
...@@ -21,9 +21,16 @@ ...@@ -21,9 +21,16 @@
package Bugzilla::Install::CPAN; package Bugzilla::Install::CPAN;
use strict; use strict;
use base qw(Exporter); use base qw(Exporter);
our @EXPORT = qw(set_cpan_config install_module BZ_LIB); our @EXPORT = qw(
BZ_LIB
check_cpan_requirements
set_cpan_config
install_module
);
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Install::Requirements qw(have_vers);
use Bugzilla::Install::Util qw(bin_loc install_string); use Bugzilla::Install::Util qw(bin_loc install_string);
use CPAN; use CPAN;
...@@ -31,6 +38,24 @@ use Cwd qw(abs_path); ...@@ -31,6 +38,24 @@ use Cwd qw(abs_path);
use File::Path qw(rmtree); use File::Path qw(rmtree);
use List::Util qw(shuffle); use List::Util qw(shuffle);
# These are required for install-module.pl to be able to install
# all modules properly.
use constant REQUIREMENTS => (
{
module => 'CPAN',
package => 'CPAN',
version => '1.81',
},
{
# When Module::Build isn't installed, the YAML module allows
# CPAN to read META.yml to determine that Module::Build first
# needs to be installed to compile a module.
module => 'YAML',
package => 'YAML',
version => 0,
},
);
# We need the absolute path of ext_libpath, because CPAN chdirs around # We need the absolute path of ext_libpath, because CPAN chdirs around
# and so we can't use a relative directory. # and so we can't use a relative directory.
# #
...@@ -46,13 +71,17 @@ use constant CPAN_DEFAULTS => { ...@@ -46,13 +71,17 @@ use constant CPAN_DEFAULTS => {
auto_commit => 0, auto_commit => 0,
# We always force builds, so there's no reason to cache them. # We always force builds, so there's no reason to cache them.
build_cache => 0, build_cache => 0,
build_requires_install_policy => 'yes',
cache_metadata => 1, cache_metadata => 1,
colorize_output => 1,
colorize_print => 'bold',
index_expire => 1, index_expire => 1,
scan_cache => 'atstart', scan_cache => 'atstart',
inhibit_startup_message => 1, inhibit_startup_message => 1,
mbuild_install_build_command => './Build', mbuild_install_build_command => './Build',
bzip2 => bin_loc('bzip2'),
curl => bin_loc('curl'), curl => bin_loc('curl'),
gzip => bin_loc('gzip'), gzip => bin_loc('gzip'),
links => bin_loc('links'), links => bin_loc('links'),
...@@ -66,13 +95,37 @@ use constant CPAN_DEFAULTS => { ...@@ -66,13 +95,37 @@ use constant CPAN_DEFAULTS => {
urllist => [shuffle qw( urllist => [shuffle qw(
http://cpan.pair.com/ http://cpan.pair.com/
http://mirror.hiwaay.net/CPAN/ http://mirror.hiwaay.net/CPAN/
http://ftp.heanet.ie/mirrors/ftp.perl.org/pub/CPAN/
ftp://ftp.dc.aleron.net/pub/CPAN/ ftp://ftp.dc.aleron.net/pub/CPAN/
http://perl.secsup.org/ http://mirrors.kernel.org/cpan/
http://mirrors.kernel.org/cpan/)], http://mirrors2.kernel.org/cpan/)],
}; };
sub check_cpan_requirements {
my ($original_dir, $original_args) = @_;
my @install;
foreach my $module (REQUIREMENTS) {
my $installed = have_vers($module, 1);
push(@install, $module) if !$installed;
}
return if !@install;
my $restart_required;
foreach my $module (@install) {
$restart_required = 1 if $module->{module} eq 'CPAN';
install_module($module->{module}, 1);
}
if ($restart_required) {
chdir $original_dir;
exec($^X, $0, @$original_args);
}
}
sub install_module { sub install_module {
my ($name, $notest) = @_; my ($name, $test) = @_;
my $bzlib = BZ_LIB; my $bzlib = BZ_LIB;
# Certain modules require special stuff in order to not prompt us. # Certain modules require special stuff in order to not prompt us.
...@@ -95,11 +148,11 @@ sub install_module { ...@@ -95,11 +148,11 @@ sub install_module {
my $module = CPAN::Shell->expand('Module', $name); my $module = CPAN::Shell->expand('Module', $name);
print install_string('install_module', print install_string('install_module',
{ module => $name, version => $module->cpan_version }) . "\n"; { module => $name, version => $module->cpan_version }) . "\n";
if ($notest) { if ($test) {
CPAN::Shell->notest('install', $name); CPAN::Shell->force('install', $name);
} }
else { else {
CPAN::Shell->force('install', $name); CPAN::Shell->notest('install', $name);
} }
# If it installed any binaries in the Bugzilla directory, delete them. # If it installed any binaries in the Bugzilla directory, delete them.
...@@ -218,7 +271,7 @@ Bugzilla::Install::CPAN - Routines to install Perl modules from CPAN. ...@@ -218,7 +271,7 @@ Bugzilla::Install::CPAN - Routines to install Perl modules from CPAN.
use Bugzilla::Install::CPAN; use Bugzilla::Install::CPAN;
set_cpan_config(); set_cpan_config();
install_module('Module::Name', 1); install_module('Module::Name');
=head1 DESCRIPTION =head1 DESCRIPTION
...@@ -245,8 +298,9 @@ Installs a module from CPAN. Takes two arguments: ...@@ -245,8 +298,9 @@ Installs a module from CPAN. Takes two arguments:
=item C<$name> - The name of the module, just like you'd pass to the =item C<$name> - The name of the module, just like you'd pass to the
C<install> command in the CPAN shell. C<install> command in the CPAN shell.
=item C<$notest> - If true, we skip running tests on this module. This =item C<$test> - If true, we run tests on this module before installing,
can greatly speed up the installation time. but we still force the install if the tests fail. This is only used
when we internally install a newer CPAN module.
=back =back
......
...@@ -542,6 +542,10 @@ sub have_vers { ...@@ -542,6 +542,10 @@ sub have_vers {
if ($module eq 'CGI' && $vnum =~ /(2\.7\d)(\d+)/) { if ($module eq 'CGI' && $vnum =~ /(2\.7\d)(\d+)/) {
$vnum = $1 . "." . $2; $vnum = $1 . "." . $2;
} }
# CPAN did a similar thing, where it has versions like 1.9304.
if ($module eq 'CPAN' and $vnum =~ /^(\d\.\d{2})\d{2}$/) {
$vnum = $1;
}
my $vstr; my $vstr;
if ($vnum eq "-1") { # string compare just in case it's non-numeric if ($vnum eq "-1") { # string compare just in case it's non-numeric
......
...@@ -26,7 +26,7 @@ use warnings; ...@@ -26,7 +26,7 @@ use warnings;
# CPAN has chdir'ed around. We do all of this in this funny order to # CPAN has chdir'ed around. We do all of this in this funny order to
# make sure that we use the lib/ modules instead of the base Perl modules, # make sure that we use the lib/ modules instead of the base Perl modules,
# in case the lib/ modules are newer. # in case the lib/ modules are newer.
use Cwd qw(abs_path); use Cwd qw(abs_path cwd);
use lib abs_path('.'); use lib abs_path('.');
use Bugzilla::Constants; use Bugzilla::Constants;
use lib abs_path(bz_locations()->{ext_libpath}); use lib abs_path(bz_locations()->{ext_libpath});
...@@ -35,14 +35,17 @@ use Bugzilla::Install::CPAN; ...@@ -35,14 +35,17 @@ use Bugzilla::Install::CPAN;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Install::Requirements; use Bugzilla::Install::Requirements;
use Bugzilla::Install::Util qw(bin_loc); use Bugzilla::Install::Util qw(bin_loc init_console vers_cmp);
use Data::Dumper; use Data::Dumper;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
our %switch; init_console();
my @original_args = @ARGV;
my $original_dir = cwd();
our %switch;
GetOptions(\%switch, 'all|a', 'upgrade-all|u', 'show-config|s', 'global|g', GetOptions(\%switch, 'all|a', 'upgrade-all|u', 'show-config|s', 'global|g',
'shell', 'help|h'); 'shell', 'help|h');
...@@ -66,12 +69,7 @@ if ($switch{'show-config'}) { ...@@ -66,12 +69,7 @@ if ($switch{'show-config'}) {
exit; exit;
} }
my $can_notest = 1; check_cpan_requirements($original_dir, \@original_args);
if (substr(CPAN->VERSION, 0, 3) < 1.8) {
$can_notest = 0;
print "* Note: If you upgrade your CPAN module, installs will be faster.\n";
print "* You can upgrade CPAN by doing: $^X install-module.pl CPAN\n";
}
if ($switch{'shell'}) { if ($switch{'shell'}) {
CPAN::shell(); CPAN::shell();
...@@ -103,12 +101,12 @@ if ($switch{'all'} || $switch{'upgrade-all'}) { ...@@ -103,12 +101,12 @@ if ($switch{'all'} || $switch{'upgrade-all'}) {
next if $cpan_name eq 'mod_perl2'; next if $cpan_name eq 'mod_perl2';
next if $cpan_name eq 'DBD::Oracle' and !$ENV{ORACLE_HOME}; next if $cpan_name eq 'DBD::Oracle' and !$ENV{ORACLE_HOME};
next if $cpan_name eq 'DBD::Pg' and !bin_loc('pg_config'); next if $cpan_name eq 'DBD::Pg' and !bin_loc('pg_config');
install_module($cpan_name, $can_notest); install_module($cpan_name);
} }
} }
foreach my $module (@ARGV) { foreach my $module (@ARGV) {
install_module($module, $can_notest); install_module($module);
} }
__END__ __END__
......
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