This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Tweak to make it clearer what to do if your working space is dirty
[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 84
b835daeb 85my $modified = my @modified = `git ls-files --modified --deleted --others`;
6a8dbfd7 86
b835daeb
YO
87die "This checkout is not clean, found file(s):\n",
88 join("\t","",@modified),
89 "$modified modified, untracked, or other file(s)\n",
90 "These files may not show in git status as they may be ignored.\n",
91 "You can use 'git clean -Xdf' to cleanup the ignored files.\n"
6a8dbfd7
NC
92 if $modified;
93
195ed8b1
NC
94sub validate {
95 my $commit = shift;
3f14869b
NC
96 if (defined $start && `git rev-list -n1 $commit ^$start^` eq "") {
97 print "Skipping $commit, as it is earlier than $start\n";
98 return;
99 }
100 if (defined $end && `git rev-list -n1 $end ^$commit^` eq "") {
101 print "Skipping $commit, as it is more recent than $end\n";
102 return;
103 }
195ed8b1
NC
104 print "Testing $commit...\n";
105 system "git checkout $commit </dev/null" and die;
106 my $ret = system $^X, $runner, '--no-clean', @ARGV;
107 die "Runner returned $ret, not 0 for revision $commit" if $ret;
108 system 'git clean -dxf </dev/null' and die;
109 system 'git reset --hard HEAD </dev/null' and die;
e2760528 110 return $commit;
195ed8b1
NC
111}
112
113if ($validate) {
e2760528
NC
114 require Text::Wrap;
115 my @built = map {validate $_} 'blead', reverse @stable;
116 if (@built) {
117 print Text::Wrap::wrap("", "", "Successfully validated @built\n");
118 exit 0;
119 }
120 print "Did not validate anything\n";
121 exit 1;
195ed8b1
NC
122}
123
c382b335
NC
124my $git_version = `git --version`;
125if (defined $git_version
126 && $git_version =~ /\Agit version (\d+\.\d+\.\d+)(.*)/) {
127 $git_version = eval "v$1";
128} else {
129 $git_version = v0.0.0;
130}
131
132if ($git_version ge v1.6.6) {
133 system "git bisect reset HEAD" and die;
134} else {
135 system "git bisect reset" and die;
136}
6a8dbfd7 137
6a8dbfd7 138# Sanity check the first and last revisions:
c382b335
NC
139system "git checkout $end" and die;
140my $ret = system $^X, $runner, @ARGV;
141die "Runner returned $ret for end revision" unless $ret;
a84ce349
NC
142die "Runner returned $ret for end revision, which is a skip"
143 if $ret == 125 * 256;
c382b335 144
4819dd2a
NC
145if (defined $start) {
146 system "git checkout $start" and die;
e295b7be 147 my $ret = system $^X, $runner, @ARGV;
4819dd2a
NC
148 die "Runner returned $ret, not 0 for start revision" if $ret;
149} else {
150 # Try to find the earliest version for which the test works
03cc0342 151 my @tried;
4819dd2a 152 foreach my $try (@stable) {
03cc0342
NC
153 if (`git rev-list -n1 $end ^$try^` eq "") {
154 print "Skipping $try, as it is more recent than end commit "
155 . (substr $end, 0, 16) . "\n";
156 # As @stable is supposed to be in age order, arguably we should
157 # last; here.
158 next;
159 }
4819dd2a 160 system "git checkout $try" and die;
e295b7be 161 my $ret = system $^X, $runner, @ARGV;
4819dd2a
NC
162 if (!$ret) {
163 $start = $try;
164 last;
165 }
03cc0342 166 push @tried, $try;
4819dd2a 167 }
03cc0342 168 die "Can't find a suitable start revision to default to.\nTried @tried"
4819dd2a
NC
169 unless defined $start;
170}
6a8dbfd7
NC
171
172system "git bisect start" and die;
173system "git bisect good $start" and die;
174system "git bisect bad $end" and die;
175
176# And now get git bisect to do the hard work:
e295b7be 177system 'git', 'bisect', 'run', $^X, $runner, @ARGV and die;
6a8dbfd7 178
c3d98a71
NC
179END {
180 my $end_time = time;
6a8dbfd7 181
c3d98a71
NC
182 printf "That took %d seconds\n", $end_time - $start_time
183 if defined $start_time;
184}
185
9b404864
NC
186=for comment
187
188Documentation for this is in bisect-runner.pl
189
190=cut
191
c3d98a71
NC
192# Local variables:
193# cperl-indent-level: 4
194# indent-tabs-mode: nil
195# End:
196#
197# ex: set ts=8 sts=4 sw=4 et: