This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
When testing the end version, bisect.pl should treat a 'skip' as fatal.
[perl5.git] / Porting / bisect.pl
CommitLineData
6a8dbfd7
NC
1#!/usr/bin/perl -w
2use strict;
3
9b404864
NC
4=for comment
5
6Documentation for this is in bisect-runner.pl
7
8=cut
9
e295b7be
NC
10# The default, auto_abbrev will treat -e as an abbreviation of --end
11# Which isn't what we want.
12use Getopt::Long qw(:config pass_through no_auto_abbrev);
6a8dbfd7 13
d3232d34
NC
14my ($start, $end, $validate, $usage, $bad, $jobs, $make);
15$bad = !GetOptions('start=s' => \$start, 'end=s' => \$end,
16 'jobs|j=i' => \$jobs, 'make=s' => \$make,
0ed3b851
NC
17 validate => \$validate, 'usage|help|?' => \$usage);
18unshift @ARGV, '--help' if $bad || $usage;
b826a648 19unshift @ARGV, '--validate' if $validate;
e2760528 20
77ae6092
NC
21my $runner = $0;
22$runner =~ s/bisect\.pl/bisect-runner.pl/;
23
24die "Can't find bisect runner $runner" unless -f $runner;
25
0ed3b851
NC
26system $^X, $runner, '--check-args', '--check-shebang', @ARGV and exit 255;
27exit 255 if $bad;
28exit 0 if $usage;
29
5842706e
NC
30{
31 my ($dev0, $ino0) = stat $0;
32 die "Can't stat $0: $!" unless defined $ino0;
33 my ($dev1, $ino1) = stat 'Porting/bisect.pl';
34 die "Can't run a bisect using the directory containing $runner"
35 if defined $dev1 && $dev0 == $dev1 && $ino0 == $ino1;
36}
37
0ed3b851 38my $start_time = time;
6a8dbfd7 39
d3232d34
NC
40if (!defined $jobs &&
41 !($^O eq 'hpux' && system((defined $make ? $make : 'make')
42 . ' --version >/dev/null 2>&1'))) {
0bc550ba
NC
43 # Try to default to (ab)use all the CPUs:
44 my $cpus;
45 if (open my $fh, '<', '/proc/cpuinfo') {
46 while (<$fh>) {
47 ++$cpus if /^processor\s+:\s+\d+$/;
48 }
49 } elsif (-x '/sbin/sysctl') {
50 $cpus = $1 if `/sbin/sysctl hw.ncpu` =~ /^hw\.ncpu: (\d+)$/;
51 } elsif (-x '/usr/bin/getconf') {
52 $cpus = $1 if `/usr/bin/getconf _NPROCESSORS_ONLN` =~ /^(\d+)$/;
53 }
54 $jobs = defined $cpus ? $cpus + 1 : 2;
55}
56
d3232d34
NC
57unshift @ARGV, '--jobs', $jobs if defined $jobs;
58unshift @ARGV, '--make', $make if defined $make;
0bc550ba 59
4819dd2a 60# We try these in this order for the start revision if none is specified.
3ffe2687
NC
61my @stable = qw(perl-5.005 perl-5.6.0 perl-5.8.0 v5.10.0 v5.12.0 v5.14.0);
62
63{
64 my ($dev_C, $ino_C) = stat 'Configure';
65 my ($dev_c, $ino_c) = stat 'configure';
66 if (defined $dev_C && defined $dev_c
67 && $dev_C == $dev_c && $ino_C == $ino_c) {
eef6290d 68 print "You seem to be on a case-insensitive file system.\n\n";
3ffe2687
NC
69 } else {
70 unshift @stable, qw(perl-5.002 perl-5.003 perl-5.004)
71 }
72}
e295b7be 73
6a8dbfd7 74$end = 'blead' unless defined $end;
c382b335
NC
75
76# Canonicalising branches to revisions before moving the checkout permits one
77# to use revisions such as 'HEAD' for --start or --end
78foreach ($start, $end) {
79 next unless $_;
80 $_ = `git rev-parse $_`;
81 die unless defined $_;
82 chomp;
83}
6a8dbfd7
NC
84
85my $modified = () = `git ls-files --modified --deleted --others`;
86
87die "This checkout is not clean - $modified modified or untracked file(s)"
88 if $modified;
89
195ed8b1
NC
90sub validate {
91 my $commit = shift;
3f14869b
NC
92 if (defined $start && `git rev-list -n1 $commit ^$start^` eq "") {
93 print "Skipping $commit, as it is earlier than $start\n";
94 return;
95 }
96 if (defined $end && `git rev-list -n1 $end ^$commit^` eq "") {
97 print "Skipping $commit, as it is more recent than $end\n";
98 return;
99 }
195ed8b1
NC
100 print "Testing $commit...\n";
101 system "git checkout $commit </dev/null" and die;
102 my $ret = system $^X, $runner, '--no-clean', @ARGV;
103 die "Runner returned $ret, not 0 for revision $commit" if $ret;
104 system 'git clean -dxf </dev/null' and die;
105 system 'git reset --hard HEAD </dev/null' and die;
e2760528 106 return $commit;
195ed8b1
NC
107}
108
109if ($validate) {
e2760528
NC
110 require Text::Wrap;
111 my @built = map {validate $_} 'blead', reverse @stable;
112 if (@built) {
113 print Text::Wrap::wrap("", "", "Successfully validated @built\n");
114 exit 0;
115 }
116 print "Did not validate anything\n";
117 exit 1;
195ed8b1
NC
118}
119
c382b335
NC
120my $git_version = `git --version`;
121if (defined $git_version
122 && $git_version =~ /\Agit version (\d+\.\d+\.\d+)(.*)/) {
123 $git_version = eval "v$1";
124} else {
125 $git_version = v0.0.0;
126}
127
128if ($git_version ge v1.6.6) {
129 system "git bisect reset HEAD" and die;
130} else {
131 system "git bisect reset" and die;
132}
6a8dbfd7 133
6a8dbfd7 134# Sanity check the first and last revisions:
c382b335
NC
135system "git checkout $end" and die;
136my $ret = system $^X, $runner, @ARGV;
137die "Runner returned $ret for end revision" unless $ret;
a84ce349
NC
138die "Runner returned $ret for end revision, which is a skip"
139 if $ret == 125 * 256;
c382b335 140
4819dd2a
NC
141if (defined $start) {
142 system "git checkout $start" and die;
e295b7be 143 my $ret = system $^X, $runner, @ARGV;
4819dd2a
NC
144 die "Runner returned $ret, not 0 for start revision" if $ret;
145} else {
146 # Try to find the earliest version for which the test works
03cc0342 147 my @tried;
4819dd2a 148 foreach my $try (@stable) {
03cc0342
NC
149 if (`git rev-list -n1 $end ^$try^` eq "") {
150 print "Skipping $try, as it is more recent than end commit "
151 . (substr $end, 0, 16) . "\n";
152 # As @stable is supposed to be in age order, arguably we should
153 # last; here.
154 next;
155 }
4819dd2a 156 system "git checkout $try" and die;
e295b7be 157 my $ret = system $^X, $runner, @ARGV;
4819dd2a
NC
158 if (!$ret) {
159 $start = $try;
160 last;
161 }
03cc0342 162 push @tried, $try;
4819dd2a 163 }
03cc0342 164 die "Can't find a suitable start revision to default to.\nTried @tried"
4819dd2a
NC
165 unless defined $start;
166}
6a8dbfd7
NC
167
168system "git bisect start" and die;
169system "git bisect good $start" and die;
170system "git bisect bad $end" and die;
171
172# And now get git bisect to do the hard work:
e295b7be 173system 'git', 'bisect', 'run', $^X, $runner, @ARGV and die;
6a8dbfd7 174
c3d98a71
NC
175END {
176 my $end_time = time;
6a8dbfd7 177
c3d98a71
NC
178 printf "That took %d seconds\n", $end_time - $start_time
179 if defined $start_time;
180}
181
9b404864
NC
182=for comment
183
184Documentation for this is in bisect-runner.pl
185
186=cut
187
c3d98a71
NC
188# Local variables:
189# cperl-indent-level: 4
190# indent-tabs-mode: nil
191# End:
192#
193# ex: set ts=8 sts=4 sw=4 et: