Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for Go older than 1.18 #612

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions version/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"bytes"
"fmt"
"runtime"
"runtime/debug"
"strings"
"text/template"
)
Expand All @@ -31,6 +32,9 @@ var (
GoVersion = runtime.Version()
GoOS = runtime.GOOS
GoArch = runtime.GOARCH

computedRevision string
computedTags string
)

// versionInfoTmpl contains the template used by Info.
Expand Down Expand Up @@ -74,3 +78,48 @@ func Info() string {
func BuildContext() string {
return fmt.Sprintf("(go=%s, platform=%s, user=%s, date=%s, tags=%s)", GoVersion, GoOS+"/"+GoArch, BuildUser, BuildDate, GetTags())
}

func GetRevision() string {
if Revision != "" {
return Revision
}
return computedRevision
}

func GetTags() string {
return computedTags
}

func init() {
computedRevision, computedTags = computeRevision()
}

func computeRevision() (string, string) {
var (
rev = "unknown"
tags = "unknown"
modified bool
)

buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return rev, tags
}
for _, v := range buildInfo.Settings {
if v.Key == "vcs.revision" {
rev = v.Value
}
if v.Key == "vcs.modified" {
if v.Value == "true" {
modified = true
}
}
if v.Key == "-tags" {
tags = v.Value
}
Comment on lines +117 to +119
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reading the BuildSettings docs and I can't find the -tags keys.

Is this something that was removed in more recent versions of go? Or just missing in the docs?

// A BuildSetting is a key-value pair describing one setting that influenced a build.
//
// Defined keys include:
//
//   - -buildmode: the buildmode flag used (typically "exe")
//   - -compiler: the compiler toolchain flag used (typically "gc")
//   - CGO_ENABLED: the effective CGO_ENABLED environment variable
//   - CGO_CFLAGS: the effective CGO_CFLAGS environment variable
//   - CGO_CPPFLAGS: the effective CGO_CPPFLAGS environment variable
//   - CGO_CXXFLAGS:  the effective CGO_CXXFLAGS environment variable
//   - CGO_LDFLAGS: the effective CGO_LDFLAGS environment variable
//   - GOARCH: the architecture target
//   - GOAMD64/GOARM/GO386/etc: the architecture feature level for GOARCH
//   - GOOS: the operating system target
//   - vcs: the version control system for the source tree where the build ran
//   - vcs.revision: the revision identifier for the current commit or checkout
//   - vcs.time: the modification time associated with vcs.revision, in RFC3339 format
//   - vcs.modified: true or false indicating whether the source tree had local modifications
type BuildSetting struct {
	// Key and Value describe the build setting.
	// Key must not contain an equals sign, space, tab, or newline.
	// Value must not contain newlines ('\n').
	Key, Value string
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good question. This isn't new code, just moving it from info_go118.go. @bboreham added it in #455.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list is not claimed to be exclusive; it says it “includes” those things.

}
if modified {
return rev + "-modified", tags
}
return rev, tags
}
25 changes: 0 additions & 25 deletions version/info_default.go

This file was deleted.

69 changes: 0 additions & 69 deletions version/info_go118.go

This file was deleted.