]>
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
/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/;
18 our $VERSION = "5999.000_002";
19 our @EXPORT_OK = qw
/prepare_files/;
21 ##################################################
24 my ($format, $basename) = @_;
27 "./$basename" when [qw
/C CPP PASCAL
/];
28 "./$basename.exe" when 'MONO';
29 java
=> $basename when 'JAVA';
30 perl
=> $basename when 'PERL';
31 python
=> $basename when 'PYTHON';
32 default { die "Don't know how to execute format $format" }
39 local *__ANON__
= 'mkrun_runner';
40 my ($name, %args) = @_;
41 get_logger
->trace("Running $name...");
42 my $basename = fileparse
$name, qr/\.[^.]*/;
43 my $ret = fork // die 'Cannot fork';
46 local $SIG{ALRM
} = sub { kill KILL
=> $ret; $tle = 1};
47 alarm $args{timeout
} if exists $args{timeout
};
51 my $signame = sig_name
$sig;
52 die [TLE
, "Time Limit Exceeded"] if $tle;
53 die [OLE
, 'Output Limit Exceeded'] if $sig && $signame eq 'XFSZ';
54 die [DIED
, "Crash (SIG$signame)"] if $sig && $signame != 'PIPE';
55 die [NZX
, "Non-zero exit status: " . ($?
>> 8)] if $?
>> 8;
57 my @fds = exists $args{fds
} ? @
{$args{fds
}} : ();
59 POSIX
::close $_ for 0 .. $^F
;
60 my $it = natatime
2, @fds;
61 while (my ($fd, $file) = $it->()) {
62 open my $fh, $file or die $!;
63 my $oldfd = fileno $fh;
65 POSIX
::dup2
$oldfd, $fd or die $!;
66 POSIX
::close $oldfd or die $!;
69 exec 'gruntmaster-exec', $args{mlimit
} // 0, $args{olimit
} // 0, command_and_args
($format, $basename), exists $args{args
} ? @
{$args{args
}} : ();
76 my ($name, $format) = @_;
77 get_logger
->trace("Preparing file $name...");
79 $Gruntmaster::Daemon
::errors
.= `gruntmaster-compile $format $name 2>&1`;
80 $Gruntmaster::Daemon
::errors
.= "\n";
81 die 'Compile error' if $?
87 for my $file (values $meta->{files
}) {
88 my ($format, $name, $content) = @
{$file}{qw
/format name content/};
90 $file->{run
} = mkrun
($format);
91 write_file
$name, $content;
92 prepare
$name, $format;
103 Gruntmaster::Daemon::Format - Utility functions for handling source files
107 use Gruntmaster::Daemon::Format qw/prepare_files/;
108 prepare_files { files => {
112 content => 'print "Hello, world!"'
123 Gruntmaster::Daemon::Format exports utility functions for handling source files.
127 =item B<prepare_files> I<$meta>
129 Compiles all the source files in C<< $meta->{files} >>.
135 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
137 =head1 COPYRIGHT AND LICENSE
139 Copyright (C) 2014 by Marius Gavrilescu
141 This library is free software: you can redistribute it and/or modify
142 it under the terms of the GNU Affero General Public License as published by
143 the Free Software Foundation, either version 3 of the License, or
144 (at your option) any later version.
This page took 0.282112 seconds and 5 git commands to generate.