diff --git a/go/sdkversion/sdkversion.go b/go/sdkversion/sdkversion.go index 46a705a..3cbb82e 100644 --- a/go/sdkversion/sdkversion.go +++ b/go/sdkversion/sdkversion.go @@ -24,7 +24,11 @@ func Version() string { // FromBuildInfo reads the SDK's version out of a build info. A dependency replaced by another module version is that // version; replaced by a local path it is the path, never empty. When the SDK is the main module it is "(devel)", -// followed by a space and the vcs.revision when the build stamped one. Without the SDK in the build it is "unknown". +// followed by a space and the vcs.revision when the build stamped one. An SDK command built from another module that +// requires the SDK (`go build git.novox.be/novox/mesh-sdk/go/cmd/mesh-compose` in a reader's tree, as mesh-build-go's +// compose job builds it: novox/hq ADR 0482 clause 5) has the SDK as its main module at the version that module pins, +// read from the module cache with no vcs stamp: it is that version, never a bare "(devel)" that names no SDK. Without +// the SDK in the build it is "unknown". func FromBuildInfo(bi *debug.BuildInfo) string { if bi == nil { return "unknown" @@ -35,6 +39,9 @@ func FromBuildInfo(bi *debug.BuildInfo) string { return "(devel) " + s.Value } } + if v := bi.Main.Version; v != "" && v != "(devel)" { + return v + } return "(devel)" } for _, d := range bi.Deps { diff --git a/go/sdkversion/sdkversion_test.go b/go/sdkversion/sdkversion_test.go index 7a4b04d..3cc60a2 100644 --- a/go/sdkversion/sdkversion_test.go +++ b/go/sdkversion/sdkversion_test.go @@ -42,6 +42,18 @@ func TestTheMainModuleIsDevelWithItsRevision(t *testing.T) { } } +// The shape go gives `go build ` run in a module that requires the SDK (captured with go1.27 from +// mesh-compose built in a reader's tree at bc0c25e51052: "mod git.novox.be/novox/mesh-sdk/go v0.1.14-…-bc0c25e51052", +// no vcs settings): the SDK is the main module at the pinned version, which names the SDK the binary carries. +func TestAnSDKCommandBuiltFromAReaderIsThePinnedVersion(t *testing.T) { + bi := &debug.BuildInfo{Path: sdkPath + "/cmd/mesh-compose", + Main: debug.Module{Path: sdkPath, Version: "v0.1.14-0.20261024112544-bc0c25e51052"}, + Settings: []debug.BuildSetting{{Key: "-trimpath", Value: "true"}, {Key: "CGO_ENABLED", Value: "0"}}} + if got := FromBuildInfo(bi); got != "v0.1.14-0.20261024112544-bc0c25e51052" { + t.Fatalf("got %q", got) + } +} + func TestNoBuildInfoIsUnknown(t *testing.T) { if got := FromBuildInfo(nil); got != "unknown" { t.Fatalf("got %q", got)