From 77a8d931b8cdcb043b683591bd0f723b6c874261 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 12 Aug 2018 15:44:13 +0200 Subject: [PATCH] Update build.go --- build.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/build.go b/build.go index 03d7f9184..99fc03622 100644 --- a/build.go +++ b/build.go @@ -241,11 +241,20 @@ func verbosePrintf(message string, args ...interface{}) { fmt.Printf("build: "+message, args...) } -// cleanEnv returns a clean environment with GOPATH and GOBIN removed (if -// present). +// cleanEnv returns a clean environment with GOPATH, GOBIN and GO111MODULE +// removed (if present). func cleanEnv() (env []string) { + removeKeys := map[string]struct{}{ + "GOPATH": struct{}{}, + "GOBIN": struct{}{}, + "GO111MODULE": struct{}{}, + } + for _, v := range os.Environ() { - if strings.HasPrefix(v, "GOPATH=") || strings.HasPrefix(v, "GOBIN=") { + data := strings.SplitN(v, "=", 2) + name := data[0] + + if _, ok := removeKeys[name]; ok { continue } @@ -554,7 +563,7 @@ func main() { if !keepGopath { verbosePrintf("remove %v\n", gopath) if err = os.RemoveAll(gopath); err != nil { - die("remove GOPATH at %s failed: %v\n", err) + die("remove GOPATH at %s failed: %v\n", gopath, err) } } else { verbosePrintf("leaving temporary GOPATH at %v\n", gopath) @@ -599,7 +608,7 @@ func main() { if runTests { verbosePrintf("running tests\n") - err = test(cwd, gopath, config.Tests...) + err = test(filepath.Join(gopath, "src"), gopath, config.Tests...) if err != nil { die("running tests failed: %v\n", err) }