diff options
| author | xieyuschen <xieyuschen@gmail.com> | 2024-10-14 19:11:53 +0800 |
|---|---|---|
| committer | Sam Thanawalla <samthanawalla@google.com> | 2025-05-13 09:21:20 -0700 |
| commit | a632009c4a0b0826871baae7e7ce7804b4089d93 (patch) | |
| tree | 4b2a1513bc5236c81f969cf940d9162bb8a98c81 /src/runtime/debug/mod.go | |
| parent | 698f86139bf72bcf7cbf08accc1c34394cb57acb (diff) | |
| download | go-a632009c4a0b0826871baae7e7ce7804b4089d93.tar.xz | |
cmd/go: support -json flag in go version
It supports features described in the issue:
* add -json flag for 'go version -m' to print json encoding of
runtime/debug.BuildSetting to standard output.
* report an error when specifying -json flag without -m.
* print build settings on seperated line for each binary
Fixes #69712
Change-Id: I79cba2109f80f7459252d197a74959694c4eea1f
Reviewed-on: https://go-review.googlesource.com/c/go/+/619955
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime/debug/mod.go')
| -rw-r--r-- | src/runtime/debug/mod.go | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/runtime/debug/mod.go b/src/runtime/debug/mod.go index 917e734284..34227d8544 100644 --- a/src/runtime/debug/mod.go +++ b/src/runtime/debug/mod.go @@ -41,29 +41,29 @@ func ReadBuildInfo() (info *BuildInfo, ok bool) { type BuildInfo struct { // GoVersion is the version of the Go toolchain that built the binary // (for example, "go1.19.2"). - GoVersion string + GoVersion string `json:",omitempty"` // Path is the package path of the main package for the binary // (for example, "golang.org/x/tools/cmd/stringer"). - Path string + Path string `json:",omitempty"` // Main describes the module that contains the main package for the binary. - Main Module + Main Module `json:""` // Deps describes all the dependency modules, both direct and indirect, // that contributed packages to the build of this binary. - Deps []*Module + Deps []*Module `json:",omitempty"` // Settings describes the build settings used to build the binary. - Settings []BuildSetting + Settings []BuildSetting `json:",omitempty"` } // A Module describes a single module included in a build. type Module struct { - Path string // module path - Version string // module version - Sum string // checksum - Replace *Module // replaced by this module + Path string `json:",omitempty"` // module path + Version string `json:",omitempty"` // module version + Sum string `json:",omitempty"` // checksum + Replace *Module `json:",omitempty"` // replaced by this module } // A BuildSetting is a key-value pair describing one setting that influenced a build. @@ -89,8 +89,9 @@ type Module struct { type BuildSetting struct { // Key and Value describe the build setting. // Key must not contain an equals sign, space, tab, or newline. + Key string `json:",omitempty"` // Value must not contain newlines ('\n'). - Key, Value string + Value string `json:",omitempty"` } // quoteKey reports whether key is required to be quoted. |
