Indexer: a same-repository module named only by a replace is a requirement
The watchman's go.mod names buildrun in a replace directive with no require line, and the walk of the module graph followed require lines only, so buildrun's requirement of the module assigner's client was never pinned and every test step of the watchman failed "no pin". The walk now takes the same-repository modules a go.mod replaces by a directory as required, with the same same-repository test, so their go.mod files are read and their other-repository requirements pinned, transitively. Builds: design 47 H-A-224, H-A-201
This commit is contained in:
@@ -60,8 +60,9 @@ func (t *goModTree) sameRepositoryDir(required string) (string, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sameRepositoryRequired are the directories (from the root, sorted, each once) of every same-repository Go module the
|
// sameRepositoryRequired are the directories (from the root, sorted, each once) of every same-repository Go module the
|
||||||
// go.mod of each start directory requires, transitively through those modules' own go.mod files (H-A-202, H-A-157). The
|
// go.mod of each start directory requires, transitively through those modules' own go.mod files (H-A-202, H-A-157). A
|
||||||
// start directories themselves are not among them.
|
// same-repository module a go.mod names in a replace directive counts as required, whether or not a require line names it
|
||||||
|
// (H-A-224). The start directories themselves are not among them.
|
||||||
func (t *goModTree) sameRepositoryRequired(start []string) []string {
|
func (t *goModTree) sameRepositoryRequired(start []string) []string {
|
||||||
seen := map[string]bool{}
|
seen := map[string]bool{}
|
||||||
for _, s := range start {
|
for _, s := range start {
|
||||||
@@ -72,7 +73,8 @@ func (t *goModTree) sameRepositoryRequired(start []string) []string {
|
|||||||
for len(queue) > 0 {
|
for len(queue) > 0 {
|
||||||
dir := queue[0]
|
dir := queue[0]
|
||||||
queue = queue[1:]
|
queue = queue[1:]
|
||||||
for _, req := range fingerprint.MeshRequiresOf(t.goMod(dir)) {
|
raw := t.goMod(dir)
|
||||||
|
for _, req := range append(fingerprint.MeshRequiresOf(raw), fingerprint.ReplacedSiblings(raw, t.f.Repository)...) {
|
||||||
d, ok := t.sameRepositoryDir(req)
|
d, ok := t.sameRepositoryDir(req)
|
||||||
if !ok || seen[d] {
|
if !ok || seen[d] {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package index
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -141,4 +142,23 @@ func TestTheEntryPinsEveryRequirementOfTheModuleGraph(t *testing.T) {
|
|||||||
if _, pinned := pins[builds]; pinned || len(pins) != 1 {
|
if _, pinned := pins[builds]; pinned || len(pins) != 1 {
|
||||||
t.Errorf("pins = %v, want %s only, never a module of the repository", pins, conditions)
|
t.Errorf("pins = %v, want %s only, never a module of the repository", pins, conditions)
|
||||||
}
|
}
|
||||||
|
// H-A-224: a same-repository module the go.mod names only in a replace directive (the watchman's buildrun) counts as
|
||||||
|
// required: its own requirement of another repository's client is pinned too.
|
||||||
|
const assigner = "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"
|
||||||
|
objects["modules/d/buildrun"] = strings.Repeat("d", 40)
|
||||||
|
ix, mods, _ = ptpIndexer(t, objects)
|
||||||
|
mod["modules/g"] += "\nreplace git.novox.be/novox/mesh-delivery/modules/d/buildrun => ../d/buildrun\n"
|
||||||
|
mod["modules/d/buildrun"] = "module git.novox.be/novox/mesh-delivery/modules/d/buildrun\n\nrequire " + assigner + ptpZero + "\n"
|
||||||
|
ix.GoMod = func(_ context.Context, _, _, dir string) ([]byte, error) {
|
||||||
|
if c, ok := mod[dir]; ok {
|
||||||
|
return []byte(c), nil
|
||||||
|
}
|
||||||
|
return []byte(ptpGoMods[dir]), nil
|
||||||
|
}
|
||||||
|
if err := ix.Apply(context.Background(), f); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if m, _ := moduleOf(t, mods, "g"); m.Inputs2 == nil || !slices.Contains(m.Inputs2.Packages, assigner) || !slices.Contains(m.Inputs2.Packages, conditions) {
|
||||||
|
t.Errorf("packages = %+v, want the replaced sibling's requirement %s pinned beside the client's", m.Inputs2, assigner)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user