]>
iEval git - gruntmaster-daemon.git/blob - lib/Gruntmaster/Daemon/Format.pm
1 package Gruntmaster
::Daemon
::Format
;
6 use parent qw
/Exporter/;
7 no if $] > 5.017011, warnings
=> 'experimental::smartmatch';
9 use Digest
::SHA qw
/sha256_hex/;
11 use File
::Basename qw
/fileparse/;
12 use File
::Copy qw
/cp/;
13 use File
::Slurp qw
/read_file write_file/;
14 use List
::MoreUtils qw
/natatime/;
15 use Log
::Log4perl qw
/get_logger/;
16 use String
::ShellQuote qw
/shell_quote/;
19 our $VERSION = '5999.000_004';
20 our @EXPORT_OK = qw
/prepare_files stopvms/;
22 ##################################################
27 my ($name, $arg) = @_;
28 return unless $ENV{GRUNTMASTER_VM
};
29 my $cmd = $ENV{GRUNTMASTER_VM
};
30 $cmd .= ' ' . $arg if $arg;
31 get_logger
->trace("Starting VM $name ($cmd)");
32 $vm{$name} = Expect
->new;
33 $vm{$name}->raw_pty(1);
34 $vm{$name}->log_stdout(0);
35 $vm{$name}->spawn($cmd);
36 $vm{$name}->expect(5, '# ') or get_logger
->logdie("Error while starting VM $name: ". $vm{$name}->error);
40 kill KILL
=> $_->pid for values %vm;
48 warn "Cannot kill VM\n" if $kill;
49 $vm{$vm}->expect(5, '# ');
51 kill KILL
=> $pid{$vm} if $kill;
56 my $er = "exec-result-$vm";
57 die "gruntmaster-exec died\n" if -z
$er;
58 my ($excode, $exmsg) = read_file
$er;
60 chomp ($excode, $exmsg); ## no critic (ProhibitParensWithBuiltins)
61 get_logger
->trace("Exec result from $vm: $excode $exmsg");
62 die [$excode, $exmsg] if $excode; ## no critic (RequireCarping)
67 my $er = "exec-result-$vm";
69 my $cmd = ">$er " . shell_quote
'gruntmaster-exec', @args;
70 get_logger
->trace("Running in VM $vm: $cmd");
71 $vm{$vm}->send($cmd, "\n");
73 $pid{$vm} = fork // die "Cannot fork\n";
75 open STDOUT
, '>', $er or die "Cannot open $er\n";
76 get_logger
->trace("Running: gruntmaster-exec @args");
77 exec 'gruntmaster-exec', @args;
85 local *__ANON__
= 'mkrun_runner';
86 my ($name, %args) = @_;
87 get_logger
->trace("Running $name...");
88 my $basename = fileparse
$name, qr/[.][^.]*/s;
89 my @args = ('--sudo');
90 push @args, '--keep-stderr' if $ENV{TEST_VERBOSE
};
91 push @args, '--timeout', $args{timeout
} if $args{timeout
};
92 push @args, '--mlimit', $args{mlimit
} if $args{mlimit
};
93 push @args, '--olimit', $args{olimit
} if $args{olimit
};
94 my @fds = exists $args{fds
} ? @
{$args{fds
}} : ();
95 my $it = natatime
2, @fds;
96 while (my ($fd, $file) = $it->()) {
97 push @args, "--fd=$fd $file";
99 execlist
$basename, @args, '--', "./$basename", @
{$args{args
}};
100 execlist_finish
$basename unless $args{nonblocking
}
105 my ($name, $format) = @_;
106 get_logger
->trace("Preparing file $name...");
109 execlist prog
=> '--fd=1 >>errors', '--fd=2 >>errors', 'gruntmaster-compile', $format, $name;
110 execlist_finish
'prog';
113 die "Compile error ($exmsg)\n"
115 $Gruntmaster::Daemon
::errors
.= read_file
'errors';
116 $Gruntmaster::Daemon
::errors
.= "\n" if -s
'errors';
123 if ($meta->{runner
} eq 'Interactive') {
124 runvm ver
=> '-serial unix:vm.sock,nowait,server';
125 runvm prog
=> '-serial unix:vm.sock,nowait';
127 runvm
$_ for keys %{$meta->{files
}};
130 for my $file (values %{$meta->{files
}}) {
131 my ($format, $name, $content) = @
{$file}{qw
/format name content/};
133 $file->{run
} = mkrun
($format);
134 write_file
$name, $content;
135 if ($ENV{GRUNTMASTER_CCACHE
}) {
136 my $key = lc sha256_hex
($content) . '-' . $format;
137 my $cachefn = "$ENV{GRUNTMASTER_CCACHE}/$key";
138 my $exefn = fileparse
$name, qr/[.][^.]*/s;
139 if (cp
$cachefn, $exefn) {
140 get_logger
->trace("File $name found in compilation cache")
142 prepare
$name, $format;
146 prepare
$name, $format
158 Gruntmaster::Daemon::Format - Utility functions for handling source files
162 use Gruntmaster::Daemon::Format qw/prepare_files/;
163 prepare_files { files => {
167 content => 'print "Hello, world!"'
178 Gruntmaster::Daemon::Format exports utility functions for handling source files.
182 =item B<prepare_files> I<$meta>
184 Compiles all the source files in C<< $meta->{files} >>.
190 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
192 =head1 COPYRIGHT AND LICENSE
194 Copyright (C) 2014 by Marius Gavrilescu
196 This library is free software: you can redistribute it and/or modify
197 it under the terms of the GNU Affero General Public License as published by
198 the Free Software Foundation, either version 3 of the License, or
199 (at your option) any later version.
This page took 0.066016 seconds and 5 git commands to generate.