dcrd/internal/version/version_buildinfo.go
Josh Rickmar bdee08b7c1 version: Include VCS build info in version string.
VCS build info is only available when built from a VCS checkout using
Go 1.18 or later.
2021-12-17 14:21:21 -06:00

34 lines
589 B
Go

// Copyright (c) 2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
//go:build go1.18
// +build go1.18
package version
import "runtime/debug"
func vcsCommitID() string {
bi, ok := debug.ReadBuildInfo()
if !ok {
return ""
}
var vcs, revision string
for _, bs := range bi.Settings {
switch bs.Key {
case "vcs":
vcs = bs.Value
case "vcs.revision":
revision = bs.Value
}
}
if vcs == "" {
return ""
}
if vcs == "git" && len(revision) > 9 {
revision = revision[:9]
}
return revision
}