6 Documentation for this is in bisect-runner.pl
10 # The default, auto_abbrev will treat -e as an abbreviation of --end
11 # Which isn't what we want.
12 use Getopt::Long qw(:config pass_through no_auto_abbrev);
14 my ($start, $end, $validate, $usage, $bad, $jobs, $make, $gold);
15 $bad = !GetOptions('start=s' => \$start, 'end=s' => \$end,
16 'jobs|j=i' => \$jobs, 'make=s' => \$make, 'gold=s' => \$gold,
17 validate => \$validate, 'usage|help|?' => \$usage);
18 unshift @ARGV, '--help' if $bad || $usage;
19 unshift @ARGV, '--validate' if $validate;
22 $runner =~ s/bisect\.pl/bisect-runner.pl/;
24 die "Can't find bisect runner $runner" unless -f $runner;
26 system $^X, $runner, '--check-args', '--check-shebang', @ARGV and exit 255;
30 my $start_time = time;
33 !($^O eq 'hpux' && system((defined $make ? $make : 'make')
34 . ' --version >/dev/null 2>&1'))) {
35 # Try to default to (ab)use all the CPUs:
37 if (open my $fh, '<', '/proc/cpuinfo') {
39 ++$cpus if /^processor\s+:\s+\d+$/;
41 } elsif (-x '/sbin/sysctl') {
42 $cpus = $1 if `/sbin/sysctl hw.ncpu` =~ /^hw\.ncpu: (\d+)$/;
43 } elsif (-x '/usr/bin/getconf') {
44 $cpus = $1 if `/usr/bin/getconf _NPROCESSORS_ONLN` =~ /^(\d+)$/;
46 $jobs = defined $cpus ? $cpus + 1 : 2;
49 unshift @ARGV, '--jobs', $jobs if defined $jobs;
50 unshift @ARGV, '--make', $make if defined $make;
52 # We try these in this order for the start revision if none is specified.
53 my @stable = map {chomp $_; $_} grep {/v5\.[0-9]+[02468]\.0$/} `git tag -l`;
54 die "git tag -l didn't seem to return any tags for stable releases"
56 unshift @stable, qw(perl-5.005 perl-5.6.0 perl-5.8.0);
59 my ($dev_C, $ino_C) = stat 'Configure';
60 my ($dev_c, $ino_c) = stat 'configure';
61 if (defined $dev_C && defined $dev_c
62 && $dev_C == $dev_c && $ino_C == $ino_c) {
63 print "You seem to be on a case-insensitive file system.\n\n";
65 unshift @stable, qw(perl-5.002 perl-5.003 perl-5.004)
69 unshift @ARGV, '--gold', defined $gold ? $gold : $stable[-1];
72 # If we have a branch blead, use that as the end
73 $end = `git rev-parse --verify --quiet blead`;
74 die unless defined $end;
76 # Else use whichever is newer - HEAD, or the most recent stable tag.
77 if (`git rev-list -n1 HEAD ^$stable[-1]` eq "") {
85 # Canonicalising branches to revisions before moving the checkout permits one
86 # to use revisions such as 'HEAD' for --start or --end
87 foreach ($start, $end) {
89 $_ = `git rev-parse $_`;
90 die unless defined $_;
95 my $modified = my @modified = `git ls-files --modified --deleted --others`;
97 my ($dev0, $ino0) = stat $0;
98 die "Can't stat $0: $!" unless defined $ino0;
99 my ($dev1, $ino1) = stat 'Porting/bisect.pl';
101 my $inplace = defined $dev1 && $dev0 == $dev1 && $ino0 == $ino1;
105 ? "Can't run a bisect using a dirty directory containing $runner"
106 : "You can use 'git clean -Xdf' to cleanup the ignored files";
108 die "This checkout is not clean, found file(s):\n",
109 join("\t","",@modified),
110 "$modified modified, untracked, or other file(s)\n",
111 "These files may not show in git status as they may be ignored.\n",
116 # We assume that it's safe to copy the runner to the temporary
117 # directory and run it from there, because a shared /tmp should be +t
118 # and hence others are not be able to delete or rename our file.
120 my ($to, $toname) = File::Temp::tempfile();
121 die "Can't create tempfile"
123 open my $from, '<', $runner
124 or die "Can't open '$runner': $!";
127 or die "Can't copy from '$runner' to '$toname': $!";
129 or die "Can't close '$runner': $!";
131 or die "Can't close '$toname': $!";
133 or die "Can't chmod 0500, '$toname': $!";
135 system $^X, $runner, '--check-args', @ARGV
136 and die "Can't run inplace for some reason. :-(";
142 if (defined $start && `git rev-list -n1 $commit ^$start^` eq "") {
143 print "Skipping $commit, as it is earlier than $start\n";
146 if (defined $end && `git rev-list -n1 $end ^$commit^` eq "") {
147 print "Skipping $commit, as it is more recent than $end\n";
150 print "Testing $commit...\n";
151 system "git checkout $commit </dev/null" and die;
152 my $ret = system $^X, $runner, '--no-clean', @ARGV;
153 die "Runner returned $ret, not 0 for revision $commit" if $ret;
154 system 'git clean -dxf </dev/null' and die;
155 system 'git reset --hard HEAD </dev/null' and die;
161 my @built = map {validate $_} 'blead', reverse @stable;
163 print Text::Wrap::wrap("", "", "Successfully validated @built\n");
166 print "Did not validate anything\n";
170 my $git_version = `git --version`;
171 if (defined $git_version
172 && $git_version =~ /\Agit version (\d+\.\d+\.\d+)(.*)/) {
173 $git_version = eval "v$1";
175 $git_version = v0.0.0;
178 if ($git_version ge v1.6.6) {
179 system "git bisect reset HEAD" and die;
181 system "git bisect reset" and die;
184 # Sanity check the first and last revisions:
185 system "git checkout $end" and die;
186 my $ret = system $^X, $runner, @ARGV;
187 die "Runner returned $ret for end revision" unless $ret;
188 die "Runner returned $ret for end revision, which is a skip"
189 if $ret == 125 * 256;
191 if (defined $start) {
192 system "git checkout $start" and die;
193 my $ret = system $^X, $runner, @ARGV;
194 die "Runner returned $ret, not 0 for start revision" if $ret;
196 # Try to find the earliest version for which the test works
198 foreach my $try (@stable) {
199 if (`git rev-list -n1 $end ^$try^` eq "") {
200 print "Skipping $try, as it is more recent than end commit "
201 . (substr $end, 0, 16) . "\n";
202 # As @stable is supposed to be in age order, arguably we should
206 system "git checkout $try" and die;
207 my $ret = system $^X, $runner, @ARGV;
214 die "Can't find a suitable start revision to default to.\nTried @tried"
215 unless defined $start;
218 system "git bisect start" and die;
219 system "git bisect good $start" and die;
220 system "git bisect bad $end" and die;
222 # And now get git bisect to do the hard work:
223 system 'git', 'bisect', 'run', $^X, $runner, @ARGV and die;
228 printf "That took %d seconds\n", $end_time - $start_time
229 if defined $start_time;
234 Documentation for this is in bisect-runner.pl
239 # cperl-indent-level: 4
240 # indent-tabs-mode: nil
243 # ex: set ts=8 sts=4 sw=4 et: