mirror of
https://github.com/golang/go
synced 2024-11-05 15:26:15 -07:00
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 HEAD5c4a86d
$ ./make.bash ... $ cat ../VERSION.cache devel +5c4a86d Tue Feb 10 01:46:30 2015 +0000 $ git checkouta1dbb92
$ ./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>
This commit is contained in:
parent
32304fc970
commit
f3b73e040c
8
src/cmd/dist/build.go
vendored
8
src/cmd/dist/build.go
vendored
@ -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())
|
||||
}
|
||||
|
2
src/cmd/dist/buildruntime.go
vendored
2
src/cmd/dist/buildruntime.go
vendored
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user