diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-01-23 18:29:20 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-01-23 18:45:59 +0000 |
commit | c24c946d24c97d98baecdbf2c37823b55add8bcb (patch) | |
tree | 14eaac76ebfac2a2d7dcbae2d4309ca0f0deb7e8 /regen/regen_lib.pl | |
parent | e8fb9efbf973fedc74b46a30a67b602d07f033e9 (diff) | |
download | perl-c24c946d24c97d98baecdbf2c37823b55add8bcb.tar.gz |
Store the SHA-256 of the source in files generated by regen_perly.pl
bison isn't available everywhere, so we can't simply re-run regen_perly.pl to
verify that perly.{act,h,tab} are up to date. So instead store the SHA-256 of
the input files, and extend t/porting/regen.t to check that the input files
haven't been changed subsequently.
Diffstat (limited to 'regen/regen_lib.pl')
-rw-r--r-- | regen/regen_lib.pl | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/regen/regen_lib.pl b/regen/regen_lib.pl index 2d4ceac14f..85defb9ab6 100644 --- a/regen/regen_lib.pl +++ b/regen/regen_lib.pl @@ -133,13 +133,29 @@ EOM } sub read_only_bottom_close_and_rename { - my $fh = shift; + my ($fh, $sources) = @_; my $name = *{$fh}->{name}; my $lang = *{$fh}->{lang}; die "No final name specified at open time for $name" unless *{$fh}->{final_name}; - print $fh $lang eq 'Perl' - ? "\n# ex: set ro:\n" : "\n/* ex: set ro: */\n"; + my $comment; + if ($sources) { + $comment = "Generated from:\n"; + foreach my $file (sort @$sources) { + my $digest = digest($file); + $comment .= "$digest $file\n"; + } + } + $comment .= "ex: set ro:"; + + if ($lang eq 'Perl') { + $comment =~ s/^/# /mg; + } else { + $comment =~ s/^/ * /mg; + $comment =~ s! \* !/* !; + $comment .= " */"; + } + print $fh "\n$comment\n"; safer_close($fh); rename_if_different($name, *{$fh}->{final_name}); } @@ -150,4 +166,17 @@ sub tab { $t; } +sub digest { + my $file = shift; + # Need to defer loading this, as the main regen scripts work back to 5.004, + # and likely we don't even have this module on every 5.8 install yet: + require Digest::SHA; + + local ($/, *FH); + open FH, "$file" or die "Can't open $file: $!"; + my $raw = <FH>; + close FH or die "Can't close $file: $!"; + return Digest::SHA::sha256_hex($raw); +}; + 1; |