// xworkdir creates a new temporary directory to hold object files
// and returns the name of that directory.
func xworkdir() string {
- name, err := ioutil.TempDir("", "go-tool-dist-")
+ name, err := ioutil.TempDir(os.Getenv("GOTMPDIR"), "go-tool-dist-")
if err != nil {
fatalf("%v", err)
}
// The -json flag prints the environment in JSON format
// instead of as a shell script.
//
+// For more about environment variables, see 'go help environment'.
+//
//
// Start a bug report
//
// See https://golang.org/doc/articles/race_detector.html.
// GOROOT
// The root of the go tree.
+// GOTMPDIR
+// The directory where the go command will write
+// temporary source files, packages, and binaries.
+// GOCACHE
+// The directory where the go command will store
+// cached information for reuse in future builds.
//
// Environment variables for use with cgo:
//
}
}
+func TestGOTMPDIR(t *testing.T) {
+ tg := testgo(t)
+ defer tg.cleanup()
+ tg.parallel()
+ tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
+ tg.makeTempdir()
+ tg.setenv("GOTMPDIR", tg.tempdir)
+ tg.setenv("GOCACHE", "off")
+
+ // complex/x is a trivial non-main package.
+ tg.run("build", "-work", "-x", "complex/w")
+ tg.grepStderr("WORK="+regexp.QuoteMeta(tg.tempdir), "did not work in $GOTMPDIR")
+}
+
func TestBuildCache(t *testing.T) {
if strings.Contains(os.Getenv("GODEBUG"), "gocacheverify") {
t.Skip("GODEBUG gocacheverify")
The -json flag prints the environment in JSON format
instead of as a shell script.
+
+For more about environment variables, see 'go help environment'.
`,
}
env := []cfg.EnvVar{
{Name: "GOARCH", Value: cfg.Goarch},
{Name: "GOBIN", Value: cfg.GOBIN},
+ {Name: "GOCACHE", Value: cache.DefaultDir()},
{Name: "GOEXE", Value: cfg.ExeSuffix},
{Name: "GOHOSTARCH", Value: runtime.GOARCH},
{Name: "GOHOSTOS", Value: runtime.GOOS},
{Name: "GOPATH", Value: cfg.BuildContext.GOPATH},
{Name: "GORACE", Value: os.Getenv("GORACE")},
{Name: "GOROOT", Value: cfg.GOROOT},
+ {Name: "GOTMPDIR", Value: os.Getenv("GOTMPDIR")},
{Name: "GOTOOLDIR", Value: base.ToolDir},
- {Name: "GOCACHE", Value: cache.DefaultDir()},
// disable escape codes in clang errors
{Name: "TERM", Value: "dumb"},
See https://golang.org/doc/articles/race_detector.html.
GOROOT
The root of the go tree.
+ GOTMPDIR
+ The directory where the go command will write
+ temporary source files, packages, and binaries.
+ GOCACHE
+ The directory where the go command will store
+ cached information for reuse in future builds.
Environment variables for use with cgo:
if cfg.BuildN {
b.WorkDir = "$WORK"
} else {
- b.WorkDir, err = ioutil.TempDir("", "go-build")
+ b.WorkDir, err = ioutil.TempDir(os.Getenv("GOTMPDIR"), "go-build")
if err != nil {
base.Fatalf("%s", err)
}