This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
bisect-runner.pl must clean up, even if it's skipping.
[perl5.git] / Porting / bisect-runner.pl
CommitLineData
6a8dbfd7
NC
1#!/usr/bin/perl -w
2use strict;
3
4use Getopt::Long;
5
4daf2803 6my @targets = qw(miniperl lib/Config.pm perl test_prep);
6a8dbfd7
NC
7
8my $target = 'test_prep';
9my $j = '9';
10my $test_should_pass = 1;
11my $clean = 1;
12my $one_liner;
13
14sub usage {
15 die "$0: [--target=...] [-j=4] [--expect-pass=0|1] thing to test";
16}
17
18unless(GetOptions('target=s' => \$target,
19 'jobs|j=i' => \$j,
20 'expect-pass=i' => \$test_should_pass,
21 'expect-fail' => sub { $test_should_pass = 0; },
22 'clean!' => \$clean, # mostly for debugging this
23 'one-liner|e=s' => \$one_liner,
24 )) {
25 usage();
26}
27
4daf2803
NC
28my $exe = $target eq 'perl' || $target eq 'test_prep' ? 'perl' : 'miniperl';
29my $expected = $target eq 'test_prep' ? 'perl' : $target;
6a8dbfd7 30
4daf2803 31unshift @ARGV, "./$exe", '-Ilib', '-e', $one_liner if defined $one_liner;
6a8dbfd7
NC
32
33usage() unless @ARGV;
34
35die "$0: Can't build $target" unless grep {@targets} $target;
36
37$j = "-j$j" if $j =~ /\A\d+\z/;
38
39sub extract_from_file {
40 my ($file, $rx, $default) = @_;
41 open my $fh, '<', $file or die "Can't open $file: $!";
42 while (<$fh>) {
43 my @got = $_ =~ $rx;
44 return wantarray ? @got : $got[0]
45 if @got;
46 }
47 return $default if defined $default;
48 return;
49}
50
ab4a15f9
NC
51sub clean {
52 if ($clean) {
53 # Needed, because files that are build products in this checked out
54 # version might be in git in the next desired version.
55 system 'git clean -dxf';
56 # Needed, because at some revisions the build alters checked out files.
57 # (eg pod/perlapi.pod). Also undoes any changes to makedepend.SH
58 system 'git reset --hard HEAD';
59 }
60}
61
62sub skip {
63 my $reason = shift;
64 clean();
65 warn "skipping - $reason";
66 exit 125;
67}
68
6a8dbfd7
NC
69# Not going to assume that system perl is yet new enough to have autodie
70system 'git clean -dxf' and die;
71
72# There was a bug in makedepend.SH which was fixed in version 96a8704c.
73# Symptom was './makedepend: 1: Syntax error: Unterminated quoted string'
74# Remove this if you're actually bisecting a problem related to makedepend.SH
75system 'git show blead:makedepend.SH > makedepend.SH' and die;
76
77my @paths = qw(/usr/local/lib64 /lib64 /usr/lib64);
78
79# if Encode is not needed for the test, you can speed up the bisect by
80# excluding it from the runs with -Dnoextensions=Encode
81# ccache is an easy win. Remove it if it causes problems.
82my @ARGS = ('-des', '-Dusedevel', '-Doptimize=-g', '-Dcc=ccache gcc',
83 '-Dld=gcc', "-Dlibpth=@paths");
84
85# Commit 1cfa4ec74d4933da adds ignore_versioned_solibs to Configure, and sets it
86# to true in hints/linux.sh
87# On dromedary, from that point on, Configure (by default) fails to find any
88# libraries, because it scans /usr/local/lib /lib /usr/lib, which only contain
89# versioned libraries. Without -lm, the build fails.
90# Telling /usr/local/lib64 /lib64 /usr/lib64 works from that commit onwards,
91# until commit faae14e6e968e1c0 adds it to the hints.
92# However, prior to 1cfa4ec74d4933da telling Configure the truth doesn't work,
93# because it will spot versioned libraries, pass them to the compiler, and then
94# bail out pretty early on. Configure won't let us override libswanted, but it
95# will let us override the entire libs list.
96
97unless (extract_from_file('Configure', 'ignore_versioned_solibs')) {
98 # Before 1cfa4ec74d4933da, so force the libs list.
99
100 my @libs;
101 # This is the current libswanted list from Configure, less the libs removed
102 # by current hints/linux.sh
103 foreach my $lib (qw(sfio socket inet nsl nm ndbm gdbm dbm db malloc dl dld
104 ld sun m crypt sec util c cposix posix ucb BSD)) {
105 foreach my $dir (@paths) {
106 next unless -f "$dir/lib$lib.so";
107 push @libs, "-l$lib";
108 last;
109 }
110 }
111 push @ARGS, "-Dlibs=@libs";
112}
113
114# </dev/null because it seems that some earlier versions of Configure can
115# call commands in a way that now has them reading from stdin (and hanging)
116my $pid = fork;
117die "Can't fork: $!" unless defined $pid;
118if (!$pid) {
119 open STDIN, '<', '/dev/null';
120 exec './Configure', @ARGS;
121 die "Failed to start Configure: $!";
122}
123waitpid $pid, 0
124 or die "wait for Configure, pid $pid failed: $!";
125
126# Skip if something went wrong with Configure
ab4a15f9 127skip('no config.sh') unless -f 'config.sh';
6a8dbfd7
NC
128
129# Correct makefile for newer GNU gcc
130# Only really needed if you comment out the use of blead's makedepend.SH
131{
132 local $^I = "";
133 local @ARGV = qw(makefile x2p/makefile);
134 while (<>) {
135 print unless /<(?:built-in|command|stdin)/;
136 }
137}
138
139# This changes to PERL_VERSION in 4d8076ea25903dcb in 1999
140my $major
141 = extract_from_file('patchlevel.h',
142 qr/^#define\s+(?:PERL_VERSION|PATCHLEVEL)\s+(\d+)\s/,
143 0);
144
9a999a97
NC
145# Parallel build for miniperl is safe
146system "make $j miniperl";
147
148if ($target ne 'miniperl') {
149 # Nearly all parallel build issues fixed by 5.10.0. Untrustworthy before that.
150 $j = '' unless $major > 10;
151
152 if ($target eq 'test_prep') {
153 if ($major < 8) {
154 # test-prep was added in 5.004_01, 3e3baf6d63945cb6.
155 # renamed to test_prep in 2001 in 5fe84fd29acaf55c.
156 # earlier than that, just make test. It will be fast enough.
157 $target = extract_from_file('Makefile.SH', qr/^(test[-_]prep):/,
158 'test');
159 }
6a8dbfd7 160 }
6a8dbfd7 161
9a999a97
NC
162 system "make $j $target";
163}
6a8dbfd7 164
ab4a15f9
NC
165skip("could not build $target")
166 if $expected =~ /perl$/ ? !-x $expected : !-r $expected;
6a8dbfd7
NC
167
168# This is what we came here to run:
169my $ret = system @ARGV;
170
ab4a15f9 171clean();
6a8dbfd7
NC
172
173my $got = ($test_should_pass ? !$ret : $ret) ? 'good' : 'bad';
174
175if ($ret) {
176 print "$got - non-zero exit from @ARGV\n";
177} else {
178 print "$got - zero exit from @ARGV\n";
179}
180
181exit($got eq 'bad');
9a999a97
NC
182
183# Local variables:
184# cperl-indent-level: 4
185# indent-tabs-mode: nil
186# End:
187#
188# ex: set ts=8 sts=4 sw=4 et: