Change 33537 by [EMAIL PROTECTED] on 2008/03/15 17:30:19

           Subject: Re: [patch] refine make regen to be more selective
           From: Jim Cromie <[EMAIL PROTECTED]>
           Message-ID: <[EMAIL PROTECTED]>
           Date: Tue, 11 Mar 2008 18:16:14 -0600

Affected files ...

... //depot/perl/embed.pl#367 edit
... //depot/perl/keywords.pl#34 edit
... //depot/perl/opcode.pl#178 edit
... //depot/perl/reentr.pl#56 edit
... //depot/perl/regen.pl#7 edit
... //depot/perl/regen_lib.pl#2 edit
... //depot/perl/warnings.pl#63 edit

Differences ...

==== //depot/perl/embed.pl#367 (xtext) ====
Index: perl/embed.pl
--- perl/embed.pl#366~33291~    2008-02-12 05:15:20.000000000 -0800
+++ perl/embed.pl       2008-03-15 10:30:19.000000000 -0700
@@ -84,8 +84,8 @@
        $F = $filename;
     }
     else {
-       safer_unlink $filename if $filename ne '/dev/null';
-       open F, ">$filename" or die "Can't open $filename: $!";
+       # safer_unlink $filename if $filename ne '/dev/null';
+       open F, ">$filename-new" or die "Can't open $filename: $!";
        binmode F;
        $F = \*F;
     }
@@ -112,6 +112,7 @@
     print $F $trailer if $trailer;
     unless (ref $filename) {
        close $F or die "Error closing $filename: $!";
+       safer_rename("$filename-new", $filename);
     }
 }
 
@@ -388,8 +389,7 @@
     return hide("PL_$pre$sym", "PL_$sym");
 }
 
-safer_unlink 'embed.h';
-open(EM, '> embed.h') or die "Can't create embed.h: $!\n";
+open(EM, '> embed.h-new') or die "Can't create embed.h: $!\n";
 binmode EM;
 
 print EM do_not_edit ("embed.h"), <<'END';
@@ -642,9 +642,9 @@
 END
 
 close(EM) or die "Error closing EM: $!";
+safer_rename('embed.h-new', 'embed.h');
 
-safer_unlink 'embedvar.h';
-open(EM, '> embedvar.h')
+open(EM, '> embedvar.h-new')
     or die "Can't create embedvar.h: $!\n";
 binmode EM;
 
@@ -739,12 +739,11 @@
 END
 
 close(EM) or die "Error closing EM: $!";
+safer_rename('embedvar.h-new', 'embedvar.h');
 
-safer_unlink 'perlapi.h';
-safer_unlink 'perlapi.c';
-open(CAPI, '> perlapi.c') or die "Can't create perlapi.c: $!\n";
+open(CAPI, '> perlapi.c-new') or die "Can't create perlapi.c: $!\n";
 binmode CAPI;
-open(CAPIH, '> perlapi.h') or die "Can't create perlapi.h: $!\n";
+open(CAPIH, '> perlapi.h-new') or die "Can't create perlapi.h: $!\n";
 binmode CAPIH;
 
 print CAPIH do_not_edit ("perlapi.h"), <<'EOT';
@@ -869,6 +868,7 @@
 /* ex: set ro: */
 EOT
 close CAPIH or die "Error closing CAPIH: $!";
+safer_rename('perlapi.h-new', 'perlapi.h');
 
 print CAPI do_not_edit ("perlapi.c"), <<'EOT';
 
@@ -950,6 +950,7 @@
 EOT
 
 close(CAPI) or die "Error closing CAPI: $!";
+safer_rename('perlapi.c-new', 'perlapi.c');
 
 # functions that take va_list* for implementing vararg functions
 # NOTE: makedef.pl must be updated if you add symbols to %vfuncs

==== //depot/perl/keywords.pl#34 (xtext) ====
Index: perl/keywords.pl
--- perl/keywords.pl#33~31812~  2007-09-07 02:25:24.000000000 -0700
+++ perl/keywords.pl    2008-03-15 10:30:19.000000000 -0700
@@ -2,8 +2,8 @@
 use strict;
 
 require 'regen_lib.pl';
-safer_unlink ("keywords.h");
-open(KW, ">keywords.h") || die "Can't create keywords.h: $!\n";
+
+open(KW, ">keywords.h-new") || die "Can't create keywords.h: $!\n";
 binmode KW;
 select KW;
 
@@ -39,6 +39,8 @@
 
 close KW or die "Error closing keywords.h: $!";
 
