This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In bisect-runner.pl, refactor the reporting code into report_and_exit().
[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
f1050811
NC
69sub report_and_exit {
70 my ($ret, $pass, $fail, $desc) = @_;
71
72 clean();
73
74 my $got = ($test_should_pass ? !$ret : $ret) ? 'good' : 'bad';
75 if ($ret) {
76 print "$got - $fail $desc\n";
77 } else {
78 print "$got - $pass $desc\n";
79 }
80
81 exit($got eq 'bad');
82}
83
6a8dbfd7
NC
84# Not going to assume that system perl is yet new enough to have autodie
85system 'git clean -dxf' and die;
86
87# There was a bug in makedepend.SH which was fixed in version 96a8704c.
88# Symptom was './makedepend: 1: Syntax error: Unterminated quoted string'
89# Remove this if you're actually bisecting a problem related to makedepend.SH
90system 'git show blead:makedepend.SH > makedepend.SH' and die;
91
92my @paths = qw(/usr/local/lib64 /lib64 /usr/lib64);
93
94# if Encode is not needed for the test, you can speed up the bisect by
95# excluding it from the runs with -Dnoextensions=Encode
96# ccache is an easy win. Remove it if it causes problems.
97my @ARGS = ('-des', '-Dusedevel', '-Doptimize=-g', '-Dcc=ccache gcc',
98 '-Dld=gcc', "-Dlibpth=@paths");
99
100# Commit 1cfa4ec74d4933da adds ignore_versioned_solibs to Configure, and sets it
101# to true in hints/linux.sh
102# On dromedary, from that point on, Configure (by default) fails to find any
103# libraries, because it scans /usr/local/lib /lib /usr/lib, which only contain
104# versioned libraries. Without -lm, the build fails.
105# Telling /usr/local/lib64 /lib64 /usr/lib64 works from that commit onwards,
106# until commit faae14e6e968e1c0 adds it to the hints.
107# However, prior to 1cfa4ec74d4933da telling Configure the truth doesn't work,
108# because it will spot versioned libraries, pass them to the compiler, and then
109# bail out pretty early on. Configure won't let us override libswanted, but it
110# will let us override the entire libs list.
111
112unless (extract_from_file('Configure', 'ignore_versioned_solibs')) {
113 # Before 1cfa4ec74d4933da, so force the libs list.
114
115 my @libs;
116 # This is the current libswanted list from Configure, less the libs removed
117 # by current hints/linux.sh
118 foreach my $lib (qw(sfio socket inet nsl nm ndbm gdbm dbm db malloc dl dld
119 ld sun m crypt sec util c cposix posix ucb BSD)) {
120 foreach my $dir (@paths) {
121 next unless -f "$dir/lib$lib.so";
122 push @libs, "-l$lib";
123 last;
124 }
125 }
126 push @ARGS, "-Dlibs=@libs";
127}
128
129# </dev/null because it seems that some earlier versions of Configure can
130# call commands in a way that now has them reading from stdin (and hanging)
131my $pid = fork;
132die "Can't fork: $!" unless defined $pid;
133if (!$pid) {
134 open STDIN, '<', '/dev/null';
135 exec './Configure', @ARGS;
136 die "Failed to start Configure: $!";
137}
138waitpid $pid, 0
139 or die "wait for Configure, pid $pid failed: $!";
140
141# Skip if something went wrong with Configure
ab4a15f9 142skip('no config.sh') unless -f 'config.sh';
6a8dbfd7
NC
143
144# Correct makefile for newer GNU gcc
145# Only really needed if you comment out the use of blead's makedepend.SH
146{
147 local $^I = "";
148 local @ARGV = qw(makefile x2p/makefile);
149 while (<>) {
150 print unless /<(?:built-in|command|stdin)/;
151 }
152}
153
154# This changes to PERL_VERSION in 4d8076ea25903dcb in 1999
155my $major
156 = extract_from_file('patchlevel.h',
157 qr/^#define\s+(?:PERL_VERSION|PATCHLEVEL)\s+(\d+)\s/,
158 0);
159
9a999a97
NC
160# Parallel build for miniperl is safe
161system "make $j miniperl";
162
163if ($target ne 'miniperl') {
164 # Nearly all parallel build issues fixed by 5.10.0. Untrustworthy before that.
165 $j = '' unless $major > 10;
166
167 if ($target eq 'test_prep') {
168 if ($major < 8) {
169 # test-prep was added in 5.004_01, 3e3baf6d63945cb6.
170 # renamed to test_prep in 2001 in 5fe84fd29acaf55c.
171 # earlier than that, just make test. It will be fast enough.
172 $target = extract_from_file('Makefile.SH', qr/^(test[-_]prep):/,
173 'test');
174 }
6a8dbfd7 175 }
6a8dbfd7 176
9a999a97
NC
177 system "make $j $target";
178}
6a8dbfd7 179
ab4a15f9
NC
180skip("could not build $target")
181 if $expected =~ /perl$/ ? !-x $expected : !-r $expected;
6a8dbfd7
NC
182
183# This is what we came here to run:
184my $ret = system @ARGV;
185
f1050811 186report_and_exit($ret, 'zero exit from', 'non-zero exit from', "@ARGV");
9a999a97
NC
187
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: