2020-02-10 17:00:30 +00:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Package version provides the version that the binary was built at.
|
|
|
|
package version
|
|
|
|
|
2021-10-22 16:44:37 +00:00
|
|
|
import (
|
2022-03-16 20:55:23 +00:00
|
|
|
"runtime/debug"
|
2021-10-22 16:44:37 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
tailscaleroot "tailscale.com"
|
|
|
|
)
|
|
|
|
|
2020-10-27 04:23:58 +00:00
|
|
|
// Long is a full version number for this build, of the form
|
2022-03-16 20:55:23 +00:00
|
|
|
// "x.y.z-commithash" for builds stamped in the usual way (see
|
|
|
|
// build_dist.sh in the root) or, for binaries built by hand with the
|
|
|
|
// go tool, it's of the form "1.23.0-dev20220316-t29837428937{,-dirty}"
|
|
|
|
// where "1.23.0" comes from ../VERSION.txt and the part after dev
|
|
|
|
// is YYYYMMDD of the commit time, and the part after -t is the commit
|
|
|
|
// hash. The dirty suffix is whether there are uncommitted changes.
|
|
|
|
var Long = ""
|
2021-10-22 16:44:37 +00:00
|
|
|
|
2020-10-27 04:23:58 +00:00
|
|
|
// Short is a short version number for this build, of the form
|
2022-03-16 20:55:23 +00:00
|
|
|
// "x.y.z" for builds stamped in the usual way (see
|
|
|
|
// build_dist.sh in the root) or, for binaries built by hand with the // go tool, it's like Long's dev form, but ending at the date part,
|
|
|
|
// of the form "1.23.0-dev20220316".
|
2021-06-03 18:19:29 +00:00
|
|
|
var Short = ""
|
2020-10-27 04:23:58 +00:00
|
|
|
|
2021-06-03 18:19:29 +00:00
|
|
|
func init() {
|
2022-03-16 20:55:23 +00:00
|
|
|
if Long != "" && Short != "" {
|
|
|
|
// Built in the recommended way, using build_dist.sh.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
bi, ok := debug.ReadBuildInfo()
|
|
|
|
if !ok {
|
|
|
|
Long = strings.TrimSpace(tailscaleroot.Version) + "-ERR-BuildInfo"
|
2021-06-03 18:19:29 +00:00
|
|
|
Short = Long
|
2022-03-16 20:55:23 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
var dirty string // "-dirty" suffix if dirty
|
|
|
|
var commitHashAbbrev, commitDate string
|
|
|
|
for _, s := range bi.Settings {
|
|
|
|
switch s.Key {
|
|
|
|
case "vcs.revision":
|
|
|
|
GitCommit = s.Value
|
|
|
|
if len(s.Value) >= 9 {
|
|
|
|
commitHashAbbrev = s.Value[:9]
|
|
|
|
}
|
|
|
|
case "vcs.time":
|
|
|
|
if len(s.Value) >= len("yyyy-mm-dd") {
|
|
|
|
commitDate = s.Value[:len("yyyy-mm-dd")]
|
|
|
|
commitDate = strings.ReplaceAll(commitDate, "-", "")
|
|
|
|
}
|
|
|
|
case "vcs.modified":
|
|
|
|
if s.Value == "true" {
|
|
|
|
dirty = "-dirty"
|
|
|
|
GitDirty = true
|
|
|
|
}
|
|
|
|
}
|
2021-06-03 18:19:29 +00:00
|
|
|
}
|
2022-03-16 20:55:23 +00:00
|
|
|
|
|
|
|
// Backup path, using Go 1.18's built-in git stamping.
|
|
|
|
Short = strings.TrimSpace(tailscaleroot.Version) + "-dev" + commitDate
|
|
|
|
Long = Short + "-t" + commitHashAbbrev + dirty
|
2021-06-03 18:19:29 +00:00
|
|
|
}
|
2020-10-27 04:23:58 +00:00
|
|
|
|
|
|
|
// GitCommit, if non-empty, is the git commit of the
|
|
|
|
// github.com/tailscale/tailscale repository at which Tailscale was
|
|
|
|
// built. Its format is the one returned by `git describe --always
|
|
|
|
// --exclude "*" --dirty --abbrev=200`.
|
2021-06-02 08:05:13 +00:00
|
|
|
var GitCommit = ""
|
2020-10-27 04:23:58 +00:00
|
|
|
|
2022-03-16 20:55:23 +00:00
|
|
|
// GitDirty is whether Go stamped the binary has having dirty version
|
|
|
|
// control changes in the working directory (debug.ReadBuildInfo
|
|
|
|
// setting "vcs.modified" was true).
|
|
|
|
var GitDirty bool
|
|
|
|
|
2020-10-27 04:23:58 +00:00
|
|
|
// ExtraGitCommit, if non-empty, is the git commit of a "supplemental"
|
|
|
|
// repository at which Tailscale was built. Its format is the same as
|
2020-10-28 23:29:26 +00:00
|
|
|
// gitCommit.
|
2020-10-27 04:23:58 +00:00
|
|
|
//
|
2020-10-28 23:29:26 +00:00
|
|
|
// ExtraGitCommit is used to track the source revision when the main
|
2020-10-27 04:23:58 +00:00
|
|
|
// Tailscale repository is integrated into and built from another
|
|
|
|
// repository (for example, Tailscale's proprietary code, or the
|
2020-10-28 23:29:26 +00:00
|
|
|
// Android OSS repository). Together, GitCommit and ExtraGitCommit
|
2020-10-27 04:23:58 +00:00
|
|
|
// exactly describe what repositories and commits were used in a
|
|
|
|
// build.
|
2021-06-02 08:05:13 +00:00
|
|
|
var ExtraGitCommit = ""
|