Skip to content

Instantly share code, notes, and snippets.

@ugexe
Created April 6, 2015 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugexe/c9222be48783d9e81163 to your computer and use it in GitHub Desktop.
Save ugexe/c9222be48783d9e81163 to your computer and use it in GitHub Desktop.
use Zef::Phase::Building;
use Zef::Depends;
use JSON::Tiny;
class Zef::Builder does Zef::Phase::Building {
has @.plugins;
submethod BUILD(:@!plugins) {
for @!plugins -> $p {
self does ::($p) if do { require ::($p); ::($p).does(Zef::Phase::Building) };
}
}
multi method pre-compile(*@paths is copy) {
my @precompiled;
while @paths.shift -> $path {
my @INC = "$path/lib".IO, "$path/blib/lib".IO;
my @sources = Zef::Depends.comb($*SPEC.catpath('', $path, 'lib'));
for @sources -> $module {
my $cu = CompUnit.new($module<file>);
my $out = "{$*CWD}/blib/{$module<file>.IO.relative}.{$*VM.precomp-ext}" andthen .IO.dirname.IO.mkdir;
$out.IO.unlink if $out.IO.e;
my $result = $cu.precomp(:force, $out, :@INC);
"[{$module<file>.subst(/ $path ['/' || '\\'] /, '')}] {'.' x 77 - $module<file>.chars} ".print;
if $result && $out.IO ~~ :e { # so just check for the file's existence
@precompiled.push($out.IO);
"OK $out".say;
}
else {
"FAILED".say;
die "Failed to compile: $out";
}
}
}
return @precompiled;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment