6 Documentation for this is in bisect-runner.pl
10 # The default, auto_abbrev will treat -e as an abbreviation of --end
11 # Which isn't what we want.
12 use Getopt::Long qw(:config pass_through no_auto_abbrev);
14 use File::Path qw(mkpath);
16 my ($start, $end, $validate, $usage, $bad, $jobs, $make, $gold,
17 $module, $with_module);
22 $bad = !GetOptions('start=s' => \$start, 'end=s' => \$end,
23 'jobs|j=i' => \$jobs, 'make=s' => \$make, 'gold=s' => \$gold,
24 validate => \$validate, 'usage|help|?' => \$usage,
25 'module=s' => \$module, 'with-module=s' => \$with_module,
26 'cpan-config-dir=s' => \$cpan_config_dir);
27 unshift @ARGV, '--help' if $bad || $usage;
28 unshift @ARGV, '--validate' if $validate;
30 if ($module || $with_module) {
31 unshift @ARGV, '--module', $module if defined $module;
32 unshift @ARGV, '--with-module', $with_module if defined $with_module;
34 if ($cpan_config_dir) {
35 my $c = File::Spec->catfile($cpan_config_dir, 'CPAN', 'MyConfig.pm');
36 die "--cpan-config-dir: $c does not exist\n" unless -e $c;
38 unshift @ARGV, '--cpan-config-dir', $cpan_config_dir;
40 $need_cpan_config = 1;
45 $runner =~ s/bisect\.pl/bisect-runner.pl/;
47 die "Can't find bisect runner $runner" unless -f $runner;
49 system $^X, $runner, '--check-args', '--check-shebang', @ARGV and exit 255;
53 my $start_time = time;
56 !($^O eq 'hpux' && system((defined $make ? $make : 'make')
57 . ' --version >/dev/null 2>&1'))) {
58 # Try to default to (ab)use all the CPUs:
60 if (open my $fh, '<', '/proc/cpuinfo') {
62 ++$cpus if /^processor\s+:\s+\d+$/;
64 } elsif (-x '/sbin/sysctl' || -x '/usr/sbin/sysctl') {
65 my $sysctl = '/sbin/sysctl';
66 $sysctl = "/usr$sysctl" unless -x $sysctl;
67 $cpus = $1 if `$sysctl hw.ncpu` =~ /^hw\.ncpu: (\d+)$/;
68 } elsif (-x '/usr/bin/getconf') {
69 $cpus = $1 if `/usr/bin/getconf _NPROCESSORS_ONLN` =~ /^(\d+)$/;
71 $jobs = defined $cpus ? $cpus + 1 : 2;
74 unshift @ARGV, '--jobs', $jobs if defined $jobs;
75 unshift @ARGV, '--make', $make if defined $make;
77 if ($need_cpan_config) {
78 # Make sure we have a CPAN::MyConfig so if we start at an old
79 # revision CPAN doesn't ask for user input to configure itself
81 my $cdir = File::Spec->catdir($ENV{HOME},".cpan","CPAN");
82 my $cfile = File::Spec->catfile($cdir, "MyConfig.pm");
86 I could not find a CPAN::MyConfig. We need to create one now so that
87 you can bisect with --module or --with-module. I'll boot up the CPAN
88 shell for you. Feel free to use defaults or change things as needed.
89 We recommend using 'manual' over 'local::lib' if it asks.
91 Type 'quit' when finished.
94 system("$^X -MCPAN -e shell");
98 # We try these in this order for the start revision if none is specified.
99 my @stable = map {chomp $_; $_} grep {/v5\.[0-9]+[02468]\.0$/} `git tag -l`;
100 die "git tag -l didn't seem to return any tags for stable releases"
102 unshift @stable, qw(perl-5.005 perl-5.6.0 perl-5.8.0);
105 my ($dev_C, $ino_C) = stat 'Configure';
106 my ($dev_c, $ino_c) = stat 'configure';
107 if (defined $dev_C && defined $dev_c
108 && $dev_C == $dev_c && $ino_C == $ino_c) {
109 print "You seem to be on a case-insensitive file system.\n\n";
111 unshift @stable, qw(perl-5.002 perl-5.003 perl-5.004)
115 unshift @ARGV, '--gold', defined $gold ? $gold : $stable[-1];
118 # If we have a branch blead, use that as the end
119 $end = `git rev-parse --verify --quiet blead`;
120 die unless defined $end;
122 # Else use whichever is newer - HEAD, or the most recent stable tag.
123 if (`git rev-list -n1 HEAD ^$stable[-1]` eq "") {
131 # Canonicalising branches to revisions before moving the checkout permits one
132 # to use revisions such as 'HEAD' for --start or --end
133 foreach ($start, $end) {
135 $_ = `git rev-parse $_`;
136 die unless defined $_;
141 my $modified = my @modified = `git ls-files --modified --deleted --others`;
143 my ($dev0, $ino0) = stat $0;
144 die "Can't stat $0: $!" unless defined $ino0;
145 my ($dev1, $ino1) = stat 'Porting/bisect.pl';
147 my $inplace = defined $dev1 && $dev0 == $dev1 && $ino0 == $ino1;
151 ? "Can't run a bisect using a dirty directory containing $runner"
152 : "You can use 'git clean -Xdf' to cleanup the ignored files";
154 die "This checkout is not clean, found file(s):\n",
155 join("\t","",@modified),
156 "$modified modified, untracked, or other file(s)\n",
157 "These files may not show in git status as they may be ignored.\n",
162 # We assume that it's safe to copy the runner to the temporary
163 # directory and run it from there, because a shared /tmp should be +t
164 # and hence others are not be able to delete or rename our file.
166 my ($to, $toname) = File::Temp::tempfile();
167 die "Can't create tempfile"
169 open my $from, '<', $runner
170 or die "Can't open '$runner': $!";
173 or die "Can't copy from '$runner' to '$toname': $!";
175 or die "Can't close '$runner': $!";
177 or die "Can't close '$toname': $!";
179 or die "Can't chmod 0500, '$toname': $!";
181 system $^X, $runner, '--check-args', @ARGV
182 and die "Can't run inplace for some reason. :-(";
188 if (defined $start && `git rev-list -n1 $commit ^$start^` eq "") {
189 print "Skipping $commit, as it is earlier than $start\n";
192 if (defined $end && `git rev-list -n1 $end ^$commit^` eq "") {
193 print "Skipping $commit, as it is more recent than $end\n";
196 print "Testing $commit...\n";
197 system "git checkout $commit </dev/null" and die;
198 my $ret = system $^X, $runner, '--no-clean', @ARGV;
199 die "Runner returned $ret, not 0 for revision $commit" if $ret;
200 system 'git clean -dxf </dev/null' and die;
201 system 'git reset --hard HEAD </dev/null' and die;
207 my @built = map {validate $_} 'blead', reverse @stable;
209 print Text::Wrap::wrap("", "", "Successfully validated @built\n");
212 print "Did not validate anything\n";
216 my $git_version = `git --version`;
217 if (defined $git_version
218 && $git_version =~ /\Agit version (\d+\.\d+\.\d+)(.*)/) {
219 $git_version = eval "v$1";
221 $git_version = v0.0.0;
224 if ($git_version ge v1.6.6) {
225 system "git bisect reset HEAD" and die;
227 system "git bisect reset" and die;
230 # Sanity check the first and last revisions:
231 system "git checkout $end" and die;
232 my $ret = system $^X, $runner, @ARGV;
233 die "Runner returned $ret for end revision" unless $ret;
234 die "Runner returned $ret for end revision, which is a skip"
235 if $ret == 125 * 256;
237 if (defined $start) {
238 system "git checkout $start" and die;
239 my $ret = system $^X, $runner, @ARGV;
240 die "Runner returned $ret, not 0 for start revision" if $ret;
242 # Try to find the earliest version for which the test works
244 foreach my $try (@stable) {
245 if (`git rev-list -n1 $end ^$try^` eq "") {
246 print "Skipping $try, as it is more recent than end commit "
247 . (substr $end, 0, 16) . "\n";
248 # As @stable is supposed to be in age order, arguably we should
252 system "git checkout $try" and die;
253 my $ret = system $^X, $runner, @ARGV;
260 die "Can't find a suitable start revision to default to.\nTried @tried"
261 unless defined $start;
264 system "git bisect start" and die;
265 system "git bisect good $start" and die;
266 system "git bisect bad $end" and die;
268 # And now get git bisect to do the hard work:
269 system 'git', 'bisect', 'run', $^X, $runner, @ARGV and die;
274 printf "That took %d seconds.\n", $end_time - $start_time
275 if defined $start_time;
280 Documentation for this is in bisect-runner.pl
284 # ex: set ts=8 sts=4 sw=4 et: