X-Git-Url: http://git.ieval.ro/?p=gruntmaster-daemon.git;a=blobdiff_plain;f=lib%2FGruntmaster%2FDaemon%2FFormat.pm;h=c49ffc1ea1b1b7336efa8ad04b76691c40531def;hp=5f34a3325dd59d873874144dfd0b39b5dd1cd478;hb=d6a1ae0d77398b2a7ed967e10e8420ac7d9980e5;hpb=9577371b26a374ad3ff73a914546701c1ae138cf diff --git a/lib/Gruntmaster/Daemon/Format.pm b/lib/Gruntmaster/Daemon/Format.pm index 5f34a33..c49ffc1 100644 --- a/lib/Gruntmaster/Daemon/Format.pm +++ b/lib/Gruntmaster/Daemon/Format.pm @@ -8,17 +8,15 @@ no if $] > 5.017011, warnings => 'experimental::smartmatch'; use POSIX qw//; use File::Basename qw/fileparse/; +use File::Slurp qw/write_file/; use Gruntmaster::Daemon::Constants qw/TLE OLE DIED NZX/; -use Log::Log4perl qw/get_logger/; use Time::HiRes qw/alarm/; use List::MoreUtils qw/natatime/; +use Log::Log4perl qw/get_logger/; use IPC::Signal qw/sig_name sig_num/; -use IPC::Open3 qw/open3/; -use File::Spec::Functions qw/devnull/; -use Fcntl qw/F_GETFD F_SETFD FD_CLOEXEC/; -our $VERSION = '0.001'; -our @EXPORT_OK = qw/mkrun/; +our $VERSION = "5999.000_002"; +our @EXPORT_OK = qw/prepare_files/; ################################################## @@ -28,9 +26,9 @@ sub command_and_args{ given($format) { "./$basename" when [qw/C CPP PASCAL/]; "./$basename.exe" when 'MONO'; - "java $basename" when 'JAVA'; - "perl $basename" when 'PERL'; - "python $basename" when 'PYTHON'; + java => $basename when 'JAVA'; + perl => $basename when 'PERL'; + python => $basename when 'PYTHON'; default { die "Don't know how to execute format $format" } } } @@ -67,8 +65,81 @@ sub mkrun{ } } exec 'gruntmaster-exec', $args{mlimit} // 0, $args{olimit} // 0, command_and_args($format, $basename), exists $args{args} ? @{$args{args}} : (); + exit 42 } } } -1 +sub prepare{ + my ($name, $format) = @_; + get_logger->trace("Preparing file $name..."); + + $Gruntmaster::Daemon::errors .= `gruntmaster-compile $format $name 2>&1`; + $Gruntmaster::Daemon::errors .= "\n"; + die 'Compile error' if $? +} + +sub prepare_files{ + my $meta = shift; + + for my $file (values $meta->{files}) { + my ($format, $name, $content) = @{$file}{qw/format name content/}; + + $file->{run} = mkrun($format); + write_file $name, $content; + prepare $name, $format; + } +} + +1; +__END__ + +=encoding utf-8 + +=head1 NAME + +Gruntmaster::Daemon::Format - Utility functions for handling source files + +=head1 SYNOPSIS + + use Gruntmaster::Daemon::Format qw/prepare_files/; + prepare_files { files => { + prog => { + name => 'prog.pl', + format => 'PERL', + content => 'print "Hello, world!"' + }, + ver => { + name => 'ver.cpp', + format => 'CPP', + content => ... + }, + }}; + +=head1 DESCRIPTION + +Gruntmaster::Daemon::Format exports utility functions for handling source files. + +=over + +=item B I<$meta> + +Compiles all the source files in C<< $meta->{files} >>. + +=back + +=head1 AUTHOR + +Marius Gavrilescu Emarius@ieval.roE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2014 by Marius Gavrilescu + +This library is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + + +=cut