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
1 #!/usr/bin/perl -w
2 use strict;
3
4 my $start_time = time;
5
6 # The default, auto_abbrev will treat -e as an abbreviation of --end
7 # Which isn't what we want.
8 use Getopt::Long qw(:config pass_through no_auto_abbrev);
9
10 my ($start, $end);
11 unshift @ARGV, '--help' unless GetOptions('start=s' => \$start,
12                                           'end=s' => \$end);
13
14 my $runner = $0;
15 $runner =~ s/bisect\.pl/bisect-runner.pl/;
16
17 die "Can't find bisect runner $runner" unless -f $runner;
18
19 system $^X, $runner, '--check-args', @ARGV and exit 255;
20
21 # We try these in this order for the start revision if none is specified.
22 my @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);
24
25 if ($start) {
26     system "git rev-parse $start >/dev/null" and die;
27 }
28 $end = 'blead' unless defined $end;
29 system "git rev-parse $end >/dev/null" and die;
30
31 my $modified = () = `git ls-files --modified --deleted --others`;
32
33 die "This checkout is not clean - $modified modified or untracked file(s)"
34     if $modified;
35
36 system "git bisect reset" and die;
37
38 # Sanity check the first and last revisions:
39 if (defined $start) {
40     system "git checkout $start" and die;
41     my $ret = system $^X, $runner, @ARGV;
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;
47         my $ret = system $^X, $runner, @ARGV;
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 }
56 system "git checkout $end" and die;
57 my $ret = system $^X, $runner, @ARGV;
58 die "Runner returned $ret for end revision" unless $ret;
59
60 system "git bisect start" and die;
61 system "git bisect good $start" and die;
62 system "git bisect bad $end" and die;
63
64 # And now get git bisect to do the hard work:
65 system 'git', 'bisect', 'run', $^X, $runner, @ARGV and die;
66
67 END {
68     my $end_time = time;
69
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: