#!/usr/bin/perl -w use strict; =for comment Documentation for this is in bisect-runner.pl =cut # The default, auto_abbrev will treat -e as an abbreviation of --end # Which isn't what we want. use Getopt::Long qw(:config pass_through no_auto_abbrev); use File::Spec; use File::Path qw(mkpath); my ($start, $end, $validate, $usage, $bad, $jobs, $make, $gold, $module, $with_module); my $need_cpan_config; my $cpan_config_dir; $bad = !GetOptions('start=s' => \$start, 'end=s' => \$end, 'jobs|j=i' => \$jobs, 'make=s' => \$make, 'gold=s' => \$gold, validate => \$validate, 'usage|help|?' => \$usage, 'module=s' => \$module, 'with-module=s' => \$with_module, 'cpan-config-dir=s' => \$cpan_config_dir); unshift @ARGV, '--help' if $bad || $usage; unshift @ARGV, '--validate' if $validate; if ($module || $with_module) { unshift @ARGV, '--module', $module if defined $module; unshift @ARGV, '--with-module', $with_module if defined $with_module; if ($cpan_config_dir) { my $c = File::Spec->catfile($cpan_config_dir, 'CPAN', 'MyConfig.pm'); die "--cpan-config-dir: $c does not exist\n" unless -e $c; unshift @ARGV, '--cpan-config-dir', $cpan_config_dir; } else { $need_cpan_config = 1; } } my $runner = $0; $runner =~ s/bisect\.pl/bisect-runner.pl/; die "Can't find bisect runner $runner" unless -f $runner; system $^X, $runner, '--check-args', '--check-shebang', @ARGV and exit 255; exit 255 if $bad; exit 0 if $usage; my $start_time = time; if (!defined $jobs && !($^O eq 'hpux' && system((defined $make ? $make : 'make') . ' --version >/dev/null 2>&1'))) { # Try to default to (ab)use all the CPUs: my $cpus; if (open my $fh, '<', '/proc/cpuinfo') { while (<$fh>) { ++$cpus if /^processor\s+:\s+\d+$/; } } elsif (-x '/sbin/sysctl' || -x '/usr/sbin/sysctl') { my $sysctl = '/sbin/sysctl'; $sysctl = "/usr$sysctl" unless -x $sysctl; $cpus = $1 if `$sysctl hw.ncpu` =~ /^hw\.ncpu: (\d+)$/; } elsif (-x '/usr/bin/getconf') { $cpus = $1 if `/usr/bin/getconf _NPROCESSORS_ONLN` =~ /^(\d+)$/; } $jobs = defined $cpus ? $cpus + 1 : 2; } unshift @ARGV, '--jobs', $jobs if defined $jobs; unshift @ARGV, '--make', $make if defined $make; if ($need_cpan_config) { # Make sure we have a CPAN::MyConfig so if we start at an old # revision CPAN doesn't ask for user input to configure itself my $cdir = File::Spec->catdir($ENV{HOME},".cpan","CPAN"); my $cfile = File::Spec->catfile($cdir, "MyConfig.pm"); unless (-e $cfile) { printf < or die "Can't copy from '$runner' to '$toname': $!"; close $from or die "Can't close '$runner': $!"; close $to or die "Can't close '$toname': $!"; chmod 0500, $toname or die "Can't chmod 0500, '$toname': $!"; $runner = $toname; system $^X, $runner, '--check-args', @ARGV and die "Can't run inplace for some reason. :-("; } } sub validate { my $commit = shift; if (defined $start && `git rev-list -n1 $commit ^$start^` eq "") { print "Skipping $commit, as it is earlier than $start\n"; return; } if (defined $end && `git rev-list -n1 $end ^$commit^` eq "") { print "Skipping $commit, as it is more recent than $end\n"; return; } print "Testing $commit...\n"; system "git checkout $commit