]>
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 Gruntmaster
::Daemon
::Constants qw
/TLE OLE DIED NZX/;
12 use Time
::HiRes qw
/alarm/;
13 use List
::MoreUtils qw
/natatime/;
14 use IPC
::Signal qw
/sig_name sig_num/;
16 our $VERSION = "5999-TRIAL";
17 our @EXPORT_OK = qw
/prepare_files/;
19 ##################################################
22 my ($format, $basename) = @_;
25 "./$basename" when [qw
/C CPP PASCAL
/];
26 "./$basename.exe" when 'MONO';
27 "java $basename" when 'JAVA';
28 "perl $basename" when 'PERL';
29 "python $basename" when 'PYTHON';
30 default { die "Don't know how to execute format $format" }
37 my ($name, %args) = @_;
38 my $basename = fileparse
$name, qr/\.[^.]*/;
39 my $ret = fork // die 'Cannot fork';
42 local $SIG{ALRM
} = sub { kill KILL
=> $ret; $tle = 1};
43 alarm $args{timeout
} if exists $args{timeout
};
47 my $signame = sig_name
$sig;
48 die [TLE
, "Time Limit Exceeded"] if $tle;
49 die [OLE
, 'Output Limit Exceeded'] if $sig && $signame eq 'XFSZ';
50 die [DIED
, "Crash (SIG$signame)"] if $sig;
51 die [NZX
, "Non-zero exit status: " . ($?
>> 8)] if $?
;
53 my @fds = exists $args{fds
} ? @
{$args{fds
}} : ();
55 POSIX
::close $_ for 0 .. $^F
;
56 my $it = natatime
2, @fds;
57 while (my ($fd, $file) = $it->()) {
58 open my $fh, $file or die $!;
59 my $oldfd = fileno $fh;
61 POSIX
::dup2
$oldfd, $fd or die $!;
62 POSIX
::close $oldfd or die $!;
65 exec 'gruntmaster-exec', $args{mlimit
} // 0, $args{olimit
} // 0, command_and_args
($format, $basename), exists $args{args
} ? @
{$args{args
}} : ();
72 my ($name, $format) = @_;
74 my $basename = fileparse
$name, qr/\.[^.]*/;
75 get_logger
->trace("Preparing file $name...");
77 $errors .= `gruntmaster-compile $format $basename $name 2>&1`;
79 die 'Compile error' if $?
85 for my $file (values $meta->{files
}) {
86 my ($format, $name, $content) = @
{$file}{qw
/format name content/};
88 $file->{run
} = mkrun
($format);
89 write_file
$name, $content;
90 prepare
$name, $format;
101 Gruntmaster::Daemon::Format - Utility functions for handling source files
105 use Gruntmaster::Daemon::Format qw/prepare_files/;
106 prepare_files { files => {
110 content => 'print "Hello, world!"'
121 Gruntmaster::Daemon::Format exports utility functions for handling source files.
125 =item B<prepare_files> I<$meta>
127 Compiles all the source files in C<< $meta->{files} >>.
133 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
135 =head1 COPYRIGHT AND LICENSE
137 Copyright (C) 2014 by Marius Gavrilescu
139 This library is free software: you can redistribute it and/or modify
140 it under the terms of the GNU Affero General Public License as published by
141 the Free Software Foundation, either version 3 of the License, or
142 (at your option) any later version.
This page took 0.062327 seconds and 4 git commands to generate.