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, and the make should
35 shlib => 'blib/arch/auto/Devel/PPPort/PPPort.so',
39 perl=s todo=s blead version=s shlib=s debug base verbose check!
44 print "\n", ident_str(), "\n\n";
46 my $fullperl = `which $opt{perl}`;
49 $ENV{SKIP_SLOW_TESTS} = 1;
53 my %stdsym = map { ($_ => 1) } qw (
70 for (`$Config{nm} $fullperl`) {
72 /\s+T\s+(\w+)\s*$/ and $sym{$1}++;
74 keys %sym >= 50 or die "less than 50 symbols found in $fullperl\n";
76 my %all = %{load_todo($opt{todo}, $opt{version})} if $opt{todo};
79 my $symmap = get_apicheck_symbol_map();
87 my(@new, @tmp, %seen);
89 my $r = run(qw(make));
90 $r->{didnotrun} and die "couldn't run make: $!\n";
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 @tmp, [$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 $r->{status} == 0 and last;
139 for my $l (@{$r->{stderr}}) {
140 if ($l =~ /undefined symbol: (\w+)/) {
147 for my $m (keys %{$symmap->{$u}}) {
150 $pl =~ s/^[Pp]erl_//;
151 my @s = grep { exists $sym{$_} } $pl, "Perl_$pl", "perl_$pl";
152 push @new, [$m, @s ? "U (@s)" : "U"];
158 @new = grep !$all{$_->[0]}, @new;
161 @new = grep !$all{$_->[0]}, @tmp;
171 die "no new TODO symbols found...";
174 # don't recheck undefined symbols reported by the dynamic linker
175 push @recheck, map { $_->[0] } grep { $_->[1] !~ /^U/ } @new;
179 $all{$_->[0]} = $_->[1];
182 write_todo($opt{todo}, $opt{version}, \%all);
186 my $ifmt = '%' . length(scalar @recheck) . 'd';
187 my $t0 = [gettimeofday];
189 RECHECK: for my $i (0 .. $#recheck) {
190 my $sym = $recheck[$i];
191 my $cur = delete $all{$sym};
193 sym('chk', $sym, $cur, sprintf(" [$ifmt/$ifmt, ETA %s]",
194 $i + 1, scalar @recheck, eta($t0, $i, scalar @recheck)));
196 write_todo($opt{todo}, $opt{version}, \%all);
198 if ($cur eq "E (Perl_$sym)") {
199 # we can try a shortcut here
200 regen_apicheck($sym);
202 my $r = run(qw(make test));
204 if (!$r->{didnotrun} && $r->{status} == 0) {
205 sym('del', $sym, $cur);
213 my $r = run(qw(make test));
215 $r->{didnotrun} and die "couldn't run make test: $!\n";
217 if ($r->{status} == 0) {
218 sym('del', $sym, $cur);
226 write_todo($opt{todo}, $opt{version}, \%all);
228 run(qw(make realclean));
234 my($what, $sym, $reason, $extra) = @_;
238 'chk' => 'bold magenta',
239 'del' => 'bold green',
241 $what = colored("$what symbol", $col{$what});
243 printf "[%s] %s %-30s # %s%s\n",
244 $opt{version}, $what, $sym, $reason, $extra;
249 my @mf_arg = ('--with-apicheck', 'OPTIMIZE=-O0 -w');
250 push @mf_arg, qw( DEFINE=-DDPPP_APICHECK_NO_PPPORT_H ) if $opt{base};
253 run(qw(make realclean));
254 run($fullperl, "Makefile.PL", @mf_arg)->{status} == 0
255 or die "cannot run Makefile.PL: $!\n";
260 unlink qw(apicheck.c apicheck.o);
261 runtool({ out => '/dev/null' }, $fullperl, 'apicheck_c.PL', map { "--api=$_" } @_)
262 or die "cannot regenerate apicheck.c\n";
267 my($file, $expver) = @_;
270 my $f = new IO::File $file or die "cannot open $file: $!\n";
273 if ($ver eq $expver) {
277 /^(\w+)\s+#\s+(.*)/ or goto nuke_file;
278 exists $sym{$1} and goto nuke_file;
286 unlink $file or die "cannot remove $file: $!\n";
294 my($file, $ver, $sym) = @_;
297 $f = new IO::File ">$file" or die "cannot open $file: $!\n";
300 # Dictionary ordering, with only alphanumerics
301 for (sort dictionary_order keys %$sym) {
302 $f->print(sprintf "%-30s # %s\n", $_, $sym->{$_});
306 sub find_undefined_symbols
308 my($perl, $shlib) = @_;
310 my $ps = read_sym(file => $perl, options => [qw( --defined-only )]);
311 my $ls = read_sym(file => $shlib, options => [qw( --undefined-only )]);
315 for my $sym (keys %$ls) {
316 unless (exists $ps->{$sym}) {
317 if ($sym !~ /\@/ and $sym !~ /^_/) {
318 push @undefined, $sym unless $stdsym{$sym};
328 my %opt = ( options => [], @_ );
330 my $r = run($Config{nm}, @{$opt{options}}, $opt{file});
332 if ($r->{didnotrun} or $r->{status}) {
333 die "cannot run $Config{nm}";
338 for (@{$r->{stdout}}) {
340 my($adr, $fmt, $sym) = /^\s*([[:xdigit:]]+)?\s+([ABCDGINRSTUVW?-])\s+(\S+)\s*$/i
341 or die "cannot parse $Config{nm} output:\n[$_]\n";
342 $sym{$sym} = { format => $fmt };
343 $sym{$sym}{address} = $adr if defined $adr;
349 sub get_apicheck_symbol_map
354 $r = run(qw(make apicheck.i));
356 last unless $r->{didnotrun} or $r->{status};
358 my %sym = map { /error: macro "(\w+)" (?:requires|passed) \d+ argument/ ? ($1 => 'A') : () }
362 for my $s (sort dictionary_order keys %sym) {
363 sym('new', $s, $sym{$s});
366 write_todo($opt{todo}, $opt{version}, \%all);
370 die "cannot run make apicheck.i ($r->{didnotrun} / $r->{status}):\n".
371 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
375 my $fh = IO::File->new('apicheck.i')
376 or die "cannot open apicheck.i: $!";
385 for my $sym (/\b([A-Za-z_]\w+)\b/g) {
386 $symmap{$sym}{$cur}++;
391 /_DPPP_test_(\w+)/ and $cur = $1;