Add an optional compilation cache
authorMarius Gavrilescu <marius@ieval.ro>
Fri, 8 May 2015 08:09:46 +0000 (11:09 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Fri, 8 May 2015 08:09:46 +0000 (11:09 +0300)
lib/Gruntmaster/Daemon/Format.pm

index a492e63..cd0e47d 100644 (file)
@@ -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
+               }
        }
 }
 
This page took 0.027784 seconds and 4 git commands to generate.