-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rbt.roc
82 lines (66 loc) · 2.68 KB
/
Rbt.roc
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
interface Rbt
exposes [Rbt, init, Job, job, Command, exec, Tool, tool, systemTool, projectFiles, fromJob, Input, sourceFile, withFilename]
imports []
# TODO: these are all out of order due to https://github.com/rtfeldman/roc/issues/1642. Once that's fixed, they should rearrange into the order in `exposes`
# TODO: how are we gonna get tools from Jobs? Maybe Tool, Command, and Job
# need to live in a single union and have private aliases outwards? I'd like
# to have this look like:
#
# Tool : [ Tool { name : Str, fromJob: Maybe Job } ]
#
# Or maybe:
#
# Tool : [ SystemTool { name : Str }, FromJob { name : Str, job : Job } ]
#
SystemToolPayload : { name : Str }
Tool := [SystemTool SystemToolPayload]
systemTool : Str -> Tool
systemTool = \name ->
@Tool (SystemTool { name })
Command := { tool : Tool, args : List Str }
exec : Tool, List Str -> Command
exec = \execTool, args ->
@Command { tool: execTool, args }
FileMapping := { source : Str, dest : Str }
sourceFile : Str -> FileMapping
sourceFile = \name -> @FileMapping { source: name, dest: name }
withFilename : FileMapping, Str -> FileMapping
withFilename = \@FileMapping { source }, dest -> @FileMapping { source, dest }
Input := [
FromProjectSource (List FileMapping),
FromJob Job (List FileMapping),
]
# Add the given file to the job's workspace (the working directory where the
# command is called.)
projectFiles : List FileMapping -> Input
projectFiles = \mappings -> @Input (FromProjectSource mappings)
# Add files from the given job to the current job's workspace.
fromJob : Job, List FileMapping -> Input
fromJob = \otherJob, mappings -> @Input (FromJob otherJob mappings)
Job := [
Job
{
command : Command,
# eventually we want this to be `List Input` but there's a bug.
# see https://github.com/roc-lang/roc/issues/4077
inputs : List [
FromProjectSource (List FileMapping),
FromJob Job (List FileMapping),
],
outputs : List Str,
env : Dict Str Str,
},
]
# TODO: these fields are all required until https://github.com/rtfeldman/roc/issues/1844 is fixed
# TODO: destructuring is broken, see https://github.com/rtfeldman/roc/issues/2512
job : { command : Command, inputs : List Input, outputs : List Str, env : Dict Str Str } -> Job
job = \{ command, inputs, outputs, env } ->
unwrappedInputs = List.map inputs (\@Input input -> input)
@Job (Job { command, inputs: unwrappedInputs, outputs, env })
Rbt := { default : Job }
init : { default : Job } -> Rbt
init = \rbt -> @Rbt rbt
tool : Job, Str -> Tool
tool = \_, _ ->
# FromJob { name, job }
@Tool (SystemTool { name: "TODO" })