Commit f3b73e04 authored by Austin Clements's avatar Austin Clements

cmd/dist: fetch version when needed, instead of at init

Currently, if there is a VERSION.cache, running make.bash will set
runtime.theVersion to the revision as of the *last* make.bash run
instead of the current make.bash run.

For example,

$ git rev-parse --short HEAD
5c4a86d0
$ ./make.bash
...
$ cat ../VERSION.cache
devel +5c4a86d0 Tue Feb 10 01:46:30 2015 +0000
$ git checkout a1dbb920
$ ./make.bash
...
$ go version
go version devel +5c4a86d0 Tue Feb 10 01:46:30 2015 +0000 linux/amd64
$ ./make.bash
...
$ go version
go version devel +a1dbb920 Tue Feb 10 02:31:27 2015 +0000 linux/amd64

This happens because go tool dist reads the potentially stale
VERSION.cache into goversion during early initialization; then cleans,
which deletes VERSION.cache; then builds the runtime using the stale
revision read in to goversion.  It isn't until make later in the build
process, when make.bash invokes go tool dist again, that VERSION.cache
gets updated with the current revision.

To address this, simply don't bother fetching the version until go
tool dist needs it and don't bother caching the value in memory.  This
is more robust since it interacts with cleaning in the expected ways.
Futhermore, there's no downside to eliminating the in-memory cache;
the file system cache is perfectly reasonable for the whole three
times make.bash consults it.

Change-Id: I8c480100e56bb2db0816e8a088177004d9e87973
Reviewed-on: https://go-review.googlesource.com/4540Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent 32304fc9
...@@ -32,7 +32,6 @@ var ( ...@@ -32,7 +32,6 @@ var (
workdir string workdir string
tooldir string tooldir string
gochar string gochar string
goversion string
oldgoos string oldgoos string
oldgoarch string oldgoarch string
oldgochar string oldgochar string
...@@ -224,8 +223,6 @@ func xinit() { ...@@ -224,8 +223,6 @@ func xinit() {
os.Setenv("LANG", "C") os.Setenv("LANG", "C")
os.Setenv("LANGUAGE", "en_US.UTF8") os.Setenv("LANGUAGE", "en_US.UTF8")
goversion = findgoversion()
workdir = xworkdir() workdir = xworkdir()
xatexit(rmworkdir) xatexit(rmworkdir)
...@@ -426,6 +423,7 @@ func setup() { ...@@ -426,6 +423,7 @@ func setup() {
} }
// For release, make sure excluded things are excluded. // For release, make sure excluded things are excluded.
goversion := findgoversion()
if strings.HasPrefix(goversion, "release.") || (strings.HasPrefix(goversion, "go") && !strings.Contains(goversion, "beta")) { if strings.HasPrefix(goversion, "release.") || (strings.HasPrefix(goversion, "go") && !strings.Contains(goversion, "beta")) {
for _, dir := range unreleased { for _, dir := range unreleased {
if p := pathf("%s/%s", goroot, dir); isdir(p) { if p := pathf("%s/%s", goroot, dir); isdir(p) {
...@@ -903,7 +901,7 @@ func install(dir string) { ...@@ -903,7 +901,7 @@ func install(dir string) {
"-D", fmt.Sprintf("GOOS=%q", goos), "-D", fmt.Sprintf("GOOS=%q", goos),
"-D", fmt.Sprintf("GOARCH=%q", goarch), "-D", fmt.Sprintf("GOARCH=%q", goarch),
"-D", fmt.Sprintf("GOROOT=%q", goroot_final), "-D", fmt.Sprintf("GOROOT=%q", goroot_final),
"-D", fmt.Sprintf("GOVERSION=%q", goversion), "-D", fmt.Sprintf("GOVERSION=%q", findgoversion()),
"-D", fmt.Sprintf("GOARM=%q", goarm), "-D", fmt.Sprintf("GOARM=%q", goarm),
"-D", fmt.Sprintf("GO386=%q", go386), "-D", fmt.Sprintf("GO386=%q", go386),
"-D", fmt.Sprintf("GO_EXTLINK_ENABLED=%q", goextlinkenabled), "-D", fmt.Sprintf("GO_EXTLINK_ENABLED=%q", goextlinkenabled),
...@@ -1460,5 +1458,5 @@ func cmdbanner() { ...@@ -1460,5 +1458,5 @@ func cmdbanner() {
// Version prints the Go version. // Version prints the Go version.
func cmdversion() { func cmdversion() {
xflagparse(0) xflagparse(0)
xprintf("%s\n", goversion) xprintf("%s\n", findgoversion())
} }
...@@ -28,7 +28,7 @@ func mkzversion(dir, file string) { ...@@ -28,7 +28,7 @@ func mkzversion(dir, file string) {
"const defaultGoroot = `%s`\n"+ "const defaultGoroot = `%s`\n"+
"const theVersion = `%s`\n"+ "const theVersion = `%s`\n"+
"const goexperiment = `%s`\n"+ "const goexperiment = `%s`\n"+
"var buildVersion = theVersion\n", goroot_final, goversion, os.Getenv("GOEXPERIMENT")) "var buildVersion = theVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"))
writefile(out, file, 0) writefile(out, file, 0)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment