]>
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';
10 use File
::Basename qw
/fileparse/;
11 use File
::Slurp qw
/read_file write_file/;
12 use List
::MoreUtils qw
/natatime/;
13 use Log
::Log4perl qw
/get_logger/;
14 use String
::ShellQuote qw
/shell_quote/;
17 our $VERSION = '5999.000_004';
18 our @EXPORT_OK = qw
/prepare_files stopvms/;
20 ##################################################
25 my ($name, $arg) = @_;
26 return unless $ENV{GRUNTMASTER_VM
};
27 my $cmd = $ENV{GRUNTMASTER_VM
};
28 $cmd .= ' ' . $arg if $arg;
29 get_logger
->trace("Starting VM $name ($cmd)");
30 $vm{$name} = Expect
::Simple
->new({
33 DisconnectCmd
=> '/sbin/poweroff -fn',
39 sub stopvms
{ %vm = () }
43 my $er = "exec-result-$vm";
45 my $cmd = ">$er " . shell_quote
'gruntmaster-exec', @args;
46 get_logger
->trace("Running in VM $vm: $cmd");
49 my $ret = fork // die "Cannot fork\n";
53 open STDOUT
, '>', $er or die "Cannot open $er\n";
54 get_logger
->trace("Running: gruntmaster-exec @args");
55 exec 'gruntmaster-exec', @args;
59 die "gruntmaster-exec died\n" if -z
$er;
60 my ($excode, $exmsg) = read_file
$er;
62 chomp ($excode, $exmsg); ## no critic (ProhibitParensWithBuiltins)
63 get_logger
->trace("Exec result: $excode $exmsg");
64 die [$excode, $exmsg] if $excode > 0; ## no critic (RequireCarping)
70 local *__ANON__
= 'mkrun_runner';
71 my ($name, %args) = @_;
72 get_logger
->trace("Running $name...");
73 my $basename = fileparse
$name, qr/[.][^.]*/s;
74 my @args = ('--sudo');
75 push @args, '--keep-stderr' if $ENV{TEST_VERBOSE
};
76 push @args, '--timeout', $args{timeout
} if $args{timeout
};
77 push @args, '--mlimit', $args{mlimit
} if $args{mlimit
};
78 push @args, '--olimit', $args{olimit
} if $args{olimit
};
79 my @fds = exists $args{fds
} ? @
{$args{fds
}} : ();
80 my $it = natatime
2, @fds;
81 while (my ($fd, $file) = $it->()) {
82 push @args, "--fd=$fd $file";
84 execlist
$basename, @args, '--', "./$basename", @
{$args{args
}}
89 my ($name, $format) = @_;
90 get_logger
->trace("Preparing file $name...");
93 execlist prog
=> '--fd=1 >>errors', '--fd=2 >>errors', 'gruntmaster-compile', $format, $name;
96 die "Compile error ($exmsg)\n"
98 $Gruntmaster::Daemon
::errors
.= read_file
'errors';
99 $Gruntmaster::Daemon
::errors
.= "\n" if -s
'errors';
106 if ($meta->{runner
} eq 'Interactive') {
107 runvm ver
=> '-serial unix:vm.sock,nowait,server';
108 runvm prog
=> '-serial unix:vm.sock,nowait';
110 runvm
$_ for keys %{$meta->{files
}};
113 for my $file (values %{$meta->{files
}}) {
114 my ($format, $name, $content) = @
{$file}{qw
/format name content/};
116 $file->{run
} = mkrun
($format);
117 write_file
$name, $content;
118 prepare
$name, $format;
129 Gruntmaster::Daemon::Format - Utility functions for handling source files
133 use Gruntmaster::Daemon::Format qw/prepare_files/;
134 prepare_files { files => {
138 content => 'print "Hello, world!"'
149 Gruntmaster::Daemon::Format exports utility functions for handling source files.
153 =item B<prepare_files> I<$meta>
155 Compiles all the source files in C<< $meta->{files} >>.
161 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
163 =head1 COPYRIGHT AND LICENSE
165 Copyright (C) 2014 by Marius Gavrilescu
167 This library is free software: you can redistribute it and/or modify
168 it under the terms of the GNU Affero General Public License as published by
169 the Free Software Foundation, either version 3 of the License, or
170 (at your option) any later version.
This page took 0.062797 seconds and 5 git commands to generate.