mesh/delivery superseded: a newer head of the same pull request
mesh/check failed: the composition: the manifest of pacman cannot be read: this manifest cannot be used: | 19c1d35939bc on 8c6e18e82286 | unit 4799 ru…
65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
// Package sdkversion says which mesh-sdk version a program was built with (novox/hq ADR 0446 clause 4: a composition
|
|
// check names its mesh-sdk version, so the controller and the assigner can be compared; ADR 0453 clause 1).
|
|
//
|
|
// The version is read from the build info, never kept by hand: a constant nobody bumps would report two different
|
|
// SDKs as one. A program that imports the SDK reports the module's pinned (pseudo-)version, or its replacement's;
|
|
// the SDK's own binaries and tests report "(devel)" with the stamped vcs.revision.
|
|
package sdkversion
|
|
|
|
import (
|
|
"runtime/debug"
|
|
)
|
|
|
|
// Module is the SDK's Go module path.
|
|
const Module = "git.novox.be/novox/mesh-sdk/go"
|
|
|
|
// Version is the mesh-sdk version this binary was built with: "unknown" when the build carries no build info.
|
|
func Version() string {
|
|
bi, ok := debug.ReadBuildInfo()
|
|
if !ok {
|
|
return "unknown"
|
|
}
|
|
return FromBuildInfo(bi)
|
|
}
|
|
|
|
// 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. 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"
|
|
}
|
|
if bi.Main.Path == Module {
|
|
for _, s := range bi.Settings {
|
|
if s.Key == "vcs.revision" && s.Value != "" {
|
|
return "(devel) " + s.Value
|
|
}
|
|
}
|
|
if v := bi.Main.Version; v != "" && v != "(devel)" {
|
|
return v
|
|
}
|
|
return "(devel)"
|
|
}
|
|
for _, d := range bi.Deps {
|
|
if d == nil || d.Path != Module {
|
|
continue
|
|
}
|
|
if r := d.Replace; r != nil {
|
|
if r.Version != "" {
|
|
return r.Version
|
|
}
|
|
if r.Path != "" {
|
|
return r.Path
|
|
}
|
|
}
|
|
if d.Version != "" {
|
|
return d.Version
|
|
}
|
|
}
|
|
return "unknown"
|
|
}
|