This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Time-Piece to CPAN version 1.23
[perl5.git] / Porting / pod_rules.pl
index 8386015..18abe87 100644 (file)
@@ -5,7 +5,6 @@ use vars qw(%Build %Targets $Verbose $Test);
 use Text::Tabs;
 use Text::Wrap;
 use Getopt::Long;
-use Carp;
 
 # Generate the sections of files listed in %Targets from pod/perl.pod
 # Mostly these are rules in Makefiles
@@ -58,7 +57,7 @@ sub my_die;
 }
 
 if ($Verbose) {
-    print "I will be building $_\n" foreach keys %Build;
+    print "I will be building $_\n" foreach sort keys %Build;
 }
 
 my $test = 1;
@@ -69,10 +68,10 @@ my $state = $Test
     ? get_pod_metadata(0, sub {
                            printf "1..%d\n", 1 + scalar keys %Build;
                            if (@_) {
-                               print "not ok $test\n";
+                               print "not ok $test # got Pod metadata\n";
                                die @_;
                            }
-                           print "ok $test\n";
+                           print "ok $test # got Pod metadata\n";
                        })
     : get_pod_metadata(1, sub { warn @_ if @_ }, values %Build);
 
@@ -130,13 +129,6 @@ sub generate_pod_mak {
     $line;
 }
 
-sub verify_contiguous {
-    my ($name, $content, $what) = @_;
-    my $sections = () = $content =~ m/\0+/g;
-    croak("$0: $name contains no $what") if $sections < 1;
-    croak("$0: $name contains discontiguous $what") if $sections > 1;
-}
-
 sub do_manifest {
     my ($name, $prev) = @_;
     my @manifest =
@@ -154,8 +146,8 @@ sub do_manifest {
 
 sub do_nmake {
     my ($name, $makefile) = @_;
-    $makefile =~ s/^\tcopy \.\.\\README.*\n/\0/gm;
-    verify_contiguous($name, $makefile, 'README copies');
+    my $re = qr/^\tcopy \.\.\\README[^\n]*\n/sm;
+    $makefile = verify_contiguous($name, $makefile, $re, 'README copies');
     # Now remove the other copies that follow
     1 while $makefile =~ s/\0\tcopy .*\n/\0/gm;
     $makefile =~ s/\0+/join ("", &generate_nmake_1)/se;
@@ -184,9 +176,9 @@ sub do_vms {
     # Looking for the macro defining the current perldelta:
     #PERLDELTA_CURRENT = [.pod]perl5139delta.pod
 
-    $makefile =~ s{\nPERLDELTA_CURRENT\s+=\s+\Q[.pod]perl\E\d+delta\.pod\n}
-                  {\0}sx;
-    verify_contiguous($name, $makefile, 'current perldelta macro');
+    my $re = qr{\nPERLDELTA_CURRENT\s+=\s+\Q[.pod]perl\E\d+delta\.pod\n}smx;
+    $makefile
+        = verify_contiguous($name, $makefile, $re, 'current perldelta macro');
     $makefile =~ s/\0+/join "\n", '', "PERLDELTA_CURRENT = [.pod]$state->{delta_target}", ''/se;
 
     $makefile;
@@ -204,15 +196,19 @@ sub do_unix {
     # pod/perl511delta.pod: pod/perldelta.pod
     #         cd pod && $(LNS) perldelta.pod perl511delta.pod
 
-    $makefile_SH =~ s!(
+    # although it seems that HP-UX make gets confused, always tried to
+    # regenerate the symlink, and then the ln -s fails, as the target exists.
+
+    my $re = qr{(
 pod/perl[a-z0-9_]+\.pod: pod/perl[a-z0-9_]+\.pod
+       \$\(RMS\) pod/perl[a-z0-9_]+\.pod
        \$\(LNS\) perl[a-z0-9_]+\.pod pod/perl[a-z0-9_]+\.pod
-)+!\0!gm;
-
-    verify_contiguous($name, $makefile_SH, 'copy rules');
+)+}sm;
+    $makefile_SH = verify_contiguous($name, $makefile_SH, $re, 'copy rules');
 
     my @copy_rules = map "
 pod/$_: pod/$state->{copies}{$_}
+       \$(RMS) pod/$_
        \$(LNS) $state->{copies}{$_} pod/$_
 ", keys %{$state->{copies}};
 
@@ -221,34 +217,8 @@ pod/$_: pod/$state->{copies}{$_}
 }
 
 # Do stuff
-while (my ($target, $name) = each %Build) {
-    print "Now processing $name\n" if $Verbose;
-
-    my $orig = slurp_or_die($name);
-    my_die "$name contains NUL bytes" if $orig =~ /\0/;
-
-    my $new = do {
-        no strict 'refs';
-        &{"do_$target"}($target, $orig);
-    };
-
-    if ($Test) {
-        printf "%s %d # $name is up to date\n",
-            $new eq $orig ? 'ok' : 'not ok',
-                ++$test;
-        next;
-    } elsif ($new eq $orig) {
-        print "Was not modified\n"
-            if $Verbose;
-        next;
-    }
-
-    my $mode = (stat $name)[2] // my_die "Can't stat $name: $!";
-    rename $name, "$name.old" or my_die "Can't rename $name to $name.old: $!";
-
-    write_or_die($name, $new);
-    chmod $mode & 0777, $name or my_die "can't chmod $mode $name: $!";
-}
+process($_, $Build{$_}, main->can("do_$_"), $Test && ++$test, $Verbose)
+    foreach sort keys %Build;
 
 # Local variables:
 # cperl-indent-level: 4