From cd1a16d15bfb46b75e8b87781fe59f32aa8029c4 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 8 May 2015 11:09:46 +0300 Subject: [PATCH] Add an optional compilation cache --- lib/Gruntmaster/Daemon/Format.pm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 + } } } -- 2.39.2