From 598a78074f645d58c824bd41d77e4f2e51bf1517 Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Mon, 22 Mar 2021 16:59:49 +0000 Subject: [PATCH] cmd/unity: do not recurse into cue.mod when searching for modules Finding a cue.mod directory indicates we have found a module. Currently, we continue to recurse into a cue.mod directory to find other modules. However, this is not correct from the perspective of unity: any modules we find within cue.mod/{gen,pkg,usr} will only ever be modules vendored as dependencies of the module we have just found, which from unity's perspective is not what we are after. Therefore skip cue.mod directories themselves. Fixes #59 --- cmd/unity/cmd/project.go | 4 +++- cmd/unity/cmd/testdata/scripts/test_project_simple.txt | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/unity/cmd/project.go b/cmd/unity/cmd/project.go index e311789..b8e0722 100644 --- a/cmd/unity/cmd/project.go +++ b/cmd/unity/cmd/project.go @@ -436,7 +436,9 @@ func (mt *moduleTester) deriveModules(dir string) (modules []*module, err error) return fmt.Errorf("failed to create module instance at %s: %v", modDir, err) } modules = append(modules, m) - return nil + // Do not recurse within the cue.mod - otherwise we might find modules + // in the vendor + return filepath.SkipDir }) return } diff --git a/cmd/unity/cmd/testdata/scripts/test_project_simple.txt b/cmd/unity/cmd/testdata/scripts/test_project_simple.txt index 6e7dd51..1930f73 100644 --- a/cmd/unity/cmd/testdata/scripts/test_project_simple.txt +++ b/cmd/unity/cmd/testdata/scripts/test_project_simple.txt @@ -17,6 +17,12 @@ stdout 'PASS' -- .unquote -- cue.mod/tests/basic1.txt cue.mod/tests/basic2.txt +-- cue.mod/pkg/acme.com/other/other.cue -- +package other + +y: 5 +-- cue.mod/pkg/acme.com/other/cue.mod/module.cue -- +module: "acme.com/other" -- cue.mod/module.cue -- module: "mod.com" @@ -40,4 +46,6 @@ Versions: ["PATH"] -- x.cue -- package x -x: 5 +import "acme.com/other" + +x: other.y