diff --git a/modules/mesh-build-go/cmd/mesh-build-go/fetch.go b/modules/mesh-build-go/cmd/mesh-build-go/fetch.go index 539790977..ccd89f18e 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/fetch.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/fetch.go @@ -738,7 +738,8 @@ func cleanDir(dir string) string { } // scopedDirs are the go.mod directories of all that a module directory dir chooses: dir itself and each directory its -// go.mod replaces with a local path, followed through their own replaces (design 47 G, A-447), in order. A directory +// go.mod replaces with a local path, followed through their own replaces (design 47 G, A-447), in order, and each package +// path of the ask holding a go.mod of its own (H-A-762). A directory // the tree holds no go.mod for is left out. A directory holding no go.mod chooses every go.mod under it (A-447a), and one that // chooses no Go module at all is an empty scope (H-A-371). func scopedDirs(tree, dir string, paths, all []string) ([]string, error) { @@ -770,6 +771,16 @@ func scopedDirs(tree, dir string, paths, all []string) ([]string, error) { } } } + // A package path of the ask that holds a Go module file of its own (the builder's builds, beside its buildrun) is a + // module the fetch gives its own module file, as the build of that path is run with it (design 47 H2, H-A-762, + // H-A-633), whether or not the module's directory holds a go.mod. + if have[dir] { + for _, p := range paths { + if d := path.Join(dir, filepath.ToSlash(p)); have[d] { + todo = append(todo, d) + } + } + } for len(todo) > 0 { d := todo[0] todo = todo[1:] diff --git a/modules/mesh-build-go/cmd/mesh-build-go/pins_test.go b/modules/mesh-build-go/cmd/mesh-build-go/pins_test.go index 105f302ca..3c7e59480 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/pins_test.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/pins_test.go @@ -415,6 +415,8 @@ func TestARequirementOfTheCheckedRepositorysOwnModuleIsTakenFromItsTree(t *testi name, own, ownDir, gomods, version string args map[string]any narrowed bool + files map[string]string // laid over the checkout, after the rest + dirs int // the Go module directories the fetch takes (default 1), each with a modfile }{ {name: "whole tree", own: "git.novox.be/novox/mesh-delivery/nested/go", ownDir: "nested/go", gomods: "go.mod\n", version: zero, args: map[string]any{"repository": "novox/mesh-delivery", "commit": commitSHA}}, @@ -430,6 +432,15 @@ func TestARequirementOfTheCheckedRepositorysOwnModuleIsTakenFromItsTree(t *testi ownDir: "modules/mesh-delivery-sdk", gomods: "modules/mesh-delivery-contracts/go/clients/meshcatalogclient/go.mod\n", version: "v0.1.3", args: map[string]any{"repository": "novox/mesh-delivery", "commit": commitSHA, "dir": "modules/mesh-delivery-contracts", "paths": []any{"go/clients/meshcatalogclient"}}, narrowed: true}, + // H-A-762 (with H-A-633): a package path with a module file of its own, beside a module directory that has one + // too (mesh-delivery-builder's builds), is of the fetch's scope: its requirement of the repository's own module is + // taken from the tree, which only a modfile of that path's directory does. + {name: "a package path with a module file of its own in a module directory that has one", own: "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk", + ownDir: "modules/mesh-delivery-sdk", gomods: "modules/mesh-delivery-builder/go.mod\nmodules/mesh-delivery-builder/builds/go.mod\n", version: zero, + args: map[string]any{"repository": "novox/mesh-delivery", "commit": commitSHA, "dir": "modules/mesh-delivery-builder", + "paths": []any{"builds", "go.mod"}}, narrowed: true, + dirs: 2, files: map[string]string{ + "modules/mesh-delivery-builder/module.json": `{"module":"mesh-delivery-builder","build":{"artifacts":[{"name":"go-builds","kind":"package","language":"go","paths":["builds"]}]}}`}}, } { t.Run(tc.name, func(t *testing.T) { ownMod := "module fixture/member\n\ngo 1.26\n\nrequire (\n\t" + tc.own + " " + tc.version + "\n)\n" @@ -447,6 +458,9 @@ func TestARequirementOfTheCheckedRepositorysOwnModuleIsTakenFromItsTree(t *testi files["modules/mesh-delivery-contracts/module.json"] = `{"module":"mesh-delivery-contracts","build":{"artifacts":[{"name":"go-meshcatalogclient","kind":"package","language":"go","paths":["go/clients/meshcatalogclient"]}]}}` files["modules/mesh-delivery-view/go.mod"] = "module git.novox.be/novox/mesh-delivery/modules/mesh-delivery-view\n\ngo 1.26\n" } + for f, body := range tc.files { + files[f] = body + } for f, body := range files { os.MkdirAll(filepath.Join(tree, filepath.Dir(f)), 0o755) os.WriteFile(filepath.Join(tree, f), []byte(body), 0o644) @@ -469,8 +483,8 @@ func TestARequirementOfTheCheckedRepositorysOwnModuleIsTakenFromItsTree(t *testi t.Fatalf("the step ended %s: %s", st.State, st.Reason) } modfiles, _ := filepath.Glob(filepath.Join(h.m.Work, "*", "pins", "*", "go.mod")) - if len(modfiles) != 1 { - t.Fatalf("modfiles = %v", modfiles) + if want := max(tc.dirs, 1); len(modfiles) != want { + t.Fatalf("modfiles = %v, want %d", modfiles, want) } root := filepath.Dir(filepath.Dir(filepath.Dir(modfiles[0]))) where := filepath.Join(root, "tree", filepath.FromSlash(tc.ownDir)) @@ -491,7 +505,7 @@ func TestARequirementOfTheCheckedRepositorysOwnModuleIsTakenFromItsTree(t *testi } var res FetchResult json.Unmarshal(st.Result, &res) - if len(res.Packages) != 1 || res.Packages[0].Package != tc.own || res.Packages[0].Built != "the fetched tree" || res.Packages[0].Named != tc.version { + if len(res.Packages) != max(tc.dirs, 1) || res.Packages[0].Package != tc.own || res.Packages[0].Built != "the fetched tree" || res.Packages[0].Named != tc.version { t.Errorf("the taken versions = %+v, want %s named %s, built from the fetched tree", res.Packages, tc.own, tc.version) } })