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';
32 shlib => 'blib/arch/auto/Devel/PPPort/PPPort.so',
36 perl=s todo=s version=s shlib=s debug base verbose check!
41 print "\n", ident_str(), "\n\n";
43 my $fullperl = `which $opt{perl}`;
46 $ENV{SKIP_SLOW_TESTS} = 1;
50 my %stdsym = map { ($_ => 1) } qw (
67 for (`$Config{nm} $fullperl`) {
69 /\s+T\s+(\w+)\s*$/ and $sym{$1}++;
71 keys %sym >= 50 or die "less than 50 symbols found in $fullperl\n";
73 my %all = %{load_todo($opt{todo}, $opt{version})};
76 my $symmap = get_apicheck_symbol_map();
84 my(@new, @tmp, %seen);
86 my $r = run(qw(make));
87 $r->{didnotrun} and die "couldn't run make: $!\n";
89 for my $l (@{$r->{stderr}}) {
90 if ($l =~ /_DPPP_test_(\w+)/) {
92 my @s = grep { exists $sym{$_} } $1, "Perl_$1", "perl_$1";
94 push @tmp, [$1, "E (@s)"];
103 if ($r->{status} == 0) {
108 @u = eval { find_undefined_symbols($fullperl, $opt{shlib}) };
109 warn "warning: $@" if $@;
114 $r = run(qw(make test));
115 $r->{didnotrun} and die "couldn't run make test: $!\n";
116 $r->{status} == 0 and last;
118 for my $l (@{$r->{stderr}}) {
119 if ($l =~ /undefined symbol: (\w+)/) {
126 for my $m (keys %{$symmap->{$u}}) {
129 $pl =~ s/^[Pp]erl_//;
130 my @s = grep { exists $sym{$_} } $pl, "Perl_$pl", "perl_$pl";
131 push @new, [$m, @s ? "U (@s)" : "U"];
137 @new = grep !$all{$_->[0]}, @new;
140 @new = grep !$all{$_->[0]}, @tmp;
150 die "no new TODO symbols found...";
153 # don't recheck undefined symbols reported by the dynamic linker
154 push @recheck, map { $_->[0] } grep { $_->[1] !~ /^U/ } @new;
158 $all{$_->[0]} = $_->[1];
161 write_todo($opt{todo}, $opt{version}, \%all);
165 my $ifmt = '%' . length(scalar @recheck) . 'd';
166 my $t0 = [gettimeofday];
168 RECHECK: for my $i (0 .. $#recheck) {
169 my $sym = $recheck[$i];
170 my $cur = delete $all{$sym};
172 sym('chk', $sym, $cur, sprintf(" [$ifmt/$ifmt, ETA %s]",
173 $i + 1, scalar @recheck, eta($t0, $i, scalar @recheck)));
175 write_todo($opt{todo}, $opt{version}, \%all);
177 if ($cur eq "E (Perl_$sym)") {
178 # we can try a shortcut here
179 regen_apicheck($sym);
181 my $r = run(qw(make test));
183 if (!$r->{didnotrun} && $r->{status} == 0) {
184 sym('del', $sym, $cur);
192 my $r = run(qw(make test));
194 $r->{didnotrun} and die "couldn't run make test: $!\n";
196 if ($r->{status} == 0) {
197 sym('del', $sym, $cur);
205 write_todo($opt{todo}, $opt{version}, \%all);
207 run(qw(make realclean));
213 my($what, $sym, $reason, $extra) = @_;
217 'chk' => 'bold magenta',
218 'del' => 'bold green',
220 $what = colored("$what symbol", $col{$what});
222 printf "[%s] %s %-30s # %s%s\n",
223 $opt{version}, $what, $sym, $reason, $extra;
228 my @mf_arg = ('--with-apicheck', 'OPTIMIZE=-O0 -w');
229 push @mf_arg, qw( DEFINE=-DDPPP_APICHECK_NO_PPPORT_H ) if $opt{base};
232 run(qw(make realclean));
233 run($fullperl, "Makefile.PL", @mf_arg)->{status} == 0
234 or die "cannot run Makefile.PL: $!\n";
239 unlink qw(apicheck.c apicheck.o);
240 runtool({ out => '/dev/null' }, $fullperl, 'apicheck_c.PL', map { "--api=$_" } @_)
241 or die "cannot regenerate apicheck.c\n";
246 my($file, $expver) = @_;
249 my $f = new IO::File $file or die "cannot open $file: $!\n";
252 if ($ver eq $expver) {
256 /^(\w+)\s+#\s+(.*)/ or goto nuke_file;
257 exists $sym{$1} and goto nuke_file;
265 unlink $file or die "cannot remove $file: $!\n";
273 my($file, $ver, $sym) = @_;
276 $f = new IO::File ">$file" or die "cannot open $file: $!\n";
279 # Dictionary ordering, with only alphanumerics
280 for (sort dictionary_order keys %$sym) {
281 $f->print(sprintf "%-30s # %s\n", $_, $sym->{$_});
285 sub find_undefined_symbols
287 my($perl, $shlib) = @_;
289 my $ps = read_sym(file => $perl, options => [qw( --defined-only )]);
290 my $ls = read_sym(file => $shlib, options => [qw( --undefined-only )]);
294 for my $sym (keys %$ls) {
295 unless (exists $ps->{$sym}) {
296 if ($sym !~ /\@/ and $sym !~ /^_/) {
297 push @undefined, $sym unless $stdsym{$sym};
307 my %opt = ( options => [], @_ );
309 my $r = run($Config{nm}, @{$opt{options}}, $opt{file});
311 if ($r->{didnotrun} or $r->{status}) {
312 die "cannot run $Config{nm}";
317 for (@{$r->{stdout}}) {
319 my($adr, $fmt, $sym) = /^\s*([[:xdigit:]]+)?\s+([ABCDGINRSTUVW?-])\s+(\S+)\s*$/i
320 or die "cannot parse $Config{nm} output:\n[$_]\n";
321 $sym{$sym} = { format => $fmt };
322 $sym{$sym}{address} = $adr if defined $adr;
328 sub get_apicheck_symbol_map
333 $r = run(qw(make apicheck.i));
335 last unless $r->{didnotrun} or $r->{status};
337 my %sym = map { /error: macro "(\w+)" (?:requires|passed) \d+ argument/ ? ($1 => 'A') : () }
341 for my $s (sort dictionary_order keys %sym) {
342 sym('new', $s, $sym{$s});
345 write_todo($opt{todo}, $opt{version}, \%all);
349 die "cannot run make apicheck.i ($r->{didnotrun} / $r->{status}):\n".
350 join('', @{$r->{stdout}})."\n---\n".join('', @{$r->{stderr}});
354 my $fh = IO::File->new('apicheck.i')
355 or die "cannot open apicheck.i: $!";
364 for my $sym (/\b([A-Za-z_]\w+)\b/g) {
365 $symmap{$sym}{$cur}++;
370 /_DPPP_test_(\w+)/ and $cur = $1;