-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.jsonnet
34 lines (31 loc) · 952 Bytes
/
lib.jsonnet
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
local yaml = importstr 'config.yaml';
local config = std.parseYaml(yaml);
local maybe(cond, obj) = if cond then obj else null;
local cmd(cmd) = 'cargo run --release -- ' + cmd;
local pipeline(stages, flag=true) = { stages: if flag then stages else {} };
local normalizePath(path) =
local parts = std.split(path, '/');
local norm(ps, pfx) =
if std.length(ps) == 0
then pfx
else if ps[0] == '.' || ps[0] == ''
then norm(ps[1:], pfx)
else if ps[0] == '..'
then norm(ps[1:], pfx[0:std.length(pfx) - 1])
else norm(ps[1:], pfx + [ps[0]]);
std.join('/', norm(parts, []));
// get the outputs of a stage.
// dir: the directory of the file defining the stage
// stage: the stage definition
local stageOuts(dir, stage) =
[
normalizePath(std.join('/', [dir, std.get(stage, 'wdir', '.'), out]))
for out in stage.outs
];
{
config: config,
maybe: maybe,
cmd: cmd,
pipeline: pipeline,
stageOuts: stageOuts,
}