+safer_rename("keywords.h-new", "keywords.h");
+
 ###########################################################################
 sub tab {
     my ($l, $t) = @_;

==== //depot/perl/opcode.pl#178 (xtext) ====
Index: perl/opcode.pl
--- perl/opcode.pl#177~33374~   2008-02-26 02:19:15.000000000 -0800
+++ perl/opcode.pl      2008-03-15 10:30:19.000000000 -0700
@@ -443,9 +443,6 @@
 close OC or die "Error closing opcode.h: $!\n";
 close ON or die "Error closing opnames.h: $!\n";
 
-foreach ('opcode.h', 'opnames.h') {
-    safer_rename_silent $_, "$_-old";
-}
 safer_rename $opcode_new, 'opcode.h';
 safer_rename $opname_new, 'opnames.h';
 
@@ -497,9 +494,6 @@
 close PP or die "Error closing pp_proto.h: $!\n";
 close PPSYM or die "Error closing pp.sym: $!\n";
 
-foreach ('pp_proto.h', 'pp.sym') {
-    safer_rename_silent $_, "$_-old";
-}
 safer_rename $pp_proto_new, 'pp_proto.h';
 safer_rename $pp_sym_new, 'pp.sym';
 

==== //depot/perl/reentr.pl#56 (text) ====
Index: perl/reentr.pl
--- perl/reentr.pl#55~33291~    2008-02-12 05:15:20.000000000 -0800
+++ perl/reentr.pl      2008-03-15 10:30:19.000000000 -0700
@@ -13,7 +13,7 @@
 use strict;
 use Getopt::Std;
 my %opts;
-getopts('U', \%opts);
+getopts('Uv', \%opts);
 
 my %map = (
           V => "void",
@@ -40,8 +40,8 @@
 # Example #3: S_CBI   means type func_r(const char*, char*, int)
 
 
-safer_unlink 'reentr.h';
-die "reentr.h: $!" unless open(H, ">reentr.h");
+# safer_unlink 'reentr.h';
+die "reentr.pl: $!" unless open(H, ">reentr.h-new");
 binmode H;
 select H;
 print <<EOF;
@@ -789,11 +789,12 @@
 EOF
 
 close(H);
+safer_rename('reentr.h-new', 'reentr.h');
 
 # Prepare to write the reentr.c.
 
-safer_unlink 'reentr.c';
-die "reentr.c: $!" unless open(C, ">reentr.c");
+# safer_unlink 'reentr.c';
+die "reentr.c: $!" unless open(C, ">reentr.c-new");
 binmode C;
 select C;
 print <<EOF;
@@ -1090,6 +1091,9 @@
 /* ex: set ro: */
 EOF
 
+close(C);
+safer_rename('reentr.c-new', 'reentr.c');
+
 __DATA__
 asctime S      |time   |const struct tm|B_SB|B_SBI|I_SB|I_SBI
 crypt CC       |crypt  |struct crypt_data|B_CCS|B_CCD|D=CRYPTD*

==== //depot/perl/regen.pl#7 (text) ====
Index: perl/regen.pl
--- perl/regen.pl#6~31165~      2007-05-07 08:35:56.000000000 -0700
+++ perl/regen.pl       2008-03-15 10:30:19.000000000 -0700
@@ -13,8 +13,8 @@
 
 require 'regen_lib.pl';
 # keep warnings.pl in sync with the CPAN distribution by not requiring core
-# changes
-safer_unlink ("warnings.h", "lib/warnings.pm");
+# changes.  Um, what ?
+# safer_unlink ("warnings.h", "lib/warnings.pm");
 
 my %gen = (
           'autodoc.pl'  => [qw[pod/perlapi.pod pod/perlintern.pod]],

==== //depot/perl/regen_lib.pl#2 (text) ====
Index: perl/regen_lib.pl
--- perl/regen_lib.pl#1~18851~  2003-03-07 22:49:35.000000000 -0800
+++ perl/regen_lib.pl   2008-03-15 10:30:19.000000000 -0700
@@ -15,6 +15,24 @@
 
 $Needs_Write = $Is_OS2 || $Is_W32 || $Is_Cygwin || $Is_NetWare;
 
+eval "use Digest::MD5 'md5'; 1;"
+    or warn "Digest::MD5 unavailable, doing unconditional regen\n";
+
+sub cksum {
+    my $pl = shift;
+    my ($buf, $cksum);
+    local *FH;
+    if (open(FH, $pl)) {
+       local $/;
+       $buf = <FH>;
+       $cksum = defined &md5 ? md5($buf) : 0;
+       close FH;
+    } else {
+       warn "$0: $pl: $!\n";
+    }
+    return $cksum;
+}
+
 sub safer_unlink {
   my @names = @_;
   my $cnt = 0;
@@ -38,8 +56,23 @@
   rename $from, $to;
 }
 
+sub safer_rename_always {
+  my ($from, $to) = @_;
+  safer_rename_silent($from, $to) or die "renaming $from to $to: $!";
+}
+
 sub safer_rename {
   my ($from, $to) = @_;
+
+  my $fc = cksum($from);
+  my $tc = cksum($to);
+  
+  if ($fc and $fc eq $tc) {
+      warn "no changes between '$from' & '$to'\n";
+      safer_unlink($from);
+      return;
+  }
+  warn "changed '$from' to '$to'\n";
   safer_rename_silent($from, $to) or die "renaming $from to $to: $!";
 }
 1;

==== //depot/perl/warnings.pl#63 (text) ====
Index: perl/warnings.pl
--- perl/warnings.pl#62~32990~  2008-01-17 06:23:48.000000000 -0800
+++ perl/warnings.pl    2008-03-15 10:30:19.000000000 -0700
@@ -3,7 +3,8 @@
 $VERSION = '1.02_02';
 
 BEGIN {
-  push @INC, './lib';
+    require 'regen_lib.pl';
+    push @INC, './lib';
 }
 use strict ;
 
@@ -249,11 +250,9 @@
     exit ;
 }
 
-unlink "warnings.h";
-unlink "lib/warnings.pm";
-open(WARN, ">warnings.h") || die "Can't create warnings.h: $!\n";
+open(WARN, ">warnings.h-new") || die "Can't create warnings.h: $!\n";
+open(PM, ">lib/warnings.pm-new") || die "Can't create lib/warnings.pm: $!\n";
 binmode WARN;
-open(PM, ">lib/warnings.pm") || die "Can't create lib/warnings.pm: $!\n";
 binmode PM;
 
 print WARN <<'EOM' ;
@@ -366,6 +365,7 @@
 EOM
 
 close WARN ;
+safer_rename("warnings.h-new", "warnings.h");
 
 while (<DATA>) {
     last if /^KEYWORDS$/ ;
@@ -427,6 +427,7 @@
 
 print PM "# ex: set ro:\n";
 close PM ;
+safer_rename("lib/warnings.pm-new", "lib/warnings.pm");
 
 __END__
 # -*- buffer-read-only: t -*-
End of Patch.

Reply via email to