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/;
-use POSIX qw/mkfifo/;
use String::ShellQuote qw/shell_quote/;
use Try::Tiny;
our (%vm);
sub runvm {
- my ($name) = @_;
+ my ($name, $arg) = @_;
return unless $ENV{GRUNTMASTER_VM};
- mkfifo "$name.in", 0600;
- mkfifo "$name.out", 0600;
- get_logger->trace("Starting VM $name");
+ my $cmd = $ENV{GRUNTMASTER_VM};
+ $cmd .= ' ' . $arg if $arg;
+ get_logger->trace("Starting VM $name ($cmd)");
$vm{$name} = Expect::Simple->new({
- Cmd => "$ENV{GRUNTMASTER_VM} $name",
+ Cmd => $cmd,
Prompt => '# ',
- DisconnectCmd => 'exit',
+ DisconnectCmd => '/sbin/poweroff -fn',
RawPty => 1,
Timeout => 10,
});
unlink $er;
chomp ($excode, $exmsg); ## no critic (ProhibitParensWithBuiltins)
get_logger->trace("Exec result: $excode $exmsg");
- die [$excode, $exmsg] if $excode > 0; ## no critic (RequireCarping)
+ die [$excode, $exmsg] if $excode; ## no critic (RequireCarping)
}
sub mkrun{
my ($name, %args) = @_;
get_logger->trace("Running $name...");
my $basename = fileparse $name, qr/[.][^.]*/s;
- my @args = ('--nobody');
- push @args, '--no-close' if $ENV{TEST_VERBOSE};
+ my @args = ('--sudo');
+ push @args, '--keep-stderr' if $ENV{TEST_VERBOSE};
push @args, '--timeout', $args{timeout} if $args{timeout};
push @args, '--mlimit', $args{mlimit} if $args{mlimit};
push @args, '--olimit', $args{olimit} if $args{olimit};
try {
execlist prog => '--fd=1 >>errors', '--fd=2 >>errors', 'gruntmaster-compile', $format, $name;
} catch {
- die "Compile error\n"
+ my $exmsg = $_->[1];
+ die "Compile error ($exmsg)\n"
} finally {
$Gruntmaster::Daemon::errors .= read_file 'errors';
- $Gruntmaster::Daemon::errors .= "\n";
+ $Gruntmaster::Daemon::errors .= "\n" if -s 'errors';
unlink 'errors';
};
}
sub prepare_files{
my $meta = shift;
- runvm $_ for keys %{$meta->{files}};
+ if ($meta->{runner} eq 'Interactive') {
+ runvm ver => '-serial unix:vm.sock,nowait,server';
+ runvm prog => '-serial unix:vm.sock,nowait';
+ } else {
+ runvm $_ for keys %{$meta->{files}};
+ }
for my $file (values %{$meta->{files}}) {
my ($format, $name, $content) = @{$file}{qw/format name content/};
$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
+ }
}
}