//
// package sys
//
-// const TheVersion = <version>
// const StackGuardMultiplier = <multiplier value>
//
func mkzversion(dir, file string) {
fmt.Fprintln(&buf)
fmt.Fprintf(&buf, "package sys\n")
fmt.Fprintln(&buf)
- fmt.Fprintf(&buf, "const TheVersion = `%s`\n", findgoversion())
fmt.Fprintf(&buf, "const StackGuardMultiplierDefault = %d\n", stackGuardMultiplierDefault())
writefile(buf.String(), file, writeSkipSame)
--- /dev/null
+# 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()) }
addstrdata1(ctxt, "runtime.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
if ctxt.Arch.Family == sys.AMD64 && objabi.GOOS == "plan9" {
flag.BoolVar(&flag8, "8", false, "use 64-bit addresses in symbol table")
// In the toolchain, the set of experiments enabled for the current
// 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
// go doc internal/experiment.Flags.
package goexperiment
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.
// It is either the commit hash and date at the time of the build or,
// when possible, a release tag like "go1.3".
func Version() string {
- return sys.TheVersion
+ return buildVersion
}
// GOOS is the running program's operating system target:
"unsafe"
)
-var buildVersion = sys.TheVersion
-
// set using cmd/go/internal/modload.ModInfoProg
var modinfo string