Skip to content

Commit

Permalink
cmd/cue: fix a regression with cue get go dropping CUE files
Browse files Browse the repository at this point in the history
In https://cuelang.org/cl/1196294 I refactored the code to swap
filepath.WalkDir for os.ReadDir, given that we didn't need to read
directory trees recursively. However, I failed to realise that
a `return nil` would be problematic when replacing a callback function
with a regular for loop, as it now stopped the entire parent func.

We didn't notice as the test used to happen to hide the bug;
the improved test now shows that the bug is fixed.

Fixes #3644.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ia0ebafcf481402faf106af26fea507da98dae47c
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1207330
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
mvdan committed Jan 16, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent c94fd55 commit b193af0
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/cue/cmd/get_go.go
Original file line number Diff line number Diff line change
@@ -595,7 +595,7 @@ func (e *extractor) importCUEFiles(p *packages.Package, dstDir, args string) err
path := filepath.Join(srcDir, name)
name, ok := strings.CutSuffix(name, ".cue")
if !ok {
return nil
continue
}
f, err := parser.ParseFile(path, nil, parser.PackageClauseOnly)
if err != nil {
7 changes: 2 additions & 5 deletions cmd/cue/cmd/testdata/script/get_go_non_local.txtar
Original file line number Diff line number Diff line change
@@ -11,11 +11,8 @@ go mod tidy
exec cue get go externalmod.test/mixfiles
cmp cue.mod/gen/externalmod.test/mixfiles/code_one_go_gen.cue cue.mod/gen/externalmod.test/mixfiles/code_one_go_gen.cue.golden
cmp cue.mod/gen/externalmod.test/mixfiles/code_two_go_gen.cue cue.mod/gen/externalmod.test/mixfiles/code_two_go_gen.cue.golden
# TODO(mvdan): fix https://cuelang.org/issue/3644
! exists cue.mod/gen/externalmod.test/mixfiles/config_one_gen.cue
! exists cue.mod/gen/externalmod.test/mixfiles/config_two_gen.cue
# cmp cue.mod/gen/externalmod.test/mixfiles/config_one_gen.cue cue.mod/gen/externalmod.test/mixfiles/config_one_gen.cue.golden
# cmp cue.mod/gen/externalmod.test/mixfiles/config_two_gen.cue cue.mod/gen/externalmod.test/mixfiles/config_two_gen.cue.golden
cmp cue.mod/gen/externalmod.test/mixfiles/config_one_gen.cue cue.mod/gen/externalmod.test/mixfiles/config_one_gen.cue.golden
cmp cue.mod/gen/externalmod.test/mixfiles/config_two_gen.cue cue.mod/gen/externalmod.test/mixfiles/config_two_gen.cue.golden

# Verify dependencies are as expected
cmp go.mod go.mod.golden

0 comments on commit b193af0

Please sign in to comment.