1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
#!/usr/bin/perl -w
use strict;
use Getopt::Long qw(:config bundling no_auto_abbrev);
my @targets = qw(config.sh miniperl lib/Config.pm perl test_prep);
my %options =
(
target => 'test_prep',
jobs => 9,
'expect-pass' => 1,
clean => 1, # mostly for debugging this
);
my @paths = qw(/usr/local/lib64 /lib64 /usr/lib64);
my %defines =
(
usedevel => '',
optimize => '-g',
cc => 'ccache gcc',
ld => 'gcc',
'libpth' => \@paths,
);
sub usage {
die "$0: [--target=...] [-j4] [--expect-pass=0|1] thing to test";
}
unless(GetOptions(\%options,
'target=s', 'jobs|j=i', 'expect-pass=i',
'expect-fail' => sub { $options{'expect-pass'} = 0; },
'clean!', 'one-liner|e=s', 'match=s', 'force-manifest',
'test-build', 'check-args', 'A=s@', 'verbose+',
'D=s@' => sub {
my (undef, $val) = @_;
if ($val =~ /\A([^=]+)=(.*)/s) {
$defines{$1} = length $2 ? $2 : "\0";
} else {
$defines{$val} = '';
}
},
'U=s@' => sub {
$defines{$_[1]} = undef;
},
)) {
usage();
}
my ($target, $j, $match) = @options{qw(target jobs match)};
my $exe = $target eq 'perl' || $target eq 'test_prep' ? 'perl' : 'miniperl';
my $expected = $target eq 'test_prep' ? 'perl' : $target;
unshift @ARGV, "./$exe", '-Ilib', '-e', $options{'one-liner'}
if defined $options{'one-liner'};
usage() unless @ARGV || $match || $options{'test-build'};
exit 0 if $options{'check-args'};
die "$0: Can't build $target" unless grep {@targets} $target;
$j = "-j$j" if $j =~ /\A\d+\z/;
# Sadly, however hard we try, I don't think that it will be possible to build
# modules in ext/ on x86_64 Linux before commit e1666bf5602ae794 on 1999/12/29,
# which updated to MakeMaker 3.7, which changed from using a hard coded ld
# in the Makefile to $(LD). On x86_64 Linux the "linker" is gcc.
sub extract_from_file {
my ($file, $rx, $default) = @_;
open my $fh, '<', $file or die "Can't open $file: $!";
while (<$fh>) {
my @got = $_ =~ $rx;
return wantarray ? @got : $got[0]
if @got;
}
return $default if defined $default;
return;
}
sub clean {
if ($options{clean}) {
# Needed, because files that are build products in this checked out
# version might be in git in the next desired version.
system 'git clean -dxf';
# Needed, because at some revisions the build alters checked out files.
# (eg pod/perlapi.pod). Also undoes any changes to makedepend.SH
system 'git reset --hard HEAD';
}
}
sub skip {
my $reason = shift;
clean();
warn "skipping - $reason";
exit 125;
}
sub report_and_exit {
my ($ret, $pass, $fail, $desc) = @_;
clean();
my $got = ($options{'expect-pass'} ? !$ret : $ret) ? 'good' : 'bad';
if ($ret) {
print "$got - $fail $desc\n";
} else {
print "$got - $pass $desc\n";
}
exit($got eq 'bad');
}
sub apply_patch {
my $patch = shift;
open my $fh, '|-', 'patch' or die "Can't run patch: $!";
print $fh $patch;
close $fh or die "Can't patch perl.c: $?, $!";
}
# Not going to assume that system perl is yet new enough to have autodie
system 'git clean -dxf' and die;
if ($match) {
my $matches;
my $re = qr/$match/;
foreach my $file (`git ls-files`) {
chomp $file;
open my $fh, '<', $file or die "Can't open $file: $!";
while (<$fh>) {
if ($_ =~ $re) {
++$matches;
$_ .= "\n" unless /\n\z/;
print "$file: $_";
}
}
close $fh or die "Can't close $file: $!";
}
report_and_exit(!$matches, 'matches for', 'no matches for', $match);
}
skip('no Configure - is this the //depot/perlext/Compiler branch?')
unless -f 'Configure';
# This changes to PERL_VERSION in 4d8076ea25903dcb in 1999
my $major
= extract_from_file('patchlevel.h',
qr/^#define\s+(?:PERL_VERSION|PATCHLEVEL)\s+(\d+)\s/,
0);
if ($major < 1) {
if (extract_from_file('Configure',
qr/^ \*=\*\) echo "\$1" >> \$optdef;;$/)) {
# This is " Spaces now allowed in -D command line options.",
# part of commit ecfc54246c2a6f42
apply_patch(<<'EOPATCH');
diff --git a/Configure b/Configure
index 3d3b38d..78ffe16 100755
--- a/Configure
+++ b/Configure
@@ -652,7 +777,8 @@ while test $# -gt 0; do
echo "$me: use '-U symbol=', not '-D symbol='." >&2
echo "$me: ignoring -D $1" >&2
;;
- *=*) echo "$1" >> $optdef;;
+ *=*) echo "$1" | \
+ sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> $optdef;;
*) echo "$1='define'" >> $optdef;;
esac
shift
EOPATCH
}
if (extract_from_file('Configure', qr/^if \$contains 'd_namlen' \$xinc\b/)) {
# Configure's original simple "grep" for d_namlen falls foul of the
# approach taken by the glibc headers:
# #ifdef _DIRENT_HAVE_D_NAMLEN
# # define _D_EXACT_NAMLEN(d) ((d)->d_namlen)
#
# where _DIRENT_HAVE_D_NAMLEN is not defined on Linux.
# This is also part of commit ecfc54246c2a6f42
apply_patch(<<'EOPATCH');
diff --git a/Configure b/Configure
index 3d3b38d..78ffe16 100755
--- a/Configure
+++ b/Configure
@@ -3935,7 +4045,8 @@ $rm -f try.c
: see if the directory entry stores field length
echo " "
-if $contains 'd_namlen' $xinc >/dev/null 2>&1; then
+$cppstdin $cppflags $cppminus < "$xinc" > try.c
+if $contains 'd_namlen' try.c >/dev/null 2>&1; then
echo "Good, your directory entry keeps length information in d_namlen." >&4
val="$define"
else
EOPATCH
}
}
# There was a bug in makedepend.SH which was fixed in version 96a8704c.
# Symptom was './makedepend: 1: Syntax error: Unterminated quoted string'
# Remove this if you're actually bisecting a problem related to makedepend.SH
system 'git show blead:makedepend.SH > makedepend.SH' and die;
# if Encode is not needed for the test, you can speed up the bisect by
# excluding it from the runs with -Dnoextensions=Encode
# ccache is an easy win. Remove it if it causes problems.
# Commit 1cfa4ec74d4933da adds ignore_versioned_solibs to Configure, and sets it
# to true in hints/linux.sh
# On dromedary, from that point on, Configure (by default) fails to find any
# libraries, because it scans /usr/local/lib /lib /usr/lib, which only contain
# versioned libraries. Without -lm, the build fails.
# Telling /usr/local/lib64 /lib64 /usr/lib64 works from that commit onwards,
# until commit faae14e6e968e1c0 adds it to the hints.
# However, prior to 1cfa4ec74d4933da telling Configure the truth doesn't work,
# because it will spot versioned libraries, pass them to the compiler, and then
# bail out pretty early on. Configure won't let us override libswanted, but it
# will let us override the entire libs list.
unless (extract_from_file('Configure', 'ignore_versioned_solibs')) {
# Before 1cfa4ec74d4933da, so force the libs list.
my @libs;
# This is the current libswanted list from Configure, less the libs removed
# by current hints/linux.sh
foreach my $lib (qw(sfio socket inet nsl nm ndbm gdbm dbm db malloc dl dld
ld sun m crypt sec util c cposix posix ucb BSD)) {
foreach my $dir (@paths) {
next unless -f "$dir/lib$lib.so";
push @libs, "-l$lib";
last;
}
}
$defines{libs} = \@libs unless exists $defines{libs};
}
# This seems to be necessary to avoid makedepend becoming confused, and hanging
# on stdin. Seems that the code after make shlist || ...here... is never run.
$defines{trnl} = q{'\n'}
if $major < 4 && !exists $defines{trnl};
$defines{usenm} = undef
if $major < 2 && !exists $defines{usenm};
my (@missing, @created_dirs);
if ($options{'force-manifest'}) {
open my $fh, '<', 'MANIFEST'
or die "Could not open MANIFEST: $!";
while (<$fh>) {
next unless /^(\S+)/;
push @missing, $1
unless -f $1;
}
close $fh or die "Can't close MANIFEST: $!";
foreach my $pathname (@missing) {
my @parts = split '/', $pathname;
my $leaf = pop @parts;
my $path = '.';
while (@parts) {
$path .= '/' . shift @parts;
next if -d $path;
mkdir $path, 0700 or die "Can't create $path: $!";
unshift @created_dirs, $path;
}
open $fh, '>', $pathname or die "Can't open $pathname: $!";
close $fh or die "Can't close $pathname: $!";
chmod 0, $pathname or die "Can't chmod 0 $pathname: $!";
}
}
my @ARGS = $target eq 'config.sh' ? '-dEs' : '-des';
foreach my $key (sort keys %defines) {
my $val = $defines{$key};
if (ref $val) {
push @ARGS, "-D$key=@$val";
} elsif (!defined $val) {
push @ARGS, "-U$key";
} elsif (!length $val) {
push @ARGS, "-D$key";
} else {
$val = "" if $val eq "\0";
push @ARGS, "-D$key=$val";
}
}
push @ARGS, map {"-A$_"} @{$options{A}};
# </dev/null because it seems that some earlier versions of Configure can
# call commands in a way that now has them reading from stdin (and hanging)
my $pid = fork;
die "Can't fork: $!" unless defined $pid;
if (!$pid) {
# Before dfe9444ca7881e71, Configure would refuse to run if stdin was not a
# tty. With that commit, the tty requirement was dropped for -de and -dE
if($major > 4) {
open STDIN, '<', '/dev/null';
} elsif (!$options{'force-manifest'}) {
# If a file in MANIFEST is missing, Configure asks if you want to
# continue (the default being 'n'). With stdin closed or /dev/null,
# it exit immediately and the check for config.sh below will skip.
# To avoid a hang, we need to check MANIFEST for ourselves, and skip
# if anything is missing.
open my $fh, '<', 'MANIFEST';
skip("Could not open MANIFEST: $!")
unless $fh;
while (<$fh>) {
next unless /^(\S+)/;
skip("$1 from MANIFEST doesn't exist")
unless -f $1;
}
close $fh or die "Can't close MANIFEST: $!";
}
exec './Configure', @ARGS;
die "Failed to start Configure: $!";
}
waitpid $pid, 0
or die "wait for Configure, pid $pid failed: $!";
if ($target eq 'config.sh') {
report_and_exit(!-f $target, 'could build', 'could not build', $target);
} elsif (!-f 'config.sh') {
# Skip if something went wrong with Configure
skip('could not build config.sh');
}
# This is probably way too paranoid:
if (@missing) {
my @errors;
foreach my $file (@missing) {
my (undef, undef, $mode, undef, undef, undef, undef, $size)
= stat $file;
if (!defined $mode) {
push @errors, "Added file $file has been deleted by Configure";
next;
}
if ($mode != 0) {
push @errors,
sprintf 'Added file %s had mode changed by Configure to %03o',
$file, $mode;
}
if ($size != 0) {
push @errors,
"Added file $file had sized changed by Configure to $size";
}
unlink $file or die "Can't unlink $file: $!";
}
foreach my $dir (@created_dirs) {
rmdir $dir or die "Can't rmdir $dir: $!";
}
skip("@errors")
if @errors;
}
# Correct makefile for newer GNU gcc
# Only really needed if you comment out the use of blead's makedepend.SH
{
local $^I = "";
local @ARGV = qw(makefile x2p/makefile);
while (<>) {
print unless /<(?:built-in|command|stdin)/;
}
}
if ($major == 2 && extract_from_file('perl.c', qr/^ fclose\(e_fp\);$/)) {
# need to patch perl.c to avoid calling fclose() twice on e_fp when using -e
# This diff is part of commit ab821d7fdc14a438. The second close was
# introduced with perl-5.002, commit a5f75d667838e8e7
# Might want a6c477ed8d4864e6 too, for the corresponding change to pp_ctl.c
# (likely without this, eval will have "fun")
apply_patch(<<'EOPATCH');
diff --git a/perl.c b/perl.c
index 03c4d48..3c814a2 100644
--- a/perl.c
+++ b/perl.c
@@ -252,6 +252,7 @@ setuid perl scripts securely.\n");
#ifndef VMS /* VMS doesn't have environ array */
origenviron = environ;
#endif
+ e_tmpname = Nullch;
if (do_undump) {
@@ -405,6 +406,7 @@ setuid perl scripts securely.\n");
if (e_fp) {
if (Fflush(e_fp) || ferror(e_fp) || fclose(e_fp))
croak("Can't write to temp file for -e: %s", Strerror(errno));
+ e_fp = Nullfp;
argc++,argv--;
scriptname = e_tmpname;
}
@@ -470,10 +472,10 @@ setuid perl scripts securely.\n");
curcop->cop_line = 0;
curstash = defstash;
preprocess = FALSE;
- if (e_fp) {
- fclose(e_fp);
- e_fp = Nullfp;
+ if (e_tmpname) {
(void)UNLINK(e_tmpname);
+ Safefree(e_tmpname);
+ e_tmpname = Nullch;
}
/* now that script is parsed, we can modify record separator */
@@ -1369,7 +1371,7 @@ SV *sv;
scriptname = xfound;
}
- origfilename = savepv(e_fp ? "-e" : scriptname);
+ origfilename = savepv(e_tmpname ? "-e" : scriptname);
curcop->cop_filegv = gv_fetchfile(origfilename);
if (strEQ(origfilename,"-"))
scriptname = "";
EOPATCH
}
# Parallel build for miniperl is safe
system "make $j miniperl";
if ($target ne 'miniperl') {
# Nearly all parallel build issues fixed by 5.10.0. Untrustworthy before that.
$j = '' unless $major > 10;
if ($target eq 'test_prep') {
if ($major < 8) {
# test-prep was added in 5.004_01, 3e3baf6d63945cb6.
# renamed to test_prep in 2001 in 5fe84fd29acaf55c.
# earlier than that, just make test. It will be fast enough.
$target = extract_from_file('Makefile.SH', qr/^(test[-_]prep):/,
'test');
}
}
system "make $j $target";
}
my $missing_target = $expected =~ /perl$/ ? !-x $expected : !-r $expected;
if ($options{'test-build'}) {
report_and_exit($missing_target, 'could build', 'could not build', $target);
} elsif ($missing_target) {
skip("could not build $target");
}
# This is what we came here to run:
my $ret = system @ARGV;
report_and_exit($ret, 'zero exit from', 'non-zero exit from', "@ARGV");
# Local variables:
# cperl-indent-level: 4
# indent-tabs-mode: nil
# End:
#
# ex: set ts=8 sts=4 sw=4 et:
|