From e03f21ba522ca8a658ccbb7e22a4fba7c3196a43 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 21 Jan 2016 17:02:21 +0000 Subject: [PATCH] Do not recompile lua generated headers all time --- src/rspamadm/lua_preprocess.pl | 93 +++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 29 deletions(-) diff --git a/src/rspamadm/lua_preprocess.pl b/src/rspamadm/lua_preprocess.pl index b17994684..d1e8f4689 100644 --- a/src/rspamadm/lua_preprocess.pl +++ b/src/rspamadm/lua_preprocess.pl @@ -2,50 +2,85 @@ use warnings FATAL => 'all'; use strict; +use Digest::MD5; -my ($in_dir, $out_dir) = @ARGV; +my ( $in_dir, $out_dir ) = @ARGV; my @files = <$in_dir/*.lua>; sub quote_file { - my ($in, $out) = @_; - - while (<$in>) { - if (/^--.USE\s*"(\S+)"$/) { - open(my $inc, '<', "$in_dir/$1.lua.in") or die "missing include $1"; - quote_file($inc, $out); - } - else { - s/^\s*//; # remove unnecessary spaces at the beginning - next if /^--/; # skip comments - next if /^\s*$/; # skip empty lines - s/(.)/'$1',/g; # split as 'c', - s/\'\\\'/\'\\\\'/g; # escape backslashes - s/\'\'\'/\'\\\'\'/g; # escape single quotes - print $out "$_'\\n',"; - } - } + my ( $in, $out ) = @_; + + while (<$in>) { + if (/^--.USE\s*"(\S+)"$/) { + open( my $inc, '<', "$in_dir/$1.lua.in" ) + or die "missing include $1"; + quote_file( $inc, $out ); + } + else { + s/^\s*//; # remove unnecessary spaces at the beginning + next if /^--/; # skip comments + next if /^\s*$/; # skip empty lines + s/(.)/'$1',/g; # split as 'c', + s/\'\\\'/\'\\\\'/g; # escape backslashes + s/\'\'\'/\'\\\'\'/g; # escape single quotes + print $out "$_'\\n',"; + } + } } -foreach my $file (@files) { - if ($file =~ /([^\/.]+)(.lua)$/) { - my $fname = "$1$2"; - my $varname = "rspamadm_script_$1"; - my $definename = uc $varname; +sub digest_for_file { + my ($file) = @_; + + open( my $in, '<', $file ) or die "file missing"; + my $digest = Digest::MD5->new->addfile($in)->hexdigest; + + return $digest; +} + +sub changed { + my ( $file, $outfile ) = @_; - open(my $in, '<', $file) or die "input missing"; - open(my $out, '>', "$out_dir/$fname.h") or die "output missing"; + open( my $out, '<', $outfile ) or return 1; + + my $in_checksum = digest_for_file($file); + my $ln = <$out>; + + if ( $ln =~ /^.*id:(\S+)\s.*$/ ) { + if ( $in_checksum ne $1 ) { + return 1; + } + else { + return 0; + } + } + + return 1; +} + +foreach my $file (@files) { + if ( $file =~ /([^\/.]+)(.lua)$/ ) { + my $fname = "$1$2"; + my $varname = "rspamadm_script_$1"; + my $definename = uc $varname; + my $outfile = "$out_dir/$fname.h"; - print $out <', $outfile ) or die "output missing"; + my $checksum = digest_for_file($file); + print $out <