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 $r->{didnotrun} and die "couldn't run make test: $!\n" .
217 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
219 if ($r->{status} == 0) {
220 display_sym('del', $sym, $cur);
228 write_todo($opt{todo}, $opt{version}, \%todo);
230 run(qw(make realclean));
236 my($what, $sym, $reason, $extra) = @_;
240 'chk' => 'bold magenta',
241 'del' => 'bold green',
243 $what = colored("$what symbol", $col{$what});
245 printf "[%s] %s %-30s # %s%s\n",
246 $opt{version}, $what, $sym, $reason, $extra;
251 my @mf_arg = ('--with-apicheck', 'OPTIMIZE=-O0 -w');
252 push @mf_arg, qw( DEFINE=-DDPPP_APICHECK_NO_PPPORT_H ) if $opt{base};
255 run(qw(make realclean));
256 my $r = run($fullperl, "Makefile.PL", @mf_arg);
257 unless ($r->{status} == 0) {
258 die "cannot run Makefile.PL: $!\n" .
259 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
265 unlink qw(apicheck.c apicheck.o);
266 runtool({ out => '/dev/null' }, $fullperl, 'apicheck_c.PL', map { "--api=$_" } @_)
267 or die "cannot regenerate apicheck.c\n";
272 my($file, $expver) = @_;
275 my $f = new IO::File $file or die "cannot open $file: $!\n";
278 if ($ver eq $expver) {
282 /^(\w+)\s+#\s+(.*)/ or goto nuke_file;
283 exists $sym{$1} and goto nuke_file;
291 unlink $file or die "cannot remove $file: $!\n";
299 my($file, $ver, $sym) = @_;
302 $f = new IO::File ">$file" or die "cannot open $file: $!\n";
305 # Dictionary ordering, with only alphanumerics
306 for (sort dictionary_order keys %$sym) {
307 $f->print(sprintf "%-30s # %s\n", $_, $sym->{$_});
311 sub find_undefined_symbols
313 my($perl, $shlib) = @_;
315 my $ps = read_sym(file => $perl, options => [qw( --defined-only )]);
316 my $ls = read_sym(file => $shlib, options => [qw( --undefined-only )]);
320 for my $sym (keys %$ls) {
321 unless (exists $ps->{$sym}) {
322 if ($sym !~ /\@/ and $sym !~ /^_/) {
323 push @undefined, $sym unless $stdsym{$sym};
333 my %opt = ( options => [], @_ );
335 my $r = run($Config{nm}, @{$opt{options}}, $opt{file});
337 if ($r->{didnotrun} or $r->{status}) {
338 die "cannot run $Config{nm}" .
339 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
344 for (@{$r->{stdout}}) {
346 my($adr, $fmt, $sym) = /^\s*([[:xdigit:]]+)?\s+([ABCDGINRSTUVW?-])\s+(\S+)\s*$/i
347 or die "cannot parse $Config{nm} output:\n[$_]\n";
348 $sym{$sym} = { format => $fmt };
349 $sym{$sym}{address} = $adr if defined $adr;
355 sub get_apicheck_symbol_map
362 $r = run(qw(make apicheck.i));
364 # Quit the loop if it succeeded
365 last unless $r->{didnotrun} or $r->{status};
367 # Get the list of macros that it failed on
368 my %sym = map { /error: macro "(\w+)" (?:requires|passed) \d+ argument/ ? ($1 => 'A') : () }
372 for my $s (sort dictionary_order keys %sym) {
373 display_sym('new', $s, $sym{$s});
374 $todo{$s} = $sym{$s};
376 write_todo($opt{todo}, $opt{version}, \%todo);
379 else { # It failed for some other reason: give up
380 die "cannot run make apicheck.i ($r->{didnotrun} / $r->{status}):\n".
381 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
385 my $fh = IO::File->new('apicheck.i')
386 or die "cannot open apicheck.i: $!";
395 for my $sym (/\b([A-Za-z_]\w+)\b/g) {
396 $symmap{$sym}{$cur}++;
401 /_DPPP_test_(\w+)/ and $cur = $1;