Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
internal/core/adt: exclude definitions in data conversion
Browse files Browse the repository at this point in the history
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 <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
  • Loading branch information
mpvl committed Sep 17, 2020
1 parent f5fa009 commit e3a03a1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cmd/cue/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,12 @@ func buildTools(cmd *Command, tags, args []string) (*cue.Instance, error) {
return nil, err
}

inst := cue.Merge(insts...).Build(ti)
inst := insts[0]
if len(insts) > 1 {
inst = cue.Merge(insts...)
}

inst = inst.Build(ti)
return inst, inst.Err
}

Expand Down
29 changes: 29 additions & 0 deletions cmd/cue/cmd/testdata/script/issue525.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cue cmd gengithub

-- x.cue --
package x

test: #Workflow & {
}

#Workflow: {
#: "working-directory": string
}
-- x_tool.cue --
package x

import (
"tool/file"
"encoding/yaml"
)

command: gengithub: {
write: file.Create & {
filename: "test.yml"
contents: """
# Generated by ci_tool.cue; do not edit

\(yaml.Marshal(test))
"""
}
}
8 changes: 5 additions & 3 deletions internal/core/adt/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,11 @@ func (v *Vertex) ToDataSingle() *Vertex {
// ToDataAll returns a new v where v and all its descendents contain only
// the regular fields.
func (v *Vertex) ToDataAll() *Vertex {
arcs := make([]*Vertex, len(v.Arcs))
for i, a := range v.Arcs {
arcs[i] = a.ToDataAll()
arcs := make([]*Vertex, 0, len(v.Arcs))
for _, a := range v.Arcs {
if a.Label.IsRegular() {
arcs = append(arcs, a.ToDataAll())
}
}
w := *v

Expand Down

0 comments on commit e3a03a1

Please sign in to comment.