mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +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"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
runtimeDebug "runtime/debug"
|
|
||||||
|
|
||||||
"tailscale.com/atomicfile"
|
"tailscale.com/atomicfile"
|
||||||
|
"tailscale.com/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -29,12 +29,7 @@ func main() {
|
|||||||
// any time.
|
// any time.
|
||||||
switch os.Args[1] {
|
switch os.Args[1] {
|
||||||
case "gocross-version":
|
case "gocross-version":
|
||||||
hash, err := embeddedCommit()
|
fmt.Println(version.GetMeta().GitCommit)
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "getting commit hash: %v", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
fmt.Println(hash)
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
case "is-gocross":
|
case "is-gocross":
|
||||||
// This subcommand exits with an error code when called on a
|
// 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...)
|
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