]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't initialize Builder in envcmd.MkEnv
authorJay Conrod <jayconrod@google.com>
Thu, 4 Jun 2020 15:41:43 +0000 (11:41 -0400)
committerJay Conrod <jayconrod@google.com>
Fri, 14 Aug 2020 21:03:46 +0000 (21:03 +0000)
The Builder isn't needed by MkEnv, and Builder.Init doesn't have side
effects that change the environment. Builder.Init does currently call
CheckGOOSARCHPair, but that's being moved out in CL 234658.

Builder.Init creates the temporary work directory used by the
builder. For the builder created in MkEnv, this directory is never
used. Creating this directory can cause unnecessary errors for
commands that don't use a builder like 'go clean' and 'go list'.

Fixes #38395
Updates #24398

Change-Id: Ib93ae55afdf958000470657f4c4ff5bd92700e46
Reviewed-on: https://go-review.googlesource.com/c/go/+/236563
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/envcmd/env.go
src/cmd/go/testdata/script/build_GOTMPDIR.txt

index 403e0f4a7b4a2957263d25472a89fb31aff6a4c4..7bd75f7305397768e7234f928da20aef59d83c0a 100644 (file)
@@ -63,9 +63,6 @@ var (
 )
 
 func MkEnv() []cfg.EnvVar {
-       var b work.Builder
-       b.Init()
-
        envFile, _ := cfg.EnvFile()
        env := []cfg.EnvVar{
                {Name: "GO111MODULE", Value: cfg.Getenv("GO111MODULE")},
index c93ca932cab5064aac1626df7f80d6fd4f1991f8..1073517c29891caf86c289af31ca6e8d2afe462f 100644 (file)
@@ -1,15 +1,50 @@
-env GO111MODULE=off
-[short] skip
-
 # Set GOCACHE to a clean directory to ensure that 'go build' has work to report.
-env GOCACHE=$WORK/gocache
+[!windows] env GOCACHE=$WORK/gocache
+[windows] env GOCACHE=$WORK\gocache
 
-# Build should use GOTMPDIR if set.
-env GOTMPDIR=$WORK/my-favorite-tmpdir
+# 'go build' should use GOTMPDIR if set.
+[!windows] env GOTMPDIR=$WORK/my-favorite-tmpdir
+[windows] env GOTMPDIR=$WORK\my-favorite-tmpdir
 mkdir $GOTMPDIR
-go build -work hello.go
+go build -x hello.go
 stderr ^WORK=.*my-favorite-tmpdir
 
+# Make GOTMPDIR a regular file. This prevents the creation of work directories,
+# so we can check that certain commands don't create them.
+# This simulates running on a full disk or a read-only volume.
+rm $GOTMPDIR
+cp hello.go $GOTMPDIR # any file will do
+
+# 'go build' should fail if GOTMPDIR is read-only.
+! go build -x .
+stderr '^go: creating work dir: \w+ '$GOTMPDIR
+
+# 'go list' should only fail if it needs to build something.
+go list -x .
+! stderr 'creating work dir'
+stdout m
+go list -m all
+stdout m
+! go list -x -export .
+stderr '^go: creating work dir: \w+ '$GOTMPDIR
+
+# 'go clean -cache' and 'go clean -modcache' should not fail.
+go clean -x -cache
+! stderr 'creating work dir'
+go clean -x -modcache
+! stderr 'creating work dir'
+
+# 'go env' should not fail for specific variables.
+# Without arguments, it needs to initialize a builder to load cgo flags, and
+# that uses a temporary directory.
+! go env
+stderr '^go: creating work dir: \w+ '$GOTMPDIR
+go env GOROOT
+
+-- go.mod --
+module m
+
+go 1.15
 -- hello.go --
 package main
 func main() { println("hello") }