aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/debug/mod.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2021-09-30 10:46:03 -0700
committerJay Conrod <jayconrod@google.com>2021-10-14 18:44:21 +0000
commit85a068fdf21bd2e4475a87ee049af4fbe797bcbe (patch)
treedad851a6a338f9928687e20591fd705e6ee306a3 /src/runtime/debug/mod.go
parent434cdd0337b9e6c7e0c369c9293cc14fd38dc80d (diff)
downloadgo-85a068fdf21bd2e4475a87ee049af4fbe797bcbe.tar.xz
runtime/debug: add GoVersion to BuildInfo
BuildInfo now includes the version of Go used to build a binary, as reported by runtime.Version() or 'go version'. For #37475 Change-Id: Id07dda357dc70599d64a9202dab894c7288de1de Reviewed-on: https://go-review.googlesource.com/c/go/+/353888 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/runtime/debug/mod.go')
-rw-r--r--src/runtime/debug/mod.go20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/runtime/debug/mod.go b/src/runtime/debug/mod.go
index 8c6c48089b..0c6488753b 100644
--- a/src/runtime/debug/mod.go
+++ b/src/runtime/debug/mod.go
@@ -7,6 +7,7 @@ package debug
import (
"bytes"
"fmt"
+ "runtime"
)
// exported from runtime
@@ -25,14 +26,22 @@ func ReadBuildInfo() (info *BuildInfo, ok bool) {
if err := bi.UnmarshalText([]byte(data)); err != nil {
return nil, false
}
+
+ // The go version is stored separately from other build info, mostly for
+ // historical reasons. It is not part of the modinfo() string, and
+ // ParseBuildInfo does not recognize it. We inject it here to hide this
+ // awkwardness from the user.
+ bi.GoVersion = runtime.Version()
+
return bi, true
}
// BuildInfo represents the build information read from a Go binary.
type BuildInfo struct {
- Path string // The main package path
- Main Module // The module containing the main package
- Deps []*Module // Module dependencies
+ GoVersion string // Version of Go that produced this binary.
+ Path string // The main package path
+ Main Module // The module containing the main package
+ Deps []*Module // Module dependencies
}
// Module represents a module.
@@ -45,6 +54,9 @@ type Module struct {
func (bi *BuildInfo) MarshalText() ([]byte, error) {
buf := &bytes.Buffer{}
+ if bi.GoVersion != "" {
+ fmt.Fprintf(buf, "go\t%s\n", bi.GoVersion)
+ }
if bi.Path != "" {
fmt.Fprintf(buf, "path\t%s\n", bi.Path)
}
@@ -116,7 +128,7 @@ func (bi *BuildInfo) UnmarshalText(data []byte) (err error) {
line []byte
ok bool
)
- // Reverse of BuildInfo.String()
+ // Reverse of BuildInfo.String(), except for go version.
for len(data) > 0 {
line, data, ok = bytes.Cut(data, newline)
if !ok {