Skip to content

Commit e3a03a1

Browse files
committed
internal/core/adt: exclude definitions in data conversion
Definitions incorrectly trigger closedness for sub structures. They also don't belong in data. IMPORTANT: this implies that it is no longer possible to refer to definitions from within tool files. As a workaround we will allow it still for single-instance commands. Fixes #525 Change-Id: I481dd16e7cacb1096f68d446ce1c5349b5cd4531 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7143 Reviewed-by: CUE cueckoo <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent f5fa009 commit e3a03a1

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

cmd/cue/cmd/common.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,12 @@ func buildTools(cmd *Command, tags, args []string) (*cue.Instance, error) {
605605
return nil, err
606606
}
607607

608-
inst := cue.Merge(insts...).Build(ti)
608+
inst := insts[0]
609+
if len(insts) > 1 {
610+
inst = cue.Merge(insts...)
611+
}
612+
613+
inst = inst.Build(ti)
609614
return inst, inst.Err
610615
}
611616

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cue cmd gengithub
2+
3+
-- x.cue --
4+
package x
5+
6+
test: #Workflow & {
7+
}
8+
9+
#Workflow: {
10+
#: "working-directory": string
11+
}
12+
-- x_tool.cue --
13+
package x
14+
15+
import (
16+
"tool/file"
17+
"encoding/yaml"
18+
)
19+
20+
command: gengithub: {
21+
write: file.Create & {
22+
filename: "test.yml"
23+
contents: """
24+
# Generated by ci_tool.cue; do not edit
25+
26+
\(yaml.Marshal(test))
27+
"""
28+
}
29+
}

internal/core/adt/composite.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,11 @@ func (v *Vertex) ToDataSingle() *Vertex {
274274
// ToDataAll returns a new v where v and all its descendents contain only
275275
// the regular fields.
276276
func (v *Vertex) ToDataAll() *Vertex {
277-
arcs := make([]*Vertex, len(v.Arcs))
278-
for i, a := range v.Arcs {
279-
arcs[i] = a.ToDataAll()
277+
arcs := make([]*Vertex, 0, len(v.Arcs))
278+
for _, a := range v.Arcs {
279+
if a.Label.IsRegular() {
280+
arcs = append(arcs, a.ToDataAll())
281+
}
280282
}
281283
w := *v
282284

0 commit comments

Comments
 (0)