Skip to content

Commit

Permalink
cmd/cue: correctly extract transitive dependencies in 'get go'
Browse files Browse the repository at this point in the history
The refactor in https://cuelang.org/cl/1173100 fixed multiple bugs
but unfortunately introduced a tricky hidden bug.
Rather than extracting all used packages to cover all dependencies,
we were repeatedly extracting the first package instead.

'cue get go' now extracts all dependencies as expected both with
and without the --local flag.

Fixes #3033.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Idc707758f758736a550a851f9bcc55b59f4b704b
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1193699
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
  • Loading branch information
mvdan committed Apr 23, 2024
1 parent 81f5a20 commit b90a5eb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/cue/cmd/get_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ func (e *extractor) extractPkg(root string, p *packages.Package) error {
for path := range e.usedPkgs {
if !e.done[path] {
e.done[path] = true
if err := e.extractPkg(root, e.allPkgs[p.PkgPath]); err != nil {
if err := e.extractPkg(root, e.allPkgs[path]); err != nil {
return err
}
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/cue/cmd/testdata/script/get_go_non_local.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ cmp go.mod go.mod.golden

# Verify that all transitive dependencies are generated properly as well.
# If any are missing, the evaluation would fail to load them.
# TODO: broken due to https://cuelang.org/issue/3033.
go get externalmod.test/imports/root@v1.0.0
exec cue get go externalmod.test/imports/root
! exec cue eval uses_imports_root.cue
stderr 'cannot find package "externalmod.test/imports/sub1"'
exec cue eval uses_imports_root.cue

-- cue.mod/module.cue --
module: "mod.test/local"
Expand Down
4 changes: 1 addition & 3 deletions cmd/cue/cmd/testdata/script/get_go_vendor.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ cmp x/x_go_gen.cue x_go_gen.cue.golden

# Verify that all transitive dependencies were generated properly.
# If any are missing, the evaluation would fail to load them.
# TODO: broken due to https://cuelang.org/issue/3033.
! exec cue eval ./x
stderr 'no CUE files in mod.test/z'
exec cue eval ./x

-- go.mod --
module mod.test
Expand Down

0 comments on commit b90a5eb

Please sign in to comment.