This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Documentation for bisect.pl and bisect-runner.pl
[perl5.git] / Porting / bisect.pl
CommitLineData
6a8dbfd7
NC
1#!/usr/bin/perl -w
2use strict;
3
4my $start_time = time;
5
e295b7be
NC
6# The default, auto_abbrev will treat -e as an abbreviation of --end
7# Which isn't what we want.
8use Getopt::Long qw(:config pass_through no_auto_abbrev);
6a8dbfd7 9
e295b7be 10my ($start, $end);
77ae6092
NC
11unshift @ARGV, '--help' unless GetOptions('start=s' => \$start,
12 'end=s' => \$end);
13
14my $runner = $0;
15$runner =~ s/bisect\.pl/bisect-runner.pl/;
16
17die "Can't find bisect runner $runner" unless -f $runner;
18
19system $^X, $runner, '--check-args', @ARGV and exit 255;
6a8dbfd7 20
4819dd2a
NC
21# We try these in this order for the start revision if none is specified.
22my @stable = qw(perl-5.002 perl-5.003 perl-5.004 perl-5.005 perl-5.6.0
23 perl-5.8.0 v5.10.0 v5.12.0 v5.14.0);
e295b7be 24
4819dd2a
NC
25if ($start) {
26 system "git rev-parse $start >/dev/null" and die;
27}
6a8dbfd7 28$end = 'blead' unless defined $end;
6a8dbfd7
NC
29system "git rev-parse $end >/dev/null" and die;
30
31my $modified = () = `git ls-files --modified --deleted --others`;
32
33die "This checkout is not clean - $modified modified or untracked file(s)"
34 if $modified;
35
36system "git bisect reset" and die;
37
6a8dbfd7 38# Sanity check the first and last revisions:
4819dd2a
NC
39if (defined $start) {
40 system "git checkout $start" and die;
e295b7be 41 my $ret = system $^X, $runner, @ARGV;
4819dd2a
NC
42 die "Runner returned $ret, not 0 for start revision" if $ret;
43} else {
44 # Try to find the earliest version for which the test works
45 foreach my $try (@stable) {
46 system "git checkout $try" and die;
e295b7be 47 my $ret = system $^X, $runner, @ARGV;
4819dd2a
NC
48 if (!$ret) {
49 $start = $try;
50 last;
51 }
52 }
53 die "Can't find a suitable start revision to default to. Tried @stable"
54 unless defined $start;
55}
6a8dbfd7 56system "git checkout $end" and die;
e295b7be 57my $ret = system $^X, $runner, @ARGV;
6a8dbfd7
NC
58die "Runner returned $ret for end revision" unless $ret;
59
60system "git bisect start" and die;
61system "git bisect good $start" and die;
62system "git bisect bad $end" and die;
63
64# And now get git bisect to do the hard work:
e295b7be 65system 'git', 'bisect', 'run', $^X, $runner, @ARGV and die;
6a8dbfd7 66
c3d98a71
NC
67END {
68 my $end_time = time;
6a8dbfd7 69
c3d98a71
NC
70 printf "That took %d seconds\n", $end_time - $start_time
71 if defined $start_time;
72}
73
74# Local variables:
75# cperl-indent-level: 4
76# indent-tabs-mode: nil
77# End:
78#
79# ex: set ts=8 sts=4 sw=4 et: