summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Bugzilla/Install/CPAN.pm74
-rw-r--r--Bugzilla/Install/Requirements.pm4
-rwxr-xr-xinstall-module.pl20
3 files changed, 77 insertions, 21 deletions
diff --git a/Bugzilla/Install/CPAN.pm b/Bugzilla/Install/CPAN.pm
index a3f83564b..811f88ec2 100644
--- a/Bugzilla/Install/CPAN.pm
+++ b/Bugzilla/Install/CPAN.pm
@@ -21,9 +21,16 @@
package Bugzilla::Install::CPAN;
use strict;
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::Install::Requirements qw(have_vers);
use Bugzilla::Install::Util qw(bin_loc install_string);
use CPAN;
@@ -31,6 +38,24 @@ use Cwd qw(abs_path);
use File::Path qw(rmtree);
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
# and so we can't use a relative directory.
#
@@ -46,13 +71,17 @@ use constant CPAN_DEFAULTS => {
auto_commit => 0,
# We always force builds, so there's no reason to cache them.
build_cache => 0,
+ build_requires_install_policy => 'yes',
cache_metadata => 1,
+ colorize_output => 1,
+ colorize_print => 'bold',
index_expire => 1,
scan_cache => 'atstart',
inhibit_startup_message => 1,
mbuild_install_build_command => './Build',
+ bzip2 => bin_loc('bzip2'),
curl => bin_loc('curl'),
gzip => bin_loc('gzip'),
links => bin_loc('links'),
@@ -66,13 +95,37 @@ use constant CPAN_DEFAULTS => {
urllist => [shuffle qw(
http://cpan.pair.com/
http://mirror.hiwaay.net/CPAN/
+ http://ftp.heanet.ie/mirrors/ftp.perl.org/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 {
- my ($name, $notest) = @_;
+ my ($name, $test) = @_;
my $bzlib = BZ_LIB;
# Certain modules require special stuff in order to not prompt us.
@@ -95,11 +148,11 @@ sub install_module {
my $module = CPAN::Shell->expand('Module', $name);
print install_string('install_module',
{ module => $name, version => $module->cpan_version }) . "\n";
- if ($notest) {
- CPAN::Shell->notest('install', $name);
+ if ($test) {
+ CPAN::Shell->force('install', $name);
}
else {
- CPAN::Shell->force('install', $name);
+ CPAN::Shell->notest('install', $name);
}
# 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.
use Bugzilla::Install::CPAN;
set_cpan_config();
- install_module('Module::Name', 1);
+ install_module('Module::Name');
=head1 DESCRIPTION
@@ -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
C<install> command in the CPAN shell.
-=item C<$notest> - If true, we skip running tests on this module. This
-can greatly speed up the installation time.
+=item C<$test> - If true, we run tests on this module before installing,
+but we still force the install if the tests fail. This is only used
+when we internally install a newer CPAN module.
=back
diff --git a/Bugzilla/Install/Requirements.pm b/Bugzilla/Install/Requirements.pm
index b80d7fa8b..83c6c2c90 100644
--- a/Bugzilla/Install/Requirements.pm
+++ b/Bugzilla/Install/Requirements.pm
@@ -542,6 +542,10 @@ sub have_vers {
if ($module eq 'CGI' && $vnum =~ /(2\.7\d)(\d+)/) {
$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;
if ($vnum eq "-1") { # string compare just in case it's non-numeric
diff --git a/install-module.pl b/install-module.pl
index f3c6ba461..a78d7ceff 100755
--- a/install-module.pl
+++ b/install-module.pl
@@ -26,7 +26,7 @@ use warnings;
# 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,
# in case the lib/ modules are newer.
-use Cwd qw(abs_path);
+use Cwd qw(abs_path cwd);
use lib abs_path('.');
use Bugzilla::Constants;
use lib abs_path(bz_locations()->{ext_libpath});
@@ -35,14 +35,17 @@ use Bugzilla::Install::CPAN;
use Bugzilla::Constants;
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 Getopt::Long;
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',
'shell', 'help|h');
@@ -66,12 +69,7 @@ if ($switch{'show-config'}) {
exit;
}
-my $can_notest = 1;
-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";
-}
+check_cpan_requirements($original_dir, \@original_args);
if ($switch{'shell'}) {
CPAN::shell();
@@ -103,12 +101,12 @@ if ($switch{'all'} || $switch{'upgrade-all'}) {
next if $cpan_name eq 'mod_perl2';
next if $cpan_name eq 'DBD::Oracle' and !$ENV{ORACLE_HOME};
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) {
- install_module($module, $can_notest);
+ install_module($module);
}
__END__