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

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/7246/head
David Anderson 1 year ago committed by Dave Anderson
parent 78980a4ccf
commit da75e49223

@ -6,8 +6,13 @@ package tailscaleroot
import _ "embed" 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 //go:embed VERSION.txt
var Version string var VersionDotTxt string
//go:embed ALPINE.txt //go:embed ALPINE.txt
var AlpineDockerTag string var AlpineDockerTag string

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

@ -80,6 +80,9 @@ var (
// isWindowsGUI is whether the current binary is the Windows GUI binary. // isWindowsGUI is whether the current binary is the Windows GUI binary.
isWindowsGUI bool isWindowsGUI bool
// majorMinorPatch is the major.minor.patch portion of Short.
majorMinorPatch string
) )
func init() { func init() {
@ -89,6 +92,12 @@ func init() {
} }
func initVersion() { 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 != "" { if Long != "" && Short != "" {
// Built in the recommended way, using build_dist.sh. // Built in the recommended way, using build_dist.sh.
return return
@ -98,7 +107,7 @@ func initVersion() {
// stamping. // stamping.
bi, ok := debug.ReadBuildInfo() bi, ok := debug.ReadBuildInfo()
if !ok { if !ok {
Long = strings.TrimSpace(tailscaleroot.Version) + "-ERR-BuildInfo" Long = strings.TrimSpace(tailscaleroot.VersionDotTxt) + "-ERR-BuildInfo"
Short = Long Short = Long
return return
} }
@ -126,7 +135,7 @@ func initVersion() {
} }
// Backup path, using Go 1.18's built-in git stamping. // 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 Long = Short + "-t" + commitHashAbbrev + dirty
} }

Loading…
Cancel
Save