]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: fetch version when needed, instead of at init
authorAustin Clements <austin@google.com>
Wed, 11 Feb 2015 04:51:25 +0000 (23:51 -0500)
committerAustin Clements <austin@google.com>
Wed, 11 Feb 2015 05:20:58 +0000 (05:20 +0000)
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
5c4a86d
$ ./make.bash
...
$ cat ../VERSION.cache
devel +5c4a86d Tue Feb 10 01:46:30 2015 +0000
$ git checkout a1dbb92
$ ./make.bash
...
$ go version
go version devel +5c4a86d Tue Feb 10 01:46:30 2015 +0000 linux/amd64
$ ./make.bash
...
$ go version
go version devel +a1dbb92 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/4540
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/dist/build.go
src/cmd/dist/buildruntime.go

index a302787c3d283435e5492e7a9d8258c122f93298..8a408831d06d48f0de4c0b9e976d933d825bccf6 100644 (file)
@@ -32,7 +32,6 @@ var (
        workdir          string
        tooldir          string
        gochar           string
-       goversion        string
        oldgoos          string
        oldgoarch        string
        oldgochar        string
@@ -224,8 +223,6 @@ func xinit() {
        os.Setenv("LANG", "C")
        os.Setenv("LANGUAGE", "en_US.UTF8")
 
-       goversion = findgoversion()
-
        workdir = xworkdir()
        xatexit(rmworkdir)
 
@@ -426,6 +423,7 @@ func setup() {
        }
 
        // For release, make sure excluded things are excluded.
+       goversion := findgoversion()
        if strings.HasPrefix(goversion, "release.") || (strings.HasPrefix(goversion, "go") && !strings.Contains(goversion, "beta")) {
                for _, dir := range unreleased {
                        if p := pathf("%s/%s", goroot, dir); isdir(p) {
@@ -903,7 +901,7 @@ func install(dir string) {
                                        "-D", fmt.Sprintf("GOOS=%q", goos),
                                        "-D", fmt.Sprintf("GOARCH=%q", goarch),
                                        "-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("GO386=%q", go386),
                                        "-D", fmt.Sprintf("GO_EXTLINK_ENABLED=%q", goextlinkenabled),
@@ -1460,5 +1458,5 @@ func cmdbanner() {
 // Version prints the Go version.
 func cmdversion() {
        xflagparse(0)
-       xprintf("%s\n", goversion)
+       xprintf("%s\n", findgoversion())
 }
index d659234578ff0be6009b3c8e34b8be89f092215e..32064ff8f4159e3b72bc2441a7528a938110e404 100644 (file)
@@ -28,7 +28,7 @@ func mkzversion(dir, file string) {
                        "const defaultGoroot = `%s`\n"+
                        "const theVersion = `%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)
 }