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 Gruntmaster
::Daemon
::Constants qw
/TLE OLE DIED NZX/;
13 use Time
::HiRes qw
/alarm/;
14 use List
::MoreUtils qw
/natatime/;
15 use Log
::Log4perl qw
/get_logger/;
16 use IPC
::Signal qw
/sig_name sig_num/;
19 our $VERSION = "5999.000_004";
20 our @EXPORT_OK = qw
/prepare_files/;
22 ##################################################
26 my $ret = fork // die 'Cannot fork';
29 die "gruntmaster-exec died\n" if -z
'exec-result';
30 my ($excode, $exmsg) = read_file
'exec-result';
32 chomp ($excode, $exmsg);
33 die [$excode, $exmsg] if $excode > 0;
35 open STDOUT
, '>exec-result';
36 exec 'gruntmaster-exec', @args;
41 my ($format, $basename) = @_;
44 "./$basename" when [qw
/C CPP GCCGO GOLANG HASKELL PASCAL
/];
45 "./$basename.exe" when 'MONO';
46 java
=> $basename when 'JAVA';
47 perl
=> $basename when 'PERL';
48 python
=> $basename when 'PYTHON';
49 default { die "Don't know how to execute format $format\n" }
56 local *__ANON__
= 'mkrun_runner';
57 my ($name, %args) = @_;
58 get_logger
->trace("Running $name...");
59 my $basename = fileparse
$name, qr/\.[^.]*/;
61 push @args, '--timeout', $args{timeout
} if $args{timeout
};
62 push @args, '--mlimit', $args{mlimit
} if $args{mlimit
};
63 push @args, '--olimit', $args{olimit
} if $args{olimit
};
64 my @fds = exists $args{fds
} ? @
{$args{fds
}} : ();
65 my $it = natatime
2, @fds;
66 while (my ($fd, $file) = $it->()) {
67 push @args, "--fd=$fd $file";
69 execlist
@args, command_and_args
($format, $basename);
74 my ($name, $format) = @_;
75 get_logger
->trace("Preparing file $name...");
78 execlist
'--fd=1 >>errors', '--fd=2 >>errors', 'gruntmaster-compile', $format, $name;
82 $Gruntmaster::Daemon
::errors
.= read_file
'errors';
83 $Gruntmaster::Daemon
::errors
.= "\n";
91 for my $file (values %{$meta->{files
}}) {
92 my ($format, $name, $content) = @
{$file}{qw
/format name content/};
94 $file->{run
} = mkrun
($format);
95 write_file
$name, $content;
96 prepare
$name, $format;
107 Gruntmaster::Daemon::Format - Utility functions for handling source files
111 use Gruntmaster::Daemon::Format qw/prepare_files/;
112 prepare_files { files => {
116 content => 'print "Hello, world!"'
127 Gruntmaster::Daemon::Format exports utility functions for handling source files.
131 =item B<prepare_files> I<$meta>
133 Compiles all the source files in C<< $meta->{files} >>.
139 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
141 =head1 COPYRIGHT AND LICENSE
143 Copyright (C) 2014 by Marius Gavrilescu
145 This library is free software: you can redistribute it and/or modify
146 it under the terms of the GNU Affero General Public License as published by
147 the Free Software Foundation, either version 3 of the License, or
148 (at your option) any later version.