mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
tool/gocross: embed the version explicitly with linker flags
We need to build gocross from multiple repos, but Go's innate git hash embedding only works when you build gocross from this repo, not when you build it from elsewhere via 'go build tailscale.com/tool/gocross'. Instead, explicitly embed the version found with 'git rev-parse HEAD', which will work from any git repo. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
7444dabb68
commit
66621ab38e
@ -16,9 +16,9 @@
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
runtimeDebug "runtime/debug"
|
||||
|
||||
"tailscale.com/atomicfile"
|
||||
"tailscale.com/version"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -29,12 +29,7 @@ func main() {
|
||||
// any time.
|
||||
switch os.Args[1] {
|
||||
case "gocross-version":
|
||||
hash, err := embeddedCommit()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "getting commit hash: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println(hash)
|
||||
fmt.Println(version.GetMeta().GitCommit)
|
||||
os.Exit(0)
|
||||
case "is-gocross":
|
||||
// This subcommand exits with an error code when called on a
|
||||
@ -132,16 +127,3 @@ func debug(format string, args ...interface{}) {
|
||||
|
||||
fmt.Fprintf(out, format, args...)
|
||||
}
|
||||
|
||||
func embeddedCommit() (string, error) {
|
||||
bi, ok := runtimeDebug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return "", fmt.Errorf("no build info")
|
||||
}
|
||||
for _, s := range bi.Settings {
|
||||
if s.Key == "vcs.revision" {
|
||||
return s.Value, nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("no git commit found")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user