diff --git a/modules/mesh-delivery-builder/internal/build/entry_test.go b/modules/mesh-delivery-builder/internal/build/entry_test.go index 5ccbf04f..f2e4f2f1 100644 --- a/modules/mesh-delivery-builder/internal/build/entry_test.go +++ b/modules/mesh-delivery-builder/internal/build/entry_test.go @@ -13,6 +13,7 @@ import ( func TestAnEntryOfTheCatalogHalfIsTheFormTheBuilderBuildsBy(t *testing.T) { e := meshcatalog.CatalogEntry{Module: "netcheck", Repository: "novox/mesh-catalog", Path: "modules/netcheck", Commit: "abc", Fp: "src2:f", ManifestDigest: "sha256:m", Bases: []string{"base"}, Packages: map[string]string{"p": "1"}, Needs: []string{"n"}, + Artifacts: []meshcatalog.Artifact{{Ref: "netcheck:lib", Kind: "package", Language: "go"}}, Inputs: &meshcatalog.EntryInputs{Toolchains: map[string]meshcatalog.ToolchainUsed{"go": {Version: "go1", Recipe: "1"}}, Paths: map[string][]string{"lib": {"a/b", "c"}}}} got := ModuleOf(e) @@ -30,4 +31,11 @@ func TestAnEntryOfTheCatalogHalfIsTheFormTheBuilderBuildsBy(t *testing.T) { if bare := ModuleOf(meshcatalog.CatalogEntry{Module: "m"}); bare.Inputs2 != nil || bare.Fp2 != "" { t.Errorf("ModuleOf of an entry with none = %+v, want nothing set", bare) } + // A module with an artifact that names no paths (a Go program beside its packages) is built from its directory whole + // (ADR 0499 clauses 1 and 4): its fetch names no paths, so the program's go.mod and main package stay in the tree. + mixed := e + mixed.Artifacts = append([]meshcatalog.Artifact{{Ref: "netcheck:program", Kind: "bundle", Language: "go"}}, e.Artifacts...) + if got := ModuleOf(mixed); got.Inputs2 == nil || len(got.Inputs2.Paths) != 0 { + t.Errorf("ModuleOf of a module with a program naming no paths = %+v, want bases and no named paths", got.Inputs2) + } } diff --git a/modules/mesh-delivery-builder/internal/build/run.go b/modules/mesh-delivery-builder/internal/build/run.go index 9eaed460..2843af9e 100644 --- a/modules/mesh-delivery-builder/internal/build/run.go +++ b/modules/mesh-delivery-builder/internal/build/run.go @@ -285,7 +285,7 @@ func (b *Builder) take(ctx context.Context, o Origin, key string, m meshcatalog. // ModuleOf is a catalog entry in the form the builder builds by: its fingerprint, manifest digest, source (repository, // directory, commit; no source stamp, design 47 H H-A-48), the toolchains its fingerprint was computed with, the bases it is -// built against, its packages and needs, and the named paths of its artifacts. +// built against, its packages and needs, and the named paths of its artifacts when every artifact names them. func ModuleOf(e meshcatalog.CatalogEntry) meshcatalog.ModulesByModuleValue { m := meshcatalog.ModulesByModuleValue{Repository: e.Repository, Path: e.Path, Commit: e.Commit, Fp2: e.Fp, None2: e.None, Manifest: meshcatalog.BareManifestDigest(e.ManifestDigest), Packages: e.Packages, Needs: e.Needs} @@ -294,7 +294,10 @@ func ModuleOf(e meshcatalog.CatalogEntry) meshcatalog.ModulesByModuleValue { } if in := e.Inputs; in != nil { m.Toolchains, m.Problems = in.Toolchains, in.Problems - if len(in.Paths) > 0 { + // Only a module whose every artifact names its paths is built from those alone (ADR 0499 clauses 1, 2 and 4): an + // artifact without paths, such as a Go program, keeps its module's directory as its build source, so a module + // with one names no paths and its fetch keeps the directory whole. + if len(in.Paths) > 0 && everyArtifactNamesPaths(e) { if m.Inputs2 == nil { m.Inputs2 = &meshcatalog.ModulesByModuleValueInputs2{} } @@ -309,6 +312,20 @@ func ModuleOf(e meshcatalog.CatalogEntry) meshcatalog.ModulesByModuleValue { return m } +// everyArtifactNamesPaths is whether the entry names artifacts and the named paths of each, by its reference or its name. +func everyArtifactNamesPaths(e meshcatalog.CatalogEntry) bool { + if len(e.Artifacts) == 0 || e.Inputs == nil { + return false + } + for _, a := range e.Artifacts { + _, name, _ := strings.Cut(a.Ref, ":") + if len(e.Inputs.Paths[a.Ref]) == 0 && len(e.Inputs.Paths[name]) == 0 { + return false + } + } + return true +} + // originOf is the catalog revision the entry of a build key came from; a key no entry named is of the first branch, as a build // of the trunk's value was before branches were watched. func (b *Builder) originOf(key string) Origin {