version: return correct Meta.MajorMinorPatch in non-dev builds

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson 2023-02-06 23:23:00 -08:00 committed by Dave Anderson
parent 78980a4ccf
commit da75e49223
3 changed files with 18 additions and 5 deletions

View File

@ -6,8 +6,13 @@
import _ "embed"
// VersionDotTxt is the contents of VERSION.txt. Despite the tempting filename,
// this does not necessarily contain the accurate version number of the build, which
// depends on the branch type and how it was built. To get version information, use
// the version package instead.
//
//go:embed VERSION.txt
var Version string
var VersionDotTxt string
//go:embed ALPINE.txt
var AlpineDockerTag string

View File

@ -6,7 +6,6 @@
import (
"strings"
tailscaleroot "tailscale.com"
"tailscale.com/tailcfg"
)
@ -95,7 +94,7 @@ type Meta struct {
// GetMeta returns version metadata about the current build.
func GetMeta() Meta {
return Meta{
MajorMinorPatch: strings.TrimSpace(tailscaleroot.Version),
MajorMinorPatch: majorMinorPatch,
Short: Short,
Long: Long,
GitCommit: GitCommit,

View File

@ -80,6 +80,9 @@
// isWindowsGUI is whether the current binary is the Windows GUI binary.
isWindowsGUI bool
// majorMinorPatch is the major.minor.patch portion of Short.
majorMinorPatch string
)
func init() {
@ -89,6 +92,12 @@ func init() {
}
func initVersion() {
defer func() {
// Must be run after Short has been initialized, easiest way to do that
// is a defer.
majorMinorPatch, _, _ = strings.Cut(Short, "-")
}()
if Long != "" && Short != "" {
// Built in the recommended way, using build_dist.sh.
return
@ -98,7 +107,7 @@ func initVersion() {
// stamping.
bi, ok := debug.ReadBuildInfo()
if !ok {
Long = strings.TrimSpace(tailscaleroot.Version) + "-ERR-BuildInfo"
Long = strings.TrimSpace(tailscaleroot.VersionDotTxt) + "-ERR-BuildInfo"
Short = Long
return
}
@ -126,7 +135,7 @@ func initVersion() {
}
// Backup path, using Go 1.18's built-in git stamping.
Short = strings.TrimSpace(tailscaleroot.Version) + "-dev" + commitDate
Short = strings.TrimSpace(tailscaleroot.VersionDotTxt) + "-dev" + commitDate
Long = Short + "-t" + commitHashAbbrev + dirty
}