From 531701f390020041b1fc6db556d1133a966669c0 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 23:09:16 +0100 Subject: [PATCH] mesh-build-go: the fetch's scope is the module's package paths named by its manifest, rows in the live form Builds: design 47 H2 H-A-765 (1), (2), H-A-762, H-A-633 --- .../mesh-build-go/cmd/mesh-build-go/fetch.go | 34 ++++++++++++-- .../cmd/mesh-build-go/pins_test.go | 46 +++++++++++++------ 2 files changed, 63 insertions(+), 17 deletions(-) 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 ccd89f18e..bb65603be 100644 --- a/modules/mesh-build-go/cmd/mesh-build-go/fetch.go +++ b/modules/mesh-build-go/cmd/mesh-build-go/fetch.go @@ -26,6 +26,7 @@ import ( sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" dforgekey "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/forgekey" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun" + "git.novox.be/novox/mesh-sdk/go/catalogue" ) var commitOK = regexp.MustCompile(`^[0-9a-f]{40}$`) @@ -737,6 +738,30 @@ func cleanDir(dir string) string { return strings.Trim(filepath.ToSlash(filepath.Clean(dir)), "/") } +// packagePaths are the named paths of the Go package artifacts of the manifest in the module directory dir of the tree, +// as the import step lists them (ModuleImports); none when the directory holds no manifest the catalogue reads. +func packagePaths(tree, dir string) []string { + raw, err := os.ReadFile(filepath.Join(tree, filepath.FromSlash(dir), "module.json")) + if err != nil { + return nil + } + manifest, err := catalogue.Decode(raw) + if err != nil || manifest.Build == nil { + return nil + } + var out []string + for _, a := range manifest.Build.Artifacts { + if a.Language == "go" && a.Kind == "package" { + for _, p := range a.Paths { + if p = strings.Trim(strings.TrimSpace(p), "./"); p != "" { + out = append(out, p) + } + } + } + } + return out +} + // 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, and each package // path of the ask holding a go.mod of its own (H-A-762). A directory @@ -771,11 +796,12 @@ 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. + // Each path of the module's Go package artifacts that holds a Go module file of its own (the builder's builds, a state + // package beside a program) is a module the fetch gives its own module file, as the build and the import step's listing + // of that path run with it (design 47 H2, H-A-762, H-A-765, H-A-633): the paths the module's manifest names, as the + // import step lists them, whether or not the ask names paths, and those the ask names. if have[dir] { - for _, p := range paths { + for _, p := range append(slices.Clone(paths), packagePaths(tree, dir)...) { if d := path.Join(dir, filepath.ToSlash(p)); have[d] { todo = append(todo, d) } 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 3c7e59480..9cbbfdeda 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 @@ -417,6 +417,7 @@ func TestARequirementOfTheCheckedRepositorysOwnModuleIsTakenFromItsTree(t *testi 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 + listed string // a path directory whose import listing must run with its own 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}}, @@ -432,15 +433,27 @@ 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", + // H-A-762, H-A-765 (with H-A-633), in the live form: the ask names no paths, the module's manifest names its package + // paths. mesh-delivery-builder's layout: a bundle and a package `builds` with a module file of its own that the + // module's file does not replace; the import step's listing of builds runs with its own modfile. + {name: "a package path with a module file of its own, named by the manifest alone", 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"]}]}}`}}, + args: map[string]any{"repository": "novox/mesh-delivery", "commit": commitSHA, "dir": "modules/mesh-delivery-builder"}, + dirs: 2, listed: "modules/mesh-delivery-builder/builds", files: map[string]string{ + "modules/mesh-delivery-builder/module.json": `{"module":"mesh-delivery-builder","build":{"artifacts":[{"name":"program","kind":"bundle","language":"go","from":"cmd/x","binary":"x"},{"name":"builds","kind":"package","language":"go","paths":["builds"]}]}}`}}, + // mesh-grants' layout: package paths whose module files the module's file does not replace; one replaces a module of + // the same repository by a directory outside its own (builds), whose own requirement lies behind a further local + // replace (deep): each module file replaces the own-repository module the graph requires, a replaced module's + // requirements included. + {name: "a module replacing a package path whose requirements are of the same repository", own: "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk", + ownDir: "modules/mesh-delivery-sdk", version: zero, + gomods: "modules/mesh-grants/go.mod\nmodules/mesh-grants/grantsstate/go.mod\nmodules/mesh-delivery-builder/builds/go.mod\nmodules/mesh-delivery-builder/builds/deep/go.mod\n", + args: map[string]any{"repository": "novox/mesh-delivery", "commit": commitSHA, "dir": "modules/mesh-grants"}, + dirs: 4, listed: "modules/mesh-grants/grantsstate", files: map[string]string{ + "modules/mesh-grants/module.json": `{"module":"mesh-grants","build":{"artifacts":[{"name":"grantsstate","kind":"package","language":"go","paths":["grantsstate"]}]}}`, + "modules/mesh-grants/grantsstate/go.mod": "module git.novox.be/novox/mesh-delivery/modules/mesh-grants/grantsstate\n\ngo 1.26\n\nrequire git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds " + zero + + "\n\nreplace git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds => ../../mesh-delivery-builder/builds\n", + "modules/mesh-delivery-builder/builds/go.mod": "module git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds\n\ngo 1.26\n\nrequire fixture/deep v0.0.0\n\nreplace fixture/deep => ./deep\n"}}, } { 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" @@ -493,12 +506,19 @@ func TestARequirementOfTheCheckedRepositorysOwnModuleIsTakenFromItsTree(t *testi t.Error("the narrowed tree holds a module the artifact does not require") } } - body, _ := os.ReadFile(modfiles[0]) - if !strings.Contains(string(body), "replace "+tc.own+" => "+where+"\n") { - t.Errorf("the module of the repository was not replaced into the modfile by %s:\n%s", where, body) + for _, modfile := range modfiles { + body, _ := os.ReadFile(modfile) + if !strings.Contains(string(body), "replace "+tc.own+" => "+where+"\n") { + t.Errorf("the module of the repository was not replaced into %s by %s:\n%s", modfile, where, body) + } + if tc.dirs <= 1 && strings.Count(string(body), "replace ") != 1 { + t.Errorf("the modfile replaces more than the one other module (its own directory again?):\n%s", body) + } } - if strings.Count(string(body), "replace ") != 1 { - t.Errorf("the modfile replaces more than the one other module (its own directory again?):\n%s", body) + if tc.listed != "" { + if env := strings.Join(h.m.buildEnv(filepath.Join(root, "tree", filepath.FromSlash(tc.listed))), " "); !strings.Contains(env, "-modfile=") { + t.Errorf("the listing of %s runs without its own modfile: %s", tc.listed, env) + } } if h.ran(" mod download -json ") || h.ran("ls-remote") { t.Error("a module of the checked repository was asked of Go or looked for among the pull request heads")