This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In bisect.pl, provide a default test for --validate, and summary output.
[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
195ed8b1 10my ($start, $end, $validate);
77ae6092 11unshift @ARGV, '--help' unless GetOptions('start=s' => \$start,
195ed8b1
NC
12 'end=s' => \$end,
13 validate => \$validate);
77ae6092 14
e2760528
NC
15@ARGV = ('--', 'sh', '-c', 'cd t && ./perl TEST base/*.t')
16 if $validate && !@ARGV;
17
77ae6092
NC
18my $runner = $0;
19$runner =~ s/bisect\.pl/bisect-runner.pl/;
20
21die "Can't find bisect runner $runner" unless -f $runner;
22
5842706e
NC
23{
24 my ($dev0, $ino0) = stat $0;
25 die "Can't stat $0: $!" unless defined $ino0;
26 my ($dev1, $ino1) = stat 'Porting/bisect.pl';
27 die "Can't run a bisect using the directory containing $runner"
28 if defined $dev1 && $dev0 == $dev1 && $ino0 == $ino1;
29}
30
77ae6092 31system $^X, $runner, '--check-args', @ARGV and exit 255;
6a8dbfd7 32
4819dd2a
NC
33# We try these in this order for the start revision if none is specified.
34my @stable = qw(perl-5.002 perl-5.003 perl-5.004 perl-5.005 perl-5.6.0
35 perl-5.8.0 v5.10.0 v5.12.0 v5.14.0);
e295b7be 36
6a8dbfd7 37$end = 'blead' unless defined $end;
c382b335
NC
38
39# Canonicalising branches to revisions before moving the checkout permits one
40# to use revisions such as 'HEAD' for --start or --end
41foreach ($start, $end) {
42 next unless $_;
43 $_ = `git rev-parse $_`;
44 die unless defined $_;
45 chomp;
46}
6a8dbfd7
NC
47
48my $modified = () = `git ls-files --modified --deleted --others`;
49
50die "This checkout is not clean - $modified modified or untracked file(s)"
51 if $modified;
52
195ed8b1
NC
53sub validate {
54 my $commit = shift;
3f14869b
NC
55 if (defined $start && `git rev-list -n1 $commit ^$start^` eq "") {
56 print "Skipping $commit, as it is earlier than $start\n";
57 return;
58 }
59 if (defined $end && `git rev-list -n1 $end ^$commit^` eq "") {
60 print "Skipping $commit, as it is more recent than $end\n";
61 return;
62 }
195ed8b1
NC
63 print "Testing $commit...\n";
64 system "git checkout $commit </dev/null" and die;
65 my $ret = system $^X, $runner, '--no-clean', @ARGV;
66 die "Runner returned $ret, not 0 for revision $commit" if $ret;
67 system 'git clean -dxf </dev/null' and die;
68 system 'git reset --hard HEAD </dev/null' and die;
e2760528 69 return $commit;
195ed8b1
NC
70}
71
72if ($validate) {
e2760528
NC
73 require Text::Wrap;
74 my @built = map {validate $_} 'blead', reverse @stable;
75 if (@built) {
76 print Text::Wrap::wrap("", "", "Successfully validated @built\n");
77 exit 0;
78 }
79 print "Did not validate anything\n";
80 exit 1;
195ed8b1
NC
81}
82
c382b335
NC
83my $git_version = `git --version`;
84if (defined $git_version
85 && $git_version =~ /\Agit version (\d+\.\d+\.\d+)(.*)/) {
86 $git_version = eval "v$1";
87} else {
88 $git_version = v0.0.0;
89}
90
91if ($git_version ge v1.6.6) {
92 system "git bisect reset HEAD" and die;
93} else {
94 system "git bisect reset" and die;
95}
6a8dbfd7 96
6a8dbfd7 97# Sanity check the first and last revisions:
c382b335
NC
98system "git checkout $end" and die;
99my $ret = system $^X, $runner, @ARGV;
100die "Runner returned $ret for end revision" unless $ret;
101
4819dd2a
NC
102if (defined $start) {
103 system "git checkout $start" and die;
e295b7be 104 my $ret = system $^X, $runner, @ARGV;
4819dd2a
NC
105 die "Runner returned $ret, not 0 for start revision" if $ret;
106} else {
107 # Try to find the earliest version for which the test works
108 foreach my $try (@stable) {
109 system "git checkout $try" and die;
e295b7be 110 my $ret = system $^X, $runner, @ARGV;
4819dd2a
NC
111 if (!$ret) {
112 $start = $try;
113 last;
114 }
115 }
116 die "Can't find a suitable start revision to default to. Tried @stable"
117 unless defined $start;
118}
6a8dbfd7
NC
119
120system "git bisect start" and die;
121system "git bisect good $start" and die;
122system "git bisect bad $end" and die;
123
124# And now get git bisect to do the hard work:
e295b7be 125system 'git', 'bisect', 'run', $^X, $runner, @ARGV and die;
6a8dbfd7 126
c3d98a71
NC
127END {
128 my $end_time = time;
6a8dbfd7 129
c3d98a71
NC
130 printf "That took %d seconds\n", $end_time - $start_time
131 if defined $start_time;
132}
133
134# Local variables:
135# cperl-indent-level: 4
136# indent-tabs-mode: nil
137# End:
138#
139# ex: set ts=8 sts=4 sw=4 et: