]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: restore the original GOCACHE before building std and cmd
authorBryan C. Mills <bcmills@google.com>
Tue, 22 Nov 2022 02:30:02 +0000 (21:30 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 26 Jan 2023 23:32:05 +0000 (23:32 +0000)
The user is likely to run other commands that need these libraries
immediately after they are built.

For #57734.
Updates #56889.

Change-Id: I2a1a234e6031d85f017ee692ea1ace8c6e0e7355
Reviewed-on: https://go-review.googlesource.com/c/go/+/452679
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/dist/build.go
src/cmd/dist/test.go

index cd3e97163620ddb453d88aff3af7b9132ebbe831..ae39e9bf306d2374d1ed651f02466de2581efeaf 100644 (file)
@@ -46,6 +46,7 @@ var (
        tooldir          string
        oldgoos          string
        oldgoarch        string
+       oldgocache       string
        exe              string
        defaultcc        map[string]string
        defaultcxx       map[string]string
@@ -234,11 +235,6 @@ func xinit() {
        os.Setenv("GOROOT", goroot)
        os.Setenv("GOROOT_FINAL", goroot_final)
 
-       // Use a build cache separate from the default user one.
-       // Also one that will be wiped out during startup, so that
-       // make.bash really does start from a clean slate.
-       os.Setenv("GOCACHE", pathf("%s/pkg/obj/go-build", goroot))
-
        // Set GOBIN to GOROOT/bin. The meaning of GOBIN has drifted over time
        // (see https://go.dev/issue/3269, https://go.dev/cl/183058,
        // https://go.dev/issue/31576). Since we want binaries installed by 'dist' to
@@ -1211,7 +1207,6 @@ func cmdenv() {
        xprintf(format, "GO111MODULE", "")
        xprintf(format, "GOARCH", goarch)
        xprintf(format, "GOBIN", gorootBin)
-       xprintf(format, "GOCACHE", os.Getenv("GOCACHE"))
        xprintf(format, "GODEBUG", os.Getenv("GODEBUG"))
        xprintf(format, "GOENV", "off")
        xprintf(format, "GOFLAGS", "")
@@ -1340,6 +1335,12 @@ func cmdbootstrap() {
        // go tool may complain.
        os.Setenv("GOPATH", pathf("%s/pkg/obj/gopath", goroot))
 
+       // Use a build cache separate from the default user one.
+       // Also one that will be wiped out during startup, so that
+       // make.bash really does start from a clean slate.
+       oldgocache = os.Getenv("GOCACHE")
+       os.Setenv("GOCACHE", pathf("%s/pkg/obj/go-build", goroot))
+
        // Disable GOEXPERIMENT when building toolchain1 and
        // go_bootstrap. We don't need any experiments for the
        // bootstrap toolchain, and this lets us avoid duplicating the
@@ -1467,6 +1468,13 @@ func cmdbootstrap() {
                copyfile(pathf("%s/compile3", tooldir), pathf("%s/compile", tooldir), writeExec)
        }
 
+       // Now that toolchain3 has been built from scratch, its compiler and linker
+       // should have accurate build IDs suitable for caching.
+       // 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 goos == oldgoos && goarch == oldgoarch {
                // Common case - not setting up for cross-compilation.
                timelog("build", "toolchain")
index 3182fd4e455003e6c348ce4c5da373ae60287b5f..0cd5113a60739e0d7dcfa3afab5716b50aad1157 100644 (file)
@@ -773,7 +773,6 @@ func (t *tester) registerTests() {
                                        pkg:    "fmt",
                                }).command(t)
                                unsetEnv(cmd, "GOROOT")
-                               unsetEnv(cmd, "GOCACHE") // TODO(bcmills): ...why‽
                                err := cmd.Run()
 
                                if rerr := os.Rename(moved, goroot); rerr != nil {
@@ -1699,18 +1698,8 @@ func (t *tester) makeGOROOTUnwritable() (undo func()) {
                }
        }
 
-       gocache := os.Getenv("GOCACHE")
-       if gocache == "" {
-               panic("GOCACHE not set")
-       }
-       gocacheSubdir, _ := filepath.Rel(dir, gocache)
-
        filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
                if suffix := strings.TrimPrefix(path, dir+string(filepath.Separator)); suffix != "" {
-                       if suffix == gocacheSubdir {
-                               // Leave GOCACHE writable: we may need to write test binaries into it.
-                               return filepath.SkipDir
-                       }
                        if suffix == ".git" {
                                // Leave Git metadata in whatever state it was in. It may contain a lot
                                // of files, and it is highly unlikely that a test will try to modify