From: Marius Gavrilescu Date: Fri, 8 May 2015 08:09:46 +0000 (+0300) Subject: Add an optional compilation cache X-Git-Tag: 5999.000_005~11 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=cd1a16d15bfb46b75e8b87781fe59f32aa8029c4;p=gruntmaster-daemon.git Add an optional compilation cache --- diff --git a/lib/Gruntmaster/Daemon/Format.pm b/lib/Gruntmaster/Daemon/Format.pm index a492e63..cd0e47d 100644 --- a/lib/Gruntmaster/Daemon/Format.pm +++ b/lib/Gruntmaster/Daemon/Format.pm @@ -6,8 +6,10 @@ use warnings; use parent qw/Exporter/; no if $] > 5.017011, warnings => 'experimental::smartmatch'; +use Digest::SHA qw/sha256_hex/; use Expect::Simple; use File::Basename qw/fileparse/; +use File::Copy qw/cp/; use File::Slurp qw/read_file write_file/; use List::MoreUtils qw/natatime/; use Log::Log4perl qw/get_logger/; @@ -115,7 +117,19 @@ sub prepare_files{ $file->{run} = mkrun($format); write_file $name, $content; - prepare $name, $format; + if ($ENV{GRUNTMASTER_CCACHE}) { + my $key = lc sha256_hex($content) . '-' . $format; + my $cachefn = "$ENV{GRUNTMASTER_CCACHE}/$key"; + my $exefn = fileparse $name, qr/[.][^.]*/s; + if (cp $cachefn, $exefn) { + get_logger->trace("File $name found in compilation cache") + } else { + prepare $name, $format; + cp $exefn, $cachefn + } + } else { + prepare $name, $format + } } }