]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: do not use user build cache in versioned trees
authorRuss Cox <rsc@golang.org>
Mon, 12 Jun 2023 20:38:24 +0000 (16:38 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 12 Jun 2023 20:59:04 +0000 (20:59 +0000)
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 <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>

src/cmd/dist/build.go

index 8eb6daa3a5de5aa8dde5e3d145ae5f223f5b9798..11f897af4c657e31155accedbd03736774cffce0 100644 (file)
@@ -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.