Skip to content

Commit c611ef2

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
cmd/dist: restore the original GOCACHE before building std and cmd
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 <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 8e0781e commit c611ef2

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/cmd/dist/build.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var (
4646
tooldir string
4747
oldgoos string
4848
oldgoarch string
49+
oldgocache string
4950
exe string
5051
defaultcc map[string]string
5152
defaultcxx map[string]string
@@ -234,11 +235,6 @@ func xinit() {
234235
os.Setenv("GOROOT", goroot)
235236
os.Setenv("GOROOT_FINAL", goroot_final)
236237

237-
// Use a build cache separate from the default user one.
238-
// Also one that will be wiped out during startup, so that
239-
// make.bash really does start from a clean slate.
240-
os.Setenv("GOCACHE", pathf("%s/pkg/obj/go-build", goroot))
241-
242238
// Set GOBIN to GOROOT/bin. The meaning of GOBIN has drifted over time
243239
// (see https://go.dev/issue/3269, https://go.dev/cl/183058,
244240
// https://go.dev/issue/31576). Since we want binaries installed by 'dist' to
@@ -1211,7 +1207,6 @@ func cmdenv() {
12111207
xprintf(format, "GO111MODULE", "")
12121208
xprintf(format, "GOARCH", goarch)
12131209
xprintf(format, "GOBIN", gorootBin)
1214-
xprintf(format, "GOCACHE", os.Getenv("GOCACHE"))
12151210
xprintf(format, "GODEBUG", os.Getenv("GODEBUG"))
12161211
xprintf(format, "GOENV", "off")
12171212
xprintf(format, "GOFLAGS", "")
@@ -1340,6 +1335,12 @@ func cmdbootstrap() {
13401335
// go tool may complain.
13411336
os.Setenv("GOPATH", pathf("%s/pkg/obj/gopath", goroot))
13421337

1338+
// Use a build cache separate from the default user one.
1339+
// Also one that will be wiped out during startup, so that
1340+
// make.bash really does start from a clean slate.
1341+
oldgocache = os.Getenv("GOCACHE")
1342+
os.Setenv("GOCACHE", pathf("%s/pkg/obj/go-build", goroot))
1343+
13431344
// Disable GOEXPERIMENT when building toolchain1 and
13441345
// go_bootstrap. We don't need any experiments for the
13451346
// bootstrap toolchain, and this lets us avoid duplicating the
@@ -1467,6 +1468,13 @@ func cmdbootstrap() {
14671468
copyfile(pathf("%s/compile3", tooldir), pathf("%s/compile", tooldir), writeExec)
14681469
}
14691470

1471+
// Now that toolchain3 has been built from scratch, its compiler and linker
1472+
// should have accurate build IDs suitable for caching.
1473+
// Now prime the build cache with the rest of the standard library for
1474+
// testing, and so that the user can run 'go install std cmd' to quickly
1475+
// iterate on local changes without waiting for a full rebuild.
1476+
os.Setenv("GOCACHE", oldgocache)
1477+
14701478
if goos == oldgoos && goarch == oldgoarch {
14711479
// Common case - not setting up for cross-compilation.
14721480
timelog("build", "toolchain")

src/cmd/dist/test.go

-11
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,6 @@ func (t *tester) registerTests() {
773773
pkg: "fmt",
774774
}).command(t)
775775
unsetEnv(cmd, "GOROOT")
776-
unsetEnv(cmd, "GOCACHE") // TODO(bcmills): ...why‽
777776
err := cmd.Run()
778777

779778
if rerr := os.Rename(moved, goroot); rerr != nil {
@@ -1699,18 +1698,8 @@ func (t *tester) makeGOROOTUnwritable() (undo func()) {
16991698
}
17001699
}
17011700

1702-
gocache := os.Getenv("GOCACHE")
1703-
if gocache == "" {
1704-
panic("GOCACHE not set")
1705-
}
1706-
gocacheSubdir, _ := filepath.Rel(dir, gocache)
1707-
17081701
filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
17091702
if suffix := strings.TrimPrefix(path, dir+string(filepath.Separator)); suffix != "" {
1710-
if suffix == gocacheSubdir {
1711-
// Leave GOCACHE writable: we may need to write test binaries into it.
1712-
return filepath.SkipDir
1713-
}
17141703
if suffix == ".git" {
17151704
// Leave Git metadata in whatever state it was in. It may contain a lot
17161705
// of files, and it is highly unlikely that a test will try to modify

0 commit comments

Comments
 (0)