// 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. 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 } } 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" }