From 6e7bc021eed9e039aa4cf4c2800e91f3145b5930 Mon Sep 17 00:00:00 2001 From: Jay Conrod Date: Thu, 21 Mar 2019 15:18:04 -0400 Subject: [PATCH] cmd/dist: set GOPATH to internal directory during build Since GO111MODULE=on by default, the Go command needs a location for the module cache, even though it doesn't need to be written when building std and cmd. If GOROOT is checked out to $HOME/go, which is also the default location for GOPATH, this causes unnecessary problems late in the build. With this change, dist sets GOPATH to $GOROOT/pkg/obj/go-path. This is next to the temporary GOCACHE, $GOROOT/pkg/obj/go-build. Fixes #30960 Change-Id: I60771ee7f7c67ced1d2dc7c66b5885703fad1b63 Reviewed-on: https://go-review.googlesource.com/c/go/+/168697 Run-TryBot: Jay Conrod Reviewed-by: Ian Lance Taylor --- src/cmd/dist/build.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index b3e9ad33e9..b724d16456 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -235,6 +235,13 @@ func xinit() { // make.bash really does start from a clean slate. os.Setenv("GOCACHE", pathf("%s/pkg/obj/go-build", goroot)) + // Set GOPATH to an internal directory. We shouldn't actually + // need to store files here, since the toolchain won't + // depend on modules outside of vendor directories, but if + // GOPATH points somewhere else (e.g., to GOROOT), the + // go tool may complain. + os.Setenv("GOPATH", pathf("%s/pkg/obj/gopath", goroot)) + // Make the environment more predictable. os.Setenv("LANG", "C") os.Setenv("LANGUAGE", "en_US.UTF8")