Commit | Line | Data |
---|---|---|
6a8dbfd7 NC |
1 | #!/usr/bin/perl -w |
2 | use strict; | |
3 | ||
390a69a9 | 4 | use Getopt::Long qw(:config bundling no_auto_abbrev); |
77ae6092 | 5 | use Pod::Usage; |
2526f4b8 | 6 | use Config; |
56bdf8a7 | 7 | use File::Temp qw(tempdir); |
effe640e | 8 | use File::Spec; |
6a8dbfd7 | 9 | |
2526f4b8 | 10 | my @targets |
3f468b94 | 11 | = qw(none config.sh config.h miniperl lib/Config.pm Fcntl perl test_prep); |
6a8dbfd7 | 12 | |
f4800c99 NC |
13 | my %options = |
14 | ( | |
f4800c99 NC |
15 | 'expect-pass' => 1, |
16 | clean => 1, # mostly for debugging this | |
17 | ); | |
6a8dbfd7 | 18 | |
e3caab27 NC |
19 | # We accept #!./miniperl and #!./perl |
20 | # We don't accept #!miniperl and #!perl as their intent is ambiguous | |
21 | my $run_with_our_perl = qr{\A#!(\./(?:mini)?perl)\b}; | |
22 | ||
fdbac266 NC |
23 | my $linux64 = `uname -sm` eq "Linux x86_64\n" ? '64' : ''; |
24 | ||
599ee4f7 NC |
25 | my @paths; |
26 | ||
27 | if ($^O eq 'linux') { | |
28 | # This is the search logic for a multi-arch library layout | |
29 | # added to linux.sh in commits 40f026236b9959b7 and dcffd848632af2c7. | |
30 | my $gcc = -x '/usr/bin/gcc' ? '/usr/bin/gcc' : 'gcc'; | |
31 | ||
32 | foreach (`$gcc -print-search-dirs`) { | |
33 | next unless /^libraries: =(.*)/; | |
34 | foreach (split ':', $1) { | |
35 | next if m/gcc/; | |
36 | next unless -d $_; | |
37 | s!/$!!; | |
38 | push @paths, $_; | |
39 | } | |
40 | } | |
8b569238 NC |
41 | push @paths, map {$_ . $linux64} qw(/usr/local/lib /lib /usr/lib) |
42 | if $linux64; | |
599ee4f7 NC |
43 | } |
44 | ||
390a69a9 NC |
45 | my %defines = |
46 | ( | |
47 | usedevel => '', | |
48 | optimize => '-g', | |
9913adee | 49 | ld => 'cc', |
8b569238 | 50 | (@paths ? (libpth => \@paths) : ()), |
390a69a9 NC |
51 | ); |
52 | ||
8b569238 NC |
53 | # Needed for the 'ignore_versioned_solibs' emulation below. |
54 | push @paths, qw(/usr/local/lib /lib /usr/lib) | |
55 | unless $linux64; | |
56 | ||
f4800c99 | 57 | unless(GetOptions(\%options, |
f624cb73 | 58 | 'target=s', 'make=s', 'jobs|j=i', 'crash', 'expect-pass=i', |
f4800c99 | 59 | 'expect-fail' => sub { $options{'expect-pass'} = 0; }, |
dd686e56 | 60 | 'clean!', 'one-liner|e=s@', 'c', 'l', 'w', 'match=s', |
66b521dd NC |
61 | 'no-match=s' => sub { |
62 | $options{match} = $_[1]; | |
63 | $options{'expect-pass'} = 0; | |
64 | }, | |
1fdd0dcc | 65 | 'force-manifest', 'force-regen', 'setpgrp!', 'timeout=i', |
b9dcd8de | 66 | 'test-build', 'validate', |
54c7e1f0 | 67 | 'all-fixups', 'early-fixup=s@', 'late-fixup=s@', 'valgrind', |
02b83d1d | 68 | 'check-args', 'check-shebang!', 'usage|help|?', 'gold=s', |
c5134773 | 69 | 'module=s', 'with-module=s', 'cpan-config-dir=s', |
02b83d1d | 70 | 'A=s@', |
390a69a9 NC |
71 | 'D=s@' => sub { |
72 | my (undef, $val) = @_; | |
73 | if ($val =~ /\A([^=]+)=(.*)/s) { | |
74 | $defines{$1} = length $2 ? $2 : "\0"; | |
75 | } else { | |
76 | $defines{$val} = ''; | |
77 | } | |
78 | }, | |
79 | 'U=s@' => sub { | |
80 | $defines{$_[1]} = undef; | |
81 | }, | |
6a8dbfd7 | 82 | )) { |
77ae6092 | 83 | pod2usage(exitval => 255, verbose => 1); |
6a8dbfd7 NC |
84 | } |
85 | ||
0bc550ba | 86 | my ($target, $match) = @options{qw(target match)}; |
e295b7be | 87 | |
b826a648 NC |
88 | @ARGV = ('sh', '-c', 'cd t && ./perl TEST base/*.t') |
89 | if $options{validate} && !@ARGV; | |
90 | ||
8fc3c209 | 91 | pod2usage(exitval => 0, verbose => 2) if $options{usage}; |
06a5399c NC |
92 | |
93 | # This needs to be done before the next arguments check, as it's populating | |
94 | # @ARGV | |
95 | if (defined $target && $target =~ /\.t\z/) { | |
96 | # t/TEST don't have a reliable way to run the test script under valgrind | |
97 | # The $ENV{VALGRIND} code was only added after v5.8.0, and is more | |
98 | # geared to logging than to exiting on failure if errors are found. | |
99 | # I guess one could fudge things by replacing the symlink t/perl with a | |
100 | # wrapper script which invokes valgrind, but leave doing that until | |
101 | # someone needs it. (If that's you, then patches welcome.) | |
102 | foreach (qw(valgrind match validate test-build one-liner)) { | |
103 | die_255("$0: Test-case targets can't be run with --$_") | |
104 | if $options{$_}; | |
105 | } | |
df99f62f | 106 | die_255("$0: Test-case targets can't be combined with an explicit test") |
06a5399c NC |
107 | if @ARGV; |
108 | ||
109 | # Needing this unless is a smell suggesting that this implementation of | |
110 | # test-case targets is not really in the right place. | |
111 | unless ($options{'check-args'}) { | |
112 | # The top level sanity tests refuse to start or end a test run at a | |
113 | # revision which skips, hence this test ensures reasonable sanity at | |
114 | # automatically picking a suitable start point for both normal operation | |
115 | # and --expect-fail | |
116 | skip("Test case $target is not a readable file") | |
117 | unless -f $target && -r _; | |
118 | } | |
119 | ||
120 | # t/TEST runs from and takes pathnames relative to t/, so need to strip | |
121 | # out a leading t, or add ../ otherwise | |
122 | unless ($target =~ s!\At/!!) { | |
123 | $target = "../$target"; | |
124 | } | |
125 | @ARGV = ('sh', '-c', "cd t && ./perl TEST " . quotemeta $target); | |
126 | $target = 'test_prep'; | |
127 | } | |
128 | ||
77ae6092 | 129 | pod2usage(exitval => 255, verbose => 1) |
56bdf8a7 | 130 | unless @ARGV || $match || $options{'test-build'} || defined $options{'one-liner'} || defined $options{module}; |
fc4401c6 NC |
131 | pod2usage(exitval => 255, verbose => 1) |
132 | if !$options{'one-liner'} && ($options{l} || $options{w}); | |
6a8dbfd7 | 133 | |
bf8fb529 NC |
134 | check_shebang($ARGV[0]) |
135 | if $options{'check-shebang'} && @ARGV && !$options{match}; | |
7cffc32d | 136 | |
f4800c99 | 137 | exit 0 if $options{'check-args'}; |
6a8dbfd7 | 138 | |
77ae6092 NC |
139 | =head1 NAME |
140 | ||
141 | bisect.pl - use git bisect to pinpoint changes | |
142 | ||
143 | =head1 SYNOPSIS | |
144 | ||
8b523b63 KW |
145 | # When did this become an error? |
146 | .../Porting/bisect.pl -e 'my $a := 2;' | |
147 | # When did this stop being an error? | |
148 | .../Porting/bisect.pl --expect-fail -e '1 // 2' | |
149 | # When did this test start failing? | |
150 | .../Porting/bisect.pl --target t/op/sort.t | |
151 | # When were all lines matching this pattern removed from all files? | |
152 | .../Porting/bisect.pl --match '\b(?:PL_)hash_seed_set\b' | |
153 | # When was some line matching this pattern added to some file? | |
154 | .../Porting/bisect.pl --expect-fail --match '\buseithreads\b' | |
155 | # When did this test program stop exiting 0? | |
156 | .../Porting/bisect.pl -- ./perl -Ilib ../test_prog.pl | |
157 | # When did this test program start crashing (any signal or coredump)? | |
158 | .../Porting/bisect.pl --crash -- ./perl -Ilib ../test_prog.pl | |
159 | # When did this first become valid syntax? | |
160 | .../Porting/bisect.pl --target=miniperl --end=v5.10.0 \ | |
161 | --expect-fail -e 'my $a := 2;' | |
162 | # What was the last revision to build with these options? | |
163 | .../Porting/bisect.pl --test-build -Dd_dosuid | |
164 | # When did this test program start generating errors from valgrind? | |
165 | .../Porting/bisect.pl --valgrind ../test_prog.pl | |
56bdf8a7 MH |
166 | # When did these cpan modules start failing to compile/pass tests? |
167 | .../Porting/bisect.pl --module=autobox,Moose | |
4b71a10e MH |
168 | # When did this code stop working in blead with these modules? |
169 | .../Porting/bisect.pl --with-module=Moose,Moo -e 'use Moose; 1;' | |
c5134773 MH |
170 | # Like the above 2 but with custom CPAN::MyConfig |
171 | .../Porting/bisect.pl --module=Moo --cpan-config-dir=/home/blah/custom/ | |
77ae6092 NC |
172 | |
173 | =head1 DESCRIPTION | |
174 | ||
facd1b88 | 175 | Together F<bisect.pl> and F<bisect-runner.pl> attempt to automate the use |
77ae6092 NC |
176 | of C<git bisect> as much as possible. With one command (and no other files) |
177 | it's easy to find out | |
178 | ||
179 | =over 4 | |
180 | ||
181 | =item * | |
182 | ||
183 | Which commit caused this example code to break? | |
184 | ||
185 | =item * | |
186 | ||
187 | Which commit caused this example code to start working? | |
188 | ||
189 | =item * | |
190 | ||
a9b1bbfe | 191 | Which commit added the first file to match this regex? |
77ae6092 NC |
192 | |
193 | =item * | |
194 | ||
a9b1bbfe | 195 | Which commit removed the last file to match this regex? |
77ae6092 NC |
196 | |
197 | =back | |
198 | ||
199 | usually without needing to know which versions of perl to use as start and | |
200 | end revisions. | |
201 | ||
facd1b88 | 202 | By default F<bisect.pl> will process all options, then use the rest of the |
77ae6092 NC |
203 | command line as arguments to list C<system> to run a test case. By default, |
204 | the test case should pass (exit with 0) on earlier perls, and fail (exit | |
06a5399c NC |
205 | non-zero) on I<blead>. F<bisect.pl> will use F<bisect-runner.pl> to find the |
206 | earliest stable perl version on which the test case passes, check that it | |
207 | fails on blead, and then use F<bisect-runner.pl> with C<git bisect run> to | |
208 | find the commit which caused the failure. | |
209 | ||
210 | Many of perl's own test scripts exit 0 even if their TAP reports test | |
211 | failures, and some need particular setup (such as running from the right | |
212 | directory, or adding C<-T> to the command line). Hence if you want to bisect | |
213 | a test script, you can specify it with the I<--target> option, and it will | |
214 | be invoked using F<t/TEST> which performs all the setup, and exits non-zero | |
215 | if the TAP reports failures. This works for any file ending C<.t>, so you can | |
216 | use it with a file outside of the working checkout, for example to test a | |
217 | particular version of a test script, as a path inside the repository will | |
218 | (of course) be testing the version of the script checked out for the current | |
219 | revision, which may be too early to have the test you are interested in. | |
77ae6092 NC |
220 | |
221 | Because the test case is the complete argument to C<system>, it is easy to | |
222 | run something other than the F<perl> built, if necessary. If you need to run | |
e3caab27 NC |
223 | the perl built, you'll probably need to invoke it as C<./perl -Ilib ...>. |
224 | As a special case, if the first argument of the test case is a readable file | |
225 | (whether executable or not), matching C<qr{\A#!./(?:mini)?perl\b}> then it | |
226 | will have C<./perl> <-Ilib> (or C<./miniperl>) prepended to it. | |
77ae6092 | 227 | |
91bcfbd8 NC |
228 | You need a clean checkout to run a bisect. You can use the checkout |
229 | containing F<Porting/bisect.pl> if you wish - in this case | |
230 | F<Porting/bisect.pl> will copy F<Porting/bisect-runner.pl> to a temporary | |
231 | file generated by C<File::Temp::tempfile()>. If doing this, beware that when | |
232 | the bisect ends (or you abort it) then your checkout is no longer at | |
233 | C<blead>, so you will need to C<git checkout blead> before restarting, to | |
234 | get the current version of F<Porting/bisect.pl> again. It's often easier | |
235 | either to copy F<Porting/bisect.pl> and F<Porting/bisect-runner.pl> to | |
236 | another directory (I<e.g.> F<~/bin>, if you have one), or to create a second | |
237 | git repository for running bisect. To create a second local repository, if | |
238 | your working checkout is called F<perl>, a simple solution is to make a | |
239 | local clone, and run from that. I<i.e.>: | |
5842706e NC |
240 | |
241 | cd .. | |
242 | git clone perl perl2 | |
243 | cd perl2 | |
244 | ../perl/Porting/bisect.pl ... | |
245 | ||
facd1b88 | 246 | By default, F<bisect-runner.pl> will automatically disable the build of |
cfadff5f NC |
247 | L<DB_File> for commits earlier than ccb44e3bf3be2c30, as it's not practical |
248 | to patch DB_File 1.70 and earlier to build with current Berkeley DB headers. | |
249 | (ccb44e3bf3be2c30 was in September 1999, between 5.005_62 and 5.005_63.) | |
250 | If your F<db.h> is old enough you can override this with C<-Unoextensions>. | |
251 | ||
77ae6092 NC |
252 | =head1 OPTIONS |
253 | ||
254 | =over 4 | |
255 | ||
256 | =item * | |
257 | ||
258 | --start I<commit-ish> | |
259 | ||
260 | Earliest revision to test, as a I<commit-ish> (a tag, commit or anything | |
facd1b88 | 261 | else C<git> understands as a revision). If not specified, F<bisect.pl> will |
91bcfbd8 NC |
262 | search stable .0 perl releases until it finds one where the test case |
263 | passes. The default is to search from 5.002 to the most recent tagged stable | |
264 | release (v5.18.0 at the time of writing). If F<bisect.pl> detects that the | |
f66c64b1 NC |
265 | checkout is on a case insensitive file system, it will search from 5.005 to |
266 | the most recent tagged stable release. Only .0 stable releases are used | |
267 | because these are the only stable releases that are parents of blead, and | |
268 | hence suitable for a bisect run. | |
77ae6092 NC |
269 | |
270 | =item * | |
271 | ||
272 | --end I<commit-ish> | |
273 | ||
274 | Most recent revision to test, as a I<commit-ish>. If not specified, defaults | |
b4f0ec5f | 275 | to I<blead>. |
77ae6092 NC |
276 | |
277 | =item * | |
278 | ||
279 | --target I<target> | |
280 | ||
281 | F<Makefile> target (or equivalent) needed, to run the test case. If specified, | |
282 | this should be one of | |
283 | ||
284 | =over 4 | |
285 | ||
286 | =item * | |
287 | ||
3f468b94 NC |
288 | I<none> |
289 | ||
290 | Don't build anything - just run the user test case against a clean checkout. | |
291 | Using this gives a couple of features that a plain C<git bisect run> can't | |
292 | offer - automatic start revision detection, and test case C<--timeout>. | |
293 | ||
294 | =item * | |
295 | ||
77ae6092 NC |
296 | I<config.sh> |
297 | ||
facd1b88 | 298 | Just run F<./Configure> |
77ae6092 NC |
299 | |
300 | =item * | |
301 | ||
302 | I<config.h> | |
303 | ||
304 | Run the various F<*.SH> files to generate F<Makefile>, F<config.h>, I<etc>. | |
305 | ||
306 | =item * | |
307 | ||
308 | I<miniperl> | |
309 | ||
310 | Build F<miniperl>. | |
311 | ||
312 | =item * | |
313 | ||
314 | I<lib/Config.pm> | |
315 | ||
316 | Use F<miniperl> to build F<lib/Config.pm> | |
317 | ||
318 | =item * | |
319 | ||
2526f4b8 NC |
320 | I<Fcntl> |
321 | ||
322 | Build F<lib/auto/Fcntl/Fnctl.so> (strictly, C<.$Config{so}>). As L<Fcntl> | |
323 | is simple XS module present since 5.000, this provides a fast test of | |
b4f0ec5f | 324 | whether XS modules can be built. Note, XS modules are built by F<miniperl>, |
2526f4b8 NC |
325 | hence this target will not build F<perl>. |
326 | ||
327 | =item * | |
328 | ||
77ae6092 NC |
329 | I<perl> |
330 | ||
331 | Build F<perl>. This also builds pure-Perl modules in F<cpan>, F<dist> and | |
2526f4b8 NC |
332 | F<ext>. XS modules (such as L<Fcntl>) are not built. |
333 | ||
334 | =item * | |
335 | ||
77ae6092 NC |
336 | I<test_prep> |
337 | ||
338 | Build everything needed to run the tests. This is the default if we're | |
339 | running test code, but is time consuming, as it means building all | |
b4f0ec5f | 340 | XS modules. For older F<Makefile>s, the previous name of C<test-prep> |
77ae6092 NC |
341 | is automatically substituted. For very old F<Makefile>s, C<make test> is |
342 | run, as there is no target provided to just get things ready, and for 5.004 | |
343 | and earlier the tests run very quickly. | |
344 | ||
06a5399c NC |
345 | =item * |
346 | ||
347 | A file ending C<.t> | |
348 | ||
349 | Build everything needed to run the tests, and then run this test script using | |
350 | F<t/TEST>. This is actually implemented internally by using the target | |
351 | I<test_prep>, and setting the test case to "sh", "-c", "cd t && ./TEST ..." | |
352 | ||
77ae6092 NC |
353 | =back |
354 | ||
355 | =item * | |
356 | ||
357 | --one-liner 'code to run' | |
358 | ||
359 | =item * | |
360 | ||
361 | -e 'code to run' | |
362 | ||
a1756669 | 363 | Example code to run, just like you'd use with C<perl -e>. |
77ae6092 NC |
364 | |
365 | This prepends C<./perl -Ilib -e 'code to run'> to the test case given, | |
facd1b88 | 366 | or F<./miniperl> if I<target> is C<miniperl>. |
77ae6092 NC |
367 | |
368 | (Usually you'll use C<-e> instead of providing a test case in the | |
dd686e56 NC |
369 | non-option arguments to F<bisect.pl>. You can repeat C<-e> on the command |
370 | line, just like you can with C<perl>) | |
77ae6092 NC |
371 | |
372 | C<-E> intentionally isn't supported, as it's an error in 5.8.0 and earlier, | |
373 | which interferes with detecting errors in the example code itself. | |
374 | ||
375 | =item * | |
376 | ||
529d2ac2 NC |
377 | -c |
378 | ||
379 | Add C<-c> to the command line, to cause perl to exit after syntax checking. | |
380 | ||
381 | =item * | |
382 | ||
fc4401c6 NC |
383 | -l |
384 | ||
385 | Add C<-l> to the command line with C<-e> | |
386 | ||
387 | This will automatically append a newline to every output line of your testcase. | |
388 | Note that you can't specify an argument to F<perl>'s C<-l> with this, as it's | |
389 | not feasible to emulate F<perl>'s somewhat quirky switch parsing with | |
390 | L<Getopt::Long>. If you need the full flexibility of C<-l>, you need to write | |
391 | a full test case, instead of using C<bisect.pl>'s C<-e> shortcut. | |
392 | ||
393 | =item * | |
394 | ||
395 | -w | |
396 | ||
397 | Add C<-w> to the command line with C<-e> | |
398 | ||
529d2ac2 NC |
399 | It's not valid to pass C<-c>, C<-l> or C<-w> to C<bisect.pl> unless you are |
400 | also using C<-e> | |
fc4401c6 NC |
401 | |
402 | =item * | |
403 | ||
77ae6092 NC |
404 | --expect-fail |
405 | ||
406 | The test case should fail for the I<start> revision, and pass for the I<end> | |
407 | revision. The bisect run will find the first commit where it passes. | |
408 | ||
409 | =item * | |
410 | ||
f624cb73 HS |
411 | --crash |
412 | ||
413 | Treat any non-crash as success, any crash as failure. (Crashing defined | |
414 | as exiting with a signal or a core dump.) | |
415 | ||
416 | =item * | |
417 | ||
28c4aad0 | 418 | -D I<config_arg=value> |
77ae6092 NC |
419 | |
420 | =item * | |
421 | ||
28c4aad0 | 422 | -U I<config_arg> |
77ae6092 NC |
423 | |
424 | =item * | |
425 | ||
28c4aad0 | 426 | -A I<config_arg=value> |
77ae6092 | 427 | |
28c4aad0 DM |
428 | Arguments (C<-A>, C<-D>, C<-U>) to pass to F<Configure>. For example, |
429 | ||
430 | -Dnoextensions=Encode | |
431 | -Uusedevel | |
432 | -Accflags=-DNO_MATHOMS | |
433 | ||
434 | Repeated C<-A> arguments are passed | |
77ae6092 | 435 | through as is. C<-D> and C<-U> are processed in order, and override |
af7c500f NC |
436 | previous settings for the same parameter. F<bisect-runner.pl> emulates |
437 | C<-Dnoextensions> when F<Configure> itself does not provide it, as it's | |
438 | often very useful to be able to disable some XS extensions. | |
77ae6092 NC |
439 | |
440 | =item * | |
441 | ||
32ffe018 NC |
442 | --make I<make-prog> |
443 | ||
444 | The C<make> command to use. If this not set, F<make> is used. If this is | |
445 | set, it also adds a C<-Dmake=...> else some recursive make invocations | |
446 | in extensions may fail. Typically one would use this as C<--make gmake> | |
447 | to use F<gmake> in place of the system F<make>. | |
448 | ||
449 | =item * | |
450 | ||
b4f0ec5f | 451 | --jobs I<jobs> |
77ae6092 NC |
452 | |
453 | =item * | |
454 | ||
b4f0ec5f | 455 | -j I<jobs> |
77ae6092 | 456 | |
d3232d34 NC |
457 | Number of C<make> jobs to run in parallel. A value of 0 suppresses |
458 | parallelism. If F</proc/cpuinfo> exists and can be parsed, or F</sbin/sysctl> | |
459 | exists and reports C<hw.ncpu>, or F</usr/bin/getconf> exists and reports | |
460 | C<_NPROCESSORS_ONLN> defaults to 1 + I<number of CPUs>. On HP-UX with the | |
461 | system make defaults to 0, otherwise defaults to 2. | |
77ae6092 NC |
462 | |
463 | =item * | |
464 | ||
b4f0ec5f | 465 | --match pattern |
77ae6092 | 466 | |
66b521dd NC |
467 | =item * |
468 | ||
469 | --no-match pattern | |
470 | ||
471 | Instead of running a test program to determine I<pass> or I<fail>, | |
472 | C<--match> will pass if the given regex matches, and hence search for the | |
473 | commit that removes the last matching file. C<--no-match> inverts the test, | |
474 | to search for the first commit that adds files that match. | |
bf8fb529 NC |
475 | |
476 | The remaining command line arguments are treated as glob patterns for files | |
477 | to match against. If none are specified, then they default as follows: | |
478 | ||
479 | =over 4 | |
480 | ||
481 | =item * | |
77ae6092 NC |
482 | |
483 | If no I<target> is specified, the match is against all files in the | |
bf8fb529 NC |
484 | repository (which is fast). |
485 | ||
486 | =item * | |
487 | ||
488 | If a I<target> is specified, that target is built, and the match is against | |
489 | only the built files. | |
490 | ||
491 | =back | |
492 | ||
493 | Treating the command line arguments as glob patterns should not cause | |
494 | problems, as the perl distribution has never shipped or built files with | |
495 | names that contain characters which are globbing metacharacters. | |
496 | ||
497 | Anything which is not a readable file is ignored, instead of generating an | |
498 | error. (If you want an error, run C<grep> or C<ack> as a test case). This | |
499 | permits one to easily search in a file that changed its name. For example: | |
500 | ||
501 | .../Porting/bisect.pl --match 'Pod.*Functions' 'pod/buildtoc*' | |
77ae6092 | 502 | |
66b521dd NC |
503 | C<--no-match ...> is implemented as C<--expect-fail --match ...> |
504 | ||
77ae6092 NC |
505 | =item * |
506 | ||
54c7e1f0 NC |
507 | --valgrind |
508 | ||
509 | Run the test program under C<valgrind>. If you need to test for memory | |
510 | errors when parsing invalid programs, the default parser fail exit code of | |
511 | 255 will always override C<valgrind>, so try putting the test case invalid | |
512 | code inside a I<string> C<eval>, so that the perl interpreter will exit with 0. | |
513 | (Be sure to check the output of $@, to avoid missing mistakes such as | |
514 | unintended C<eval> failures due to incorrect C<@INC>) | |
515 | ||
516 | Specifically, this option prepends C<valgrind> C<--error-exitcode=124> to | |
517 | the command line that runs the testcase, to cause valgrind to exit non-zero | |
518 | if it detects errors, with the assumption that the test program itself | |
519 | always exits with zero. If you require more flexibility than this, either | |
520 | specify your C<valgrind> invocation explicitly as part of the test case, or | |
521 | use a wrapper script to control the command line or massage the exit codes. | |
522 | ||
523 | =item * | |
524 | ||
77ae6092 NC |
525 | --test-build |
526 | ||
527 | Test that the build completes, without running any test case. | |
528 | ||
529 | By default, if the build for the desired I<target> fails to complete, | |
530 | F<bisect-runner.pl> reports a I<skip> back to C<git bisect>, the assumption | |
531 | being that one wants to find a commit which changed state "builds && passes" | |
532 | to "builds && fails". If instead one is interested in which commit broke the | |
533 | build (possibly for particular F<Configure> options), use I<--test-build> | |
534 | to treat a build failure as a failure, not a "skip". | |
535 | ||
b4f0ec5f NC |
536 | Often this option isn't as useful as it first seems, because I<any> build |
537 | failure will be reported to C<git bisect> as a failure, not just the failure | |
538 | that you're interested in. Generally, to debug a particular problem, it's | |
539 | more useful to use a I<target> that builds properly at the point of interest, | |
540 | and then a test case that runs C<make>. For example: | |
541 | ||
542 | .../Porting/bisect.pl --start=perl-5.000 --end=perl-5.002 \ | |
543 | --expect-fail --force-manifest --target=miniperl make perl | |
544 | ||
facd1b88 NC |
545 | will find the first revision capable of building L<DynaLoader> and then |
546 | F<perl>, without becoming confused by revisions where F<miniperl> won't | |
b4f0ec5f NC |
547 | even link. |
548 | ||
77ae6092 NC |
549 | =item * |
550 | ||
56bdf8a7 MH |
551 | --module module1,module2,... |
552 | ||
553 | Install this (or these) module(s), die when it (the last of those) | |
554 | cannot be updated to the current version. | |
555 | ||
556 | Misnomer. the argument can be any argument that can be passed to CPAN | |
557 | shell's install command. B<But>: since we only have the uptodate | |
558 | command to verify that an install has taken place, we are unable to | |
559 | determine success for arguments like | |
560 | MSCHWERN/Test-Simple-1.005000_005.tar.gz. | |
561 | ||
562 | In so far, it is not such a misnomer. | |
563 | ||
6f8f872e | 564 | Note that this and I<--with-module> will both require a C<CPAN::MyConfig>. |
63caac63 | 565 | If F<$ENV{HOME}/.cpan/CPAN/MyConfig.pm> does not exist, a CPAN shell will |
fbaf6793 MH |
566 | be started up for you so you can configure one. Feel free to let |
567 | CPAN pick defaults for you. Enter 'quit' when you are done, and | |
c5134773 | 568 | then everything should be all set. Alternatively, you may |
6f8f872e | 569 | specify a custom C<CPAN::MyConfig> by using I<--cpan-config-dir>. |
fbaf6793 | 570 | |
120bcf3c MH |
571 | Also, if you want to bisect a module that needs a display (like |
572 | TK) and you don't want random screens appearing and disappearing | |
573 | on your computer while you're working, you can do something like | |
574 | this: | |
575 | ||
576 | In a terminal: | |
577 | ||
e7b6553a KW |
578 | $ while true; do date ; if ! ps auxww | grep -v grep \ |
579 | | grep -q Xvfb; then Xvfb :121 & fi; echo -n 'sleeping 60 '; \ | |
580 | sleep 60; done | |
120bcf3c MH |
581 | |
582 | And then: | |
583 | ||
584 | DISPLAY=":121" .../Porting/bisect.pl --module=TK | |
585 | ||
586 | (Some display alternatives are vncserver and Xnest.) | |
587 | ||
56bdf8a7 MH |
588 | =item * |
589 | ||
4b71a10e MH |
590 | --with-module module1,module2,... |
591 | ||
6f8f872e | 592 | Like I<--module> above, except this simply installs the requested |
4b71a10e MH |
593 | modules and they can then be used in other tests. |
594 | ||
595 | For example: | |
596 | ||
597 | .../Porting/bisect.pl --with-module=Moose -e 'use Moose; ...' | |
598 | ||
599 | =item * | |
600 | ||
c5134773 MH |
601 | --cpan-config-dir /home/blah/custom |
602 | ||
603 | If defined, this will cause L<CPAN> to look for F<CPAN/MyConfig.pm> inside of | |
604 | the specified directory, instead of using the default config of | |
605 | F<$ENV{HOME}/.cpan/>. | |
606 | ||
607 | If no default config exists, a L<CPAN> shell will be fired up for you to | |
608 | configure things. Letting L<CPAN> automatically configure things for you | |
609 | should work well enough. You probably want to choose I<manual> instead of | |
610 | I<local::lib> if it asks. When you're finished with configuration, just | |
611 | type I<q> and hit I<ENTER> and the bisect should continue. | |
612 | ||
613 | =item * | |
614 | ||
b4f0ec5f NC |
615 | --force-manifest |
616 | ||
77ae6092 NC |
617 | By default, a build will "skip" if any files listed in F<MANIFEST> are not |
618 | present. Usually this is useful, as it avoids false-failures. However, there | |
619 | are some long ranges of commits where listed files are missing, which can | |
620 | cause a bisect to abort because all that remain are skipped revisions. | |
621 | ||
622 | In these cases, particularly if the test case uses F<miniperl> and no modules, | |
623 | it may be more useful to force the build to continue, even if files | |
624 | F<MANIFEST> are missing. | |
625 | ||
626 | =item * | |
627 | ||
bfa52998 NC |
628 | --force-regen |
629 | ||
630 | Run C<make regen_headers> before building F<miniperl>. This may fix a build | |
631 | that otherwise would skip because the generated headers at that revision | |
632 | are stale. It's not the default because it conceals this error in the true | |
633 | state of such revisions. | |
634 | ||
635 | =item * | |
636 | ||
77ae6092 NC |
637 | --expect-pass [0|1] |
638 | ||
639 | C<--expect-pass=0> is equivalent to C<--expect-fail>. I<1> is the default. | |
640 | ||
641 | =item * | |
642 | ||
1fdd0dcc NC |
643 | --timeout I<seconds> |
644 | ||
645 | Run the testcase with the given timeout. If this is exceeded, kill it (and | |
646 | by default all its children), and treat it as a failure. | |
647 | ||
648 | =item * | |
649 | ||
b9dcd8de NC |
650 | --setpgrp |
651 | ||
652 | Run the testcase in its own process group. Specifically, call C<setpgrp 0, 0> | |
1fdd0dcc NC |
653 | just before C<exec>-ing the user testcase. The default is not to set the |
654 | process group, unless a timeout is used. | |
b9dcd8de NC |
655 | |
656 | =item * | |
657 | ||
86905c1e NC |
658 | --all-fixups |
659 | ||
660 | F<bisect-runner.pl> will minimally patch various files on a platform and | |
661 | version dependent basis to get the build to complete. Normally it defers | |
662 | doing this as long as possible - C<.SH> files aren't patched until after | |
663 | F<Configure> is run, and C<C> and C<XS> code isn't patched until after | |
664 | F<miniperl> is built. If C<--all-fixups> is specified, all the fixups are | |
665 | done before running C<Configure>. In rare cases adding this may cause a | |
666 | bisect to abort, because an inapplicable patch or other fixup is attempted | |
6c728274 | 667 | for a revision which would usually have already I<skip>ped. If this happens, |
86905c1e NC |
668 | please report it as a bug, giving the OS and problem revision. |
669 | ||
670 | =item * | |
671 | ||
df14fc13 NC |
672 | --early-fixup file |
673 | ||
674 | =item * | |
675 | ||
676 | --late-fixup file | |
677 | ||
678 | Specify a file containing a patch or other fixup for the source code. The | |
679 | action to take depends on the first line of the fixup file | |
680 | ||
681 | =over 4 | |
682 | ||
683 | =item * | |
684 | ||
685 | C<#!perl> | |
686 | ||
687 | If the first line starts C<#!perl> then the file is run using C<$^X> | |
688 | ||
689 | =item * | |
690 | ||
691 | C<#!/absolute/path> | |
692 | ||
693 | If a shebang line is present the file is executed using C<system> | |
694 | ||
695 | =item * | |
696 | ||
697 | C<I<filename> =~ /I<pattern>/> | |
698 | ||
699 | =item * | |
700 | ||
701 | C<I<filename> !~ /I<pattern>/> | |
702 | ||
703 | If I<filename> does not exist then the fixup file's contents are ignored. | |
704 | Otherwise, for C<=~>, if it contains a line matching I<pattern>, then the | |
705 | file is fed to C<patch -p1> on standard input. For C<=~>, the patch is | |
706 | applied if no lines match the pattern. | |
707 | ||
708 | As the empty pattern in Perl is a special case (it matches the most recent | |
8c09dc11 | 709 | successful match) which is not useful here, the treatment of an empty pattern |
df14fc13 NC |
710 | is special-cased. C<I<filename> =~ //> applies the patch if filename is |
711 | present. C<I<filename> !~ //> applies the patch if filename missing. This | |
712 | makes it easy to unconditionally apply patches to files, and to use a patch | |
713 | as a way of creating a new file. | |
714 | ||
715 | =item * | |
716 | ||
717 | Otherwise, the file is assumed to be a patch, and always applied. | |
718 | ||
719 | =back | |
720 | ||
721 | I<early-fixup>s are applied before F<./Configure> is run. I<late-fixup>s are | |
722 | applied just after F<./Configure> is run. | |
723 | ||
724 | These options can be specified more than once. I<file> is actually expanded | |
725 | as a glob pattern. Globs that do not match are errors, as are missing files. | |
726 | ||
727 | =item * | |
728 | ||
77ae6092 NC |
729 | --no-clean |
730 | ||
731 | Tell F<bisect-runner.pl> not to clean up after the build. This allows one | |
732 | to use F<bisect-runner.pl> to build the current particular perl revision for | |
733 | interactive testing, or for debugging F<bisect-runner.pl>. | |
734 | ||
735 | Passing this to F<bisect.pl> will likely cause the bisect to fail badly. | |
736 | ||
737 | =item * | |
738 | ||
195ed8b1 NC |
739 | --validate |
740 | ||
f66c64b1 NC |
741 | Test that all stable (.0) revisions can be built. By default, attempts to |
742 | build I<blead>, then tagged stable releases in reverse order down to | |
743 | I<perl-5.002> (or I<perl5.005> on a case insensitive file system). Stops at | |
744 | the first failure, without cleaning the checkout. Use I<--start> to specify | |
745 | the earliest revision to test, I<--end> to specify the most recent. Useful | |
746 | for validating a new OS/CPU/compiler combination. For example | |
195ed8b1 | 747 | |
fc4401c6 | 748 | ../perl/Porting/bisect.pl --validate -le 'print "Hello from $]"' |
195ed8b1 | 749 | |
e2760528 NC |
750 | If no testcase is specified, the default is to use F<t/TEST> to run |
751 | F<t/base/*.t> | |
752 | ||
195ed8b1 NC |
753 | =item * |
754 | ||
77ae6092 NC |
755 | --check-args |
756 | ||
757 | Validate the options and arguments, and exit silently if they are valid. | |
758 | ||
759 | =item * | |
760 | ||
7cffc32d NC |
761 | --check-shebang |
762 | ||
763 | Validate that the test case isn't an executable file with a | |
764 | C<#!/usr/bin/perl> line (or similar). As F<bisect-runner.pl> does B<not> | |
e3caab27 NC |
765 | automatically prepend C<./perl> to the test case, a I<#!> line specifying an |
766 | external F<perl> binary will cause the test case to always run with I<that> | |
767 | F<perl>, not the F<perl> built by the bisect runner. Likely this is not what | |
768 | you wanted. If your test case is actually a wrapper script to run other | |
7cffc32d NC |
769 | commands, you should run it with an explicit interpreter, to be clear. For |
770 | example, instead of C<../perl/Porting/bisect.pl ~/test/testcase.pl> you'd | |
771 | run C<../perl/Porting/bisect.pl /usr/bin/perl ~/test/testcase.pl> | |
772 | ||
773 | =item * | |
774 | ||
02b83d1d NC |
775 | --gold |
776 | ||
777 | Revision to use when checking out known-good recent versions of files, | |
778 | such as F<makedepend.SH>. F<bisect-runner.pl> defaults this to I<blead>, | |
779 | but F<bisect.pl> will default it to the most recent stable release. | |
780 | ||
781 | =item * | |
782 | ||
77ae6092 NC |
783 | --usage |
784 | ||
785 | =item * | |
786 | ||
787 | --help | |
788 | ||
789 | =item * | |
790 | ||
791 | -? | |
792 | ||
793 | Display the usage information and exit. | |
794 | ||
795 | =back | |
796 | ||
797 | =cut | |
798 | ||
f6647108 NC |
799 | # Ensure we always exit with 255, to cause git bisect to abort. |
800 | sub croak_255 { | |
801 | my $message = join '', @_; | |
802 | if ($message =~ /\n\z/) { | |
803 | print STDERR $message; | |
804 | } else { | |
805 | my (undef, $file, $line) = caller 1; | |
806 | print STDERR "@_ at $file line $line\n"; | |
807 | } | |
808 | exit 255; | |
809 | } | |
810 | ||
811 | sub die_255 { | |
812 | croak_255(@_); | |
813 | } | |
814 | ||
815 | die_255("$0: Can't build $target") | |
816 | if defined $target && !grep {@targets} $target; | |
6a8dbfd7 | 817 | |
df14fc13 NC |
818 | foreach my $phase (qw(early late)) { |
819 | next unless $options{"$phase-fixup"}; | |
820 | my $bail_out; | |
821 | require File::Glob; | |
822 | my @expanded; | |
823 | foreach my $glob (@{$options{"$phase-fixup"}}) { | |
824 | my @got = File::Glob::bsd_glob($glob); | |
825 | push @expanded, @got ? @got : $glob; | |
826 | } | |
827 | @expanded = sort @expanded; | |
828 | $options{"$phase-fixup"} = \@expanded; | |
829 | foreach (@expanded) { | |
830 | unless (-f $_) { | |
831 | print STDERR "$phase-fixup '$_' is not a readable file\n"; | |
832 | ++$bail_out; | |
833 | } | |
834 | } | |
835 | exit 255 if $bail_out; | |
836 | } | |
837 | ||
8f13c642 NC |
838 | unless (exists $defines{cc}) { |
839 | # If it fails, the heuristic of 63f9ec3008baf7d6 is noisy, and hence | |
c34d8429 | 840 | # confusing. |
8f13c642 NC |
841 | # FIXME - really it should be replaced with a proper test of |
842 | # "can we build something?" and a helpful diagnostic if we can't. | |
843 | # For now, simply move it here. | |
c34d8429 | 844 | $defines{cc} = (`ccache -V`, $?) ? 'cc' : 'ccache cc'; |
8f13c642 NC |
845 | } |
846 | ||
0bc550ba | 847 | my $j = $options{jobs} ? "-j$options{jobs}" : ''; |
6a8dbfd7 | 848 | |
32ffe018 NC |
849 | if (exists $options{make}) { |
850 | if (!exists $defines{make}) { | |
851 | $defines{make} = $options{make}; | |
852 | } | |
853 | } else { | |
854 | $options{make} = 'make'; | |
855 | } | |
856 | ||
0142f0ce NC |
857 | # Sadly, however hard we try, I don't think that it will be possible to build |
858 | # modules in ext/ on x86_64 Linux before commit e1666bf5602ae794 on 1999/12/29, | |
859 | # which updated to MakeMaker 3.7, which changed from using a hard coded ld | |
860 | # in the Makefile to $(LD). On x86_64 Linux the "linker" is gcc. | |
861 | ||
69bf9aba NC |
862 | sub open_or_die { |
863 | my $file = shift; | |
864 | my $mode = @_ ? shift : '<'; | |
f6647108 | 865 | open my $fh, $mode, $file or croak_255("Can't open $file: $!"); |
69bf9aba NC |
866 | ${*$fh{SCALAR}} = $file; |
867 | return $fh; | |
868 | } | |
869 | ||
870 | sub close_or_die { | |
871 | my $fh = shift; | |
872 | return if close $fh; | |
f6647108 NC |
873 | croak_255("Can't close: $!") unless ref $fh eq 'GLOB'; |
874 | croak_255("Can't close ${*$fh{SCALAR}}: $!"); | |
69bf9aba NC |
875 | } |
876 | ||
d953d40d NC |
877 | sub system_or_die { |
878 | my $command = '</dev/null ' . shift; | |
f6647108 | 879 | system($command) and croak_255("'$command' failed, \$!=$!, \$?=$?"); |
d953d40d NC |
880 | } |
881 | ||
12641c3b NC |
882 | sub run_with_options { |
883 | my $options = shift; | |
884 | my $name = $options->{name}; | |
885 | $name = "@_" unless defined $name; | |
886 | ||
1fdd0dcc NC |
887 | my $setgrp = $options->{setpgrp}; |
888 | if ($options->{timeout}) { | |
889 | # Unless you explicitly disabled it on the commandline, set it: | |
890 | $setgrp = 1 unless defined $setgrp; | |
891 | } | |
12641c3b NC |
892 | my $pid = fork; |
893 | die_255("Can't fork: $!") unless defined $pid; | |
894 | if (!$pid) { | |
895 | if (exists $options->{stdin}) { | |
896 | open STDIN, '<', $options->{stdin} | |
1fdd0dcc | 897 | or die "Can't open STDIN from $options->{stdin}: $!"; |
12641c3b | 898 | } |
1fdd0dcc | 899 | if ($setgrp) { |
b9dcd8de NC |
900 | setpgrp 0, 0 |
901 | or die "Can't setpgrp 0, 0: $!"; | |
902 | } | |
12641c3b NC |
903 | { exec @_ }; |
904 | die_255("Failed to start $name: $!"); | |
905 | } | |
1fdd0dcc NC |
906 | my $start; |
907 | if ($options->{timeout}) { | |
908 | require Errno; | |
909 | require POSIX; | |
910 | die_255("No POSIX::WNOHANG") | |
911 | unless &POSIX::WNOHANG; | |
912 | $start = time; | |
913 | $SIG{ALRM} = sub { | |
914 | my $victim = $setgrp ? -$pid : $pid; | |
915 | my $delay = 1; | |
916 | kill 'TERM', $victim; | |
917 | waitpid(-1, &POSIX::WNOHANG); | |
918 | while (kill 0, $victim) { | |
919 | sleep $delay; | |
920 | waitpid(-1, &POSIX::WNOHANG); | |
921 | $delay *= 2; | |
922 | if ($delay > 8) { | |
923 | if (kill 'KILL', $victim) { | |
924 | print STDERR "$0: Had to kill 'KILL', $victim\n" | |
925 | } elsif (! $!{ESRCH}) { | |
926 | print STDERR "$0: kill 'KILL', $victim failed: $!\n"; | |
927 | } | |
928 | last; | |
929 | } | |
930 | } | |
931 | report_and_exit(0, 'No timeout', 'Timeout', "when running $name"); | |
932 | }; | |
933 | alarm $options->{timeout}; | |
934 | } | |
12641c3b | 935 | waitpid $pid, 0 |
1fdd0dcc NC |
936 | or die_255("wait for $name, pid $pid failed: $!"); |
937 | alarm 0; | |
938 | if ($options->{timeout}) { | |
939 | my $elapsed = time - $start; | |
940 | if ($elapsed / $options->{timeout} > 0.8) { | |
941 | print STDERR "$0: Beware, took $elapsed seconds of $options->{timeout} permitted to run $name\n"; | |
942 | } | |
943 | } | |
12641c3b NC |
944 | return $?; |
945 | } | |
946 | ||
6a8dbfd7 NC |
947 | sub extract_from_file { |
948 | my ($file, $rx, $default) = @_; | |
69bf9aba | 949 | my $fh = open_or_die($file); |
6a8dbfd7 NC |
950 | while (<$fh>) { |
951 | my @got = $_ =~ $rx; | |
952 | return wantarray ? @got : $got[0] | |
953 | if @got; | |
954 | } | |
955 | return $default if defined $default; | |
956 | return; | |
957 | } | |
958 | ||
c59e8fd6 NC |
959 | sub edit_file { |
960 | my ($file, $munger) = @_; | |
961 | local $/; | |
69bf9aba | 962 | my $fh = open_or_die($file); |
c59e8fd6 | 963 | my $orig = <$fh>; |
f6647108 | 964 | die_255("Can't read $file: $!") unless defined $orig && close $fh; |
c59e8fd6 NC |
965 | my $new = $munger->($orig); |
966 | return if $new eq $orig; | |
69bf9aba | 967 | $fh = open_or_die($file, '>'); |
f6647108 | 968 | print $fh $new or die_255("Can't print to $file: $!"); |
69bf9aba | 969 | close_or_die($fh); |
c59e8fd6 NC |
970 | } |
971 | ||
6fe55cbd NC |
972 | # AIX supplies a pre-historic patch program, which certainly predates Linux |
973 | # and is probably older than NT. It can't cope with unified diffs. Meanwhile, | |
974 | # it's hard enough to get git diff to output context diffs, let alone git show, | |
975 | # and nearly all the patches embedded here are unified. So it seems that the | |
976 | # path of least resistance is to convert unified diffs to context diffs: | |
977 | ||
978 | sub process_hunk { | |
979 | my ($from_out, $to_out, $has_from, $has_to, $delete, $add) = @_; | |
980 | ++$$has_from if $delete; | |
981 | ++$$has_to if $add; | |
982 | ||
983 | if ($delete && $add) { | |
984 | $$from_out .= "! $_\n" foreach @$delete; | |
985 | $$to_out .= "! $_\n" foreach @$add; | |
986 | } elsif ($delete) { | |
987 | $$from_out .= "- $_\n" foreach @$delete; | |
988 | } elsif ($add) { | |
989 | $$to_out .= "+ $_\n" foreach @$add; | |
990 | } | |
991 | } | |
992 | ||
993 | # This isn't quite general purpose, as it can't cope with | |
994 | # '\ No newline at end of file' | |
995 | sub ud2cd { | |
996 | my $diff_in = shift; | |
997 | my $diff_out = ''; | |
998 | ||
999 | # Stuff before the diff | |
1000 | while ($diff_in =~ s/\A(?!\*\*\* )(?!--- )([^\n]*\n?)//ms && length $1) { | |
1001 | $diff_out .= $1; | |
1002 | } | |
1003 | ||
1004 | if (!length $diff_in) { | |
f6647108 | 1005 | die_255("That didn't seem to be a diff"); |
6fe55cbd NC |
1006 | } |
1007 | ||
1008 | if ($diff_in =~ /\A\*\*\* /ms) { | |
1009 | warn "Seems to be a context diff already\n"; | |
1010 | return $diff_out . $diff_in; | |
1011 | } | |
1012 | ||
1013 | # Loop for files | |
1014 | FILE: while (1) { | |
1015 | if ($diff_in =~ s/\A((?:diff |index )[^\n]+\n)//ms) { | |
1016 | $diff_out .= $1; | |
1017 | next; | |
1018 | } | |
1019 | if ($diff_in !~ /\A--- /ms) { | |
1020 | # Stuff after the diff; | |
1021 | return $diff_out . $diff_in; | |
1022 | } | |
1023 | $diff_in =~ s/\A([^\n]+\n?)//ms; | |
1024 | my $line = $1; | |
f6647108 | 1025 | die_255("Can't parse '$line'") unless $line =~ s/\A--- /*** /ms; |
6fe55cbd NC |
1026 | $diff_out .= $line; |
1027 | $diff_in =~ s/\A([^\n]+\n?)//ms; | |
1028 | $line = $1; | |
f6647108 | 1029 | die_255("Can't parse '$line'") unless $line =~ s/\A\+\+\+ /--- /ms; |
6fe55cbd NC |
1030 | $diff_out .= $line; |
1031 | ||
1032 | # Loop for hunks | |
1033 | while (1) { | |
1034 | next FILE | |
1035 | unless $diff_in =~ s/\A\@\@ (-([0-9]+),([0-9]+) \+([0-9]+),([0-9]+)) \@\@[^\n]*\n?//; | |
1036 | my ($hunk, $from_start, $from_count, $to_start, $to_count) | |
1037 | = ($1, $2, $3, $4, $5); | |
1038 | my $from_end = $from_start + $from_count - 1; | |
1039 | my $to_end = $to_start + $to_count - 1; | |
1040 | my ($from_out, $to_out, $has_from, $has_to, $add, $delete); | |
1041 | while (length $diff_in && ($from_count || $to_count)) { | |
f6647108 NC |
1042 | die_255("Confused in $hunk") |
1043 | unless $diff_in =~ s/\A([^\n]*)\n//ms; | |
6fe55cbd NC |
1044 | my $line = $1; |
1045 | $line = ' ' unless length $line; | |
1046 | if ($line =~ /^ .*/) { | |
1047 | process_hunk(\$from_out, \$to_out, \$has_from, \$has_to, | |
1048 | $delete, $add); | |
1049 | undef $delete; | |
1050 | undef $add; | |
1051 | $from_out .= " $line\n"; | |
1052 | $to_out .= " $line\n"; | |
1053 | --$from_count; | |
1054 | --$to_count; | |
1055 | } elsif ($line =~ /^-(.*)/) { | |
1056 | push @$delete, $1; | |
1057 | --$from_count; | |
1058 | } elsif ($line =~ /^\+(.*)/) { | |
1059 | push @$add, $1; | |
1060 | --$to_count; | |
1061 | } else { | |
f6647108 | 1062 | die_255("Can't parse '$line' as part of hunk $hunk"); |
6fe55cbd NC |
1063 | } |
1064 | } | |
1065 | process_hunk(\$from_out, \$to_out, \$has_from, \$has_to, | |
1066 | $delete, $add); | |
f6647108 | 1067 | die_255("No lines in hunk $hunk") |
6fe55cbd | 1068 | unless length $from_out || length $to_out; |
f6647108 | 1069 | die_255("No changes in hunk $hunk") |
6fe55cbd NC |
1070 | unless $has_from || $has_to; |
1071 | $diff_out .= "***************\n"; | |
1072 | $diff_out .= "*** $from_start,$from_end ****\n"; | |
1073 | $diff_out .= $from_out if $has_from; | |
1074 | $diff_out .= "--- $to_start,$to_end ----\n"; | |
1075 | $diff_out .= $to_out if $has_to; | |
1076 | } | |
1077 | } | |
1078 | } | |
1079 | ||
1080 | { | |
1081 | my $use_context; | |
1082 | ||
1083 | sub placate_patch_prog { | |
1084 | my $patch = shift; | |
1085 | ||
1086 | if (!defined $use_context) { | |
1087 | my $version = `patch -v 2>&1`; | |
f6647108 | 1088 | die_255("Can't run `patch -v`, \$?=$?, bailing out") |
6fe55cbd NC |
1089 | unless defined $version; |
1090 | if ($version =~ /Free Software Foundation/) { | |
1091 | $use_context = 0; | |
1092 | } elsif ($version =~ /Header: patch\.c,v.*\blwall\b/) { | |
1093 | # The system patch is older than Linux, and probably older than | |
1094 | # Windows NT. | |
1095 | $use_context = 1; | |
ccb58ea9 NC |
1096 | } elsif ($version =~ /Header: patch\.c,v.*\babhinav\b/) { |
1097 | # Thank you HP. No, we have no idea *which* version this is: | |
1098 | # $Header: patch.c,v 76.1.1.2.1.3 2001/12/03 12:24:52 abhinav Exp $ | |
1099 | $use_context = 1; | |
6fe55cbd NC |
1100 | } else { |
1101 | # Don't know. | |
1102 | $use_context = 0; | |
1103 | } | |
1104 | } | |
1105 | ||
1106 | return $use_context ? ud2cd($patch) : $patch; | |
1107 | } | |
1108 | } | |
1109 | ||
c59e8fd6 | 1110 | sub apply_patch { |
58a28a53 NC |
1111 | my ($patch, $what, $files) = @_; |
1112 | $what = 'patch' unless defined $what; | |
1113 | unless (defined $files) { | |
bff4c287 | 1114 | $patch =~ m!^--- [ab]/(\S+)\n\+\+\+ [ba]/\1!sm; |
58a28a53 NC |
1115 | $files = " $1"; |
1116 | } | |
6fe55cbd | 1117 | my $patch_to_use = placate_patch_prog($patch); |
f6647108 | 1118 | open my $fh, '|-', 'patch', '-p1' or die_255("Can't run patch: $!"); |
6fe55cbd | 1119 | print $fh $patch_to_use; |
5fceabf3 NC |
1120 | return if close $fh; |
1121 | print STDERR "Patch is <<'EOPATCH'\n${patch}EOPATCH\n"; | |
56a20cc1 NC |
1122 | print STDERR "\nConverted to a context diff <<'EOCONTEXT'\n${patch_to_use}EOCONTEXT\n" |
1123 | if $patch_to_use ne $patch; | |
f6647108 | 1124 | die_255("Can't $what$files: $?, $!"); |
c59e8fd6 NC |
1125 | } |
1126 | ||
4e540a4e NC |
1127 | sub apply_commit { |
1128 | my ($commit, @files) = @_; | |
58a28a53 NC |
1129 | my $patch = `git show $commit @files`; |
1130 | if (!defined $patch) { | |
f6647108 NC |
1131 | die_255("Can't get commit $commit for @files: $?") if @files; |
1132 | die_255("Can't get commit $commit: $?"); | |
58a28a53 NC |
1133 | } |
1134 | apply_patch($patch, "patch $commit", @files ? " for @files" : ''); | |
4e540a4e NC |
1135 | } |
1136 | ||
1137 | sub revert_commit { | |
1138 | my ($commit, @files) = @_; | |
58a28a53 NC |
1139 | my $patch = `git show -R $commit @files`; |
1140 | if (!defined $patch) { | |
f6647108 NC |
1141 | die_255("Can't get revert commit $commit for @files: $?") if @files; |
1142 | die_255("Can't get revert commit $commit: $?"); | |
58a28a53 NC |
1143 | } |
1144 | apply_patch($patch, "revert $commit", @files ? " for @files" : ''); | |
4e540a4e NC |
1145 | } |
1146 | ||
91ad6f8a NC |
1147 | sub checkout_file { |
1148 | my ($file, $commit) = @_; | |
02b83d1d | 1149 | $commit ||= $options{gold} || 'blead'; |
91ad6f8a | 1150 | system "git show $commit:$file > $file </dev/null" |
f6647108 | 1151 | and die_255("Could not extract $file at revision $commit"); |
91ad6f8a NC |
1152 | } |
1153 | ||
7cffc32d NC |
1154 | sub check_shebang { |
1155 | my $file = shift; | |
1156 | return unless -e $file; | |
e3caab27 NC |
1157 | my $fh = open_or_die($file); |
1158 | my $line = <$fh>; | |
1159 | return if $line =~ $run_with_our_perl; | |
7cffc32d | 1160 | if (!-x $file) { |
f6647108 | 1161 | die_255("$file is not executable. |
7cffc32d NC |
1162 | system($file, ...) is always going to fail. |
1163 | ||
f6647108 | 1164 | Bailing out"); |
7cffc32d | 1165 | } |
7cffc32d | 1166 | return unless $line =~ m{\A#!(/\S+/perl\S*)\s}; |
f6647108 | 1167 | die_255("$file will always be run by $1 |
7cffc32d NC |
1168 | It won't be tested by the ./perl we build. |
1169 | If you intended to run it with that perl binary, please change your | |
1170 | test case to | |
1171 | ||
1172 | $1 @ARGV | |
1173 | ||
1174 | If you intended to test it with the ./perl we build, please change your | |
1175 | test case to | |
1176 | ||
1177 | ./perl -Ilib @ARGV | |
1178 | ||
1179 | [You may also need to add -- before ./perl to prevent that -Ilib as being | |
1180 | parsed as an argument to bisect.pl] | |
1181 | ||
f6647108 | 1182 | Bailing out"); |
7cffc32d NC |
1183 | } |
1184 | ||
ab4a15f9 | 1185 | sub clean { |
f4800c99 | 1186 | if ($options{clean}) { |
ab4a15f9 NC |
1187 | # Needed, because files that are build products in this checked out |
1188 | # version might be in git in the next desired version. | |
082484dd | 1189 | system 'git clean -qdxf </dev/null'; |
ab4a15f9 NC |
1190 | # Needed, because at some revisions the build alters checked out files. |
1191 | # (eg pod/perlapi.pod). Also undoes any changes to makedepend.SH | |
9da8cb0a | 1192 | system 'git reset --hard HEAD </dev/null'; |
ab4a15f9 NC |
1193 | } |
1194 | } | |
1195 | ||
1196 | sub skip { | |
1197 | my $reason = shift; | |
1198 | clean(); | |
1199 | warn "skipping - $reason"; | |
1200 | exit 125; | |
1201 | } | |
1202 | ||
f1050811 | 1203 | sub report_and_exit { |
37c43f74 | 1204 | my ($good, $pass, $fail, $desc) = @_; |
f1050811 NC |
1205 | |
1206 | clean(); | |
1207 | ||
37c43f74 NC |
1208 | my $got = ($options{'expect-pass'} ? $good : !$good) ? 'good' : 'bad'; |
1209 | if ($good) { | |
f1050811 | 1210 | print "$got - $pass $desc\n"; |
37c43f74 NC |
1211 | } else { |
1212 | print "$got - $fail $desc\n"; | |
f1050811 NC |
1213 | } |
1214 | ||
1215 | exit($got eq 'bad'); | |
1216 | } | |
1217 | ||
b518173e | 1218 | sub run_report_and_exit { |
1fdd0dcc NC |
1219 | my $ret = run_with_options({setprgp => $options{setpgrp}, |
1220 | timeout => $options{timeout}, | |
1221 | }, @_); | |
f624cb73 | 1222 | $ret &= 0xff if $options{crash}; |
37c43f74 | 1223 | report_and_exit(!$ret, 'zero exit from', 'non-zero exit from', "@_"); |
b518173e NC |
1224 | } |
1225 | ||
0afef97d | 1226 | sub match_and_exit { |
bf8fb529 | 1227 | my ($target, @globs) = @_; |
0afef97d NC |
1228 | my $matches = 0; |
1229 | my $re = qr/$match/; | |
1230 | my @files; | |
1231 | ||
bf8fb529 NC |
1232 | if (@globs) { |
1233 | require File::Glob; | |
1234 | foreach (sort map { File::Glob::bsd_glob($_)} @globs) { | |
1235 | if (!-f $_ || !-r _) { | |
1236 | warn "Skipping matching '$_' as it is not a readable file\n"; | |
1237 | } else { | |
1238 | push @files, $_; | |
1239 | } | |
1240 | } | |
1241 | } else { | |
0afef97d NC |
1242 | local $/ = "\0"; |
1243 | @files = defined $target ? `git ls-files -o -z`: `git ls-files -z`; | |
1244 | chomp @files; | |
1245 | } | |
1246 | ||
1247 | foreach my $file (@files) { | |
69bf9aba | 1248 | my $fh = open_or_die($file); |
0afef97d NC |
1249 | while (<$fh>) { |
1250 | if ($_ =~ $re) { | |
1251 | ++$matches; | |
72e11947 | 1252 | if (/[^[:^cntrl:]\h\v]/) { # Matches non-spacing non-C1 controls |
0afef97d NC |
1253 | print "Binary file $file matches\n"; |
1254 | } else { | |
1255 | $_ .= "\n" unless /\n\z/; | |
1256 | print "$file: $_"; | |
1257 | } | |
1258 | } | |
1259 | } | |
69bf9aba | 1260 | close_or_die($fh); |
0afef97d | 1261 | } |
37c43f74 | 1262 | report_and_exit($matches, |
0afef97d NC |
1263 | $matches == 1 ? '1 match for' : "$matches matches for", |
1264 | 'no matches for', $match); | |
1265 | } | |
1266 | ||
6a8dbfd7 | 1267 | # Not going to assume that system perl is yet new enough to have autodie |
d953d40d | 1268 | system_or_die('git clean -dxf'); |
6a8dbfd7 | 1269 | |
0afef97d | 1270 | if (!defined $target) { |
bf8fb529 | 1271 | match_and_exit(undef, @ARGV) if $match; |
0afef97d | 1272 | $target = 'test_prep'; |
3f468b94 NC |
1273 | } elsif ($target eq 'none') { |
1274 | match_and_exit(undef, @ARGV) if $match; | |
1275 | run_report_and_exit(@ARGV); | |
bc96a05a NC |
1276 | } |
1277 | ||
4b081584 NC |
1278 | skip('no Configure - is this the //depot/perlext/Compiler branch?') |
1279 | unless -f 'Configure'; | |
1280 | ||
1f1c8096 NC |
1281 | my $case_insensitive; |
1282 | { | |
1283 | my ($dev_C, $ino_C) = stat 'Configure'; | |
f6647108 | 1284 | die_255("Could not stat Configure: $!") unless defined $dev_C; |
1f1c8096 NC |
1285 | my ($dev_c, $ino_c) = stat 'configure'; |
1286 | ++$case_insensitive | |
1287 | if defined $dev_c && $dev_C == $dev_c && $ino_C == $ino_c; | |
1288 | } | |
1289 | ||
dbcdc176 NC |
1290 | # This changes to PERL_VERSION in 4d8076ea25903dcb in 1999 |
1291 | my $major | |
1292 | = extract_from_file('patchlevel.h', | |
1293 | qr/^#define\s+(?:PERL_VERSION|PATCHLEVEL)\s+(\d+)\s/, | |
1294 | 0); | |
1295 | ||
fbaecb45 NC |
1296 | my $unfixable_db_file; |
1297 | ||
1298 | if ($major < 10 | |
1299 | && !extract_from_file('ext/DB_File/DB_File.xs', | |
1300 | qr!^#else /\* Berkeley DB Version > 2 \*/$!)) { | |
1301 | # This DB_File.xs is really too old to patch up. | |
1302 | # Skip DB_File, unless we're invoked with an explicit -Unoextensions | |
1303 | if (!exists $defines{noextensions}) { | |
1304 | $defines{noextensions} = 'DB_File'; | |
1305 | } elsif (defined $defines{noextensions}) { | |
1306 | $defines{noextensions} .= ' DB_File'; | |
1307 | } | |
1308 | ++$unfixable_db_file; | |
1309 | } | |
1310 | ||
750ce942 NC |
1311 | patch_Configure(); |
1312 | patch_hints(); | |
86905c1e NC |
1313 | if ($options{'all-fixups'}) { |
1314 | patch_SH(); | |
1315 | patch_C(); | |
1316 | patch_ext(); | |
1317 | } | |
df14fc13 | 1318 | apply_fixups($options{'early-fixup'}); |
750ce942 | 1319 | |
6a8dbfd7 NC |
1320 | # if Encode is not needed for the test, you can speed up the bisect by |
1321 | # excluding it from the runs with -Dnoextensions=Encode | |
1322 | # ccache is an easy win. Remove it if it causes problems. | |
6a8dbfd7 NC |
1323 | # Commit 1cfa4ec74d4933da adds ignore_versioned_solibs to Configure, and sets it |
1324 | # to true in hints/linux.sh | |
1325 | # On dromedary, from that point on, Configure (by default) fails to find any | |
1326 | # libraries, because it scans /usr/local/lib /lib /usr/lib, which only contain | |
1327 | # versioned libraries. Without -lm, the build fails. | |
1328 | # Telling /usr/local/lib64 /lib64 /usr/lib64 works from that commit onwards, | |
1329 | # until commit faae14e6e968e1c0 adds it to the hints. | |
1330 | # However, prior to 1cfa4ec74d4933da telling Configure the truth doesn't work, | |
1331 | # because it will spot versioned libraries, pass them to the compiler, and then | |
1332 | # bail out pretty early on. Configure won't let us override libswanted, but it | |
1333 | # will let us override the entire libs list. | |
1334 | ||
40c94856 NC |
1335 | foreach (@{$options{A}}) { |
1336 | push @paths, $1 if /^libpth=(.*)/s; | |
1337 | } | |
1338 | ||
6a8dbfd7 NC |
1339 | unless (extract_from_file('Configure', 'ignore_versioned_solibs')) { |
1340 | # Before 1cfa4ec74d4933da, so force the libs list. | |
1341 | ||
1342 | my @libs; | |
1343 | # This is the current libswanted list from Configure, less the libs removed | |
1344 | # by current hints/linux.sh | |
665ff1e9 | 1345 | foreach my $lib (qw(sfio socket inet nsl nm ndbm gdbm dbm db malloc dl |
6a8dbfd7 NC |
1346 | ld sun m crypt sec util c cposix posix ucb BSD)) { |
1347 | foreach my $dir (@paths) { | |
40c94856 NC |
1348 | # Note the wonderful consistency of dot-or-not in the config vars: |
1349 | next unless -f "$dir/lib$lib.$Config{dlext}" | |
1350 | || -f "$dir/lib$lib$Config{lib_ext}"; | |
6a8dbfd7 NC |
1351 | push @libs, "-l$lib"; |
1352 | last; | |
1353 | } | |
1354 | } | |
390a69a9 | 1355 | $defines{libs} = \@libs unless exists $defines{libs}; |
6a8dbfd7 NC |
1356 | } |
1357 | ||
390a69a9 NC |
1358 | $defines{usenm} = undef |
1359 | if $major < 2 && !exists $defines{usenm}; | |
0142f0ce | 1360 | |
05ec8abc NC |
1361 | my ($missing, $created_dirs); |
1362 | ($missing, $created_dirs) = force_manifest() | |
1363 | if $options{'force-manifest'}; | |
67382a3b | 1364 | |
af7c500f | 1365 | my @ARGS = '-dEs'; |
390a69a9 NC |
1366 | foreach my $key (sort keys %defines) { |
1367 | my $val = $defines{$key}; | |
1368 | if (ref $val) { | |
1369 | push @ARGS, "-D$key=@$val"; | |
1370 | } elsif (!defined $val) { | |
1371 | push @ARGS, "-U$key"; | |
1372 | } elsif (!length $val) { | |
1373 | push @ARGS, "-D$key"; | |
1374 | } else { | |
1375 | $val = "" if $val eq "\0"; | |
1376 | push @ARGS, "-D$key=$val"; | |
1377 | } | |
1378 | } | |
1379 | push @ARGS, map {"-A$_"} @{$options{A}}; | |
1380 | ||
56bdf8a7 MH |
1381 | my $prefix; |
1382 | ||
63caac63 | 1383 | # Testing a module? We need to install perl/cpan modules to a temp dir |
4b71a10e | 1384 | if ($options{module} || $options{'with-module'}) { |
56bdf8a7 MH |
1385 | $prefix = tempdir(CLEANUP => 1); |
1386 | ||
1387 | push @ARGS, "-Dprefix=$prefix"; | |
1388 | push @ARGS, "-Uversiononly", "-Dinstallusrbinperl=n"; | |
1389 | } | |
1390 | ||
12641c3b NC |
1391 | # If a file in MANIFEST is missing, Configure asks if you want to |
1392 | # continue (the default being 'n'). With stdin closed or /dev/null, | |
1393 | # it exits immediately and the check for config.sh below will skip. | |
1394 | # Without redirecting stdin, the commands called will attempt to read from | |
1395 | # stdin (and thus effectively hang) | |
1396 | run_with_options({stdin => '/dev/null', name => 'Configure'}, | |
1397 | './Configure', @ARGS); | |
6a8dbfd7 | 1398 | |
86905c1e | 1399 | patch_SH() unless $options{'all-fixups'}; |
df14fc13 | 1400 | apply_fixups($options{'late-fixup'}); |
bb723266 | 1401 | |
16a77b27 | 1402 | if (-f 'config.sh' && $major < 10 && $defines{noextensions}) { |
05ec8abc | 1403 | # Emulate noextensions if Configure doesn't support it. |
16a77b27 | 1404 | fake_noextensions(); |
d953d40d | 1405 | system_or_die('./Configure -S'); |
af7c500f NC |
1406 | } |
1407 | ||
0afef97d | 1408 | if ($target =~ /config\.s?h/) { |
bf8fb529 | 1409 | match_and_exit($target, @ARGV) if $match && -f $target; |
37c43f74 | 1410 | report_and_exit(-f $target, 'could build', 'could not build', $target) |
30a13282 NC |
1411 | if $options{'test-build'}; |
1412 | ||
18815322 NC |
1413 | skip("could not build $target") unless -f $target; |
1414 | ||
b518173e | 1415 | run_report_and_exit(@ARGV); |
dd4e46d7 NC |
1416 | } elsif (!-f 'config.sh') { |
1417 | # Skip if something went wrong with Configure | |
1418 | ||
1419 | skip('could not build config.sh'); | |
1420 | } | |
6a8dbfd7 | 1421 | |
05ec8abc NC |
1422 | force_manifest_cleanup($missing, $created_dirs) |
1423 | if $missing; | |
67382a3b | 1424 | |
bfa52998 NC |
1425 | if($options{'force-regen'} |
1426 | && extract_from_file('Makefile', qr/\bregen_headers\b/)) { | |
1427 | # regen_headers was added in e50aee73b3d4c555, patch.1m for perl5.001 | |
1428 | # It's not worth faking it for earlier revisions. | |
d953d40d | 1429 | system_or_die('make regen_headers'); |
bfa52998 NC |
1430 | } |
1431 | ||
86905c1e NC |
1432 | unless ($options{'all-fixups'}) { |
1433 | patch_C(); | |
1434 | patch_ext(); | |
1435 | } | |
750ce942 NC |
1436 | |
1437 | # Parallel build for miniperl is safe | |
32ffe018 | 1438 | system "$options{make} $j miniperl </dev/null"; |
750ce942 | 1439 | |
6c2d645d NC |
1440 | # This is the file we expect make to create |
1441 | my $expected_file = $target =~ /^test/ ? 't/perl' | |
750ce942 NC |
1442 | : $target eq 'Fcntl' ? "lib/auto/Fcntl/Fcntl.$Config{so}" |
1443 | : $target; | |
6c2d645d NC |
1444 | # This is the target we tell make to build in order to get $expected_file |
1445 | my $real_target = $target eq 'Fcntl' ? $expected_file : $target; | |
750ce942 NC |
1446 | |
1447 | if ($target ne 'miniperl') { | |
1448 | # Nearly all parallel build issues fixed by 5.10.0. Untrustworthy before that. | |
1449 | $j = '' if $major < 10; | |
1450 | ||
1451 | if ($real_target eq 'test_prep') { | |
1452 | if ($major < 8) { | |
1453 | # test-prep was added in 5.004_01, 3e3baf6d63945cb6. | |
1454 | # renamed to test_prep in 2001 in 5fe84fd29acaf55c. | |
1455 | # earlier than that, just make test. It will be fast enough. | |
1456 | $real_target = extract_from_file('Makefile.SH', | |
1457 | qr/^(test[-_]prep):/, | |
1458 | 'test'); | |
1459 | } | |
1460 | } | |
1461 | ||
32ffe018 | 1462 | system "$options{make} $j $real_target </dev/null"; |
6f8c21fa NC |
1463 | } |
1464 | ||
56bdf8a7 | 1465 | # Testing a cpan module? See if it will install |
4b71a10e | 1466 | if ($options{module} || $options{'with-module'}) { |
56bdf8a7 MH |
1467 | # First we need to install this perl somewhere |
1468 | system_or_die('./installperl'); | |
1469 | ||
4b71a10e | 1470 | my @m = split(',', $options{module} || $options{'with-module'}); |
56bdf8a7 MH |
1471 | |
1472 | my $bdir = File::Temp::tempdir( | |
1473 | CLEANUP => 1, | |
1474 | ) or die $!; | |
1475 | ||
6822d2c9 MH |
1476 | # Don't ever stop to ask the user for input |
1477 | $ENV{AUTOMATED_TESTING} = 1; | |
1478 | $ENV{PERL_MM_USE_DEFAULT} = 1; | |
1479 | ||
176804e8 MH |
1480 | # Don't let these interfere with our cpan installs |
1481 | delete $ENV{PERL_MB_OPT}; | |
1482 | delete $ENV{PERL_MM_OPT}; | |
1483 | ||
effe640e MH |
1484 | # Make sure we load up our CPAN::MyConfig and then |
1485 | # override the build_dir so we have a fresh one | |
1486 | # every build | |
c5134773 MH |
1487 | my $cdir = $options{'cpan-config-dir'} |
1488 | || File::Spec->catfile($ENV{HOME},".cpan"); | |
effe640e | 1489 | |
56bdf8a7 MH |
1490 | my @cpanshell = ( |
1491 | "$prefix/bin/perl", | |
effe640e MH |
1492 | "-I", "$cdir", |
1493 | "-MCPAN::MyConfig", | |
56bdf8a7 MH |
1494 | "-MCPAN", |
1495 | "-e","\$CPAN::Config->{build_dir}=q{$bdir};", | |
1496 | "-e", | |
1497 | ); | |
1498 | ||
1499 | for (@m) { | |
1500 | s/-/::/g if /-/ and !m|/|; | |
1501 | } | |
1502 | my $install = join ",", map { "'$_'" } @m; | |
1503 | my $last = $m[-1]; | |
1504 | my $shellcmd = "install($install); die unless CPAN::Shell->expand(Module => '$last')->uptodate;"; | |
1505 | ||
4b71a10e MH |
1506 | if ($options{module}) { |
1507 | run_report_and_exit(@cpanshell, $shellcmd); | |
1508 | } else { | |
1509 | my $ret = run_with_options({setprgp => $options{setpgrp}, | |
1510 | timeout => $options{timeout}, | |
1511 | }, @cpanshell, $shellcmd); | |
1512 | $ret &= 0xff if $options{crash}; | |
1513 | ||
1514 | # Failed? Give up | |
1515 | if ($ret) { | |
1516 | report_and_exit(!$ret, 'zero exit from', 'non-zero exit from', "@_"); | |
1517 | } | |
1518 | } | |
56bdf8a7 MH |
1519 | } |
1520 | ||
6c2d645d NC |
1521 | my $expected_file_found = $expected_file =~ /perl$/ |
1522 | ? -x $expected_file : -r $expected_file; | |
750ce942 | 1523 | |
63af1e78 NC |
1524 | if ($expected_file_found && $expected_file eq 't/perl') { |
1525 | # Check that it isn't actually pointing to ../miniperl, which will happen | |
1526 | # if the sanity check ./miniperl -Ilib -MExporter -e '<?>' fails, and | |
1527 | # Makefile tries to run minitest. | |
1528 | ||
1529 | # Of course, helpfully sometimes it's called ../perl, other times .././perl | |
1530 | # and who knows if that list is exhaustive... | |
1531 | my ($dev0, $ino0) = stat 't/perl'; | |
1532 | my ($dev1, $ino1) = stat 'perl'; | |
1533 | unless (defined $dev0 && defined $dev1 && $dev0 == $dev1 && $ino0 == $ino1) { | |
1534 | undef $expected_file_found; | |
1535 | my $link = readlink $expected_file; | |
1536 | warn "'t/perl' => '$link', not 'perl'"; | |
f6647108 | 1537 | die_255("Could not realink t/perl: $!") unless defined $link; |
63af1e78 NC |
1538 | } |
1539 | } | |
1540 | ||
750ce942 | 1541 | if ($options{'test-build'}) { |
37c43f74 | 1542 | report_and_exit($expected_file_found, 'could build', 'could not build', |
750ce942 | 1543 | $real_target); |
6c2d645d | 1544 | } elsif (!$expected_file_found) { |
750ce942 | 1545 | skip("could not build $real_target"); |
f50dca98 NC |
1546 | } |
1547 | ||
bf8fb529 | 1548 | match_and_exit($real_target, @ARGV) if $match; |
750ce942 NC |
1549 | |
1550 | if (defined $options{'one-liner'}) { | |
1551 | my $exe = $target =~ /^(?:perl$|test)/ ? 'perl' : 'miniperl'; | |
dd686e56 | 1552 | unshift @ARGV, map {('-e', $_)} @{$options{'one-liner'}}; |
529d2ac2 NC |
1553 | foreach (qw(c l w)) { |
1554 | unshift @ARGV, "-$_" if $options{$_}; | |
1555 | } | |
fc4401c6 | 1556 | unshift @ARGV, "./$exe", '-Ilib'; |
f50dca98 NC |
1557 | } |
1558 | ||
e3caab27 NC |
1559 | if (-f $ARGV[0]) { |
1560 | my $fh = open_or_die($ARGV[0]); | |
1561 | my $line = <$fh>; | |
1562 | unshift @ARGV, $1, '-Ilib' | |
1563 | if $line =~ $run_with_our_perl; | |
1564 | } | |
1565 | ||
54c7e1f0 NC |
1566 | if ($options{valgrind}) { |
1567 | # Turns out to be too confusing to use an optional argument with the path | |
1568 | # of the valgrind binary, as if --valgrind takes an optional argument, | |
1569 | # then specifying it as the last option eats the first part of the testcase. | |
1570 | # ie this: .../bisect.pl --valgrind testcase | |
1571 | # is treated as --valgrind=testcase and as there is no test case given, | |
1572 | # it's an invalid commandline, bailing out with the usage message. | |
1573 | ||
1574 | # Currently, the test script can't signal a skip with 125, so anything | |
1575 | # non-zero would do. But to keep that option open in future, use 124 | |
1576 | unshift @ARGV, 'valgrind', '--error-exitcode=124'; | |
1577 | } | |
1578 | ||
750ce942 NC |
1579 | # This is what we came here to run: |
1580 | ||
1581 | if (exists $Config{ldlibpthname}) { | |
1582 | require Cwd; | |
1583 | my $varname = $Config{ldlibpthname}; | |
1584 | my $cwd = Cwd::getcwd(); | |
1585 | if (defined $ENV{$varname}) { | |
1586 | $ENV{$varname} = $cwd . $Config{path_sep} . $ENV{$varname}; | |
1587 | } else { | |
1588 | $ENV{$varname} = $cwd; | |
f50dca98 | 1589 | } |
750ce942 NC |
1590 | } |
1591 | ||
b518173e | 1592 | run_report_and_exit(@ARGV); |
750ce942 | 1593 | |
f2f0a0ff NC |
1594 | ############################################################################ |
1595 | # | |
05ec8abc | 1596 | # Patching, editing and faking routines only below here. |
f2f0a0ff NC |
1597 | # |
1598 | ############################################################################ | |
1599 | ||
05ec8abc NC |
1600 | sub fake_noextensions { |
1601 | edit_file('config.sh', sub { | |
1602 | my @lines = split /\n/, shift; | |
1603 | my @ext = split /\s+/, $defines{noextensions}; | |
1604 | foreach (@lines) { | |
1605 | next unless /^extensions=/ || /^dynamic_ext/; | |
1606 | foreach my $ext (@ext) { | |
1607 | s/\b$ext( )?\b/$1/; | |
1608 | } | |
1609 | } | |
1610 | return join "\n", @lines; | |
1611 | }); | |
1612 | } | |
1613 | ||
1614 | sub force_manifest { | |
1615 | my (@missing, @created_dirs); | |
1616 | my $fh = open_or_die('MANIFEST'); | |
1617 | while (<$fh>) { | |
1618 | next unless /^(\S+)/; | |
1619 | # -d is special case needed (at least) between 27332437a2ed1941 and | |
1620 | # bf3d9ec563d25054^ inclusive, as manifest contains ext/Thread/Thread | |
1621 | push @missing, $1 | |
1622 | unless -f $1 || -d $1; | |
1623 | } | |
1624 | close_or_die($fh); | |
1625 | ||
1626 | foreach my $pathname (@missing) { | |
1627 | my @parts = split '/', $pathname; | |
1628 | my $leaf = pop @parts; | |
1629 | my $path = '.'; | |
1630 | while (@parts) { | |
1631 | $path .= '/' . shift @parts; | |
1632 | next if -d $path; | |
f6647108 | 1633 | mkdir $path, 0700 or die_255("Can't create $path: $!"); |
05ec8abc NC |
1634 | unshift @created_dirs, $path; |
1635 | } | |
1636 | $fh = open_or_die($pathname, '>'); | |
1637 | close_or_die($fh); | |
f6647108 | 1638 | chmod 0, $pathname or die_255("Can't chmod 0 $pathname: $!"); |
05ec8abc NC |
1639 | } |
1640 | return \@missing, \@created_dirs; | |
1641 | } | |
1642 | ||
1643 | sub force_manifest_cleanup { | |
1644 | my ($missing, $created_dirs) = @_; | |
1645 | # This is probably way too paranoid: | |
1646 | my @errors; | |
1647 | require Fcntl; | |
1648 | foreach my $file (@$missing) { | |
1649 | my (undef, undef, $mode, undef, undef, undef, undef, $size) | |
1650 | = stat $file; | |
1651 | if (!defined $mode) { | |
1652 | push @errors, "Added file $file has been deleted by Configure"; | |
1653 | next; | |
1654 | } | |
1655 | if (Fcntl::S_IMODE($mode) != 0) { | |
1656 | push @errors, | |
1657 | sprintf 'Added file %s had mode changed by Configure to %03o', | |
1658 | $file, $mode; | |
1659 | } | |
1660 | if ($size != 0) { | |
1661 | push @errors, | |
1662 | "Added file $file had sized changed by Configure to $size"; | |
1663 | } | |
f6647108 | 1664 | unlink $file or die_255("Can't unlink $file: $!"); |
05ec8abc NC |
1665 | } |
1666 | foreach my $dir (@$created_dirs) { | |
f6647108 | 1667 | rmdir $dir or die_255("Can't rmdir $dir: $!"); |
05ec8abc NC |
1668 | } |
1669 | skip("@errors") | |
1670 | if @errors; | |
1671 | } | |
1672 | ||
750ce942 NC |
1673 | sub patch_Configure { |
1674 | if ($major < 1) { | |
1675 | if (extract_from_file('Configure', | |
1676 | qr/^\t\t\*=\*\) echo "\$1" >> \$optdef;;$/)) { | |
1677 | # This is " Spaces now allowed in -D command line options.", | |
1678 | # part of commit ecfc54246c2a6f42 | |
1679 | apply_patch(<<'EOPATCH'); | |
1680 | diff --git a/Configure b/Configure | |
1681 | index 3d3b38d..78ffe16 100755 | |
1682 | --- a/Configure | |
1683 | +++ b/Configure | |
1684 | @@ -652,7 +777,8 @@ while test $# -gt 0; do | |
1685 | echo "$me: use '-U symbol=', not '-D symbol='." >&2 | |
1686 | echo "$me: ignoring -D $1" >&2 | |
1687 | ;; | |
1688 | - *=*) echo "$1" >> $optdef;; | |
1689 | + *=*) echo "$1" | \ | |
1690 | + sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> $optdef;; | |
1691 | *) echo "$1='define'" >> $optdef;; | |
1692 | esac | |
1693 | shift | |
1694 | EOPATCH | |
1695 | } | |
1696 | ||
1697 | if (extract_from_file('Configure', qr/^if \$contains 'd_namlen' \$xinc\b/)) { | |
1698 | # Configure's original simple "grep" for d_namlen falls foul of the | |
1699 | # approach taken by the glibc headers: | |
1700 | # #ifdef _DIRENT_HAVE_D_NAMLEN | |
1701 | # # define _D_EXACT_NAMLEN(d) ((d)->d_namlen) | |
1702 | # | |
1703 | # where _DIRENT_HAVE_D_NAMLEN is not defined on Linux. | |
1704 | # This is also part of commit ecfc54246c2a6f42 | |
1705 | apply_patch(<<'EOPATCH'); | |
1706 | diff --git a/Configure b/Configure | |
1707 | index 3d3b38d..78ffe16 100755 | |
1708 | --- a/Configure | |
1709 | +++ b/Configure | |
1710 | @@ -3935,7 +4045,8 @@ $rm -f try.c | |
1711 | ||
1712 | : see if the directory entry stores field length | |
1713 | echo " " | |
1714 | -if $contains 'd_namlen' $xinc >/dev/null 2>&1; then | |
1715 | +$cppstdin $cppflags $cppminus < "$xinc" > try.c | |
1716 | +if $contains 'd_namlen' try.c >/dev/null 2>&1; then | |
1717 | echo "Good, your directory entry keeps length information in d_namlen." >&4 | |
1718 | val="$define" | |
1719 | else | |
1720 | EOPATCH | |
1721 | } | |
f50dca98 | 1722 | } |
750ce942 NC |
1723 | |
1724 | if ($major < 2 | |
1725 | && !extract_from_file('Configure', | |
1726 | qr/Try to guess additional flags to pick up local libraries/)) { | |
1727 | my $mips = extract_from_file('Configure', | |
1728 | qr!(''\) if (?:\./)?mips; then)!); | |
1729 | # This is part of perl-5.001n. It's needed, to add -L/usr/local/lib to | |
730ad6b9 DS |
1730 | # the ld flags if libraries are found there. It shifts the code to set |
1731 | # up libpth earlier, and then adds the code to add libpth entries to | |
750ce942 NC |
1732 | # ldflags |
1733 | # mips was changed to ./mips in ecfc54246c2a6f42, perl5.000 patch.0g | |
1734 | apply_patch(sprintf <<'EOPATCH', $mips); | |
1735 | diff --git a/Configure b/Configure | |
1736 | index 53649d5..0635a6e 100755 | |
1737 | --- a/Configure | |
1738 | +++ b/Configure | |
1739 | @@ -2749,6 +2749,52 @@ EOM | |
1740 | ;; | |
1741 | esac | |
f50dca98 | 1742 | |
750ce942 NC |
1743 | +: Set private lib path |
1744 | +case "$plibpth" in | |
1745 | +'') if ./mips; then | |
1746 | + plibpth="$incpath/usr/lib /usr/local/lib /usr/ccs/lib" | |
1747 | + fi;; | |
1748 | +esac | |
1749 | +case "$libpth" in | |
1750 | +' ') dlist='';; | |
1751 | +'') dlist="$plibpth $glibpth";; | |
1752 | +*) dlist="$libpth";; | |
1753 | +esac | |
1754 | + | |
1755 | +: Now check and see which directories actually exist, avoiding duplicates | |
1756 | +libpth='' | |
1757 | +for xxx in $dlist | |
1758 | +do | |
1759 | + if $test -d $xxx; then | |
1760 | + case " $libpth " in | |
1761 | + *" $xxx "*) ;; | |
1762 | + *) libpth="$libpth $xxx";; | |
1763 | + esac | |
1764 | + fi | |
1765 | +done | |
1766 | +$cat <<'EOM' | |
1767 | + | |
1768 | +Some systems have incompatible or broken versions of libraries. Among | |
1769 | +the directories listed in the question below, please remove any you | |
1770 | +know not to be holding relevant libraries, and add any that are needed. | |
1771 | +Say "none" for none. | |
1772 | + | |
1773 | +EOM | |
1774 | +case "$libpth" in | |
1775 | +'') dflt='none';; | |
1776 | +*) | |
1777 | + set X $libpth | |
1778 | + shift | |
1779 | + dflt=${1+"$@"} | |
1780 | + ;; | |
1781 | +esac | |
1782 | +rp="Directories to use for library searches?" | |
1783 | +. ./myread | |
1784 | +case "$ans" in | |
1785 | +none) libpth=' ';; | |
1786 | +*) libpth="$ans";; | |
1787 | +esac | |
1788 | + | |
1789 | : flags used in final linking phase | |
1790 | case "$ldflags" in | |
1791 | '') if ./venix; then | |
1792 | @@ -2765,6 +2811,23 @@ case "$ldflags" in | |
1793 | ;; | |
1794 | *) dflt="$ldflags";; | |
1795 | esac | |
1796 | + | |
1797 | +: Possible local library directories to search. | |
1798 | +loclibpth="/usr/local/lib /opt/local/lib /usr/gnu/lib" | |
1799 | +loclibpth="$loclibpth /opt/gnu/lib /usr/GNU/lib /opt/GNU/lib" | |
1800 | + | |
1801 | +: Try to guess additional flags to pick up local libraries. | |
1802 | +for thislibdir in $libpth; do | |
1803 | + case " $loclibpth " in | |
1804 | + *" $thislibdir "*) | |
1805 | + case "$dflt " in | |
1806 | + "-L$thislibdir ") ;; | |
1807 | + *) dflt="$dflt -L$thislibdir" ;; | |
1808 | + esac | |
1809 | + ;; | |
1810 | + esac | |
1811 | +done | |
1812 | + | |
1813 | echo " " | |
1814 | rp="Any additional ld flags (NOT including libraries)?" | |
1815 | . ./myread | |
1816 | @@ -2828,52 +2891,6 @@ n) echo "OK, that should do.";; | |
1817 | esac | |
1818 | $rm -f try try.* core | |
1819 | ||
1820 | -: Set private lib path | |
1821 | -case "$plibpth" in | |
1822 | -%s | |
1823 | - plibpth="$incpath/usr/lib /usr/local/lib /usr/ccs/lib" | |
1824 | - fi;; | |
1825 | -esac | |
1826 | -case "$libpth" in | |
1827 | -' ') dlist='';; | |
1828 | -'') dlist="$plibpth $glibpth";; | |
1829 | -*) dlist="$libpth";; | |
1830 | -esac | |
1831 | - | |
1832 | -: Now check and see which directories actually exist, avoiding duplicates | |
1833 | -libpth='' | |
1834 | -for xxx in $dlist | |
1835 | -do | |
1836 | - if $test -d $xxx; then | |
1837 | - case " $libpth " in | |
1838 | - *" $xxx "*) ;; | |
1839 | - *) libpth="$libpth $xxx";; | |
1840 | - esac | |
1841 | - fi | |
1842 | -done | |
1843 | -$cat <<'EOM' | |
f50dca98 | 1844 | - |
750ce942 NC |
1845 | -Some systems have incompatible or broken versions of libraries. Among |
1846 | -the directories listed in the question below, please remove any you | |
1847 | -know not to be holding relevant libraries, and add any that are needed. | |
1848 | -Say "none" for none. | |
1849 | - | |
1850 | -EOM | |
1851 | -case "$libpth" in | |
1852 | -'') dflt='none';; | |
1853 | -*) | |
1854 | - set X $libpth | |
1855 | - shift | |
1856 | - dflt=${1+"$@"} | |
1857 | - ;; | |
1858 | -esac | |
1859 | -rp="Directories to use for library searches?" | |
1860 | -. ./myread | |
1861 | -case "$ans" in | |
1862 | -none) libpth=' ';; | |
1863 | -*) libpth="$ans";; | |
1864 | -esac | |
1865 | - | |
1866 | : compute shared library extension | |
1867 | case "$so" in | |
1868 | '') | |
f50dca98 NC |
1869 | EOPATCH |
1870 | } | |
686af304 | 1871 | |
54591b5a NC |
1872 | if ($major == 4 && extract_from_file('Configure', qr/^d_gethbynam=/)) { |
1873 | # Fixes a bug introduced in 4599a1dedd47b916 | |
1874 | apply_commit('3cbc818d1d0ac470'); | |
1875 | } | |
1876 | ||
1877 | if ($major == 4 && extract_from_file('Configure', | |
1878 | qr/gethbadd_addr_type=`echo \$gethbadd_addr_type/)) { | |
1879 | # Fixes a bug introduced in 3fd537d4b944bc7a | |
1880 | apply_commit('6ff9219da6cf8cfd'); | |
1881 | } | |
1882 | ||
1883 | if ($major == 4 && extract_from_file('Configure', | |
1884 | qr/^pthreads_created_joinable=/)) { | |
1885 | # Fix for bug introduced in 52e1cb5ebf5e5a8c | |
1886 | # Part of commit ce637636a41b2fef | |
1887 | edit_file('Configure', sub { | |
1888 | my $code = shift; | |
1889 | $code =~ s{^pthreads_created_joinable=''} | |
1890 | {d_pthreads_created_joinable=''}ms | |
1891 | or die_255("Substitution failed"); | |
1892 | $code =~ s{^pthreads_created_joinable='\$pthreads_created_joinable'} | |
1893 | {d_pthreads_created_joinable='\$d_pthreads_created_joinable'}ms | |
1894 | or die_255("Substitution failed"); | |
1895 | return $code; | |
1896 | }); | |
1897 | } | |
1898 | ||
750ce942 NC |
1899 | if ($major < 5 && extract_from_file('Configure', |
1900 | qr!if \$cc \$ccflags try\.c -o try >/dev/null 2>&1; then!)) { | |
1901 | # Analogous to the more general fix of dfe9444ca7881e71 | |
1902 | # Without this flags such as -m64 may not be passed to this compile, | |
1903 | # which results in a byteorder of '1234' instead of '12345678', which | |
1904 | # can then cause crashes. | |
686af304 | 1905 | |
750ce942 NC |
1906 | if (extract_from_file('Configure', qr/xxx_prompt=y/)) { |
1907 | # 8e07c86ebc651fe9 or later | |
1908 | # ("This is my patch patch.1n for perl5.001.") | |
1909 | apply_patch(<<'EOPATCH'); | |
1910 | diff --git a/Configure b/Configure | |
1911 | index 62249dd..c5c384e 100755 | |
1912 | --- a/Configure | |
1913 | +++ b/Configure | |
1914 | @@ -8247,7 +8247,7 @@ main() | |
1915 | } | |
1916 | EOCP | |
1917 | xxx_prompt=y | |
1918 | - if $cc $ccflags try.c -o try >/dev/null 2>&1 && ./try > /dev/null; then | |
1919 | + if $cc $ccflags $ldflags try.c -o try >/dev/null 2>&1 && ./try > /dev/null; then | |
1920 | dflt=`./try` | |
1921 | case "$dflt" in | |
1922 | [1-4][1-4][1-4][1-4]|12345678|87654321) | |
1923 | EOPATCH | |
1924 | } else { | |
1925 | apply_patch(<<'EOPATCH'); | |
1926 | diff --git a/Configure b/Configure | |
1927 | index 53649d5..f1cd64a 100755 | |
1928 | --- a/Configure | |
1929 | +++ b/Configure | |
1930 | @@ -6362,7 +6362,7 @@ main() | |
1931 | printf("\n"); | |
1932 | } | |
1933 | EOCP | |
1934 | - if $cc $ccflags try.c -o try >/dev/null 2>&1 ; then | |
1935 | + if $cc $ccflags $ldflags try.c -o try >/dev/null 2>&1 ; then | |
1936 | dflt=`./try` | |
1937 | case "$dflt" in | |
1938 | ????|????????) echo "(The test program ran ok.)";; | |
1939 | EOPATCH | |
1940 | } | |
1941 | } | |
9a999a97 | 1942 | |
750ce942 NC |
1943 | if ($major < 6 && !extract_from_file('Configure', |
1944 | qr!^\t-A\)$!)) { | |
1945 | # This adds the -A option to Configure, which is incredibly useful | |
1946 | # Effectively this is commits 02e93a22d20fc9a5, 5f83a3e9d818c3ad, | |
1947 | # bde6b06b2c493fef, f7c3111703e46e0c and 2 lines of trailing whitespace | |
1948 | # removed by 613d6c3e99b9decc, but applied at slightly different | |
1949 | # locations to ensure a clean patch back to 5.000 | |
1950 | # Note, if considering patching to the intermediate revisions to fix | |
1951 | # bugs in -A handling, f7c3111703e46e0c is from 2002, and hence | |
1952 | # $major == 8 | |
1953 | ||
1954 | # To add to the fun, early patches add -K and -O options, and it's not | |
1955 | # trivial to get patch to put the C<. ./posthint.sh> in the right place | |
1956 | edit_file('Configure', sub { | |
1957 | my $code = shift; | |
1958 | $code =~ s/(optstr = ")([^"]+";\s*# getopt-style specification)/$1A:$2/ | |
f6647108 | 1959 | or die_255("Substitution failed"); |
750ce942 NC |
1960 | $code =~ s!^(: who configured the system)! |
1961 | touch posthint.sh | |
1962 | . ./posthint.sh | |
2526f4b8 | 1963 | |
750ce942 | 1964 | $1!ms |
f6647108 | 1965 | or die_255("Substitution failed"); |
750ce942 NC |
1966 | return $code; |
1967 | }); | |
1968 | apply_patch(<<'EOPATCH'); | |
1969 | diff --git a/Configure b/Configure | |
1970 | index 4b55fa6..60c3c64 100755 | |
1971 | --- a/Configure | |
1972 | +++ b/Configure | |
1973 | @@ -1150,6 +1150,7 @@ set X `for arg in "$@"; do echo "X$arg"; done | | |
1974 | eval "set $*" | |
1975 | shift | |
1976 | rm -f options.awk | |
1977 | +rm -f posthint.sh | |
1978 | ||
1979 | : set up default values | |
1980 | fastread='' | |
1981 | @@ -1172,6 +1173,56 @@ while test $# -gt 0; do | |
1982 | case "$1" in | |
1983 | -d) shift; fastread=yes;; | |
1984 | -e) shift; alldone=cont;; | |
1985 | + -A) | |
1986 | + shift | |
1987 | + xxx='' | |
1988 | + yyy="$1" | |
1989 | + zzz='' | |
1990 | + uuu=undef | |
1991 | + case "$yyy" in | |
1992 | + *=*) zzz=`echo "$yyy"|sed 's!=.*!!'` | |
1993 | + case "$zzz" in | |
1994 | + *:*) zzz='' ;; | |
1995 | + *) xxx=append | |
1996 | + zzz=" "`echo "$yyy"|sed 's!^[^=]*=!!'` | |
1997 | + yyy=`echo "$yyy"|sed 's!=.*!!'` ;; | |
1998 | + esac | |
1999 | + ;; | |
2000 | + esac | |
2001 | + case "$xxx" in | |
2002 | + '') case "$yyy" in | |
2003 | + *:*) xxx=`echo "$yyy"|sed 's!:.*!!'` | |
2004 | + yyy=`echo "$yyy"|sed 's!^[^:]*:!!'` | |
2005 | + zzz=`echo "$yyy"|sed 's!^[^=]*=!!'` | |
2006 | + yyy=`echo "$yyy"|sed 's!=.*!!'` ;; | |
2007 | + *) xxx=`echo "$yyy"|sed 's!:.*!!'` | |
2008 | + yyy=`echo "$yyy"|sed 's!^[^:]*:!!'` ;; | |
2009 | + esac | |
2010 | + ;; | |
2011 | + esac | |
2012 | + case "$xxx" in | |
2013 | + append) | |
2014 | + echo "$yyy=\"\${$yyy}$zzz\"" >> posthint.sh ;; | |
2015 | + clear) | |
2016 | + echo "$yyy=''" >> posthint.sh ;; | |
2017 | + define) | |
2018 | + case "$zzz" in | |
2019 | + '') zzz=define ;; | |
2020 | + esac | |
2021 | + echo "$yyy='$zzz'" >> posthint.sh ;; | |
2022 | + eval) | |
2023 | + echo "eval \"$yyy=$zzz\"" >> posthint.sh ;; | |
2024 | + prepend) | |
2025 | + echo "$yyy=\"$zzz\${$yyy}\"" >> posthint.sh ;; | |
2026 | + undef) | |
2027 | + case "$zzz" in | |
2028 | + '') zzz="$uuu" ;; | |
2029 | + esac | |
2030 | + echo "$yyy=$zzz" >> posthint.sh ;; | |
2031 | + *) echo "$me: unknown -A command '$xxx', ignoring -A $1" >&2 ;; | |
2032 | + esac | |
2033 | + shift | |
2034 | + ;; | |
2035 | -f) | |
2036 | shift | |
2037 | cd .. | |
2038 | EOPATCH | |
2039 | } | |
9a999a97 | 2040 | |
d1ac19b7 NC |
2041 | if ($major < 8 && $^O eq 'aix') { |
2042 | edit_file('Configure', sub { | |
2043 | my $code = shift; | |
2044 | # Replicate commit a8c676c69574838b | |
2045 | # Whitespace allowed at the ends of /lib/syscalls.exp lines | |
2046 | # and half of commit c6912327ae30e6de | |
2047 | # AIX syscalls.exp scan: the syscall might be marked 32, 3264, or 64 | |
2048 | $code =~ s{(\bsed\b.*\bsyscall)(?:\[0-9\]\*)?(\$.*/lib/syscalls\.exp)} | |
2049 | {$1 . "[0-9]*[ \t]*" . $2}e; | |
2050 | return $code; | |
2051 | }); | |
2052 | } | |
2053 | ||
750ce942 NC |
2054 | if ($major < 8 && !extract_from_file('Configure', |
2055 | qr/^\t\tif test ! -t 0; then$/)) { | |
2056 | # Before dfe9444ca7881e71, Configure would refuse to run if stdin was | |
2057 | # not a tty. With that commit, the tty requirement was dropped for -de | |
2058 | # and -dE | |
2059 | # Commit aaeb8e512e8e9e14 dropped the tty requirement for -S | |
2060 | # For those older versions, it's probably easiest if we simply remove | |
2061 | # the sanity test. | |
2062 | edit_file('Configure', sub { | |
2063 | my $code = shift; | |
2064 | $code =~ s/test ! -t 0/test Perl = rules/; | |
2065 | return $code; | |
2066 | }); | |
6a8dbfd7 | 2067 | } |
6a8dbfd7 | 2068 | |
750ce942 NC |
2069 | if ($major == 8 || $major == 9) { |
2070 | # Fix symbol detection to that of commit 373dfab3839ca168 if it's any | |
2071 | # intermediate version 5129fff43c4fe08c or later, as the intermediate | |
2072 | # versions don't work correctly on (at least) Sparc Linux. | |
2073 | # 5129fff43c4fe08c adds the first mention of mistrustnm. | |
2074 | # 373dfab3839ca168 removes the last mention of lc="" | |
2075 | edit_file('Configure', sub { | |
2076 | my $code = shift; | |
2077 | return $code | |
2078 | if $code !~ /\btc="";/; # 373dfab3839ca168 or later | |
2079 | return $code | |
2080 | if $code !~ /\bmistrustnm\b/; # before 5129fff43c4fe08c | |
2081 | my $fixed = <<'EOC'; | |
6a8dbfd7 | 2082 | |
750ce942 NC |
2083 | : is a C symbol defined? |
2084 | csym='tlook=$1; | |
2085 | case "$3" in | |
2086 | -v) tf=libc.tmp; tdc="";; | |
2087 | -a) tf=libc.tmp; tdc="[]";; | |
2088 | *) tlook="^$1\$"; tf=libc.list; tdc="()";; | |
2089 | esac; | |
2090 | tx=yes; | |
2091 | case "$reuseval-$4" in | |
2092 | true-) ;; | |
2093 | true-*) tx=no; eval "tval=\$$4"; case "$tval" in "") tx=yes;; esac;; | |
2094 | esac; | |
2095 | case "$tx" in | |
2096 | yes) | |
2097 | tval=false; | |
2098 | if $test "$runnm" = true; then | |
2099 | if $contains $tlook $tf >/dev/null 2>&1; then | |
2100 | tval=true; | |
2101 | elif $test "$mistrustnm" = compile -o "$mistrustnm" = run; then | |
2102 | echo "void *(*(p()))$tdc { extern void *$1$tdc; return &$1; } int main() { if(p()) return(0); else return(1); }"> try.c; | |
2103 | $cc -o try $optimize $ccflags $ldflags try.c >/dev/null 2>&1 $libs && tval=true; | |
2104 | $test "$mistrustnm" = run -a -x try && { $run ./try$_exe >/dev/null 2>&1 || tval=false; }; | |
2105 | $rm -f try$_exe try.c core core.* try.core; | |
2106 | fi; | |
2107 | else | |
2108 | echo "void *(*(p()))$tdc { extern void *$1$tdc; return &$1; } int main() { if(p()) return(0); else return(1); }"> try.c; | |
2109 | $cc -o try $optimize $ccflags $ldflags try.c $libs >/dev/null 2>&1 && tval=true; | |
2110 | $rm -f try$_exe try.c; | |
2111 | fi; | |
2112 | ;; | |
2113 | *) | |
2114 | case "$tval" in | |
2115 | $define) tval=true;; | |
2116 | *) tval=false;; | |
2117 | esac; | |
2118 | ;; | |
2119 | esac; | |
2120 | eval "$2=$tval"' | |
67382a3b | 2121 | |
750ce942 NC |
2122 | EOC |
2123 | $code =~ s/\n: is a C symbol defined\?\n.*?\neval "\$2=\$tval"'\n\n/$fixed/sm | |
f6647108 | 2124 | or die_255("substitution failed"); |
750ce942 NC |
2125 | return $code; |
2126 | }); | |
2127 | } | |
2128 | ||
2129 | if ($major < 10 | |
2130 | && extract_from_file('Configure', qr/^set malloc\.h i_malloc$/)) { | |
2131 | # This is commit 01d07975f7ef0e7d, trimmed, with $compile inlined as | |
2132 | # prior to bd9b35c97ad661cc Configure had the malloc.h test before the | |
2133 | # definition of $compile. | |
2134 | apply_patch(<<'EOPATCH'); | |
2135 | diff --git a/Configure b/Configure | |
2136 | index 3d2e8b9..6ce7766 100755 | |
2137 | --- a/Configure | |
2138 | +++ b/Configure | |
2139 | @@ -6743,5 +6743,22 @@ set d_dosuid | |
2140 | ||
2141 | : see if this is a malloc.h system | |
2142 | -set malloc.h i_malloc | |
2143 | -eval $inhdr | |
2144 | +: we want a real compile instead of Inhdr because some systems have a | |
2145 | +: malloc.h that just gives a compile error saying to use stdlib.h instead | |
2146 | +echo " " | |
2147 | +$cat >try.c <<EOCP | |
2148 | +#include <stdlib.h> | |
2149 | +#include <malloc.h> | |
2150 | +int main () { return 0; } | |
2151 | +EOCP | |
2152 | +set try | |
2153 | +if $cc $optimize $ccflags $ldflags -o try $* try.c $libs > /dev/null 2>&1; then | |
2154 | + echo "<malloc.h> found." >&4 | |
2155 | + val="$define" | |
2156 | +else | |
2157 | + echo "<malloc.h> NOT found." >&4 | |
2158 | + val="$undef" | |
2159 | +fi | |
2160 | +$rm -f try.c try | |
2161 | +set i_malloc | |
2162 | +eval $setvar | |
2163 | ||
2164 | EOPATCH | |
2165 | } | |
67382a3b | 2166 | } |
6a8dbfd7 | 2167 | |
750ce942 NC |
2168 | sub patch_hints { |
2169 | if ($^O eq 'freebsd') { | |
2170 | # There are rather too many version-specific FreeBSD hints fixes to | |
2171 | # patch individually. Also, more than once the FreeBSD hints file has | |
2172 | # been written in what turned out to be a rather non-future-proof style, | |
2173 | # with case statements treating the most recent version as the | |
2174 | # exception, instead of treating previous versions' behaviour explicitly | |
2175 | # and changing the default to cater for the current behaviour. (As | |
2176 | # strangely, future versions inherit the current behaviour.) | |
2177 | checkout_file('hints/freebsd.sh'); | |
2178 | } elsif ($^O eq 'darwin') { | |
2179 | if ($major < 8) { | |
2180 | # We can't build on darwin without some of the data in the hints | |
2181 | # file. Probably less surprising to use the earliest version of | |
2182 | # hints/darwin.sh and then edit in place just below, than use | |
2183 | # blead's version, as that would create a discontinuity at | |
2184 | # f556e5b971932902 - before it, hints bugs would be "fixed", after | |
2185 | # it they'd resurface. This way, we should give the illusion of | |
2186 | # monotonic bug fixing. | |
2187 | my $faking_it; | |
2188 | if (!-f 'hints/darwin.sh') { | |
2189 | checkout_file('hints/darwin.sh', 'f556e5b971932902'); | |
2190 | ++$faking_it; | |
2191 | } | |
0afef97d | 2192 | |
750ce942 NC |
2193 | edit_file('hints/darwin.sh', sub { |
2194 | my $code = shift; | |
2195 | # Part of commit 8f4f83badb7d1ba9, which mostly undoes | |
2196 | # commit 0511a818910f476c. | |
2197 | $code =~ s/^cppflags='-traditional-cpp';$/cppflags="\${cppflags} -no-cpp-precomp"/m; | |
2198 | # commit 14c11978e9b52e08/803bb6cc74d36a3f | |
2199 | # Without this, code in libperl.bundle links against op.o | |
2200 | # in preference to opmini.o on the linker command line, | |
2201 | # and hence miniperl tries to use File::Glob instead of | |
2202 | # csh | |
2203 | $code =~ s/^(lddlflags=)/ldflags="\${ldflags} -flat_namespace"\n$1/m; | |
2204 | # f556e5b971932902 also patches Makefile.SH with some | |
2205 | # special case code to deal with useshrplib for darwin. | |
2206 | # Given that post 5.8.0 the darwin hints default was | |
2207 | # changed to false, and it would be very complex to splice | |
2208 | # in that code in various versions of Makefile.SH back | |
2209 | # to 5.002, lets just turn it off. | |
2210 | $code =~ s/^useshrplib='true'/useshrplib='false'/m | |
2211 | if $faking_it; | |
1f1c8096 NC |
2212 | |
2213 | # Part of commit d235852b65d51c44 | |
2214 | # Don't do this on a case sensitive HFS+ partition, as it | |
2215 | # breaks the build for 5.003 and earlier. | |
2216 | if ($case_insensitive | |
2217 | && $code !~ /^firstmakefile=GNUmakefile/) { | |
2218 | $code .= "\nfirstmakefile=GNUmakefile;\n"; | |
2219 | } | |
2220 | ||
750ce942 NC |
2221 | return $code; |
2222 | }); | |
2223 | } | |
2224 | } elsif ($^O eq 'netbsd') { | |
2225 | if ($major < 6) { | |
2226 | # These are part of commit 099685bc64c7dbce | |
2227 | edit_file('hints/netbsd.sh', sub { | |
2228 | my $code = shift; | |
2229 | my $fixed = <<'EOC'; | |
2230 | case "$osvers" in | |
2231 | 0.9|0.8*) | |
2232 | usedl="$undef" | |
2233 | ;; | |
2234 | *) | |
2235 | if [ -f /usr/libexec/ld.elf_so ]; then | |
2236 | d_dlopen=$define | |
2237 | d_dlerror=$define | |
2238 | ccdlflags="-Wl,-E -Wl,-R${PREFIX}/lib $ccdlflags" | |
2239 | cccdlflags="-DPIC -fPIC $cccdlflags" | |
2240 | lddlflags="--whole-archive -shared $lddlflags" | |
2241 | elif [ "`uname -m`" = "pmax" ]; then | |
9f1d18fe | 2242 | # NetBSD 1.3 and 1.3.1 on pmax shipped an 'old' ld.so, which will not work. |
750ce942 NC |
2243 | d_dlopen=$undef |
2244 | elif [ -f /usr/libexec/ld.so ]; then | |
2245 | d_dlopen=$define | |
2246 | d_dlerror=$define | |
2247 | ccdlflags="-Wl,-R${PREFIX}/lib $ccdlflags" | |
2248 | # we use -fPIC here because -fpic is *NOT* enough for some of the | |
2249 | # extensions like Tk on some netbsd platforms (the sparc is one) | |
2250 | cccdlflags="-DPIC -fPIC $cccdlflags" | |
2251 | lddlflags="-Bforcearchive -Bshareable $lddlflags" | |
2252 | else | |
2253 | d_dlopen=$undef | |
2254 | fi | |
2255 | ;; | |
2256 | esac | |
2257 | EOC | |
2258 | $code =~ s/^case "\$osvers" in\n0\.9\|0\.8.*?^esac\n/$fixed/ms; | |
2259 | return $code; | |
2260 | }); | |
2261 | } | |
2262 | } elsif ($^O eq 'openbsd') { | |
2263 | if ($major < 8) { | |
2264 | checkout_file('hints/openbsd.sh', '43051805d53a3e4c') | |
2265 | unless -f 'hints/openbsd.sh'; | |
2266 | my $which = extract_from_file('hints/openbsd.sh', | |
2267 | qr/# from (2\.8|3\.1) onwards/, | |
2268 | ''); | |
2269 | if ($which eq '') { | |
2270 | my $was = extract_from_file('hints/openbsd.sh', | |
2271 | qr/(lddlflags="(?:-Bforcearchive )?-Bshareable)/); | |
2272 | # This is commit 154d43cbcf57271c and parts of 5c75dbfa77b0949c | |
2273 | # and 29b5585702e5e025 | |
2274 | apply_patch(sprintf <<'EOPATCH', $was); | |
2275 | diff --git a/hints/openbsd.sh b/hints/openbsd.sh | |
2276 | index a7d8bf2..5b79709 100644 | |
2277 | --- a/hints/openbsd.sh | |
2278 | +++ b/hints/openbsd.sh | |
2279 | @@ -37,7 +37,25 @@ OpenBSD.alpha|OpenBSD.mips|OpenBSD.powerpc|OpenBSD.vax) | |
2280 | # we use -fPIC here because -fpic is *NOT* enough for some of the | |
2281 | # extensions like Tk on some OpenBSD platforms (ie: sparc) | |
2282 | cccdlflags="-DPIC -fPIC $cccdlflags" | |
2283 | - %s $lddlflags" | |
2284 | + case "$osvers" in | |
2285 | + [01].*|2.[0-7]|2.[0-7].*) | |
2286 | + lddlflags="-Bshareable $lddlflags" | |
2287 | + ;; | |
2288 | + 2.[8-9]|3.0) | |
2289 | + ld=${cc:-cc} | |
2290 | + lddlflags="-shared -fPIC $lddlflags" | |
2291 | + ;; | |
2292 | + *) # from 3.1 onwards | |
2293 | + ld=${cc:-cc} | |
2294 | + lddlflags="-shared -fPIC $lddlflags" | |
2295 | + libswanted=`echo $libswanted | sed 's/ dl / /'` | |
2296 | + ;; | |
2297 | + esac | |
2298 | + | |
2299 | + # We need to force ld to export symbols on ELF platforms. | |
2300 | + # Without this, dlopen() is crippled. | |
2301 | + ELF=`${cc:-cc} -dM -E - </dev/null | grep __ELF__` | |
2302 | + test -n "$ELF" && ldflags="-Wl,-E $ldflags" | |
2303 | ;; | |
2304 | esac | |
2305 | ||
2306 | EOPATCH | |
2307 | } elsif ($which eq '2.8') { | |
2308 | # This is parts of 5c75dbfa77b0949c and 29b5585702e5e025, and | |
2309 | # possibly eb9cd59d45ad2908 | |
2310 | my $was = extract_from_file('hints/openbsd.sh', | |
2311 | qr/lddlflags="(-shared(?: -fPIC)?) \$lddlflags"/); | |
0afef97d | 2312 | |
750ce942 NC |
2313 | apply_patch(sprintf <<'EOPATCH', $was); |
2314 | --- a/hints/openbsd.sh 2011-10-21 17:25:20.000000000 +0200 | |
2315 | +++ b/hints/openbsd.sh 2011-10-21 16:58:43.000000000 +0200 | |
2316 | @@ -44,11 +44,21 @@ | |
2317 | [01].*|2.[0-7]|2.[0-7].*) | |
2318 | lddlflags="-Bshareable $lddlflags" | |
2319 | ;; | |
2320 | - *) # from 2.8 onwards | |
2321 | + 2.[8-9]|3.0) | |
2322 | ld=${cc:-cc} | |
2323 | - lddlflags="%s $lddlflags" | |
2324 | + lddlflags="-shared -fPIC $lddlflags" | |
2325 | + ;; | |
2326 | + *) # from 3.1 onwards | |
2327 | + ld=${cc:-cc} | |
2328 | + lddlflags="-shared -fPIC $lddlflags" | |
2329 | + libswanted=`echo $libswanted | sed 's/ dl / /'` | |
2330 | ;; | |
2331 | esac | |
2332 | + | |
2333 | + # We need to force ld to export symbols on ELF platforms. | |
2334 | + # Without this, dlopen() is crippled. | |
2335 | + ELF=`${cc:-cc} -dM -E - </dev/null | grep __ELF__` | |
2336 | + test -n "$ELF" && ldflags="-Wl,-E $ldflags" | |
2337 | ;; | |
2338 | esac | |
2339 | ||
2340 | EOPATCH | |
2341 | } elsif ($which eq '3.1' | |
2342 | && !extract_from_file('hints/openbsd.sh', | |
2343 | qr/We need to force ld to export symbols on ELF platforms/)) { | |
2344 | # This is part of 29b5585702e5e025 | |
2345 | apply_patch(<<'EOPATCH'); | |
2346 | diff --git a/hints/openbsd.sh b/hints/openbsd.sh | |
2347 | index c6b6bc9..4839d04 100644 | |
2348 | --- a/hints/openbsd.sh | |
2349 | +++ b/hints/openbsd.sh | |
2350 | @@ -54,6 +54,11 @@ alpha-2.[0-8]|mips-*|vax-*|powerpc-2.[0-7]|m88k-*) | |
2351 | libswanted=`echo $libswanted | sed 's/ dl / /'` | |
2352 | ;; | |
2353 | esac | |
2354 | + | |
2355 | + # We need to force ld to export symbols on ELF platforms. | |
2356 | + # Without this, dlopen() is crippled. | |
2357 | + ELF=`${cc:-cc} -dM -E - </dev/null | grep __ELF__` | |
2358 | + test -n "$ELF" && ldflags="-Wl,-E $ldflags" | |
2359 | ;; | |
2360 | esac | |
2361 | ||
2362 | EOPATCH | |
2363 | } | |
2364 | } | |
2365 | } elsif ($^O eq 'linux') { | |
2366 | if ($major < 1) { | |
2367 | # sparc linux seems to need the -Dbool=char -DHAS_BOOL part of | |
2368 | # perl5.000 patch.0n: [address Configure and build issues] | |
2369 | edit_file('hints/linux.sh', sub { | |
2370 | my $code = shift; | |
2371 | $code =~ s!-I/usr/include/bsd!-Dbool=char -DHAS_BOOL!g; | |
2372 | return $code; | |
2373 | }); | |
2374 | } | |
915f531b | 2375 | |
750ce942 NC |
2376 | if ($major <= 9) { |
2377 | if (`uname -sm` =~ qr/^Linux sparc/) { | |
2378 | if (extract_from_file('hints/linux.sh', qr/sparc-linux/)) { | |
2379 | # Be sure to use -fPIC not -fpic on Linux/SPARC | |
2380 | apply_commit('f6527d0ef0c13ad4'); | |
2381 | } elsif(!extract_from_file('hints/linux.sh', | |
2382 | qr/^sparc-linux\)$/)) { | |
2383 | my $fh = open_or_die('hints/linux.sh', '>>'); | |
f6647108 | 2384 | print $fh <<'EOT' or die_255($!); |
750ce942 NC |
2385 | |
2386 | case "`uname -m`" in | |
2387 | sparc*) | |
2388 | case "$cccdlflags" in | |
2389 | *-fpic*) cccdlflags="`echo $cccdlflags|sed 's/-fpic/-fPIC/'`" ;; | |
2390 | *) cccdlflags="$cccdlflags -fPIC" ;; | |
2391 | esac | |
2392 | ;; | |
2393 | esac | |
2394 | EOT | |
2395 | close_or_die($fh); | |
2396 | } | |
2397 | } | |
2398 | } | |
1f0f6439 NC |
2399 | } elsif ($^O eq 'solaris') { |
2400 | if (($major == 13 || $major == 14) | |
2401 | && extract_from_file('hints/solaris_2.sh', qr/getconfldllflags/)) { | |
2402 | apply_commit('c80bde4388070c45'); | |
2403 | } | |
915f531b NC |
2404 | } |
2405 | } | |
2406 | ||
bb723266 NC |
2407 | sub patch_SH { |
2408 | # Cwd.xs added in commit 0d2079faa739aaa9. Cwd.pm moved to ext/ 8 years | |
2409 | # later in commit 403f501d5b37ebf0 | |
2410 | if ($major > 0 && <*/Cwd/Cwd.xs>) { | |
2411 | if ($major < 10 | |
2412 | && !extract_from_file('Makefile.SH', qr/^extra_dep=''$/)) { | |
2413 | # The Makefile.PL for Unicode::Normalize needs | |
2414 | # lib/unicore/CombiningClass.pl. Even without a parallel build, we | |
2415 | # need a dependency to ensure that it builds. This is a variant of | |
2416 | # commit 9f3ef600c170f61e. Putting this for earlier versions gives | |
2417 | # us a spot on which to hang the edits below | |
2418 | apply_patch(<<'EOPATCH'); | |
2419 | diff --git a/Makefile.SH b/Makefile.SH | |
2420 | index f61d0db..6097954 100644 | |
2421 | --- a/Makefile.SH | |
2422 | +++ b/Makefile.SH | |
2423 | @@ -155,10 +155,20 @@ esac | |
2424 | ||
2425 | : Prepare dependency lists for Makefile. | |
2426 | dynamic_list=' ' | |
2427 | +extra_dep='' | |
2428 | for f in $dynamic_ext; do | |
2429 | : the dependency named here will never exist | |
2430 | base=`echo "$f" | sed 's/.*\///'` | |
2431 | - dynamic_list="$dynamic_list lib/auto/$f/$base.$dlext" | |
2432 | + this_target="lib/auto/$f/$base.$dlext" | |
2433 | + dynamic_list="$dynamic_list $this_target" | |
2434 | + | |
2435 | + : Parallel makes reveal that we have some interdependencies | |
2436 | + case $f in | |
2437 | + Math/BigInt/FastCalc) extra_dep="$extra_dep | |
2438 | +$this_target: lib/auto/List/Util/Util.$dlext" ;; | |
2439 | + Unicode/Normalize) extra_dep="$extra_dep | |
2440 | +$this_target: lib/unicore/CombiningClass.pl" ;; | |
2441 | + esac | |
2442 | done | |
2443 | ||
2444 | static_list=' ' | |
2445 | @@ -987,2 +997,9 @@ n_dummy $(nonxs_ext): miniperl$(EXE_EXT) preplibrary $(DYNALOADER) FORCE | |
2446 | @$(LDLIBPTH) sh ext/util/make_ext nonxs $@ MAKE=$(MAKE) LIBPERL_A=$(LIBPERL) | |
2447 | +!NO!SUBS! | |
2448 | + | |
2449 | +$spitshell >>Makefile <<EOF | |
2450 | +$extra_dep | |
2451 | +EOF | |
2452 | + | |
2453 | +$spitshell >>Makefile <<'!NO!SUBS!' | |
2454 | ||
2455 | EOPATCH | |
2456 | } | |
c0960282 | 2457 | |
67bec938 NC |
2458 | if ($major == 15 && $^O !~ /^(linux|darwin|.*bsd)$/ |
2459 | && extract_from_file('Makefile.SH', qr/^V.* \?= /)) { | |
2460 | # Remove the GNU-make-ism (which the BSD makes also support, but | |
2461 | # most other makes choke on) | |
2462 | apply_patch(<<'EOPATCH'); | |
2463 | diff --git a/Makefile.SH b/Makefile.SH | |
2464 | index 94952bd..13e9001 100755 | |
2465 | --- a/Makefile.SH | |
2466 | +++ b/Makefile.SH | |
2467 | @@ -338,8 +338,8 @@ linux*|darwin) | |
2468 | $spitshell >>$Makefile <<!GROK!THIS! | |
2469 | # If you're going to use valgrind and it can't be invoked as plain valgrind | |
2470 | # then you'll need to change this, or override it on the make command line. | |
2471 | -VALGRIND ?= valgrind | |
2472 | -VG_TEST ?= ./perl -e 1 2>/dev/null | |
2473 | +VALGRIND = valgrind | |
2474 | +VG_TEST = ./perl -e 1 2>/dev/null | |
2475 | ||
2476 | !GROK!THIS! | |
2477 | ;; | |
2478 | EOPATCH | |
2479 | } | |
2480 | ||
c0960282 NC |
2481 | if ($major == 11) { |
2482 | if (extract_from_file('patchlevel.h', | |
2483 | qr/^#include "unpushed\.h"/)) { | |
2484 | # I had thought it easier to detect when building one of the 52 | |
2485 | # commits with the original method of incorporating the git | |
2486 | # revision and drop parallel make flags. Commits shown by | |
2487 | # git log 46807d8e809cc127^..dcff826f70bf3f64^ ^d4fb0a1f15d1a1c4 | |
2488 | # However, it's not actually possible to make miniperl for that | |
2489 | # configuration as-is, because the file .patchnum is only made | |
2490 | # as a side effect of target 'all' | |
2491 | # I also don't think that it's "safe" to simply run | |
2492 | # make_patchnum.sh before the build. We need the proper | |
2493 | # dependency rules in the Makefile to *stop* it being run again | |
2494 | # at the wrong time. | |
2495 | # This range is important because contains the commit that | |
2496 | # merges Schwern's y2038 work. | |
2497 | apply_patch(<<'EOPATCH'); | |
2498 | diff --git a/Makefile.SH b/Makefile.SH | |
2499 | index 9ad8b6f..106e721 100644 | |
2500 | --- a/Makefile.SH | |
2501 | +++ b/Makefile.SH | |
2502 | @@ -540,9 +544,14 @@ sperl.i: perl.c $(h) | |
2503 | ||
2504 | .PHONY: all translators utilities make_patchnum | |
2505 | ||
2506 | -make_patchnum: | |
2507 | +make_patchnum: lib/Config_git.pl | |
2508 | + | |
2509 | +lib/Config_git.pl: make_patchnum.sh | |
2510 | sh $(shellflags) make_patchnum.sh | |
2511 | ||
2512 | +# .patchnum, unpushed.h and lib/Config_git.pl are built by make_patchnum.sh | |
2513 | +unpushed.h .patchnum: lib/Config_git.pl | |
2514 | + | |
2515 | # make sure that we recompile perl.c if .patchnum changes | |
2516 | perl$(OBJ_EXT): .patchnum unpushed.h | |
2517 | ||
2518 | EOPATCH | |
2519 | } elsif (-f '.gitignore' | |
2520 | && extract_from_file('.gitignore', qr/^\.patchnum$/)) { | |
2521 | # 8565263ab8a47cda to 46807d8e809cc127^ inclusive. | |
2522 | edit_file('Makefile.SH', sub { | |
2523 | my $code = shift; | |
2524 | $code =~ s/^make_patchnum:\n/make_patchnum: .patchnum | |
2525 | ||
2526 | .sha1: .patchnum | |
2527 | ||
2528 | .patchnum: make_patchnum.sh | |
2529 | /m; | |
2530 | return $code; | |
2531 | }); | |
74adbdfa NC |
2532 | } elsif (-f 'lib/.gitignore' |
2533 | && extract_from_file('lib/.gitignore', | |
2534 | qr!^/Config_git.pl!) | |
2535 | && !extract_from_file('Makefile.SH', | |
2536 | qr/^uudmap\.h.*:bitcount.h$/)) { | |
2537 | # Between commits and dcff826f70bf3f64 and 0f13ebd5d71f8177^ | |
2538 | edit_file('Makefile.SH', sub { | |
2539 | my $code = shift; | |
2540 | # Bug introduced by 344af494c35a9f0f | |
2541 | # fixed in 0f13ebd5d71f8177 | |
2542 | $code =~ s{^(pod/perlapi\.pod) (pod/perlintern\.pod): } | |
2543 | {$1: $2\n\n$2: }m; | |
2544 | # Bug introduced by efa50c51e3301a2c | |
2545 | # fixed in 0f13ebd5d71f8177 | |
2546 | $code =~ s{^(uudmap\.h) (bitcount\.h): } | |
2547 | {$1: $2\n\n$2: }m; | |
93a0b6a3 NC |
2548 | |
2549 | # The rats nest of getting git_version.h correct | |
2550 | ||
2551 | if ($code =~ s{git_version\.h: stock_git_version\.h | |
2552 | \tcp stock_git_version\.h git_version\.h} | |
2553 | {}m) { | |
2554 | # before 486cd780047ff224 | |
2555 | ||
2556 | # We probably can't build between | |
2557 | # 953f6acfa20ec275^ and 8565263ab8a47cda | |
2558 | # inclusive, but all commits in that range | |
2559 | # relate to getting make_patchnum.sh working, | |
2560 | # so it is extremely unlikely to be an | |
2561 | # interesting bisect target. They will skip. | |
2562 | ||
2563 | # No, don't spawn a submake if | |
2564 | # make_patchnum.sh or make_patchnum.pl fails | |
2565 | $code =~ s{\|\| \$\(MAKE\) miniperl.*} | |
2566 | {}m; | |
2567 | $code =~ s{^\t(sh.*make_patchnum\.sh.*)} | |
2568 | {\t-$1}m; | |
2569 | ||
2570 | # Use an external perl to run make_patchnum.pl | |
2571 | # because miniperl still depends on | |
2572 | # git_version.h | |
2573 | $code =~ s{^\t.*make_patchnum\.pl} | |
2574 | {\t-$^X make_patchnum.pl}m; | |
2575 | ||
2576 | ||
2577 | # "Truth in advertising" - running | |
2578 | # make_patchnum generates 2 files. | |
2579 | $code =~ s{^make_patchnum:.*}{ | |
2580 | make_patchnum: lib/Config_git.pl | |
2581 | ||
2582 | git_version.h: lib/Config_git.pl | |
2583 | ||
2584 | perlmini\$(OBJ_EXT): git_version.h | |
2585 | ||
2586 | lib/Config_git.pl:}m; | |
2587 | } | |
356fb8dd NC |
2588 | # Right, now we've corrected Makefile.SH to |
2589 | # correctly describe how lib/Config_git.pl and | |
2590 | # git_version.h are made, we need to fix the rest | |
2591 | ||
2592 | # This emulates commit 2b63e250843b907e | |
2593 | # This might duplicate the rule stating that | |
2594 | # git_version.h depends on lib/Config_git.pl | |
2595 | # This is harmless. | |
2596 | $code =~ s{^(?:lib/Config_git\.pl )?git_version\.h: (.* make_patchnum\.pl.*)} | |
2597 | {git_version.h: lib/Config_git.pl | |
2598 | ||
2599 | lib/Config_git.pl: $1}m; | |
2600 | ||
97897675 NC |
2601 | # This emulates commits 0f13ebd5d71f8177 and |
2602 | # and a04d4598adc57886. It ensures that | |
2603 | # lib/Config_git.pl is built before configpm, | |
2604 | # and that configpm is run exactly once. | |
2605 | $code =~ s{^(\$\(.*?\) )?(\$\(CONFIGPOD\))(: .*? configpm Porting/Glossary)( lib/Config_git\.pl)?}{ | |
2606 | # If present, other files depend on $(CONFIGPOD) | |
2607 | ($1 ? "$1: $2\n\n" : '') | |
2608 | # Then the rule we found | |
2609 | . $2 . $3 | |
2610 | # Add dependency if not there | |
2611 | . ($4 ? $4 : ' lib/Config_git.pl') | |
2612 | }me; | |
2613 | ||
74adbdfa NC |
2614 | return $code; |
2615 | }); | |
c0960282 NC |
2616 | } |
2617 | } | |
2618 | ||
bb723266 NC |
2619 | if ($major < 14) { |
2620 | # Commits dc0655f797469c47 and d11a62fe01f2ecb2 | |
2621 | edit_file('Makefile.SH', sub { | |
2622 | my $code = shift; | |
2623 | foreach my $ext (qw(Encode SDBM_File)) { | |
2624 | next if $code =~ /\b$ext\) extra_dep=/s; | |
2625 | $code =~ s!(\) extra_dep="\$extra_dep | |
2626 | \$this_target: .*?" ;;) | |
2627 | ( esac | |
2628 | )!$1 | |
2629 | $ext) extra_dep="\$extra_dep | |
2630 | \$this_target: lib/auto/Cwd/Cwd.\$dlext" ;; | |
2631 | $2!; | |
2632 | } | |
2633 | return $code; | |
2634 | }); | |
2635 | } | |
2636 | } | |
2637 | ||
2638 | if ($major == 7) { | |
2639 | # Remove commits 9fec149bb652b6e9 and 5bab1179608f81d8, which add/amend | |
2640 | # rules to automatically run regen scripts that rebuild C headers. These | |
2641 | # cause problems because a git checkout doesn't preserve relative file | |
2642 | # modification times, hence the regen scripts may fire. This will | |
2643 | # obscure whether the repository had the correct generated headers | |
2644 | # checked in. | |
2645 | # Also, the dependency rules for running the scripts were not correct, | |
2646 | # which could cause spurious re-builds on re-running make, and can cause | |
2647 | # complete build failures for a parallel make. | |
2648 | if (extract_from_file('Makefile.SH', | |
2649 | qr/Writing it this way gives make a big hint to always run opcode\.pl before/)) { | |
2650 | apply_commit('70c6e6715e8fec53'); | |
2651 | } elsif (extract_from_file('Makefile.SH', | |
2652 | qr/^opcode\.h opnames\.h pp_proto\.h pp\.sym: opcode\.pl$/)) { | |
2653 | revert_commit('9fec149bb652b6e9'); | |
2654 | } | |
2655 | } | |
2656 | ||
e628fd8c NC |
2657 | if ($^O eq 'aix' && $major >= 11 && $major <= 15 |
2658 | && extract_from_file('makedef.pl', qr/^use Config/)) { | |
2659 | edit_file('Makefile.SH', sub { | |
2660 | # The AIX part of commit e6807d8ab22b761c | |
2661 | # It's safe to substitute lib/Config.pm for config.sh | |
2662 | # as lib/Config.pm depends on config.sh | |
2663 | # If the tree is post e6807d8ab22b761c, the substitution | |
2664 | # won't match, which is harmless. | |
2665 | my $code = shift; | |
2666 | $code =~ s{^(perl\.exp:.* )config\.sh(\b.*)} | |
2667 | {$1 . '$(CONFIGPM)' . $2}me; | |
2668 | return $code; | |
2669 | }); | |
2670 | } | |
2671 | ||
bb723266 NC |
2672 | # There was a bug in makedepend.SH which was fixed in version 96a8704c. |
2673 | # Symptom was './makedepend: 1: Syntax error: Unterminated quoted string' | |
2674 | # Remove this if you're actually bisecting a problem related to | |
2675 | # makedepend.SH | |
2676 | # If you do this, you may need to add in code to correct the output of older | |
2677 | # makedepends, which don't correctly filter newer gcc output such as | |
2678 | # <built-in> | |
2679 | checkout_file('makedepend.SH'); | |
2680 | ||
2681 | if ($major < 4 && -f 'config.sh' | |
2682 | && !extract_from_file('config.sh', qr/^trnl=/)) { | |
2683 | # This seems to be necessary to avoid makedepend becoming confused, | |
2684 | # and hanging on stdin. Seems that the code after | |
2685 | # make shlist || ...here... is never run. | |
2686 | edit_file('makedepend.SH', sub { | |
2687 | my $code = shift; | |
2688 | $code =~ s/^trnl='\$trnl'$/trnl='\\n'/m; | |
2689 | return $code; | |
2690 | }); | |
2691 | } | |
2692 | } | |
2693 | ||
2694 | sub patch_C { | |
2695 | # This is ordered by $major, as it's likely that different platforms may | |
2696 | # well want to share code. | |
2697 | ||
2698 | if ($major == 2 && extract_from_file('perl.c', qr/^\tfclose\(e_fp\);$/)) { | |
2699 | # need to patch perl.c to avoid calling fclose() twice on e_fp when | |
2700 | # using -e | |
2701 | # This diff is part of commit ab821d7fdc14a438. The second close was | |
2702 | # introduced with perl-5.002, commit a5f75d667838e8e7 | |
2703 | # Might want a6c477ed8d4864e6 too, for the corresponding change to | |
2704 | # pp_ctl.c (likely without this, eval will have "fun") | |
2705 | apply_patch(<<'EOPATCH'); | |
2706 | diff --git a/perl.c b/perl.c | |
2707 | index 03c4d48..3c814a2 100644 | |
2708 | --- a/perl.c | |
2709 | +++ b/perl.c | |
2710 | @@ -252,6 +252,7 @@ setuid perl scripts securely.\n"); | |
2711 | #ifndef VMS /* VMS doesn't have environ array */ | |
2712 | origenviron = environ; | |
2713 | #endif | |
2714 | + e_tmpname = Nullch; | |
2715 | ||
2716 | if (do_undump) { | |
2717 | ||
2718 | @@ -405,6 +406,7 @@ setuid perl scripts securely.\n"); | |
2719 | if (e_fp) { | |
2720 | if (Fflush(e_fp) || ferror(e_fp) || fclose(e_fp)) | |
2721 | croak("Can't write to temp file for -e: %s", Strerror(errno)); | |
2722 | + e_fp = Nullfp; | |
2723 | argc++,argv--; | |
2724 | scriptname = e_tmpname; | |
2725 | } | |
2726 | @@ -470,10 +472,10 @@ setuid perl scripts securely.\n"); | |
2727 | curcop->cop_line = 0; | |
2728 | curstash = defstash; | |
2729 | preprocess = FALSE; | |
2730 | - if (e_fp) { | |
2731 | - fclose(e_fp); | |
2732 | - e_fp = Nullfp; | |
2733 | + if (e_tmpname) { | |
2734 | (void)UNLINK(e_tmpname); | |
2735 | + Safefree(e_tmpname); | |
2736 | + e_tmpname = Nullch; | |
2737 | } | |
2738 | ||
2739 | /* now that script is parsed, we can modify record separator */ | |
2740 | @@ -1369,7 +1371,7 @@ SV *sv; | |
2741 | scriptname = xfound; | |
2742 | } | |
2743 | ||
2744 | - origfilename = savepv(e_fp ? "-e" : scriptname); | |
2745 | + origfilename = savepv(e_tmpname ? "-e" : scriptname); | |
2746 | curcop->cop_filegv = gv_fetchfile(origfilename); | |
2747 | if (strEQ(origfilename,"-")) | |
2748 | scriptname = ""; | |
2749 | ||
2750 | EOPATCH | |
2751 | } | |
2752 | ||
2753 | if ($major < 3 && $^O eq 'openbsd' | |
2754 | && !extract_from_file('pp_sys.c', qr/BSD_GETPGRP/)) { | |
2755 | # Part of commit c3293030fd1b7489 | |
2756 | apply_patch(<<'EOPATCH'); | |
2757 | diff --git a/pp_sys.c b/pp_sys.c | |
2758 | index 4608a2a..f0c9d1d 100644 | |
2759 | --- a/pp_sys.c | |
2760 | +++ b/pp_sys.c | |
2761 | @@ -2903,8 +2903,8 @@ PP(pp_getpgrp) | |
2762 | pid = 0; | |
2763 | else | |
2764 | pid = SvIVx(POPs); | |
2765 | -#ifdef USE_BSDPGRP | |
2766 | - value = (I32)getpgrp(pid); | |
2767 | +#ifdef BSD_GETPGRP | |
2768 | + value = (I32)BSD_GETPGRP(pid); | |
2769 | #else | |
2770 | if (pid != 0) | |
2771 | DIE("POSIX getpgrp can't take an argument"); | |
2772 | @@ -2933,8 +2933,8 @@ PP(pp_setpgrp) | |
2773 | } | |
2774 | ||
2775 | TAINT_PROPER("setpgrp"); | |
2776 | -#ifdef USE_BSDPGRP | |
2777 | - SETi( setpgrp(pid, pgrp) >= 0 ); | |
2778 | +#ifdef BSD_SETPGRP | |
2779 | + SETi( BSD_SETPGRP(pid, pgrp) >= 0 ); | |
2780 | #else | |
2781 | if ((pgrp != 0) || (pid != 0)) { | |
2782 | DIE("POSIX setpgrp can't take an argument"); | |
2783 | EOPATCH | |
2784 | } | |
2785 | ||
2786 | if ($major < 4 && $^O eq 'openbsd') { | |
2787 | my $bad; | |
2788 | # Need changes from commit a6e633defa583ad5. | |
2789 | # Commits c07a80fdfe3926b5 and f82b3d4130164d5f changed the same part | |
2790 | # of perl.h | |
2791 | ||
2792 | if (extract_from_file('perl.h', | |
2793 | qr/^#ifdef HAS_GETPGRP2$/)) { | |
2794 | $bad = <<'EOBAD'; | |
2795 | *************** | |
2796 | *** 57,71 **** | |
2797 | #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s) | |
2798 | #define TAINT_ENV() if (tainting) taint_env() | |
2799 | ||
2800 | ! #ifdef HAS_GETPGRP2 | |
2801 | ! # ifndef HAS_GETPGRP | |
2802 | ! # define HAS_GETPGRP | |
2803 | ! # endif | |
2804 | ! #endif | |
2805 | ! | |
2806 | ! #ifdef HAS_SETPGRP2 | |
2807 | ! # ifndef HAS_SETPGRP | |
2808 | ! # define HAS_SETPGRP | |
2809 | ! # endif | |
2810 | #endif | |
2811 | ||
2812 | EOBAD | |
2813 | } elsif (extract_from_file('perl.h', | |
2814 | qr/Gack, you have one but not both of getpgrp2/)) { | |
2815 | $bad = <<'EOBAD'; | |
2816 | *************** | |
2817 | *** 56,76 **** | |
2818 | #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s) | |
2819 | #define TAINT_ENV() if (tainting) taint_env() | |
2820 | ||
2821 | ! #if defined(HAS_GETPGRP2) && defined(HAS_SETPGRP2) | |
2822 | ! # define getpgrp getpgrp2 | |
2823 | ! # define setpgrp setpgrp2 | |
2824 | ! # ifndef HAS_GETPGRP | |
2825 | ! # define HAS_GETPGRP | |
2826 | ! # endif | |
2827 | ! # ifndef HAS_SETPGRP | |
2828 | ! # define HAS_SETPGRP | |
2829 | ! # endif | |
2830 | ! # ifndef USE_BSDPGRP | |
2831 | ! # define USE_BSDPGRP | |
2832 | ! # endif | |
2833 | ! #else | |
2834 | ! # if defined(HAS_GETPGRP2) || defined(HAS_SETPGRP2) | |
2835 | ! #include "Gack, you have one but not both of getpgrp2() and setpgrp2()." | |
2836 | ! # endif | |
2837 | #endif | |
2838 | ||
2839 | EOBAD | |
2840 | } elsif (extract_from_file('perl.h', | |
2841 | qr/^#ifdef USE_BSDPGRP$/)) { | |
2842 | $bad = <<'EOBAD' | |
2843 | *************** | |
2844 | *** 91,116 **** | |
2845 | #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s) | |
2846 | #define TAINT_ENV() if (tainting) taint_env() | |
2847 | ||
2848 | ! #ifdef USE_BSDPGRP | |
2849 | ! # ifdef HAS_GETPGRP | |
2850 | ! # define BSD_GETPGRP(pid) getpgrp((pid)) | |
2851 | ! # endif | |
2852 | ! # ifdef HAS_SETPGRP | |
2853 | ! # define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp)) | |
2854 | ! # endif | |
2855 | ! #else | |
2856 | ! # ifdef HAS_GETPGRP2 | |
2857 | ! # define BSD_GETPGRP(pid) getpgrp2((pid)) | |
2858 | ! # ifndef HAS_GETPGRP | |
2859 | ! # define HAS_GETPGRP | |
2860 | ! # endif | |
2861 | ! # endif | |
2862 | ! # ifdef HAS_SETPGRP2 | |
2863 | ! # define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp)) | |
2864 | ! # ifndef HAS_SETPGRP | |
2865 | ! # define HAS_SETPGRP | |
2866 | ! # endif | |
2867 | ! # endif | |
2868 | #endif | |
2869 | ||
2870 | #ifndef _TYPES_ /* If types.h defines this it's easy. */ | |
2871 | EOBAD | |
2872 | } | |
2873 | if ($bad) { | |
2874 | apply_patch(<<"EOPATCH"); | |
2875 | *** a/perl.h 2011-10-21 09:46:12.000000000 +0200 | |
2876 | --- b/perl.h 2011-10-21 09:46:12.000000000 +0200 | |
2877 | $bad--- 91,144 ---- | |
2878 | #define TAINT_PROPER(s) if (tainting) taint_proper(no_security, s) | |
2879 | #define TAINT_ENV() if (tainting) taint_env() | |
2880 | ||
2881 | ! /* XXX All process group stuff is handled in pp_sys.c. Should these | |
2882 | ! defines move there? If so, I could simplify this a lot. --AD 9/96. | |
2883 | ! */ | |
2884 | ! /* Process group stuff changed from traditional BSD to POSIX. | |
2885 | ! perlfunc.pod documents the traditional BSD-style syntax, so we'll | |
2886 | ! try to preserve that, if possible. | |
2887 | ! */ | |
2888 | ! #ifdef HAS_SETPGID | |
2889 | ! # define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp)) | |
2890 | ! #else | |
2891 | ! # if defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP) | |
2892 | ! # define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp)) | |
2893 | ! # else | |
2894 | ! # ifdef HAS_SETPGRP2 /* DG/UX */ | |
2895 | ! # define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp)) | |
2896 | ! # endif | |
2897 | ! # endif | |
2898 | ! #endif | |
2899 | ! #if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP) | |
2900 | ! # define HAS_SETPGRP /* Well, effectively it does . . . */ | |
2901 | ! #endif | |
2902 | ! | |
2903 | ! /* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes | |
2904 | ! our life easier :-) so we'll try it. | |
2905 | ! */ | |
2906 | ! #ifdef HAS_GETPGID | |
2907 | ! # define BSD_GETPGRP(pid) getpgid((pid)) | |
2908 | ! #else | |
2909 | ! # if defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP) | |
2910 | ! # define BSD_GETPGRP(pid) getpgrp((pid)) | |
2911 | ! # else | |
2912 | ! # ifdef HAS_GETPGRP2 /* DG/UX */ | |
2913 | ! # define BSD_GETPGRP(pid) getpgrp2((pid)) | |
2914 | ! # endif | |
2915 | ! # endif | |
2916 | ! #endif | |
2917 | ! #if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP) | |
2918 | ! # define HAS_GETPGRP /* Well, effectively it does . . . */ | |
2919 | ! #endif | |
2920 | ! | |
2921 | ! /* These are not exact synonyms, since setpgrp() and getpgrp() may | |
2922 | ! have different behaviors, but perl.h used to define USE_BSDPGRP | |
2923 | ! (prior to 5.003_05) so some extension might depend on it. | |
2924 | ! */ | |
2925 | ! #if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP) | |
2926 | ! # ifndef USE_BSDPGRP | |
2927 | ! # define USE_BSDPGRP | |
2928 | ! # endif | |
2929 | #endif | |
2930 | ||
2931 | #ifndef _TYPES_ /* If types.h defines this it's easy. */ | |
2932 | EOPATCH | |
2933 | } | |
2934 | } | |
2935 | ||
8245f086 NC |
2936 | if ($major < 4 && $^O eq 'hpux' |
2937 | && extract_from_file('sv.c', qr/i = _filbuf\(/)) { | |
2938 | apply_patch(<<'EOPATCH'); | |
2939 | diff --git a/sv.c b/sv.c | |
2940 | index a1f1d60..0a806f1 100644 | |
2941 | --- a/sv.c | |
2942 | +++ b/sv.c | |
2943 | @@ -2641,7 +2641,7 @@ I32 append; | |
2944 | ||
2945 | FILE_cnt(fp) = cnt; /* deregisterize cnt and ptr */ | |
2946 | FILE_ptr(fp) = ptr; | |
2947 | - i = _filbuf(fp); /* get more characters */ | |
2948 | + i = __filbuf(fp); /* get more characters */ | |
2949 | cnt = FILE_cnt(fp); | |
2950 | ptr = FILE_ptr(fp); /* reregisterize cnt and ptr */ | |
2951 | ||
2952 | ||
2953 | EOPATCH | |
2954 | } | |
2955 | ||
bb723266 NC |
2956 | if ($major == 4 && extract_from_file('scope.c', qr/\(SV\*\)SSPOPINT/)) { |
2957 | # [PATCH] 5.004_04 +MAINT_TRIAL_1 broken when sizeof(int) != sizeof(void) | |
2958 | # Fixes a bug introduced in 161b7d1635bc830b | |
2959 | apply_commit('9002cb76ec83ef7f'); | |
2960 | } | |
2961 | ||
2962 | if ($major == 4 && extract_from_file('av.c', qr/AvARRAY\(av\) = 0;/)) { | |
2963 | # Fixes a bug introduced in 1393e20655efb4bc | |
2964 | apply_commit('e1c148c28bf3335b', 'av.c'); | |
2965 | } | |
2966 | ||
6626a474 NC |
2967 | if ($major == 4) { |
2968 | my $rest = extract_from_file('perl.c', qr/delimcpy(.*)/); | |
2969 | if (defined $rest and $rest !~ /,$/) { | |
2970 | # delimcpy added in fc36a67e8855d031, perl.c refactored to use it. | |
2971 | # bug introduced in 2a92aaa05aa1acbf, fixed in 8490252049bf42d3 | |
2972 | # code then moved to util.c in commit 491527d0220de34e | |
2973 | apply_patch(<<'EOPATCH'); | |
bb723266 NC |
2974 | diff --git a/perl.c b/perl.c |
2975 | index 4eb69e3..54bbb00 100644 | |
2976 | --- a/perl.c | |
2977 | +++ b/perl.c | |
2978 | @@ -1735,7 +1735,7 @@ SV *sv; | |
2979 | if (len < sizeof tokenbuf) | |
2980 | tokenbuf[len] = '\0'; | |
2981 | #else /* ! (atarist || DOSISH) */ | |
2982 | - s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf, s, bufend | |
2983 | + s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf, s, bufend, | |
2984 | ':', | |
2985 | &len); | |
2986 | #endif /* ! (atarist || DOSISH) */ | |
2987 | EOPATCH | |
6626a474 | 2988 | } |
bb723266 NC |
2989 | } |
2990 | ||
2991 | if ($major == 4 && $^O eq 'linux') { | |
2992 | # Whilst this is fixed properly in f0784f6a4c3e45e1 which provides the | |
2993 | # Configure probe, it's easier to back out the problematic changes made | |
c8ac76a5 NC |
2994 | # in these previous commits. |
2995 | ||
2996 | # In maint-5.004, the simplest addition is to "correct" the file to | |
2997 | # use the same pre-processor macros as blead had used. Whilst commit | |
2998 | # 9b599b2a63d2324d (reverted below) is described as | |
2999 | # [win32] merge change#887 from maintbranch | |
3000 | # it uses __sun__ and __svr4__ instead of the __sun and __SVR4 of the | |
3001 | # maint branch commit 6cdf74fe31f049dc | |
3002 | ||
3003 | edit_file('doio.c', sub { | |
3004 | my $code = shift; | |
3005 | $code =~ s{defined\(__sun\) && defined\(__SVR4\)} | |
3006 | {defined(__sun__) && defined(__svr4__)}g; | |
3007 | return $code; | |
3008 | }); | |
3009 | ||
bb723266 NC |
3010 | if (extract_from_file('doio.c', |
3011 | qr!^/\* XXX REALLY need metaconfig test \*/$!)) { | |
3012 | revert_commit('4682965a1447ea44', 'doio.c'); | |
3013 | } | |
3014 | if (my $token = extract_from_file('doio.c', | |
3015 | qr!^#if (defined\(__sun(?:__)?\)) && defined\(__svr4__\) /\* XXX Need metaconfig test \*/$!)) { | |
3016 | my $patch = `git show -R 9b599b2a63d2324d doio.c`; | |
3017 | $patch =~ s/defined\(__sun__\)/$token/g; | |
3018 | apply_patch($patch); | |
3019 | } | |
3020 | if (extract_from_file('doio.c', | |
3021 | qr!^/\* linux \(and Solaris2\?\) uses :$!)) { | |
3022 | revert_commit('8490252049bf42d3', 'doio.c'); | |
3023 | } | |
3024 | if (extract_from_file('doio.c', | |
3025 | qr/^ unsemds.buf = &semds;$/)) { | |
3026 | revert_commit('8e591e46b4c6543e'); | |
3027 | } | |
3028 | if (extract_from_file('doio.c', | |
3029 | qr!^#ifdef __linux__ /\* XXX Need metaconfig test \*/$!)) { | |
3030 | # Reverts part of commit 3e3baf6d63945cb6 | |
3031 | apply_patch(<<'EOPATCH'); | |
3032 | diff --git b/doio.c a/doio.c | |
3033 | index 62b7de9..0d57425 100644 | |
3034 | --- b/doio.c | |
3035 | +++ a/doio.c | |
3036 | @@ -1333,9 +1331,6 @@ SV **sp; | |
3037 | char *a; | |
3038 | I32 id, n, cmd, infosize, getinfo; | |
3039 | I32 ret = -1; | |
3040 | -#ifdef __linux__ /* XXX Need metaconfig test */ | |
3041 | - union semun unsemds; | |
3042 | -#endif | |
3043 | ||
3044 | id = SvIVx(*++mark); | |
3045 | n = (optype == OP_SEMCTL) ? SvIVx(*++mark) : 0; | |
3046 | @@ -1364,29 +1359,11 @@ SV **sp; | |
3047 | infosize = sizeof(struct semid_ds); | |
3048 | else if (cmd == GETALL || cmd == SETALL) | |
3049 | { | |
3050 | -#ifdef __linux__ /* XXX Need metaconfig test */ | |
3051 | -/* linux uses : | |
3052 | - int semctl (int semid, int semnun, int cmd, union semun arg) | |
3053 | - | |
3054 | - union semun { | |
3055 | - int val; | |
3056 | - struct semid_ds *buf; | |
3057 | - ushort *array; | |
3058 | - }; | |
3059 | -*/ | |
3060 | - union semun semds; | |
3061 | - if (semctl(id, 0, IPC_STAT, semds) == -1) | |
3062 | -#else | |
3063 | struct semid_ds semds; | |
3064 | if (semctl(id, 0, IPC_STAT, &semds) == -1) | |
3065 | -#endif | |
3066 | return -1; | |
3067 | getinfo = (cmd == GETALL); | |
3068 | -#ifdef __linux__ /* XXX Need metaconfig test */ | |
3069 | - infosize = semds.buf->sem_nsems * sizeof(short); | |
3070 | -#else | |
3071 | infosize = semds.sem_nsems * sizeof(short); | |
3072 | -#endif | |
3073 | /* "short" is technically wrong but much more portable | |
3074 | than guessing about u_?short(_t)? */ | |
3075 | } | |
3076 | @@ -1429,12 +1406,7 @@ SV **sp; | |
3077 | #endif | |
3078 | #ifdef HAS_SEM | |
3079 | case OP_SEMCTL: | |
3080 | -#ifdef __linux__ /* XXX Need metaconfig test */ | |
3081 | - unsemds.buf = (struct semid_ds *)a; | |
3082 | - ret = semctl(id, n, cmd, unsemds); | |
3083 | -#else | |
3084 | ret = semctl(id, n, cmd, (struct semid_ds *)a); | |
3085 | -#endif | |
3086 | break; | |
3087 | #endif | |
3088 | #ifdef HAS_SHM | |
3089 | EOPATCH | |
3090 | } | |
3091 | # Incorrect prototype added as part of 8ac853655d9b7447, fixed as part | |
3092 | # of commit dc45a647708b6c54, with at least one intermediate | |
3093 | # modification. Correct prototype for gethostbyaddr has socklen_t | |
3094 | # second. Linux has uint32_t first for getnetbyaddr. | |
3095 | # Easiest just to remove, instead of attempting more complex patching. | |
3096 | # Something similar may be needed on other platforms. | |
3097 | edit_file('pp_sys.c', sub { | |
3098 | my $code = shift; | |
3099 | $code =~ s/^ struct hostent \*(?:PerlSock_)?gethostbyaddr\([^)]+\);$//m; | |
3100 | $code =~ s/^ struct netent \*getnetbyaddr\([^)]+\);$//m; | |
3101 | return $code; | |
3102 | }); | |
3103 | } | |
3104 | ||
d1ac19b7 NC |
3105 | if ($major < 5 && $^O eq 'aix' |
3106 | && !extract_from_file('pp_sys.c', | |
3107 | qr/defined\(HOST_NOT_FOUND\) && !defined\(h_errno\)/)) { | |
3108 | # part of commit dc45a647708b6c54 | |
3109 | # Andy Dougherty's configuration patches (Config_63-01 up to 04). | |
3110 | apply_patch(<<'EOPATCH') | |
3111 | diff --git a/pp_sys.c b/pp_sys.c | |
3112 | index c2fcb6f..efa39fb 100644 | |
3113 | --- a/pp_sys.c | |
3114 | +++ b/pp_sys.c | |
3115 | @@ -54,7 +54,7 @@ extern "C" int syscall(unsigned long,...); | |
3116 | #endif | |
3117 | #endif | |
3118 | ||
3119 | -#ifdef HOST_NOT_FOUND | |
3120 | +#if defined(HOST_NOT_FOUND) && !defined(h_errno) | |
3121 | extern int h_errno; | |
3122 | #endif | |
3123 | ||
3124 | EOPATCH | |
3125 | } | |
3126 | ||
df01cf53 | 3127 | if ($major == 5 |
31940c07 NC |
3128 | && `git rev-parse HEAD` eq "22c35a8c2392967a5ba6b5370695be464bd7012c\n") { |
3129 | # Commit 22c35a8c2392967a is significant, | |
3130 | # "phase 1 of somewhat major rearrangement of PERL_OBJECT stuff" | |
3131 | # but doesn't build due to 2 simple errors. blead in this broken state | |
3132 | # was merged to the cfgperl branch, and then these were immediately | |
3133 | # corrected there. cfgperl (with the fixes) was merged back to blead. | |
3134 | # The resultant rather twisty maze of commits looks like this: | |
3135 | ||
911bfca9 | 3136 | =begin comment |
31940c07 NC |
3137 | |
3138 | * | | commit 137225782c183172f360c827424b9b9f8adbef0e | |
3139 | |\ \ \ Merge: 22c35a8 2a8ee23 | |
3140 | | |/ / Author: Gurusamy Sarathy <gsar@cpan.org> | |
3141 | | | | Date: Fri Oct 30 17:38:36 1998 +0000 | |
3142 | | | | | |
3143 | | | | integrate cfgperl tweaks into mainline | |
3144 | | | | | |
3145 | | | | p4raw-id: //depot/perl@2144 | |
3146 | | | | | |
3147 | | * | commit 2a8ee23279873759693fa83eca279355db2b665c | |
3148 | | | | Author: Jarkko Hietaniemi <jhi@iki.fi> | |
3149 | | | | Date: Fri Oct 30 13:27:39 1998 +0000 | |
3150 | | | | | |
3151 | | | | There can be multiple yacc/bison errors. | |
3152 | | | | | |
3153 | | | | p4raw-id: //depot/cfgperl@2143 | |
3154 | | | | | |
3155 | | * | commit 93fb2ac393172fc3e2c14edb20b718309198abbc | |
3156 | | | | Author: Jarkko Hietaniemi <jhi@iki.fi> | |
3157 | | | | Date: Fri Oct 30 13:18:43 1998 +0000 | |
3158 | | | | | |
3159 | | | | README.posix-bc update. | |
3160 | | | | | |
3161 | | | | p4raw-id: //depot/cfgperl@2142 | |
3162 | | | | | |
3163 | | * | commit 4ec43091e8e6657cb260b5e563df30aaa154effe | |
3164 | | | | Author: Jarkko Hietaniemi <jhi@iki.fi> | |
3165 | | | | Date: Fri Oct 30 09:12:59 1998 +0000 | |
3166 | | | | | |
3167 | | | | #2133 fallout. | |
3168 | | | | | |
3169 | | | | p4raw-id: //depot/cfgperl@2141 | |
3170 | | | | | |
3171 | | * | commit 134ca994cfefe0f613d43505a885e4fc2100b05c | |
3172 | | |\ \ Merge: 7093112 22c35a8 | |
3173 | | |/ / Author: Jarkko Hietaniemi <jhi@iki.fi> | |
3174 | |/| | Date: Fri Oct 30 08:43:18 1998 +0000 | |
3175 | | | | | |
3176 | | | | Integrate from mainperl. | |
3177 | | | | | |
3178 | | | | p4raw-id: //depot/cfgperl@2140 | |
3179 | | | | | |
3180 | * | | commit 22c35a8c2392967a5ba6b5370695be464bd7012c | |
3181 | | | | Author: Gurusamy Sarathy <gsar@cpan.org> | |
3182 | | | | Date: Fri Oct 30 02:51:39 1998 +0000 | |
3183 | | | | | |
3184 | | | | phase 1 of somewhat major rearrangement of PERL_OBJECT stuff | |
3185 | | | | (objpp.h is gone, embed.pl now does some of that); objXSUB.h | |
3186 | | | | should soon be automated also; the global variables that | |
3187 | | | | escaped the PL_foo conversion are now reined in; renamed | |
3188 | | | | MAGIC in regcomp.h to REG_MAGIC to avoid collision with the | |
3189 | | | | type of same name; duplicated lists of pp_things in various | |
3190 | | | | places is now gone; result has only been tested on win32 | |
3191 | | | | | |
3192 | | | | p4raw-id: //depot/perl@2133 | |
3193 | ||
911bfca9 NC |
3194 | =end comment |
3195 | ||
31940c07 NC |
3196 | =cut |
3197 | ||
3198 | # and completely confuses git bisect (and at least me), causing it to | |
3199 | # the bisect run to confidently return the wrong answer, an unrelated | |
3200 | # commit on the cfgperl branch. | |
3201 | ||
3202 | apply_commit('4ec43091e8e6657c'); | |
3203 | } | |
3204 | ||
3205 | if ($major == 5 | |
df01cf53 NC |
3206 | && extract_from_file('pp_sys.c', qr/PERL_EFF_ACCESS_R_OK/) |
3207 | && !extract_from_file('pp_sys.c', qr/XXX Configure test needed for eaccess/)) { | |
3208 | # Between 5ff3f7a4e03a6b10 and c955f1177b2e311d^ | |
3209 | # This is the meat of commit c955f1177b2e311d (without the other | |
3210 | # indenting changes that would cause a conflict). | |
3211 | # Without this 538 revisions won't build on (at least) Linux | |
3212 | apply_patch(<<'EOPATCH'); | |
3213 | diff --git a/pp_sys.c b/pp_sys.c | |
3214 | index d60c8dc..867dee4 100644 | |
3215 | --- a/pp_sys.c | |
3216 | +++ b/pp_sys.c | |
3217 | @@ -198,9 +198,18 @@ static char zero_but_true[ZBTLEN + 1] = "0 but true"; | |
3218 | # if defined(I_SYS_SECURITY) | |
3219 | # include <sys/security.h> | |
3220 | # endif | |
3221 | -# define PERL_EFF_ACCESS_R_OK(p) (eaccess((p), R_OK, ACC_SELF)) | |
3222 | -# define PERL_EFF_ACCESS_W_OK(p) (eaccess((p), W_OK, ACC_SELF)) | |
3223 | -# define PERL_EFF_ACCESS_X_OK(p) (eaccess((p), X_OK, ACC_SELF)) | |
3224 | + /* XXX Configure test needed for eaccess */ | |
3225 | +# ifdef ACC_SELF | |
3226 | + /* HP SecureWare */ | |
3227 | +# define PERL_EFF_ACCESS_R_OK(p) (eaccess((p), R_OK, ACC_SELF)) | |
3228 | +# define PERL_EFF_ACCESS_W_OK(p) (eaccess((p), W_OK, ACC_SELF)) | |
3229 | +# define PERL_EFF_ACCESS_X_OK(p) (eaccess((p), X_OK, ACC_SELF)) | |
3230 | +# else | |
3231 | + /* SCO */ | |
3232 | +# define PERL_EFF_ACCESS_R_OK(p) (eaccess((p), R_OK)) | |
3233 | +# define PERL_EFF_ACCESS_W_OK(p) (eaccess((p), W_OK)) | |
3234 | +# define PERL_EFF_ACCESS_X_OK(p) (eaccess((p), X_OK)) | |
3235 | +# endif | |
3236 | #endif | |
3237 | ||
3238 | #if !defined(PERL_EFF_ACCESS_R_OK) && defined(HAS_ACCESSX) && defined(ACC_SELF) | |
3239 | EOPATCH | |
3240 | } | |
3241 | ||
bb35dd48 NC |
3242 | if ($major == 5 |
3243 | && extract_from_file('mg.c', qr/If we're still on top of the stack, pop us off/) | |
af6a5d0e | 3244 | && !extract_from_file('mg.c', qr/PL_savestack_ix -= popval/)) { |
bb35dd48 NC |
3245 | # Fix up commit 455ece5e082708b1: |
3246 | # SSNEW() API for allocating memory on the savestack | |
3247 | # Message-Id: <tqemtae338.fsf@puma.genscan.com> | |
3248 | # Subject: [PATCH 5.005_51] (was: why SAVEDESTRUCTOR()...) | |
3249 | apply_commit('3c8a44569607336e', 'mg.c'); | |
3250 | } | |
3251 | ||
6863570c NC |
3252 | if ($major == 5) { |
3253 | if (extract_from_file('doop.c', qr/croak\(no_modify\);/) | |
3254 | && extract_from_file('doop.c', qr/croak\(PL_no_modify\);/)) { | |
3255 | # Whilst the log suggests that this would only fix 5 commits, in | |
3256 | # practice this area of history is a complete tarpit, and git bisect | |
3257 | # gets very confused by the skips in the middle of the back and | |
3258 | # forth merging between //depot/perl and //depot/cfgperl | |
3259 | apply_commit('6393042b638dafd3'); | |
3260 | } | |
3261 | ||
3262 | # One error "fixed" with another: | |
3263 | if (extract_from_file('pp_ctl.c', | |
3264 | qr/\Qstatic void *docatch_body _((void *o));\E/)) { | |
3265 | apply_commit('5b51e982882955fe'); | |
3266 | } | |
3267 | # Which is then fixed by this: | |
3268 | if (extract_from_file('pp_ctl.c', | |
3269 | qr/\Qstatic void *docatch_body _((valist\E/)) { | |
3270 | apply_commit('47aa779ee4c1a50e'); | |
3271 | } | |
3272 | ||
3273 | if (extract_from_file('thrdvar.h', qr/PERLVARI\(Tprotect/) | |
3274 | && !extract_from_file('embedvar.h', qr/PL_protect/)) { | |
3275 | # Commit 312caa8e97f1c7ee didn't update embedvar.h | |
3276 | apply_commit('e0284a306d2de082', 'embedvar.h'); | |
3277 | } | |
3278 | } | |
3279 | ||
3280 | if ($major == 5 | |
3281 | && extract_from_file('sv.c', | |
3282 | qr/PerlDir_close\(IoDIRP\((?:\(IO\*\))?sv\)\);/) | |
3283 | && !(extract_from_file('toke.c', | |
3284 | qr/\QIoDIRP(FILTER_DATA(AvFILLp(PL_rsfp_filters))) = NULL\E/) | |
3285 | || extract_from_file('toke.c', | |
3286 | qr/\QIoDIRP(datasv) = (DIR*)NULL;\E/))) { | |
3287 | # Commit 93578b34124e8a3b, //depot/perl@3298 | |
3288 | # close directory handles properly when localized, | |
3289 | # tweaked slightly by commit 1236053a2c722e2b, | |
3290 | # add test case for change#3298 | |
3291 | # | |
3292 | # The fix is the last part of: | |
3293 | # | |
3294 | # various fixes for clean build and test on win32; configpm broken, | |
3295 | # needed to open myconfig.SH rather than myconfig; sundry adjustments | |
3296 | # to bytecode stuff; tweaks to DYNAMIC_ENV_FETCH code to make it | |
3297 | # work under win32; getenv_sv() changed to getenv_len() since SVs | |
3298 | # aren't visible in the lower echelons; remove bogus exports from | |
3299 | # config.sym; PERL_OBJECT-ness for C++ exception support; null out | |
3300 | # IoDIRP in filter_del() or sv_free() will attempt to close it | |
3301 | # | |
3302 | # The changed code is modified subsequently by commit e0c198038146b7a4 | |
3303 | apply_commit('a6c403648ecd5cc7', 'toke.c'); | |
3304 | } | |
3305 | ||
bb723266 NC |
3306 | if ($major < 6 && $^O eq 'netbsd' |
3307 | && !extract_from_file('unixish.h', | |
3308 | qr/defined\(NSIG\).*defined\(__NetBSD__\)/)) { | |
3309 | apply_patch(<<'EOPATCH') | |
3310 | diff --git a/unixish.h b/unixish.h | |
3311 | index 2a6cbcd..eab2de1 100644 | |
3312 | --- a/unixish.h | |
3313 | +++ b/unixish.h | |
3314 | @@ -89,7 +89,7 @@ | |
3315 | */ | |
3316 | /* #define ALTERNATE_SHEBANG "#!" / **/ | |
3317 | ||
3318 | -#if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX) | |
3319 | +#if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX) || defined(__NetBSD__) | |
3320 | # include <signal.h> | |
3321 | #endif | |
3322 | ||
3323 | EOPATCH | |
3324 | } | |
3325 | ||
7ffe6e18 NC |
3326 | if ($major == 7 && $^O eq 'aix' && |
3327 | extract_from_file('ext/List/Util/Util.xs', qr/PUSHBLOCK/) | |
3328 | && !extract_from_file('makedef.pl', qr/^Perl_cxinc/)) { | |
3329 | # Need this to get List::Utils 1.03 and later to compile. | |
3330 | # 1.03 also expects to call Perl_pp_rand. Commit d3632a54487acc5f | |
3331 | # fixes this (for the unthreaded case), but it's not until 1.05, | |
3332 | # two days later, that this is fixed properly. | |
3333 | apply_commit('cbb96eed3f175499'); | |
3334 | } | |
3335 | ||
bb723266 NC |
3336 | if (($major >= 7 || $major <= 9) && $^O eq 'openbsd' |
3337 | && `uname -m` eq "sparc64\n" | |
3338 | # added in 2000 by commit cb434fcc98ac25f5: | |
3339 | && extract_from_file('regexec.c', | |
3340 | qr!/\* No need to save/restore up to this paren \*/!) | |
3341 | # re-indented in 2006 by commit 95b2444054382532: | |
3342 | && extract_from_file('regexec.c', qr/^\t\tCURCUR cc;$/)) { | |
3343 | # Need to work around a bug in (at least) OpenBSD's 4.6's sparc64 # | |
3344 | # compiler ["gcc (GCC) 3.3.5 (propolice)"]. Between commits | |
3345 | # 3ec562b0bffb8b8b (2002) and 1a4fad37125bac3e^ (2005) the darling thing | |
3346 | # fails to compile any code for the statement cc.oldcc = PL_regcc; | |
3347 | # | |
3348 | # If you refactor the code to "fix" that, or force the issue using set | |
3349 | # in the debugger, the stack smashing detection code fires on return | |
3350 | # from S_regmatch(). Turns out that the compiler doesn't allocate any | |
3351 | # (or at least enough) space for cc. | |
3352 | # | |
3353 | # Restore the "uninitialised" value for cc before function exit, and the | |
3354 | # stack smashing code is placated. "Fix" 3ec562b0bffb8b8b (which | |
3355 | # changes the size of auto variables used elsewhere in S_regmatch), and | |
3356 | # the crash is visible back to bc517b45fdfb539b (which also changes | |
3357 | # buffer sizes). "Unfix" 1a4fad37125bac3e and the crash is visible until | |
3358 | # 5b47454deb66294b. Problem goes away if you compile with -O, or hack | |
3359 | # the code as below. | |
3360 | # | |
3361 | # Hence this turns out to be a bug in (old) gcc. Not a security bug we | |
3362 | # still need to fix. | |
3363 | apply_patch(<<'EOPATCH'); | |
3364 | diff --git a/regexec.c b/regexec.c | |
3365 | index 900b491..6251a0b 100644 | |
3366 | --- a/regexec.c | |
3367 | +++ b/regexec.c | |
3368 | @@ -2958,7 +2958,11 @@ S_regmatch(pTHX_ regnode *prog) | |
3369 | I,I | |
3370 | *******************************************************************/ | |
3371 | case CURLYX: { | |
3372 | - CURCUR cc; | |
3373 | + union { | |
3374 | + CURCUR hack_cc; | |
3375 | + char hack_buff[sizeof(CURCUR) + 1]; | |
3376 | + } hack; | |
3377 | +#define cc hack.hack_cc | |
3378 | CHECKPOINT cp = PL_savestack_ix; | |
3379 | /* No need to save/restore up to this paren */ | |
3380 | I32 parenfloor = scan->flags; | |
3381 | @@ -2983,6 +2987,7 @@ S_regmatch(pTHX_ regnode *prog) | |
3382 | n = regmatch(PREVOPER(next)); /* start on the WHILEM */ | |
3383 | regcpblow(cp); | |
3384 | PL_regcc = cc.oldcc; | |
3385 | +#undef cc | |
3386 | saySAME(n); | |
3387 | } | |
3388 | /* NOT REACHED */ | |
3389 | EOPATCH | |
3390 | } | |
3391 | ||
3392 | if ($major < 8 && $^O eq 'openbsd' | |
3393 | && !extract_from_file('perl.h', qr/include <unistd\.h>/)) { | |
3394 | # This is part of commit 3f270f98f9305540, applied at a slightly | |
3395 | # different location in perl.h, where the context is stable back to | |
3396 | # 5.000 | |
3397 | apply_patch(<<'EOPATCH'); | |
3398 | diff --git a/perl.h b/perl.h | |
3399 | index 9418b52..b8b1a7c 100644 | |
3400 | --- a/perl.h | |
3401 | +++ b/perl.h | |
3402 | @@ -496,6 +496,10 @@ register struct op *Perl_op asm(stringify(OP_IN_REGISTER)); | |
3403 | # include <sys/param.h> | |
3404 | #endif | |
3405 | ||
3406 | +/* If this causes problems, set i_unistd=undef in the hint file. */ | |
3407 | +#ifdef I_UNISTD | |
3408 | +# include <unistd.h> | |
3409 | +#endif | |
3410 | ||
3411 | /* Use all the "standard" definitions? */ | |
3412 | #if defined(STANDARD_C) && defined(I_STDLIB) | |
3413 | EOPATCH | |
3414 | } | |
3415 | } | |
3416 | ||
f2f0a0ff NC |
3417 | sub patch_ext { |
3418 | if (-f 'ext/POSIX/Makefile.PL' | |
3419 | && extract_from_file('ext/POSIX/Makefile.PL', | |
3420 | qr/Explicitly avoid including/)) { | |
3421 | # commit 6695a346c41138df, which effectively reverts 170888cff5e2ffb7 | |
3422 | ||
3423 | # PERL5LIB is populated by make_ext.pl with paths to the modules we need | |
3424 | # to run, don't override this with "../../lib" since that may not have | |
3425 | # been populated yet in a parallel build. | |
3426 | apply_commit('6695a346c41138df'); | |
3427 | } | |
3428 | ||
06cebb71 NC |
3429 | if (-f 'ext/Hash/Util/Makefile.PL' |
3430 | && extract_from_file('ext/Hash/Util/Makefile.PL', | |
3431 | qr/\bDIR\b.*'FieldHash'/)) { | |
3432 | # ext/Hash/Util/Makefile.PL should not recurse to FieldHash's Makefile.PL | |
3433 | # *nix, VMS and Win32 all know how to (and have to) call the latter directly. | |
3434 | # As is, targets in ext/Hash/Util/FieldHash get called twice, which may result | |
3435 | # in race conditions, and certainly messes up make clean; make distclean; | |
3436 | apply_commit('550428fe486b1888'); | |
3437 | } | |
3438 | ||
f2f0a0ff NC |
3439 | if ($major < 8 && $^O eq 'darwin' && !-f 'ext/DynaLoader/dl_dyld.xs') { |
3440 | checkout_file('ext/DynaLoader/dl_dyld.xs', 'f556e5b971932902'); | |
3441 | apply_patch(<<'EOPATCH'); | |
3442 | diff -u a/ext/DynaLoader/dl_dyld.xs~ a/ext/DynaLoader/dl_dyld.xs | |
3443 | --- a/ext/DynaLoader/dl_dyld.xs~ 2011-10-11 21:41:27.000000000 +0100 | |
3444 | +++ b/ext/DynaLoader/dl_dyld.xs 2011-10-11 21:42:20.000000000 +0100 | |
3445 | @@ -41,6 +41,35 @@ | |
3446 | #include "perl.h" | |
3447 | #include "XSUB.h" | |
3448 | ||
3449 | +#ifndef pTHX | |
3450 | +# define pTHX void | |
3451 | +# define pTHX_ | |
3452 | +#endif | |
3453 | +#ifndef aTHX | |
3454 | +# define aTHX | |
3455 | +# define aTHX_ | |
3456 | +#endif | |
3457 | +#ifndef dTHX | |
3458 | +# define dTHXa(a) extern int Perl___notused(void) | |
3459 | +# define dTHX extern int Perl___notused(void) | |
3460 | +#endif | |
3461 | + | |
3462 | +#ifndef Perl_form_nocontext | |
3463 | +# define Perl_form_nocontext form | |
3464 | +#endif | |
3465 | + | |
3466 | +#ifndef Perl_warn_nocontext | |
3467 | +# define Perl_warn_nocontext warn | |
3468 | +#endif | |
3469 | + | |
3470 | +#ifndef PTR2IV | |
3471 | +# define PTR2IV(p) (IV)(p) | |
3472 | +#endif | |
3473 | + | |
3474 | +#ifndef get_av | |
3475 | +# define get_av perl_get_av | |
3476 | +#endif | |
3477 | + | |
3478 | #define DL_LOADONCEONLY | |
3479 | ||
3480 | #include "dlutils.c" /* SaveError() etc */ | |
3481 | @@ -185,7 +191,7 @@ | |
3482 | CODE: | |
3483 | DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s,%x):\n", filename,flags)); | |
3484 | if (flags & 0x01) | |
3485 | - Perl_warn(aTHX_ "Can't make loaded symbols global on this platform while loading %s",filename); | |
3486 | + Perl_warn_nocontext("Can't make loaded symbols global on this platform while loading %s",filename); | |
3487 | RETVAL = dlopen(filename, mode) ; | |
3488 | DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%x\n", RETVAL)); | |
3489 | ST(0) = sv_newmortal() ; | |
3490 | EOPATCH | |
3491 | if ($major < 4 && !extract_from_file('util.c', qr/^form/m)) { | |
3492 | apply_patch(<<'EOPATCH'); | |
3493 | diff -u a/ext/DynaLoader/dl_dyld.xs~ a/ext/DynaLoader/dl_dyld.xs | |
3494 | --- a/ext/DynaLoader/dl_dyld.xs~ 2011-10-11 21:56:25.000000000 +0100 | |
3495 | +++ b/ext/DynaLoader/dl_dyld.xs 2011-10-11 22:00:00.000000000 +0100 | |
3496 | @@ -60,6 +60,18 @@ | |
3497 | # define get_av perl_get_av | |
3498 | #endif | |
3499 | ||
3500 | +static char * | |
3501 | +form(char *pat, ...) | |
3502 | +{ | |
3503 | + char *retval; | |
3504 | + va_list args; | |
3505 | + va_start(args, pat); | |
3506 | + vasprintf(&retval, pat, &args); | |
3507 | + va_end(args); | |
3508 | + SAVEFREEPV(retval); | |
3509 | + return retval; | |
3510 | +} | |
3511 | + | |
3512 | #define DL_LOADONCEONLY | |
3513 | ||
3514 | #include "dlutils.c" /* SaveError() etc */ | |
3515 | EOPATCH | |
3516 | } | |
3517 | } | |
3518 | ||
3519 | if ($major < 10) { | |
fbaecb45 NC |
3520 | if ($unfixable_db_file) { |
3521 | # Nothing we can do. | |
f2f0a0ff NC |
3522 | } elsif (!extract_from_file('ext/DB_File/DB_File.xs', |
3523 | qr/^#ifdef AT_LEAST_DB_4_1$/)) { | |
3524 | # This line is changed by commit 3245f0580c13b3ab | |
3525 | my $line = extract_from_file('ext/DB_File/DB_File.xs', | |
3526 | qr/^( status = \(?RETVAL->dbp->open\)?\(RETVAL->dbp, name, NULL, RETVAL->type, $)/); | |
3527 | apply_patch(<<"EOPATCH"); | |
3528 | diff --git a/ext/DB_File/DB_File.xs b/ext/DB_File/DB_File.xs | |
3529 | index 489ba96..fba8ded 100644 | |
3530 | --- a/ext/DB_File/DB_File.xs | |
3531 | +++ b/ext/DB_File/DB_File.xs | |
3532 | \@\@ -183,4 +187,8 \@\@ | |
3533 | #endif | |
3534 | ||
3535 | +#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) | |
3536 | +# define AT_LEAST_DB_4_1 | |
3537 | +#endif | |
3538 | + | |
3539 | /* map version 2 features & constants onto their version 1 equivalent */ | |
3540 | ||
3541 | \@\@ -1334,7 +1419,12 \@\@ SV * sv ; | |
3542 | #endif | |
3543 | ||
3544 | +#ifdef AT_LEAST_DB_4_1 | |
3545 | + status = (RETVAL->dbp->open)(RETVAL->dbp, NULL, name, NULL, RETVAL->type, | |
3546 | + Flags, mode) ; | |
3547 | +#else | |
3548 | $line | |
3549 | Flags, mode) ; | |
3550 | +#endif | |
3551 | /* printf("open returned %d %s\\n", status, db_strerror(status)) ; */ | |
3552 | ||
3553 | EOPATCH | |
3554 | } | |
3555 | } | |
3556 | ||
3557 | if ($major < 10 and -f 'ext/IPC/SysV/SysV.xs') { | |
3558 | edit_file('ext/IPC/SysV/SysV.xs', sub { | |
3559 | my $xs = shift; | |
3560 | my $fixed = <<'EOFIX'; | |
3561 | ||
3562 | #include <sys/types.h> | |
3563 | #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) | |
3564 | #ifndef HAS_SEM | |
3565 | # include <sys/ipc.h> | |
3566 | #endif | |
3567 | # ifdef HAS_MSG | |
3568 | # include <sys/msg.h> | |
3569 | # endif | |
3570 | # ifdef HAS_SHM | |
3571 | # if defined(PERL_SCO) || defined(PERL_ISC) | |
3572 | # include <sys/sysmacros.h> /* SHMLBA */ | |
3573 | # endif | |
3574 | # include <sys/shm.h> | |
3575 | # ifndef HAS_SHMAT_PROTOTYPE | |
3576 | extern Shmat_t shmat (int, char *, int); | |
3577 | # endif | |
3578 | # if defined(HAS_SYSCONF) && defined(_SC_PAGESIZE) | |
3579 | # undef SHMLBA /* not static: determined at boot time */ | |
3580 | # define SHMLBA sysconf(_SC_PAGESIZE) | |
3581 | # elif defined(HAS_GETPAGESIZE) | |
3582 | # undef SHMLBA /* not static: determined at boot time */ | |
3583 | # define SHMLBA getpagesize() | |
3584 | # endif | |
3585 | # endif | |
3586 | #endif | |
3587 | EOFIX | |
3588 | $xs =~ s! | |
3589 | #include <sys/types\.h> | |
3590 | .* | |
3591 | (#ifdef newCONSTSUB|/\* Required)!$fixed$1!ms; | |
3592 | return $xs; | |
3593 | }); | |
3594 | } | |
3595 | } | |
3596 | ||
df14fc13 NC |
3597 | sub apply_fixups { |
3598 | my $fixups = shift; | |
3599 | return unless $fixups; | |
3600 | foreach my $file (@$fixups) { | |
3601 | my $fh = open_or_die($file); | |
3602 | my $line = <$fh>; | |
3603 | close_or_die($fh); | |
3604 | if ($line =~ /^#!perl\b/) { | |
3605 | system $^X, $file | |
3606 | and die_255("$^X $file failed: \$!=$!, \$?=$?"); | |
3607 | } elsif ($line =~ /^#!(\/\S+)/) { | |
3608 | system $file | |
3609 | and die_255("$file failed: \$!=$!, \$?=$?"); | |
3610 | } else { | |
3611 | if (my ($target, $action, $pattern) | |
3612 | = $line =~ m#^(\S+) ([=!])~ /(.*)/#) { | |
3613 | if (length $pattern) { | |
3614 | next unless -f $target; | |
3615 | if ($action eq '=') { | |
3616 | next unless extract_from_file($target, $pattern); | |
3617 | } else { | |
3618 | next if extract_from_file($target, $pattern); | |
3619 | } | |
3620 | } else { | |
3621 | # Avoid the special case meaning of the empty pattern, | |
3622 | # and instead use this to simply test for the file being | |
3623 | # present or absent | |
3624 | if ($action eq '=') { | |
3625 | next unless -f $target; | |
3626 | } else { | |
3627 | next if -f $target; | |
3628 | } | |
3629 | } | |
3630 | } | |
3631 | system_or_die("patch -p1 <$file"); | |
3632 | } | |
3633 | } | |
3634 | } | |
3635 | ||
9a999a97 | 3636 | # ex: set ts=8 sts=4 sw=4 et: |