cd0e47d495df05296a9e32c20534544d728b67b6
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
::Simple
->new({
35 DisconnectCmd
=> '/sbin/poweroff -fn',
41 sub stopvms
{ %vm = () }
45 my $er = "exec-result-$vm";
47 my $cmd = ">$er " . shell_quote
'gruntmaster-exec', @args;
48 get_logger
->trace("Running in VM $vm: $cmd");
51 my $ret = fork // die "Cannot fork\n";
55 open STDOUT
, '>', $er or die "Cannot open $er\n";
56 get_logger
->trace("Running: gruntmaster-exec @args");
57 exec 'gruntmaster-exec', @args;
61 die "gruntmaster-exec died\n" if -z
$er;
62 my ($excode, $exmsg) = read_file
$er;
64 chomp ($excode, $exmsg); ## no critic (ProhibitParensWithBuiltins)
65 get_logger
->trace("Exec result: $excode $exmsg");
66 die [$excode, $exmsg] if $excode > 0; ## no critic (RequireCarping)
72 local *__ANON__
= 'mkrun_runner';
73 my ($name, %args) = @_;
74 get_logger
->trace("Running $name...");
75 my $basename = fileparse
$name, qr/[.][^.]*/s;
76 my @args = ('--sudo');
77 push @args, '--keep-stderr' if $ENV{TEST_VERBOSE
};
78 push @args, '--timeout', $args{timeout
} if $args{timeout
};
79 push @args, '--mlimit', $args{mlimit
} if $args{mlimit
};
80 push @args, '--olimit', $args{olimit
} if $args{olimit
};
81 my @fds = exists $args{fds
} ? @
{$args{fds
}} : ();
82 my $it = natatime
2, @fds;
83 while (my ($fd, $file) = $it->()) {
84 push @args, "--fd=$fd $file";
86 execlist
$basename, @args, '--', "./$basename", @
{$args{args
}}
91 my ($name, $format) = @_;
92 get_logger
->trace("Preparing file $name...");
95 execlist prog
=> '--fd=1 >>errors', '--fd=2 >>errors', 'gruntmaster-compile', $format, $name;
98 die "Compile error ($exmsg)\n"
100 $Gruntmaster::Daemon
::errors
.= read_file
'errors';
101 $Gruntmaster::Daemon
::errors
.= "\n" if -s
'errors';
108 if ($meta->{runner
} eq 'Interactive') {
109 runvm ver
=> '-serial unix:vm.sock,nowait,server';
110 runvm prog
=> '-serial unix:vm.sock,nowait';
112 runvm
$_ for keys %{$meta->{files
}};
115 for my $file (values %{$meta->{files
}}) {
116 my ($format, $name, $content) = @
{$file}{qw
/format name content/};
118 $file->{run
} = mkrun
($format);
119 write_file
$name, $content;
120 if ($ENV{GRUNTMASTER_CCACHE
}) {
121 my $key = lc sha256_hex
($content) . '-' . $format;
122 my $cachefn = "$ENV{GRUNTMASTER_CCACHE}/$key";
123 my $exefn = fileparse
$name, qr/[.][^.]*/s;
124 if (cp
$cachefn, $exefn) {
125 get_logger
->trace("File $name found in compilation cache")
127 prepare
$name, $format;
131 prepare
$name, $format
143 Gruntmaster::Daemon::Format - Utility functions for handling source files
147 use Gruntmaster::Daemon::Format qw/prepare_files/;
148 prepare_files { files => {
152 content => 'print "Hello, world!"'
163 Gruntmaster::Daemon::Format exports utility functions for handling source files.
167 =item B<prepare_files> I<$meta>
169 Compiles all the source files in C<< $meta->{files} >>.
175 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
177 =head1 COPYRIGHT AND LICENSE
179 Copyright (C) 2014 by Marius Gavrilescu
181 This library is free software: you can redistribute it and/or modify
182 it under the terms of the GNU Affero General Public License as published by
183 the Free Software Foundation, either version 3 of the License, or
184 (at your option) any later version.
This page took 0.03387 seconds and 4 git commands to generate.