From: Russ Cox Date: Mon, 12 Jun 2023 20:38:24 +0000 (-0400) Subject: cmd/dist: do not use user build cache in versioned trees X-Git-Tag: go1.21rc1~27 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f7e11723e527c1a12e76180e29d52e1fcefce57b;p=gostls13.git cmd/dist: do not use user build cache in versioned trees There is no guarantee that the user build cache will have correct data if we are using a versioned build (with a VERSION file), because that overrides the use of tool build IDs for staleness. An earlier build might have run with a buggy compiler, and we don't want those files lying around. Change-Id: I831956911162ccbd0b4d943c305b3537918fe119 Reviewed-on: https://go-review.googlesource.com/c/go/+/502699 Auto-Submit: Russ Cox Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Run-TryBot: Russ Cox --- diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index 8eb6daa3a5..11f897af4c 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -1496,7 +1496,16 @@ func cmdbootstrap() { // Now prime the build cache with the rest of the standard library for // testing, and so that the user can run 'go install std cmd' to quickly // iterate on local changes without waiting for a full rebuild. - os.Setenv("GOCACHE", oldgocache) + if _, err := os.Stat(pathf("%s/VERSION", goroot)); err == nil { + // If we have a VERSION file, then we use the Go version + // instead of build IDs as a cache key, and there is no guarantee + // that code hasn't changed since the last time we ran a build + // with this exact VERSION file (especially if someone is working + // on a release branch). We must not fall back to the shared build cache + // in this case. Leave $GOCACHE alone. + } else { + os.Setenv("GOCACHE", oldgocache) + } if goos == oldgoos && goarch == oldgoarch { // Common case - not setting up for cross-compilation.