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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
|
{ "template":
{ "doc": ["Create a pandoc template with arguments"]
, "string_fields": ["name", "args"]
, "target_fields": ["data", "lua filters"]
, "field_doc":
{ "name": ["Name of the template to use"]
, "args": ["Additional pandoc arguments"]
, "data": ["Template data files"]
, "lua filters": ["Files that should be used as lua filters"]
}
, "expression":
{ "type": "let*"
, "bindings":
[ [ "data"
, { "type": "disjoint_map_union"
, "msg": "Data files may not conflict"
, "$1":
{ "type": "foreach"
, "var": "x"
, "range": {"type": "FIELD", "name": "data"}
, "body":
{ "type": "map_union"
, "$1":
[ {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "x"}}
, { "type": "DEP_ARTIFACTS"
, "dep": {"type": "var", "name": "x"}
}
]
}
}
}
]
, [ "lua filters"
, { "type": "disjoint_map_union"
, "msg": "Lua filters may not conflict"
, "$1":
{ "type": "foreach"
, "var": "x"
, "range": {"type": "FIELD", "name": "lua filters"}
, "body":
{ "type": "map_union"
, "$1":
[ {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "x"}}
, { "type": "DEP_ARTIFACTS"
, "dep": {"type": "var", "name": "x"}
}
]
}
}
}
]
]
, "body":
{ "type": "RESULT"
, "artifacts": {"type": "var", "name": "data"}
, "runfiles": {"type": "var", "name": "data"}
, "provides":
{ "type": "map_union"
, "$1":
[ { "type": "singleton_map"
, "key": "template-name"
, "value":
{"type": "join", "$1": {"type": "FIELD", "name": "name"}}
}
, { "type": "singleton_map"
, "key": "template-args"
, "value": {"type": "FIELD", "name": "args"}
}
, { "type": "singleton_map"
, "key": "lua filters"
, "value": {"type": "var", "name": "lua filters"}
}
]
}
}
}
}
, "metadata":
{ "doc":
["Generate a file with meta data from data provided through context"]
, "config_vars": ["SOURCE_DATE_EPOCH", "DATE_FORMAT"]
, "config_doc":
{ "SOURCE_DATE_EPOCH":
[ "The timestamp to include (in seconds since Jan 1, 1970 00:00 UTC);"
, "ignored if unset or value is 0."
]
, "DATE_FORMAT":
["The format to use for time stamps (defaults to \"%Y-%m-%d %H:%M\")."]
}
, "expression":
{ "type": "let*"
, "bindings":
[ [ "script"
, { "type": "join"
, "separator": "\n"
, "$1":
{ "type": "++"
, "$1":
[ ["echo", "echo ---"]
, { "type": "if"
, "cond": {"type": "var", "name": "SOURCE_DATE_EPOCH"}
, "then":
[ { "type": "join_cmd"
, "$1":
[ "date"
, "-d"
, { "type": "join"
, "$1":
[ "@"
, { "type": "json_encode"
, "$1":
{"type": "var", "name": "SOURCE_DATE_EPOCH"}
}
]
}
, { "type": "join"
, "$1":
[ "+date: \""
, { "type": "var"
, "name": "DATE_FORMAT"
, "default": "%Y-%m-%d %H:%M"
}
, "\""
]
}
]
}
]
}
, ["echo ---", "echo\n"]
]
}
}
]
, [ "data"
, { "type": "ACTION"
, "cmd": ["sh", "-c", "sh ./generate > metadata.yaml"]
, "outs": ["metadata.yaml"]
, "inputs":
{ "type": "singleton_map"
, "key": "generate"
, "value":
{"type": "BLOB", "data": {"type": "var", "name": "script"}}
}
}
]
]
, "body": {"type": "RESULT", "artifacts": {"type": "var", "name": "data"}}
}
}
, "standalone":
{ "doc": ["Create a standalone document from the given inputs"]
, "target_fields": ["srcs", "template", "data", "meta data files"]
, "string_fields": ["out", "meta data", "via"]
, "field_doc":
{ "srcs":
[ "The files to build the document from, in order."
, "Honors the order within a [\"files\", \"ordered\"] target."
]
, "data": ["Additional files needed for building (e.g., images)"]
, "out":
["The name of the output file.", "Must not conflict with input files."]
, "template": ["The template definition to use"]
, "meta data":
[ "Additional meta data to be set. Each entry has to have the"
, "form \"key=value\"."
]
, "meta data files":
["Additional meta data files to be taken into account"]
, "via":
[ "If a non-empty string is given, first convert all input files to this"
, "format, if not of this format already."
, "(entries in this field are concatenated)"
]
}
, "config_vars": ["env", "TYPESETTING_EXECUTION_PROPERTIES"]
, "config_doc":
{ "env":
[ "Any override to the default environment which sets only"
, "PATH, SOURCE_DATE_EPOCH, and TEXINPUTS"
]
, "TYPESETTING_EXECUTION_PROPERTIES":
[ "Map of additional remote-execution properties to add for the typesetting"
, "actions; defaults to the empty map."
]
}
, "implicit": {"metadata": [["./", ".", "metadata"]]}
, "imports":
{ "src names": ["./", "../files", "order"]
, "stage": ["./", "..", "stage_singleton_field"]
}
, "expression":
{ "type": "let*"
, "bindings":
[ [ "out"
, { "type": "assert_non_empty"
, "msg": "A valid output name has to be provided"
, "$1": {"type": "join", "$1": {"type": "FIELD", "name": "out"}}
}
]
, [ "env"
, { "type": "map_union"
, "$1":
[ { "type": "singleton_map"
, "key": "PATH"
, "value": "/bin:/usr/bin:/usr/local/bin"
}
, { "type": "singleton_map"
, "key": "SOURCE_DATE_EPOCH"
, "value": "0"
}
, {"type": "singleton_map", "key": "TEXINPUTS", "value": "data:"}
, {"type": "var", "name": "env", "default": {"type": "empty_map"}}
]
}
]
, [ "srcs"
, { "type": "disjoint_map_union"
, "msg": "Sources may not conflict"
, "$1":
{ "type": "foreach"
, "var": "x"
, "range": {"type": "FIELD", "name": "srcs"}
, "body":
{ "type": "map_union"
, "$1":
[ {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "x"}}
, { "type": "DEP_ARTIFACTS"
, "dep": {"type": "var", "name": "x"}
}
]
}
}
}
]
, [ "extra"
, { "type": "disjoint_map_union"
, "msg": "Data files may not conflict"
, "$1":
{ "type": "foreach"
, "var": "x"
, "range": {"type": "FIELD", "name": "data"}
, "body":
{ "type": "map_union"
, "$1":
[ {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "x"}}
, { "type": "DEP_ARTIFACTS"
, "dep": {"type": "var", "name": "x"}
}
]
}
}
}
]
, [ "extra"
, { "type": "to_subdir"
, "subdir": "data"
, "$1": {"type": "var", "name": "extra"}
}
]
, ["via", {"type": "join", "$1": {"type": "FIELD", "name": "via"}}]
, [".via", {"type": "join", "$1": [".", {"type": "var", "name": "via"}]}]
, [ "srcs"
, { "type": "if"
, "cond": {"type": "var", "name": "via"}
, "else": {"type": "var", "name": "srcs"}
, "then":
{ "type": "disjoint_map_union"
, "msg": "Converted files must not overlap"
, "$1":
{ "type": "foreach_map"
, "range": {"type": "var", "name": "srcs"}
, "body":
{ "type": "let*"
, "bindings":
[ [ "old"
, { "type": "singleton_map"
, "key": {"type": "var", "name": "_"}
, "value": {"type": "var", "name": "$_"}
}
]
, [ "new_name"
, { "type": "change_ending"
, "ending": {"type": "var", "name": ".via"}
, "$1": {"type": "var", "name": "_"}
}
]
]
, "body":
{ "type": "if"
, "cond":
{ "type": "=="
, "$1": {"type": "var", "name": "_"}
, "$2": {"type": "var", "name": "new_name"}
}
, "then": {"type": "var", "name": "old"}
, "else":
{ "type": "ACTION"
, "inputs":
{ "type": "map_union"
, "$1":
[ {"type": "var", "name": "extra"}
, {"type": "var", "name": "old"}
]
}
, "outs": [{"type": "var", "name": "new_name"}]
, "env": {"type": "var", "name": "env"}
, "cmd":
[ "pandoc"
, "-o"
, {"type": "var", "name": "new_name"}
, {"type": "var", "name": "_"}
]
, "execution properties":
{ "type": "var"
, "name": "TYPESETTING_EXECUTION_PROPERTIES"
, "default": {"type": "empty_map"}
}
}
}
}
}
}
}
]
, [ "srcs"
, { "type": "to_subdir"
, "subdir": "srcs"
, "$1": {"type": "var", "name": "srcs"}
}
]
, [ "data"
, { "type": "disjoint_map_union"
, "msg": "Template files may not conflict"
, "$1":
{ "type": "foreach"
, "var": "x"
, "range": {"type": "FIELD", "name": "template"}
, "body":
{ "type": "map_union"
, "$1":
[ {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "x"}}
, { "type": "DEP_ARTIFACTS"
, "dep": {"type": "var", "name": "x"}
}
]
}
}
}
]
, [ "data"
, { "type": "to_subdir"
, "subdir": "data"
, "$1":
{ "type": "disjoint_map_union"
, "msg": "Template may not contain a \"data\" directory"
, "$1":
[ {"type": "var", "name": "data"}
, {"type": "var", "name": "extra"}
]
}
}
]
, [ "lua filters"
, { "type": "disjoint_map_union"
, "msg": "Lua filters may not conflict"
, "$1":
{ "type": "foreach"
, "var": "x"
, "range": {"type": "FIELD", "name": "template"}
, "body":
{ "type": "DEP_PROVIDES"
, "provider": "lua filters"
, "dep": {"type": "var", "name": "x"}
}
}
}
]
, [ "lua filters"
, { "type": "to_subdir"
, "subdir": "lua"
, "$1": {"type": "var", "name": "lua filters"}
}
]
, [ "template-name"
, { "type": "join"
, "$1":
{ "type": "foreach"
, "var": "x"
, "range": {"type": "FIELD", "name": "template"}
, "body":
{ "type": "DEP_PROVIDES"
, "dep": {"type": "var", "name": "x"}
, "provider": "template-name"
, "default": "default"
}
}
}
]
, [ "template-args"
, { "type": "++"
, "$1":
{ "type": "foreach"
, "var": "x"
, "range": {"type": "FIELD", "name": "template"}
, "body":
{ "type": "DEP_PROVIDES"
, "dep": {"type": "var", "name": "x"}
, "provider": "template-args"
}
}
}
]
, [ "_"
, { "type": "if"
, "cond":
{ "type": "lookup"
, "map": {"type": "var", "name": "srcs"}
, "key": {"type": "var", "name": "out"}
}
, "then":
{ "type": "fail"
, "msg":
[ "Output must be disjoint from inputs."
, "Output file name is"
, {"type": "var", "name": "out"}
, "input files are"
, {"type": "keys", "$1": {"type": "var", "name": "srcs"}}
]
}
}
]
, ["src names", {"type": "CALL_EXPRESSION", "name": "src names"}]
, [ "src names"
, { "type": "if"
, "cond": {"type": "var", "name": "via"}
, "else": {"type": "var", "name": "src names"}
, "then":
{ "type": "foreach"
, "range": {"type": "var", "name":"src names"}
, "body":
{ "type": "change_ending"
, "ending": {"type": "var", "name": ".via"}
, "$1": {"type": "var", "name": "_"}
}
}
}
]
, [ "src names"
, { "type": "foreach"
, "var": "name"
, "range": {"type": "var", "name": "src names"}
, "body":
{"type": "join", "$1": ["srcs/", {"type": "var", "name": "name"}]}
}
]
, [ "meta data args"
, { "type": "++"
, "$1":
{ "type": "foreach"
, "var": "x"
, "range": {"type": "FIELD", "name": "meta data"}
, "body": ["-M", {"type": "var", "name": "x"}]
}
}
]
, [ "filter args"
, { "type": "++"
, "$1":
{ "type": "foreach"
, "var": "x"
, "range":
{"type": "keys", "$1": {"type": "var", "name": "lua filters"}}
, "body": ["--lua-filter", {"type": "var", "name": "x"}]
}
}
]
, [ "metadata"
, { "type": "let*"
, "bindings":
[["fieldname", "metadata"], ["location", "metadata.yaml"]]
, "body": {"type": "CALL_EXPRESSION", "name": "stage"}
}
]
, [ "extra metadata files"
, { "type": "++"
, "$1":
{ "type": "foreach"
, "range": {"type": "FIELD", "name": "meta data files"}
, "body":
{ "type": "values"
, "$1":
{"type": "DEP_ARTIFACTS", "dep": {"type": "var", "name": "_"}}
}
}
}
]
, [ "staged extra metadata"
, { "type": "map_union"
, "$1":
{ "type": "foreach_map"
, "range":
{ "type": "enumerate"
, "$1": {"type": "var", "name": "extra metadata files"}
}
, "body":
{ "type": "singleton_map"
, "key":
{ "type": "join"
, "$1": ["metadta", {"type": "var", "name": "_"}, ".yaml"]
}
, "value": {"type": "var", "name": "$_"}
}
}
}
]
, [ "generated"
, { "type": "ACTION"
, "inputs":
{ "type": "map_union"
, "$1":
[ {"type": "var", "name": "srcs"}
, {"type": "var", "name": "data"}
, {"type": "var", "name": "lua filters"}
, {"type": "var", "name": "metadata"}
, {"type": "var", "name": "staged extra metadata"}
]
}
, "outs": [{"type": "var", "name": "out"}]
, "env": {"type": "var", "name": "env"}
, "cmd":
{ "type": "++"
, "$1":
[ [ "pandoc"
, "--data-dir=./data"
, "--resource-path=./data"
, "-o"
, {"type": "var", "name": "out"}
, "-s"
, "-N"
]
, { "type": "if"
, "cond": {"type": "var", "name": "template-name"}
, "then":
["--template", {"type": "var", "name": "template-name"}]
}
, ["--metadata-file", "metadata.yaml"]
, { "type": "++"
, "$1":
{ "type": "foreach"
, "range":
{ "type": "keys"
, "$1": {"type": "var", "name": "staged extra metadata"}
}
, "body": ["--metadata-file", {"type": "var", "name": "_"}]
}
}
, {"type": "var", "name": "template-args"}
, {"type": "var", "name": "filter args"}
, {"type": "var", "name": "meta data args"}
, {"type": "var", "name": "src names"}
]
}
, "execution properties":
{ "type": "var"
, "name": "TYPESETTING_EXECUTION_PROPERTIES"
, "default": {"type": "empty_map"}
}
}
]
]
, "body":
{"type": "RESULT", "artifacts": {"type": "var", "name": "generated"}}
}
}
}
|