mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime,cmd/link: include GOEXPERIMENTs in runtime.Version(), "go version X"
This adds the set of GOEXPERIMENTs to the build version if it differs from the default set of experiments. This exposes the experiment settings via runtime.Version() and "go version <binary>". Change-Id: I143dbbc50f66a4cf175469199974e18848075af6 Reviewed-on: https://go-review.googlesource.com/c/go/+/307820 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
a8e55538af
commit
5159c83641
6 changed files with 36 additions and 5 deletions
2
src/cmd/dist/buildruntime.go
vendored
2
src/cmd/dist/buildruntime.go
vendored
|
|
@ -19,7 +19,6 @@ import (
|
||||||
//
|
//
|
||||||
// package sys
|
// package sys
|
||||||
//
|
//
|
||||||
// const TheVersion = <version>
|
|
||||||
// const StackGuardMultiplier = <multiplier value>
|
// const StackGuardMultiplier = <multiplier value>
|
||||||
//
|
//
|
||||||
func mkzversion(dir, file string) {
|
func mkzversion(dir, file string) {
|
||||||
|
|
@ -28,7 +27,6 @@ func mkzversion(dir, file string) {
|
||||||
fmt.Fprintln(&buf)
|
fmt.Fprintln(&buf)
|
||||||
fmt.Fprintf(&buf, "package sys\n")
|
fmt.Fprintf(&buf, "package sys\n")
|
||||||
fmt.Fprintln(&buf)
|
fmt.Fprintln(&buf)
|
||||||
fmt.Fprintf(&buf, "const TheVersion = `%s`\n", findgoversion())
|
|
||||||
fmt.Fprintf(&buf, "const StackGuardMultiplierDefault = %d\n", stackGuardMultiplierDefault())
|
fmt.Fprintf(&buf, "const StackGuardMultiplierDefault = %d\n", stackGuardMultiplierDefault())
|
||||||
|
|
||||||
writefile(buf.String(), file, writeSkipSame)
|
writefile(buf.String(), file, writeSkipSame)
|
||||||
|
|
|
||||||
16
src/cmd/go/testdata/script/version_goexperiment.txt
vendored
Normal file
16
src/cmd/go/testdata/script/version_goexperiment.txt
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# Test that experiments appear in "go version <binary>"
|
||||||
|
|
||||||
|
# This test requires rebuilding the runtime, which takes a while.
|
||||||
|
[short] skip
|
||||||
|
|
||||||
|
env GOEXPERIMENT=fieldtrack
|
||||||
|
go build -o main$GOEXE version.go
|
||||||
|
go version main$GOEXE
|
||||||
|
stdout 'X:fieldtrack$'
|
||||||
|
exec ./main$GOEXE
|
||||||
|
stderr 'X:fieldtrack$'
|
||||||
|
|
||||||
|
-- version.go --
|
||||||
|
package main
|
||||||
|
import "runtime"
|
||||||
|
func main() { println(runtime.Version()) }
|
||||||
|
|
@ -118,6 +118,12 @@ func Main(arch *sys.Arch, theArch Arch) {
|
||||||
addstrdata1(ctxt, "runtime.defaultGOROOT="+final)
|
addstrdata1(ctxt, "runtime.defaultGOROOT="+final)
|
||||||
addstrdata1(ctxt, "cmd/internal/objabi.defaultGOROOT="+final)
|
addstrdata1(ctxt, "cmd/internal/objabi.defaultGOROOT="+final)
|
||||||
|
|
||||||
|
buildVersion := objabi.Version
|
||||||
|
if goexperiment := objabi.GOEXPERIMENT(); goexperiment != "" {
|
||||||
|
buildVersion += " X:" + goexperiment
|
||||||
|
}
|
||||||
|
addstrdata1(ctxt, "runtime.buildVersion="+buildVersion)
|
||||||
|
|
||||||
// TODO(matloob): define these above and then check flag values here
|
// TODO(matloob): define these above and then check flag values here
|
||||||
if ctxt.Arch.Family == sys.AMD64 && objabi.GOOS == "plan9" {
|
if ctxt.Arch.Family == sys.AMD64 && objabi.GOOS == "plan9" {
|
||||||
flag.BoolVar(&flag8, "8", false, "use 64-bit addresses in symbol table")
|
flag.BoolVar(&flag8, "8", false, "use 64-bit addresses in symbol table")
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,9 @@
|
||||||
// In the toolchain, the set of experiments enabled for the current
|
// In the toolchain, the set of experiments enabled for the current
|
||||||
// build should be accessed via objabi.Experiment.
|
// build should be accessed via objabi.Experiment.
|
||||||
//
|
//
|
||||||
|
// The set of experiments is included in the output of runtime.Version()
|
||||||
|
// and "go version <binary>" if it differs from the default experiments.
|
||||||
|
//
|
||||||
// For the set of experiments supported by the current toolchain, see
|
// For the set of experiments supported by the current toolchain, see
|
||||||
// go doc internal/experiment.Flags.
|
// go doc internal/experiment.Flags.
|
||||||
package goexperiment
|
package goexperiment
|
||||||
|
|
|
||||||
|
|
@ -240,11 +240,21 @@ func GOROOT() string {
|
||||||
return defaultGOROOT
|
return defaultGOROOT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buildVersion is the Go tree's version string at build time.
|
||||||
|
//
|
||||||
|
// If any GOEXPERIMENTs are set to non-default values, it will include
|
||||||
|
// "X:<GOEXPERIMENT>".
|
||||||
|
//
|
||||||
|
// This is set by the linker.
|
||||||
|
//
|
||||||
|
// This is accessed by "go version <binary>".
|
||||||
|
var buildVersion string
|
||||||
|
|
||||||
// Version returns the Go tree's version string.
|
// Version returns the Go tree's version string.
|
||||||
// It is either the commit hash and date at the time of the build or,
|
// It is either the commit hash and date at the time of the build or,
|
||||||
// when possible, a release tag like "go1.3".
|
// when possible, a release tag like "go1.3".
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return sys.TheVersion
|
return buildVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
// GOOS is the running program's operating system target:
|
// GOOS is the running program's operating system target:
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
var buildVersion = sys.TheVersion
|
|
||||||
|
|
||||||
// set using cmd/go/internal/modload.ModInfoProg
|
// set using cmd/go/internal/modload.ModInfoProg
|
||||||
var modinfo string
|
var modinfo string
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue