Skip to content

Commit 4136481

Browse files
jlongtinempvl
authored andcommitted
cue/tools/flow: allow tasks in hidden fields
This updates the flow Config object to allow Tasks in hidden fields. Change-Id: I8809d83e7543e33cdec4950014efdac39a88be71 Signed-off-by: Joel Longtine <joel@longtine.io> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/532797 Unity-Result: CUEcueckoo <cueckoo@cuelang.org> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
1 parent b1edc14 commit 4136481

File tree

4 files changed

+102
-5
lines changed

4 files changed

+102
-5
lines changed

tools/flow/flow.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ type Config struct {
135135
// concrete and cannot change.
136136
IgnoreConcrete bool
137137

138+
// FindHiddenTasks allows tasks to be defined in hidden fields.
139+
FindHiddenTasks bool
140+
138141
// UpdateFunc is called whenever the information in the controller is
139142
// updated. This includes directly after initialization. The task may be
140143
// nil if this call is not the result of a task completing.

tools/flow/flow_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ func TestFlow(t *testing.T) {
7272
}
7373

7474
cfg := &flow.Config{
75-
Root: cue.ParsePath("root"),
76-
InferTasks: t.Bool("InferTasks"),
77-
IgnoreConcrete: t.Bool("IgnoreConcrete"),
78-
UpdateFunc: updateFunc,
75+
Root: cue.ParsePath("root"),
76+
InferTasks: t.Bool("InferTasks"),
77+
IgnoreConcrete: t.Bool("IgnoreConcrete"),
78+
FindHiddenTasks: t.Bool("FindHiddenTasks"),
79+
UpdateFunc: updateFunc,
7980
}
8081

8182
c := flow.New(cfg, v, taskFunc)

tools/flow/tasks.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ func (c *Controller) findRootTasks(v cue.Value) {
6868
return
6969
}
7070

71-
for iter, _ := v.Fields(); iter.Next(); {
71+
opts := []cue.Option{}
72+
73+
if c.cfg.FindHiddenTasks {
74+
opts = append(opts, cue.Hidden(true), cue.Definitions(false))
75+
}
76+
77+
for iter, _ := v.Fields(opts...); iter.Next(); {
7278
c.findRootTasks(iter.Value())
7379
}
7480
}

tools/flow/testdata/hidden.txtar

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#FindHiddenTasks: true
2+
-- in.cue --
3+
root: {
4+
a: {
5+
$id: "valToOut"
6+
val: "foo"
7+
out: string
8+
}
9+
_b: {
10+
$id: "valToOut"
11+
$after: a
12+
val: "bar"
13+
out: string
14+
}
15+
c: {
16+
$id: "valToOut"
17+
out: a.out + _b.out
18+
}
19+
// These tasks should _not_ run, because they are definitions.
20+
_#c: {
21+
$id: "valToOut"
22+
out: c.out + "baz"
23+
}
24+
#d: {
25+
$id: "valToOut"
26+
out: c.out + "baz"
27+
}
28+
}
29+
-- out/run/errors --
30+
-- out/run/t0 --
31+
graph TD
32+
t0("root.a [Ready]")
33+
t1("root._b [Waiting]")
34+
t1-->t0
35+
t2("root.c [Waiting]")
36+
t2-->t0
37+
t2-->t1
38+
39+
-- out/run/t1 --
40+
graph TD
41+
t0("root.a [Terminated]")
42+
t1("root._b [Ready]")
43+
t1-->t0
44+
t2("root.c [Waiting]")
45+
t2-->t0
46+
t2-->t1
47+
48+
-- out/run/t1/value --
49+
{
50+
$id: "valToOut"
51+
val: "foo"
52+
out: "foo"
53+
}
54+
-- out/run/t2 --
55+
graph TD
56+
t0("root.a [Terminated]")
57+
t1("root._b [Terminated]")
58+
t1-->t0
59+
t2("root.c [Ready]")
60+
t2-->t0
61+
t2-->t1
62+
63+
-- out/run/t2/value --
64+
{
65+
$id: "valToOut"
66+
$after: {
67+
$id: "valToOut"
68+
val: "foo"
69+
out: "foo"
70+
}
71+
val: "bar"
72+
out: "bar"
73+
}
74+
-- out/run/t3 --
75+
graph TD
76+
t0("root.a [Terminated]")
77+
t1("root._b [Terminated]")
78+
t1-->t0
79+
t2("root.c [Terminated]")
80+
t2-->t0
81+
t2-->t1
82+
83+
-- out/run/t3/value --
84+
{
85+
$id: "valToOut"
86+
out: "foobar"
87+
}

0 commit comments

Comments
 (0)