2 ################################################################################
4 # mktodo.pl -- generate baseline and todo files
6 ################################################################################
8 # Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
9 # Version 2.x, Copyright (C) 2001, Paul Marquess.
10 # Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
12 # This program is free software; you can redistribute it and/or
13 # modify it under the same terms as Perl itself.
15 ################################################################################
23 use Time::HiRes qw( gettimeofday tv_interval );
25 require './devel/devtools.pl';
28 blead => 0, # ? Is this perl blead
33 todo => "", # If no --todo, this is a blead perl
34 shlib => 'blib/arch/auto/Devel/PPPort/PPPort.so',
38 perl=s todo=s blead version=s shlib=s debug base verbose check!
43 print "\n", ident_str(), "\n\n";
45 my $fullperl = `which $opt{perl}`;
48 $ENV{SKIP_SLOW_TESTS} = 1;
52 my %stdsym = map { ($_ => 1) } qw (
69 for (`$Config{nm} $fullperl`) {
71 /\s+T\s+(\w+)\s*$/ and $sym{$1}++;
73 keys %sym >= 50 or die "less than 50 symbols found in $fullperl\n";
75 my %todo = %{load_todo($opt{todo}, $opt{version})} if $opt{todo};
78 my $symmap = get_apicheck_symbol_map();
86 my(@new, @already_in_sym, %seen);
88 my $r = run(qw(make));
89 $r->{didnotrun} and die "couldn't run make: $!\n" .
90 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
92 # If there were warnings, we ask the user before continuing when creating
93 # the base files of blead. This leads to a potential early exit when things
94 # aren't working right.
95 if ($opt{blead} && $opt{base}) {
96 undef $opt{blead}; # Only warn once.
97 if (@{$r->{stderr}}) {
98 print STDERR "Warnings and errors from compiling blead:\n";
99 print STDERR @{$r->{stderr}};
100 ask_or_quit("\nUnexpected warnings when compiling blead can lead to"
101 . " wrong results. Please examine the above list.\n"
102 . "Shall I proceed?");
105 print STDERR "blead compiled without warnings nor errors.\n"
106 . "Proceeding with everything else\n";
110 for my $l (@{$r->{stderr}}) {
111 if ($l =~ /_DPPP_test_(\w+)/) {
113 my @s = grep { exists $sym{$_} } $1, "Perl_$1", "perl_$1";
115 push @already_in_sym, [$1, "E (@s)"];
118 push @new, [$1, "E"];
124 if ($r->{status} == 0) {
129 @u = eval { find_undefined_symbols($fullperl, $opt{shlib}) };
130 warn "warning: $@" if $@;
135 $r = run(qw(make test));
136 $r->{didnotrun} and die "couldn't run make test: $!\n" .
137 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
138 $r->{status} == 0 and last;
140 for my $l (@{$r->{stderr}}) {
141 if ($l =~ /undefined symbol: (\w+)/) {
148 for my $m (keys %{$symmap->{$u}}) {
151 $pl =~ s/^[Pp]erl_//;
152 my @s = grep { exists $sym{$_} } $pl, "Perl_$pl", "perl_$pl";
153 push @new, [$m, @s ? "U (@s)" : "U"];
159 @new = grep !$todo{$_->[0]}, @new;
162 @new = grep !$todo{$_->[0]}, @already_in_sym;
172 die "no new TODO symbols found...";
175 # don't recheck undefined symbols reported by the dynamic linker
176 push @recheck, map { $_->[0] } grep { $_->[1] !~ /^U/ } @new;
179 display_sym('new', @$_);
180 $todo{$_->[0]} = $_->[1];
183 write_todo($opt{todo}, $opt{version}, \%todo);
187 my $ifmt = '%' . length(scalar @recheck) . 'd';
188 my $t0 = [gettimeofday];
190 RECHECK: for my $i (0 .. $#recheck) {
191 my $sym = $recheck[$i];
192 my $cur = delete $todo{$sym};
194 display_sym('chk', $sym, $cur, sprintf(" [$ifmt/$ifmt, ETA %s]",
195 $i + 1, scalar @recheck, eta($t0, $i, scalar @recheck)));
197 write_todo($opt{todo}, $opt{version}, \%todo);
199 if ($cur eq "E (Perl_$sym)") {
200 # we can try a shortcut here
201 regen_apicheck($sym);
203 my $r = run(qw(make test));
205 if (!$r->{didnotrun} && $r->{status} == 0) {
206 display_sym('del', $sym, $cur);
214 my $r = run(qw(make test));
216 # This regenerated apicheck.c
217 dump_apicheck() if $opt{debug};
219 $r->{didnotrun} and die "couldn't run make test: $!\n" .
220 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
222 if ($r->{status} == 0) {
223 display_sym('del', $sym, $cur);
231 write_todo($opt{todo}, $opt{version}, \%todo);
233 run(qw(make realclean));
239 my($what, $sym, $reason, $extra) = @_;
243 'chk' => 'bold magenta',
244 'del' => 'bold green',
246 $what = colored("$what symbol", $col{$what});
248 printf "[%s] %s %-30s # %s%s\n",
249 $opt{version}, $what, $sym, $reason, $extra;
254 my @mf_arg = ('--with-apicheck', 'OPTIMIZE=-O0 -w');
255 push @mf_arg, qw( DEFINE=-DDPPP_APICHECK_NO_PPPORT_H ) if $opt{base};
258 run(qw(make realclean));
259 my $r = run($fullperl, "Makefile.PL", @mf_arg);
260 unless ($r->{status} == 0) {
261 die "cannot run Makefile.PL: $!\n" .
262 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
268 unlink qw(apicheck.c apicheck.o);
269 runtool({ out => '/dev/null' }, $fullperl, 'apicheck_c.PL', map { "--api=$_" } @_)
270 or die "cannot regenerate apicheck.c\n";
271 dump_apicheck() if $opt{debug};
276 my $apicheck = "apicheck.c";
277 my $f = new IO::File $apicheck or die "cannot open $apicheck: $!\n";
279 print STDERR __FILE__, ": ", __LINE__, ": $apicheck (",
281 " lines) for $fullperl";
282 print STDERR " and '" if @_;
283 print STDERR join "', '", @_;
284 print STDERR "'" if @_;
287 print STDERR $n++, " ", $_ for @lines;
292 my($file, $expver) = @_;
295 my $f = new IO::File $file or die "cannot open $file: $!\n";
298 if ($ver eq $expver) {
302 /^(\w+)\s+#\s+(.*)/ or goto nuke_file;
303 exists $sym{$1} and goto nuke_file;
311 unlink $file or die "cannot remove $file: $!\n";
319 my($file, $ver, $sym) = @_;
322 $f = new IO::File ">$file" or die "cannot open $file: $!\n";
325 # Dictionary ordering, with only alphanumerics
326 for (sort dictionary_order keys %$sym) {
327 $f->print(sprintf "%-30s # %s\n", $_, $sym->{$_});
331 sub find_undefined_symbols
333 my($perl, $shlib) = @_;
335 my $ps = read_sym(file => $perl, options => [qw( --defined-only )]);
336 my $ls = read_sym(file => $shlib, options => [qw( --undefined-only )]);
340 for my $sym (keys %$ls) {
341 next if $sym =~ /\@/ or $sym =~ /^_/ or exists $stdsym{$sym};
342 unless (exists $ps->{$sym}) {
343 push @undefined, $sym;
352 my %opt = ( options => [], @_ );
354 my $r = run($Config{nm}, @{$opt{options}}, $opt{file});
356 if ($r->{didnotrun} or $r->{status}) {
357 die "cannot run $Config{nm}" .
358 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
363 for (@{$r->{stdout}}) {
365 my($adr, $fmt, $sym) = /^\s*([[:xdigit:]]+)?\s+([ABCDGINRSTUVW?-])\s+(\S+)\s*$/i
366 or die "cannot parse $Config{nm} output:\n[$_]\n";
367 $sym{$sym} = { format => $fmt };
368 $sym{$sym}{address} = $adr if defined $adr;
374 sub get_apicheck_symbol_map
381 $r = run(qw(make apicheck.i));
383 # Quit the loop if it succeeded
384 last unless $r->{didnotrun} or $r->{status};
386 # Get the list of macros that it failed on
387 my %sym = map { /error: macro "(\w+)" (?:requires|passed) \d+ argument/ ? ($1 => 'A') : () }
391 for my $s (sort dictionary_order keys %sym) {
392 display_sym('new', $s, $sym{$s});
393 $todo{$s} = $sym{$s};
395 write_todo($opt{todo}, $opt{version}, \%todo);
398 else { # It failed for some other reason: give up
399 die "cannot run make apicheck.i ($r->{didnotrun} / $r->{status}):\n".
400 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
404 my $fh = IO::File->new('apicheck.i')
405 or die "cannot open apicheck.i: $!";
414 for my $sym (/\b([A-Za-z_]\w+)\b/g) {
415 $symmap{$sym}{$cur}++;
420 /_DPPP_test_(\w+)/ and $cur = $1;