This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RealPPPort_xs.PL: Fix spelling in comment
[perl5.git] / dist / Devel-PPPort / devel / regenerate
CommitLineData
0c96388f
MHM
1#!/usr/bin/perl -w
2################################################################################
3#
4# regenerate -- regenerate baseline and todo files
5#
6################################################################################
7#
b2049988 8# Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
0c96388f
MHM
9# Version 2.x, Copyright (C) 2001, Paul Marquess.
10# Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
11#
12# This program is free software; you can redistribute it and/or
13# modify it under the same terms as Perl itself.
14#
15################################################################################
16
17use strict;
18use File::Path;
19use File::Copy;
20use Getopt::Long;
21use Pod::Usage;
22
3d7c117d 23require './devel/devtools.pl';
f100f28c 24require './parts/ppptools.pl';
0c96388f
MHM
25
26our %opt = (
ba120f6f 27 check => 1,
337a666a 28 debug => 0,
ba120f6f 29 verbose => 0,
0c96388f
MHM
30);
31
a58fa8f3 32GetOptions(\%opt, qw( check! verbose install=s blead=s blead-version=s
0f50f756 33 debug=i debug-start=s)) or die pod2usage();
0c96388f
MHM
34
35identify();
36
37unless (-e 'parts/embed.fnc' and -e 'parts/apidoc.fnc') {
38 print "\nOooops, $0 must be run from the Devel::PPPort root directory.\n";
39 quit_now();
40}
41
dfaee99f 42ask_or_quit("Are you SURE you have:\n1) updated parts/embed.fnc to latest blead?\n2) run devel/mkapidoc.sh to update parts/apidoc.fnc?\n3) run devel/mkppport_fnc.pl to update parts/ppport.fnc?\n");
0c96388f
MHM
43
44my %files = map { ($_ => [glob "parts/$_/5*"]) } qw( base todo );
45
46my(@notwr, @wr);
47for my $f (map @$_, values %files) {
48 push @{-w $f ? \@wr : \@notwr}, $f;
49}
50
51if (@notwr) {
52 if (@wr) {
53 print "\nThe following files are not writable:\n\n";
54 print " $_\n" for @notwr;
55 print "\nAre you sure you have checked out these files?\n";
56 }
57 else {
58 print "\nAll baseline / todo file are not writable.\n";
59 ask_or_quit("Do you want to try to check out these files?");
60 unless (runtool("wco", "-l", "-t", "locked by $0", @notwr)) {
61 print "\nSomething went wrong while checking out the files.\n";
62 quit_now();
63 }
64 }
65}
66
f100f28c
KW
67
68if (-e 'ppport.h') {
69 my $blead = $opt{blead};
70 $blead = get_and_sort_perls(\%opt)->[0]->{path} unless $blead;
71
72 # Get list of things we provide
73 my %provided = map { /^(\w+)/ ? ( $1 => 1 ) : () }
74 `$blead ppport.h --list-provided`;
75
76 # Get the list of macros that are hard to test.
77 my @unorthodox = map { exists $_->{flags}{u} ? $_->{name} : () }
78 parse_embed(qw(parts/embed.fnc parts/apidoc.fnc parts/ppport.fnc));
79
80 # Keep on that list only the things we provide
81 @unorthodox = grep { exists $provided{$_} } @unorthodox;
82
83 # And get the list of known hard things.
84 my $hard_ref = &known_but_hard_to_test_for;
85
86 # If we provide something, it better be on the known things list
87 my @bad = grep { ! exists $hard_ref->{$_} } @unorthodox;
88 if (@bad) {
89 print "The following items need to be manually added to the list in",
90 " part/inc/ppptools: known_but_hard_to_test_for(): ",
91 join ", ", @bad, "\n";
92 quit_now();
93 }
94}
95
0c96388f
MHM
96for my $dir (qw( base todo )) {
97 my $cur = "parts/$dir";
98 my $old = "$cur-old";
99 if (-e $old) {
100 ask_or_quit("Do you want me to remove the old $old directory?");
101 rmtree($old);
102 }
103 mkdir $old;
104 print "\nBacking up $cur in $old.\n";
105 for my $src (@{$files{$dir}}) {
106 my $dst = $src;
744ef08f 107 $dst =~ s/\Q$cur/$old/ or die "Ooops!";
0c96388f
MHM
108 move($src, $dst) or die "Moving $src to $dst failed: $!\n";
109 }
110}
111
49ef49fe 112my @perlargs;
0f50f756 113push @perlargs, "--debug=$opt{debug}" if $opt{debug};
0ebe8a01
KW
114push @perlargs, "--install=$opt{install}" if $opt{install};
115push @perlargs, "--blead=$opt{blead}" if $opt{blead};
a58fa8f3 116push @perlargs, "--debug-start=$opt{'debug-start'}" if $opt{'debug-start'};
49ef49fe 117
0c96388f 118my $T0 = time;
ba120f6f
MHM
119my @args = ddverbose();
120push @args, '--nocheck' unless $opt{check};
0ebe8a01 121push @args, "--blead-version=$opt{'blead-version'}" if $opt{'blead-version'};
49ef49fe 122push @args, @perlargs;
0c96388f 123
3bb63d38 124# Find out what symbols were in what releases
0c96388f
MHM
125print "\nBuilding baseline files...\n\n";
126
ba120f6f 127unless (runperl('devel/mktodo', '--base', @args)) {
0c96388f
MHM
128 print "\nSomething went wrong while building the baseline files.\n";
129 quit_now();
130}
131
3bb63d38
KW
132# Then find out what ppport.h buys us by repeating the process above, but
133# using ppport.h
0c96388f
MHM
134print "\nBuilding todo files...\n\n";
135
ba120f6f 136unless (runperl('devel/mktodo', @args)) {
635ff94c 137 print "\nSomething went wrong while building the todo files.\n";
0c96388f
MHM
138 quit_now();
139}
140
40f4ec07 141print "\nAdding remaining info...\n\n";
0c96388f
MHM
142
143unless (runperl('Makefile.PL') and
144 runtool('make') and
49ef49fe 145 runperl('devel/scanprov', '--mode=write', @perlargs)) {
0c96388f
MHM
146 print "\nSomething went wrong while adding the baseline info.\n";
147 quit_now();
148}
149
150my($wall, $usr, $sys, $cusr, $csys) = (time - $T0, times);
151my $cpu = sprintf "%.2f", $usr + $sys + $cusr + $csys;
152$usr = sprintf "%.2f", $usr + $cusr;
153$sys = sprintf "%.2f", $sys + $csys;
154
155print <<END;
156
157API info regenerated successfully.
158
159Finished in $wall wallclock secs ($usr usr + $sys sys = $cpu CPU)
160
161Don't forget to check in the files in parts/base and parts/todo.
162
163END
164
ba120f6f
MHM
165__END__
166
167=head1 NAME
168
c4a2ac43 169regenerate - Automatically regenerate Devel::PPPort's API information
ba120f6f
MHM
170
171=head1 SYNOPSIS
172
173 regenerate [options]
174
175 --nocheck don't recheck symbols that caused an error
176 --verbose show verbose output
177
178=head1 COPYRIGHT
179
b2049988 180Copyright (c) 2006-2013, Marcus Holland-Moritz.
ba120f6f
MHM
181
182This program is free software; you can redistribute it and/or
183modify it under the same terms as Perl itself.
184
185=head1 SEE ALSO
186
187See L<Devel::PPPort> and L<HACKERS>.
188
189=cut