From 0b62f85c948a26479b86a287b814e2521d1be65f Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 16 Dec 2024 18:03:27 +0000 Subject: [PATCH] Remove Go <1.18 compile support for version VCS IDs We are far beyond requiring a newer Go version than this. No functional change. --- version/version.go | 26 +++++++++++++++++++++++++- version/version_buildinfo.go | 32 -------------------------------- version/version_nobuildinfo.go | 11 ----------- 3 files changed, 25 insertions(+), 44 deletions(-) delete mode 100644 version/version_buildinfo.go delete mode 100644 version/version_nobuildinfo.go diff --git a/version/version.go b/version/version.go index 56e74e866..12c745166 100644 --- a/version/version.go +++ b/version/version.go @@ -1,5 +1,5 @@ // Copyright (c) 2013-2014 The btcsuite developers -// Copyright (c) 2015-2021 The Decred developers +// Copyright (c) 2015-2024 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -8,6 +8,7 @@ package version import ( "bytes" "fmt" + "runtime/debug" "strings" ) @@ -42,6 +43,29 @@ func init() { } } +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 +} + // String returns the application version as a properly formed string per the // semantic versioning 2.0.0 spec (https://semver.org/). func String() string { diff --git a/version/version_buildinfo.go b/version/version_buildinfo.go deleted file mode 100644 index 06a70370c..000000000 --- a/version/version_buildinfo.go +++ /dev/null @@ -1,32 +0,0 @@ -// 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 - -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 -} diff --git a/version/version_nobuildinfo.go b/version/version_nobuildinfo.go deleted file mode 100644 index 3355972ad..000000000 --- a/version/version_nobuildinfo.go +++ /dev/null @@ -1,11 +0,0 @@ -// 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 - -package version - -func vcsCommitID() string { - return "" -}