-
Notifications
You must be signed in to change notification settings - Fork 0
/
ce-run
executable file
·112 lines (82 loc) · 2.61 KB
/
ce-run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/perl
use warnings;
use strict;
use v5.10;
use FindBin;
use lib $FindBin::Bin;
use File::Basename;
use compeval;
use compeval::Task;
use compeval::GFS;
my $no_exec = 0;
my $gfs;
my %inputs;
sub exec_workflow {
my ($workflow, $label, $indent, $basedir) = @_;
if ($workflow->kind eq 'input') {
my $inputfile = $inputs{$workflow->value};
my $filename = $gfs->pathof_output($workflow, 0, sha1f($inputfile));
my $status = -e $filename ? 'ok' : 'MISSING!!!';
say $indent, "$label: INPUT('".$workflow->value."') $filename $status";
return $filename;
} elsif ($workflow->kind eq 'literal') {
my $filename = $gfs->pathof_output($workflow, 0, $workflow->value);
my $status = -e $filename ? 'ok' : 'MISSING!!!';
say $indent, "$label: FILE('".$workflow->value."') $filename $status";
return $filename;
} elsif ($workflow->kind eq 'computation') {
my $compname = $workflow->value;
my $computation = $workflow->computation($basedir);
my @args;
# Recurse to inputs
for my $input ($workflow->inputs) {
my $inpworkflow = $workflow->input($input);
push @args, exec_workflow($inpworkflow, $input->{label}, $indent.' ', $basedir);
}
say $indent, "$compname ($label)";
my @sha1args = map { sha1f($_) } @args;
my @outputs;
my $missing = 0;
for my $output ($workflow->outputs_slice) {
my $filename = $gfs->pathof_output($workflow, $output+0, @sha1args);
system('mkdir', '-p', dirname($filename));
my $status = -e $filename ? 'ok' : 'MISSING';
$missing += not -e $filename;
say $indent.'`> ', ($computation->outputs)[$output].": $filename $status";
push @outputs, $filename;
}
# Re-exec if any output is missing
if ($missing > 0 and not $no_exec) {
say $indent.'`* ', 'computing...';
$computation->exec(@args, @outputs);
}
return @outputs;
}
}
# Initialize task
my $task = compeval::Task->new('.');
# Process parameters
if ($ARGV[0] eq '-n') {
$no_exec = 1;
shift @ARGV;
}
$gfs = compeval::GFS->new(shift @ARGV, '.');
my @inputnames = $task->inputnames;
if (@ARGV != @inputnames) {
die "expected ".(scalar @inputnames)." inputs, got ".(scalar @ARGV);
}
%inputs = map { $inputnames[$_] => $ARGV[$_] } 0..$#inputnames;
# Store inputs in GFS (this is not essential, just for future reference)
unless ($no_exec) {
for my $inputfile (@ARGV) {
my $filename = $gfs->pathof($gfs->nameof_input(sha1f($inputfile)));
system('mkdir', '-p', dirname($filename));
system('cp', $inputfile, $filename);
}
}
# Execute!
my @outputs = exec_workflow($task->workflow(), 'TASK', '', '.');
say "\nTask outputs are:";
for my $outputfile (@outputs) {
say ' ', $outputfile;
}