This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In bisect-runner.pl, only force Configure's libpth on x86_64 Linux.
[perl5.git] / Porting / bisect-runner.pl
CommitLineData
6a8dbfd7
NC
1#!/usr/bin/perl -w
2use strict;
3
390a69a9 4use Getopt::Long qw(:config bundling no_auto_abbrev);
77ae6092 5use Pod::Usage;
6a8dbfd7 6
0afef97d 7my @targets = qw(config.sh config.h miniperl lib/Config.pm perl test_prep);
6a8dbfd7 8
e4516dd0
NC
9my $cpus;
10if (open my $fh, '<', '/proc/cpuinfo') {
11 while (<$fh>) {
12 ++$cpus if /^processor\s+:\s+\d+$/;
13 }
14}
15
f4800c99
NC
16my %options =
17 (
e4516dd0 18 jobs => defined $cpus ? $cpus + 1 : 2,
f4800c99
NC
19 'expect-pass' => 1,
20 clean => 1, # mostly for debugging this
21 );
6a8dbfd7 22
390a69a9
NC
23my @paths = qw(/usr/local/lib64 /lib64 /usr/lib64);
24
25my %defines =
26 (
27 usedevel => '',
28 optimize => '-g',
29 cc => 'ccache gcc',
30 ld => 'gcc',
e4516dd0 31 (`uname -sm` eq "Linux x86_64\n" ? (libpth => \@paths) : ()),
390a69a9
NC
32 );
33
f4800c99
NC
34unless(GetOptions(\%options,
35 'target=s', 'jobs|j=i', 'expect-pass=i',
36 'expect-fail' => sub { $options{'expect-pass'} = 0; },
37 'clean!', 'one-liner|e=s', 'match=s', 'force-manifest',
77ae6092 38 'test-build', 'check-args', 'A=s@', 'usage|help|?',
390a69a9
NC
39 'D=s@' => sub {
40 my (undef, $val) = @_;
41 if ($val =~ /\A([^=]+)=(.*)/s) {
42 $defines{$1} = length $2 ? $2 : "\0";
43 } else {
44 $defines{$val} = '';
45 }
46 },
47 'U=s@' => sub {
48 $defines{$_[1]} = undef;
49 },
6a8dbfd7 50 )) {
77ae6092 51 pod2usage(exitval => 255, verbose => 1);
6a8dbfd7
NC
52}
53
f4800c99 54my ($target, $j, $match) = @options{qw(target jobs match)};
e295b7be 55
77ae6092
NC
56pod2usage(exitval => 255, verbose => 1) if $options{usage};
57pod2usage(exitval => 255, verbose => 1)
58 unless @ARGV || $match || $options{'test-build'} || defined $options{'one-liner'};
6a8dbfd7 59
f4800c99 60exit 0 if $options{'check-args'};
6a8dbfd7 61
77ae6092
NC
62=head1 NAME
63
64bisect.pl - use git bisect to pinpoint changes
65
66=head1 SYNOPSIS
67
68 # When did this become an error?
69 .../Porting/bisect.pl -e 'my $a := 2;'
71d80638 70 # When did this stop being an error?
77ae6092
NC
71 .../Porting/bisect.pl --expect-fail -e '1 // 2'
72 # When did this stop matching?
73 .../Porting/bisect.pl --match '\b(?:PL_)hash_seed_set\b'
74 # When did this start matching?
75 .../Porting/bisect.pl --expect-fail --match '\buseithreads\b'
76 # When did this test program stop working?
77 .../Porting/bisect.pl --target=perl -- ./perl -Ilib test_prog.pl
78 # When did this first become valid syntax?
79 .../Porting/bisect.pl --target=miniperl --end=v5.10.0 \
80 --expect-fail -e 'my $a := 2;'
81 # What was the last revision to build with these options?
82 .../Porting/bisect.pl --test-build -Dd_dosuid
83
84=head1 DESCRIPTION
85
86Together C<bisect.pl> and C<bisect-runner.pl> attempt to automate the use
87of C<git bisect> as much as possible. With one command (and no other files)
88it's easy to find out
89
90=over 4
91
92=item *
93
94Which commit caused this example code to break?
95
96=item *
97
98Which commit caused this example code to start working?
99
100=item *
101
102Which commit added the first to match this regex?
103
104=item *
105
106Which commit removed the last to match this regex?
107
108=back
109
110usually without needing to know which versions of perl to use as start and
111end revisions.
112
113By default C<bisect.pl> will process all options, then use the rest of the
114command line as arguments to list C<system> to run a test case. By default,
115the test case should pass (exit with 0) on earlier perls, and fail (exit
116non-zero) on I<blead>. C<bisect.pl> will use C<bisect-runner.pl> to find the
117earliest stable perl version on which the test case passes, check that it
118fails on blead, and then use C<bisect-runner.pl> with C<git bisect run> to
119find the commit which caused the failure.
120
121Because the test case is the complete argument to C<system>, it is easy to
122run something other than the F<perl> built, if necessary. If you need to run
123the perl built, you'll probably need to invoke it as C<./perl -Ilib ...>
124
125=head1 OPTIONS
126
127=over 4
128
129=item *
130
131--start I<commit-ish>
132
133Earliest revision to test, as a I<commit-ish> (a tag, commit or anything
71d80638 134else C<git> understands as a revision). If not specified, C<bisect.pl> will
77ae6092
NC
135search stable perl releases from 5.002 to 5.14.0 until it finds one where
136the test case passes.
137
138=item *
139
140--end I<commit-ish>
141
142Most recent revision to test, as a I<commit-ish>. If not specified, defaults
143to I<blead>
144
145=item *
146
147--target I<target>
148
149F<Makefile> target (or equivalent) needed, to run the test case. If specified,
150this should be one of
151
152=over 4
153
154=item *
155
156I<config.sh>
157
158Just run C<Configure>
159
160=item *
161
162I<config.h>
163
164Run the various F<*.SH> files to generate F<Makefile>, F<config.h>, I<etc>.
165
166=item *
167
168I<miniperl>
169
170Build F<miniperl>.
171
172=item *
173
174I<lib/Config.pm>
175
176Use F<miniperl> to build F<lib/Config.pm>
177
178=item *
179
180I<perl>
181
182Build F<perl>. This also builds pure-Perl modules in F<cpan>, F<dist> and
183F<ext>.
184
185=item *
186
187I<test_prep>
188
189Build everything needed to run the tests. This is the default if we're
190running test code, but is time consuming, as it means building all
191C<XS> modules. For older F<Makefile>s, the previous name of C<test-prep>
192is automatically substituted. For very old F<Makefile>s, C<make test> is
193run, as there is no target provided to just get things ready, and for 5.004
194and earlier the tests run very quickly.
195
196=back
197
198=item *
199
200--one-liner 'code to run'
201
202=item *
203
204-e 'code to run'
205
206Example code to run, just like you'd use with C<perl -e>.
207
208This prepends C<./perl -Ilib -e 'code to run'> to the test case given,
209or C<./miniperl> if I<target> is C<miniperl>
210
211(Usually you'll use C<-e> instead of providing a test case in the
212non-option arguments to C<bisect.pl>)
213
214C<-E> intentionally isn't supported, as it's an error in 5.8.0 and earlier,
215which interferes with detecting errors in the example code itself.
216
217=item *
218
219--expect-fail
220
221The test case should fail for the I<start> revision, and pass for the I<end>
222revision. The bisect run will find the first commit where it passes.
223
224=item *
225
226-Dusethreads
227
228=item *
229
230-Uusedevel
231
232=item *
233
234-Accflags=-DNO_MATHOMS
235
236Arguments to pass to F<Configure>. Repeated C<-A> arguments are passed
237through as is. C<-D> and C<-U> are processed in order, and override
238previous settings for the same parameter.
239
240=item *
241
242--jobs
243
244=item *
245
246-j
247
e4516dd0
NC
248Number of C<make> jobs to run in parallel. If F</proc/cpuinfo> exists and can
249be parsed, defaults to 1 + I<number of CPUs>. Otherwise defaults to 2.
77ae6092
NC
250
251=item *
252
253--match
254
255Instead of running a test program to determine I<pass> or I<fail>, pass
256if the given regex matches, and hence search for the commit that removes
257the last matching file.
258
259If no I<target> is specified, the match is against all files in the
260repository (which is fast). If a I<target> is specified, that target is
261built, and the match is against only the built files. C<--expect-fail> can
262be used with C<--match> to search for a commit that adds files that match.
263
264=item *
265
266--test-build
267
268Test that the build completes, without running any test case.
269
270By default, if the build for the desired I<target> fails to complete,
271F<bisect-runner.pl> reports a I<skip> back to C<git bisect>, the assumption
272being that one wants to find a commit which changed state "builds && passes"
273to "builds && fails". If instead one is interested in which commit broke the
274build (possibly for particular F<Configure> options), use I<--test-build>
275to treat a build failure as a failure, not a "skip".
276
277=item *
278
279By default, a build will "skip" if any files listed in F<MANIFEST> are not
280present. Usually this is useful, as it avoids false-failures. However, there
281are some long ranges of commits where listed files are missing, which can
282cause a bisect to abort because all that remain are skipped revisions.
283
284In these cases, particularly if the test case uses F<miniperl> and no modules,
285it may be more useful to force the build to continue, even if files
286F<MANIFEST> are missing.
287
288=item *
289
290--expect-pass [0|1]
291
292C<--expect-pass=0> is equivalent to C<--expect-fail>. I<1> is the default.
293
294=item *
295
296--no-clean
297
298Tell F<bisect-runner.pl> not to clean up after the build. This allows one
299to use F<bisect-runner.pl> to build the current particular perl revision for
300interactive testing, or for debugging F<bisect-runner.pl>.
301
302Passing this to F<bisect.pl> will likely cause the bisect to fail badly.
303
304=item *
305
306--check-args
307
308Validate the options and arguments, and exit silently if they are valid.
309
310=item *
311
312--usage
313
314=item *
315
316--help
317
318=item *
319
320-?
321
322Display the usage information and exit.
323
324=back
325
326=cut
327
0afef97d 328die "$0: Can't build $target" if defined $target && !grep {@targets} $target;
6a8dbfd7
NC
329
330$j = "-j$j" if $j =~ /\A\d+\z/;
331
0142f0ce
NC
332# Sadly, however hard we try, I don't think that it will be possible to build
333# modules in ext/ on x86_64 Linux before commit e1666bf5602ae794 on 1999/12/29,
334# which updated to MakeMaker 3.7, which changed from using a hard coded ld
335# in the Makefile to $(LD). On x86_64 Linux the "linker" is gcc.
336
6a8dbfd7
NC
337sub extract_from_file {
338 my ($file, $rx, $default) = @_;
339 open my $fh, '<', $file or die "Can't open $file: $!";
340 while (<$fh>) {
341 my @got = $_ =~ $rx;
342 return wantarray ? @got : $got[0]
343 if @got;
344 }
345 return $default if defined $default;
346 return;
347}
348
ab4a15f9 349sub clean {
f4800c99 350 if ($options{clean}) {
ab4a15f9
NC
351 # Needed, because files that are build products in this checked out
352 # version might be in git in the next desired version.
353 system 'git clean -dxf';
354 # Needed, because at some revisions the build alters checked out files.
355 # (eg pod/perlapi.pod). Also undoes any changes to makedepend.SH
356 system 'git reset --hard HEAD';
357 }
358}
359
360sub skip {
361 my $reason = shift;
362 clean();
363 warn "skipping - $reason";
364 exit 125;
365}
366
f1050811
NC
367sub report_and_exit {
368 my ($ret, $pass, $fail, $desc) = @_;
369
370 clean();
371
f4800c99 372 my $got = ($options{'expect-pass'} ? !$ret : $ret) ? 'good' : 'bad';
f1050811
NC
373 if ($ret) {
374 print "$got - $fail $desc\n";
375 } else {
376 print "$got - $pass $desc\n";
377 }
378
379 exit($got eq 'bad');
380}
381
0afef97d
NC
382sub match_and_exit {
383 my $target = shift;
384 my $matches = 0;
385 my $re = qr/$match/;
386 my @files;
387
388 {
389 local $/ = "\0";
390 @files = defined $target ? `git ls-files -o -z`: `git ls-files -z`;
391 chomp @files;
392 }
393
394 foreach my $file (@files) {
395 open my $fh, '<', $file or die "Can't open $file: $!";
396 while (<$fh>) {
397 if ($_ =~ $re) {
398 ++$matches;
399 if (tr/\t\r\n -~\200-\377//c) {
400 print "Binary file $file matches\n";
401 } else {
402 $_ .= "\n" unless /\n\z/;
403 print "$file: $_";
404 }
405 }
406 }
407 close $fh or die "Can't close $file: $!";
408 }
409 report_and_exit(!$matches,
410 $matches == 1 ? '1 match for' : "$matches matches for",
411 'no matches for', $match);
412}
413
0142f0ce
NC
414sub apply_patch {
415 my $patch = shift;
416
f1193e4b 417 my ($file) = $patch =~ qr!^diff.*a/(\S+) b/\1!;
eb315236 418 open my $fh, '|-', 'patch', '-p1' or die "Can't run patch: $!";
0142f0ce 419 print $fh $patch;
f1193e4b 420 close $fh or die "Can't patch $file: $?, $!";
0142f0ce
NC
421}
422
6a8dbfd7
NC
423# Not going to assume that system perl is yet new enough to have autodie
424system 'git clean -dxf' and die;
425
0afef97d
NC
426if (!defined $target) {
427 match_and_exit() if $match;
428 $target = 'test_prep';
bc96a05a
NC
429}
430
4b081584
NC
431skip('no Configure - is this the //depot/perlext/Compiler branch?')
432 unless -f 'Configure';
433
dbcdc176
NC
434# This changes to PERL_VERSION in 4d8076ea25903dcb in 1999
435my $major
436 = extract_from_file('patchlevel.h',
437 qr/^#define\s+(?:PERL_VERSION|PATCHLEVEL)\s+(\d+)\s/,
438 0);
439
0142f0ce
NC
440if ($major < 1) {
441 if (extract_from_file('Configure',
442 qr/^ \*=\*\) echo "\$1" >> \$optdef;;$/)) {
443 # This is " Spaces now allowed in -D command line options.",
444 # part of commit ecfc54246c2a6f42
445 apply_patch(<<'EOPATCH');
446diff --git a/Configure b/Configure
447index 3d3b38d..78ffe16 100755
448--- a/Configure
449+++ b/Configure
450@@ -652,7 +777,8 @@ while test $# -gt 0; do
451 echo "$me: use '-U symbol=', not '-D symbol='." >&2
452 echo "$me: ignoring -D $1" >&2
453 ;;
454- *=*) echo "$1" >> $optdef;;
455+ *=*) echo "$1" | \
456+ sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> $optdef;;
457 *) echo "$1='define'" >> $optdef;;
458 esac
459 shift
460EOPATCH
461 }
462 if (extract_from_file('Configure', qr/^if \$contains 'd_namlen' \$xinc\b/)) {
463 # Configure's original simple "grep" for d_namlen falls foul of the
464 # approach taken by the glibc headers:
465 # #ifdef _DIRENT_HAVE_D_NAMLEN
466 # # define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
467 #
468 # where _DIRENT_HAVE_D_NAMLEN is not defined on Linux.
469 # This is also part of commit ecfc54246c2a6f42
470 apply_patch(<<'EOPATCH');
471diff --git a/Configure b/Configure
472index 3d3b38d..78ffe16 100755
473--- a/Configure
474+++ b/Configure
475@@ -3935,7 +4045,8 @@ $rm -f try.c
476
477 : see if the directory entry stores field length
478 echo " "
479-if $contains 'd_namlen' $xinc >/dev/null 2>&1; then
480+$cppstdin $cppflags $cppminus < "$xinc" > try.c
481+if $contains 'd_namlen' try.c >/dev/null 2>&1; then
482 echo "Good, your directory entry keeps length information in d_namlen." >&4
483 val="$define"
484 else
485EOPATCH
486 }
487}
488
6a8dbfd7
NC
489# There was a bug in makedepend.SH which was fixed in version 96a8704c.
490# Symptom was './makedepend: 1: Syntax error: Unterminated quoted string'
491# Remove this if you're actually bisecting a problem related to makedepend.SH
492system 'git show blead:makedepend.SH > makedepend.SH' and die;
493
6a8dbfd7
NC
494# if Encode is not needed for the test, you can speed up the bisect by
495# excluding it from the runs with -Dnoextensions=Encode
496# ccache is an easy win. Remove it if it causes problems.
6a8dbfd7
NC
497# Commit 1cfa4ec74d4933da adds ignore_versioned_solibs to Configure, and sets it
498# to true in hints/linux.sh
499# On dromedary, from that point on, Configure (by default) fails to find any
500# libraries, because it scans /usr/local/lib /lib /usr/lib, which only contain
501# versioned libraries. Without -lm, the build fails.
502# Telling /usr/local/lib64 /lib64 /usr/lib64 works from that commit onwards,
503# until commit faae14e6e968e1c0 adds it to the hints.
504# However, prior to 1cfa4ec74d4933da telling Configure the truth doesn't work,
505# because it will spot versioned libraries, pass them to the compiler, and then
506# bail out pretty early on. Configure won't let us override libswanted, but it
507# will let us override the entire libs list.
508
509unless (extract_from_file('Configure', 'ignore_versioned_solibs')) {
510 # Before 1cfa4ec74d4933da, so force the libs list.
511
512 my @libs;
513 # This is the current libswanted list from Configure, less the libs removed
514 # by current hints/linux.sh
515 foreach my $lib (qw(sfio socket inet nsl nm ndbm gdbm dbm db malloc dl dld
516 ld sun m crypt sec util c cposix posix ucb BSD)) {
517 foreach my $dir (@paths) {
518 next unless -f "$dir/lib$lib.so";
519 push @libs, "-l$lib";
520 last;
521 }
522 }
390a69a9 523 $defines{libs} = \@libs unless exists $defines{libs};
6a8dbfd7
NC
524}
525
4b081584
NC
526# This seems to be necessary to avoid makedepend becoming confused, and hanging
527# on stdin. Seems that the code after make shlist || ...here... is never run.
390a69a9
NC
528$defines{trnl} = q{'\n'}
529 if $major < 4 && !exists $defines{trnl};
4b081584 530
390a69a9
NC
531$defines{usenm} = undef
532 if $major < 2 && !exists $defines{usenm};
0142f0ce 533
67382a3b
NC
534my (@missing, @created_dirs);
535
f4800c99 536if ($options{'force-manifest'}) {
67382a3b
NC
537 open my $fh, '<', 'MANIFEST'
538 or die "Could not open MANIFEST: $!";
539 while (<$fh>) {
540 next unless /^(\S+)/;
541 push @missing, $1
542 unless -f $1;
543 }
544 close $fh or die "Can't close MANIFEST: $!";
545
546 foreach my $pathname (@missing) {
547 my @parts = split '/', $pathname;
548 my $leaf = pop @parts;
549 my $path = '.';
550 while (@parts) {
551 $path .= '/' . shift @parts;
552 next if -d $path;
553 mkdir $path, 0700 or die "Can't create $path: $!";
554 unshift @created_dirs, $path;
555 }
556 open $fh, '>', $pathname or die "Can't open $pathname: $!";
557 close $fh or die "Can't close $pathname: $!";
558 chmod 0, $pathname or die "Can't chmod 0 $pathname: $!";
559 }
560}
561
dd4e46d7 562my @ARGS = $target eq 'config.sh' ? '-dEs' : '-des';
390a69a9
NC
563foreach my $key (sort keys %defines) {
564 my $val = $defines{$key};
565 if (ref $val) {
566 push @ARGS, "-D$key=@$val";
567 } elsif (!defined $val) {
568 push @ARGS, "-U$key";
569 } elsif (!length $val) {
570 push @ARGS, "-D$key";
571 } else {
572 $val = "" if $val eq "\0";
573 push @ARGS, "-D$key=$val";
574 }
575}
576push @ARGS, map {"-A$_"} @{$options{A}};
577
6a8dbfd7
NC
578# </dev/null because it seems that some earlier versions of Configure can
579# call commands in a way that now has them reading from stdin (and hanging)
580my $pid = fork;
581die "Can't fork: $!" unless defined $pid;
582if (!$pid) {
dbcdc176
NC
583 # Before dfe9444ca7881e71, Configure would refuse to run if stdin was not a
584 # tty. With that commit, the tty requirement was dropped for -de and -dE
8754c3bb 585 if($major > 4) {
67382a3b 586 open STDIN, '<', '/dev/null';
f4800c99 587 } elsif (!$options{'force-manifest'}) {
8754c3bb
NC
588 # If a file in MANIFEST is missing, Configure asks if you want to
589 # continue (the default being 'n'). With stdin closed or /dev/null,
590 # it exit immediately and the check for config.sh below will skip.
591 # To avoid a hang, we need to check MANIFEST for ourselves, and skip
592 # if anything is missing.
593 open my $fh, '<', 'MANIFEST';
594 skip("Could not open MANIFEST: $!")
595 unless $fh;
596 while (<$fh>) {
597 next unless /^(\S+)/;
598 skip("$1 from MANIFEST doesn't exist")
599 unless -f $1;
600 }
601 close $fh or die "Can't close MANIFEST: $!";
602 }
6a8dbfd7
NC
603 exec './Configure', @ARGS;
604 die "Failed to start Configure: $!";
605}
606waitpid $pid, 0
607 or die "wait for Configure, pid $pid failed: $!";
608
0afef97d
NC
609if ($target =~ /config\.s?h/) {
610 match_and_exit($target) if $match && -f $target;
dd4e46d7
NC
611 report_and_exit(!-f $target, 'could build', 'could not build', $target);
612} elsif (!-f 'config.sh') {
613 # Skip if something went wrong with Configure
614
615 skip('could not build config.sh');
616}
6a8dbfd7 617
67382a3b
NC
618# This is probably way too paranoid:
619if (@missing) {
620 my @errors;
eb4906f4 621 require Fcntl;
67382a3b
NC
622 foreach my $file (@missing) {
623 my (undef, undef, $mode, undef, undef, undef, undef, $size)
624 = stat $file;
625 if (!defined $mode) {
626 push @errors, "Added file $file has been deleted by Configure";
627 next;
628 }
eb4906f4 629 if (Fcntl::S_IMODE($mode) != 0) {
67382a3b
NC
630 push @errors,
631 sprintf 'Added file %s had mode changed by Configure to %03o',
632 $file, $mode;
633 }
634 if ($size != 0) {
635 push @errors,
636 "Added file $file had sized changed by Configure to $size";
637 }
638 unlink $file or die "Can't unlink $file: $!";
639 }
640 foreach my $dir (@created_dirs) {
641 rmdir $dir or die "Can't rmdir $dir: $!";
642 }
6c0925a0
NC
643 skip("@errors")
644 if @errors;
67382a3b
NC
645}
646
6a8dbfd7
NC
647# Correct makefile for newer GNU gcc
648# Only really needed if you comment out the use of blead's makedepend.SH
649{
650 local $^I = "";
651 local @ARGV = qw(makefile x2p/makefile);
652 while (<>) {
653 print unless /<(?:built-in|command|stdin)/;
654 }
655}
6a8dbfd7 656
0142f0ce
NC
657if ($major == 2 && extract_from_file('perl.c', qr/^ fclose\(e_fp\);$/)) {
658 # need to patch perl.c to avoid calling fclose() twice on e_fp when using -e
659 # This diff is part of commit ab821d7fdc14a438. The second close was
660 # introduced with perl-5.002, commit a5f75d667838e8e7
661 # Might want a6c477ed8d4864e6 too, for the corresponding change to pp_ctl.c
662 # (likely without this, eval will have "fun")
663 apply_patch(<<'EOPATCH');
664diff --git a/perl.c b/perl.c
665index 03c4d48..3c814a2 100644
666--- a/perl.c
667+++ b/perl.c
668@@ -252,6 +252,7 @@ setuid perl scripts securely.\n");
669 #ifndef VMS /* VMS doesn't have environ array */
670 origenviron = environ;
671 #endif
672+ e_tmpname = Nullch;
673
674 if (do_undump) {
675
676@@ -405,6 +406,7 @@ setuid perl scripts securely.\n");
677 if (e_fp) {
678 if (Fflush(e_fp) || ferror(e_fp) || fclose(e_fp))
679 croak("Can't write to temp file for -e: %s", Strerror(errno));
680+ e_fp = Nullfp;
681 argc++,argv--;
682 scriptname = e_tmpname;
683 }
684@@ -470,10 +472,10 @@ setuid perl scripts securely.\n");
685 curcop->cop_line = 0;
686 curstash = defstash;
687 preprocess = FALSE;
688- if (e_fp) {
689- fclose(e_fp);
690- e_fp = Nullfp;
691+ if (e_tmpname) {
692 (void)UNLINK(e_tmpname);
693+ Safefree(e_tmpname);
694+ e_tmpname = Nullch;
695 }
696
697 /* now that script is parsed, we can modify record separator */
698@@ -1369,7 +1371,7 @@ SV *sv;
699 scriptname = xfound;
700 }
701
702- origfilename = savepv(e_fp ? "-e" : scriptname);
703+ origfilename = savepv(e_tmpname ? "-e" : scriptname);
704 curcop->cop_filegv = gv_fetchfile(origfilename);
705 if (strEQ(origfilename,"-"))
706 scriptname = "";
707
708EOPATCH
709}
710
9a999a97
NC
711# Parallel build for miniperl is safe
712system "make $j miniperl";
713
714if ($target ne 'miniperl') {
715 # Nearly all parallel build issues fixed by 5.10.0. Untrustworthy before that.
372ba1f9 716 $j = '' if $major < 10;
9a999a97
NC
717
718 if ($target eq 'test_prep') {
719 if ($major < 8) {
720 # test-prep was added in 5.004_01, 3e3baf6d63945cb6.
721 # renamed to test_prep in 2001 in 5fe84fd29acaf55c.
722 # earlier than that, just make test. It will be fast enough.
723 $target = extract_from_file('Makefile.SH', qr/^(test[-_]prep):/,
724 'test');
725 }
6a8dbfd7 726 }
6a8dbfd7 727
eb315236
NC
728 if ($major < 10
729 and -f 'ext/IPC/SysV/SysV.xs',
730 and my ($line) = extract_from_file('ext/IPC/SysV/SysV.xs',
731 qr!^(# *include <asm/page.h>)$!)) {
732 apply_patch(<<"EOPATCH");
733diff --git a/ext/IPC/SysV/SysV.xs b/ext/IPC/SysV/SysV.xs
734index 35a8fde..62a7965 100644
735--- a/ext/IPC/SysV/SysV.xs
736+++ b/ext/IPC/SysV/SysV.xs
737\@\@ -4,7 +4,6 \@\@
738
739 #include <sys/types.h>
740 #ifdef __linux__
741-$line
742 #endif
743 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
744 #ifndef HAS_SEM
745EOPATCH
746 }
9a999a97
NC
747 system "make $j $target";
748}
6a8dbfd7 749
a1371303 750my $expected = $target =~ /^test/ ? 't/perl' : $target;
67382a3b
NC
751my $missing_target = $expected =~ /perl$/ ? !-x $expected : !-r $expected;
752
f4800c99 753if ($options{'test-build'}) {
67382a3b
NC
754 report_and_exit($missing_target, 'could build', 'could not build', $target);
755} elsif ($missing_target) {
756 skip("could not build $target");
757}
6a8dbfd7 758
0afef97d
NC
759match_and_exit($target) if $match;
760
761if (defined $options{'one-liner'}) {
372ba1f9 762 my $exe = $target ne 'miniperl' ? 'perl' : 'miniperl';
0afef97d
NC
763 unshift @ARGV, "./$exe", '-Ilib', '-e', $options{'one-liner'};
764}
765
6a8dbfd7
NC
766# This is what we came here to run:
767my $ret = system @ARGV;
768
f1050811 769report_and_exit($ret, 'zero exit from', 'non-zero exit from', "@ARGV");
9a999a97
NC
770
771# Local variables:
772# cperl-indent-level: 4
773# indent-tabs-mode: nil
774# End:
775#
776# ex: set ts=8 sts=4 sw=4 et: