The import form's fingerprint left the pins out, so an importer whose trunk build reported its imports never moved on a re-pin and was never built again against the release. Every form now takes its sorted pins; a build that stands keeps its fingerprint while its pins are the ones it was built with, and a fingerprint with no pin stays as it was. Builds: design 47 H H-A-172, H-A-167
138 lines
7.7 KiB
Go
138 lines
7.7 KiB
Go
package index
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
|
|
|
|
"mesh-delivery-indexer/internal/fingerprint"
|
|
)
|
|
|
|
// form is a module's fingerprint, or why it has none, and the version of each mesh Go module of another repository
|
|
// its build is pinned to.
|
|
type form struct {
|
|
fp, none string
|
|
versions sdkstep.PackageVersions
|
|
// stands: fp is the held fingerprint of the build that reported the imports, made with the pins built (its held
|
|
// packages) from the import form raw; pinnedOf keeps it while the pins are those (H-A-172).
|
|
stands bool
|
|
raw string
|
|
built map[string]string
|
|
}
|
|
|
|
// formOf is the module's fingerprint from its kept inputs (bases already its bases' fingerprints) and toolchains, in the
|
|
// form they call for (novox/hq ADR 0593 §2, §4):
|
|
//
|
|
// - **The import form**, for a module whose last trunk build reported its imports (kept.Imports) when every import is
|
|
// published (the packages state): the content digest of each imported package and the requirements' digest of each
|
|
// mesh Go module holding one. Its versions are each holding module's published commit (another repository's only); an
|
|
// import set naming none of another repository while the go.mod requires one keeps the version line's (refined).
|
|
// - **A change of form never rebuilds by itself** (§4): kept.ImportForm is the import-form fingerprint of the inputs
|
|
// the build that reported the imports was built from. While the import form computes to it, nothing the build was
|
|
// built from changed: the module keeps the fingerprint it holds (prev), in whatever form, and its versions.
|
|
// Otherwise the import form is written, and ImportForm moves with it.
|
|
// - **The version line** otherwise (no import set, or an import none publishes): the version of each mesh Go module of
|
|
// another repository its go.mod requires, at any version (design 47 H-A-157), read as the indexer always read it
|
|
// (fingerprint.HeldVersionsOf), and the content of each mesh Go module of its own repository its go.mod replaces by a
|
|
// directory (fingerprint.VersionLine), so a change of that directory alone moves it (review finding 2). Its versions are the other repositories' alone.
|
|
// A package of another repository none of them publishes takes the commit the gate's source names for its repository
|
|
// (heads, design 47 G A-365).
|
|
// - **An accepted series** (DLV-I6): published and pins come from acceptedSeries, so a mesh Go module of another
|
|
// repository whose series the module accepts enters, in either form, by its series' newest published version and the
|
|
// digests of that version's commit.
|
|
//
|
|
// It sets kept.ImportForm when it writes the import form.
|
|
func formOf(module, repository string, kept *meshcatalog.ModulesByModuleValueInputs2, toolchains map[string]meshcatalogclient.Toolchain2, prev meshcatalog.ModulesByModuleValue, held map[string]meshcatalog.ModulesByModuleValue, published map[string]meshcatalog.PackagesByModuleValue, pins sdkstep.PackageVersions, heads map[string]string, logf func(string, ...any)) form {
|
|
in := inputsFrom(module, *kept, toolchains)
|
|
if len(kept.Imports) > 0 {
|
|
r := fingerprint.Resolve(repository, kept.Imports, published)
|
|
if len(r.Missing) == 0 {
|
|
in.Imports, in.Requires = r.Digests, r.Requires
|
|
fp, none := fingerprint.Of(in)
|
|
switch {
|
|
case fp == "":
|
|
return form{none: none}
|
|
case kept.ImportForm == fp && prev.Fp2 != "":
|
|
// The build that reported the imports stands, and so do its versions.
|
|
return form{fp: prev.Fp2, versions: refined(sdkstep.PackageVersions(prev.Packages), r.Versions, module, repository, kept, held, pins, heads),
|
|
stands: true, raw: fp, built: prev.Packages}
|
|
}
|
|
kept.ImportForm = fp
|
|
return form{fp: fp, versions: refined(r.Versions, nil, module, repository, kept, held, pins, heads)}
|
|
}
|
|
if logf != nil {
|
|
logf("%s: no published package holds %s, so its fingerprint takes the version line", module, strings.Join(r.Missing, ", "))
|
|
}
|
|
}
|
|
// The fingerprint written here is the version line's, not the import form's: no import form is held for the inputs it was
|
|
// computed from, so a later pass whose import form computes the same does not take this one for the build's (issue 1966).
|
|
kept.ImportForm = ""
|
|
versions := lineVersions(module, repository, kept, held, pins, heads, logf)
|
|
in.Packages = fingerprint.VersionLine(repository, kept.Packages, versions, published)
|
|
fp, none := fingerprint.Of(in)
|
|
if fp == "" {
|
|
return form{none: none}
|
|
}
|
|
return form{fp: fp, versions: versions}
|
|
}
|
|
|
|
// refined are an import form's versions: the first of sets that names a package, else, while the module's go.mod
|
|
// requires a mesh package of another repository (kept.Packages), the version line's, so a build's reported imports
|
|
// refine the go.mod's set and never empty it (design 47 H-A-157); nil when nothing names one.
|
|
func refined(versions, then sdkstep.PackageVersions, module, repository string, kept *meshcatalog.ModulesByModuleValueInputs2, held map[string]meshcatalog.ModulesByModuleValue, pins sdkstep.PackageVersions, heads map[string]string) sdkstep.PackageVersions {
|
|
switch {
|
|
case len(versions) > 0:
|
|
return versions
|
|
case len(then) > 0:
|
|
return then
|
|
case len(fingerprint.OtherPackages(kept.Packages, repository)) > 0:
|
|
return lineVersions(module, repository, kept, held, pins, heads, nil)
|
|
}
|
|
return versions
|
|
}
|
|
|
|
// lineVersions are the version line's versions of the mesh Go modules of other repositories the module's go.mod requires
|
|
// (kept.Packages): each as the indexer has always read it, an accepted series' pin over it, else the commit the gate's
|
|
// source names for its repository.
|
|
func lineVersions(module, repository string, kept *meshcatalog.ModulesByModuleValueInputs2, held map[string]meshcatalog.ModulesByModuleValue, pins sdkstep.PackageVersions, heads map[string]string, logf func(string, ...any)) sdkstep.PackageVersions {
|
|
others := fingerprint.OtherPackages(kept.Packages, repository)
|
|
versions, unpublished := fingerprint.HeldVersionsOf(others, held)
|
|
for p, v := range pins { // an accepted series' newest published version (acceptedSeries, DLV-I6)
|
|
if slices.Contains(others, p) {
|
|
if versions == nil {
|
|
versions = sdkstep.PackageVersions{}
|
|
}
|
|
versions[p] = v
|
|
unpublished = slices.DeleteFunc(unpublished, func(u string) bool { return u == p })
|
|
}
|
|
}
|
|
// A mesh Go package no module the indexer holds publishes is built at the commit the gate's source names for its
|
|
// repository, as an import of the same repository is; once a version is published, the version applies (design 47 G A-365).
|
|
for _, p := range slices.Clone(unpublished) {
|
|
if repo, _, ok := trunk.PackageRepository(p); ok {
|
|
if head := heads[repo]; len(head) == 40 {
|
|
if versions == nil {
|
|
versions = sdkstep.PackageVersions{}
|
|
}
|
|
versions[p] = head
|
|
unpublished = slices.DeleteFunc(unpublished, func(u string) bool { return u == p })
|
|
}
|
|
}
|
|
}
|
|
if len(unpublished) > 0 && logf != nil {
|
|
logf("%s: no module the indexer holds publishes %s, so its fingerprint takes no version of it", module, strings.Join(unpublished, ", "))
|
|
}
|
|
return versions
|
|
}
|
|
|
|
// inputsFrom is the fingerprint's inputs of module m from its kept inputs and the given toolchains, no package of
|
|
// either form yet.
|
|
func inputsFrom(module string, k meshcatalog.ModulesByModuleValueInputs2, toolchains map[string]meshcatalogclient.Toolchain2) fingerprint.Inputs {
|
|
return fingerprint.Inputs{Module: module, Tree: k.Tree, Bases: k.Bases, Builder: k.Builder, Contexts: k.Contexts,
|
|
Locks: k.Locks, Toolchains: toolchains}
|
|
}
|