2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 19:08:55 +00:00

Update build.go

This commit is contained in:
Alexander Neumann 2018-08-12 15:44:13 +02:00
parent abc923f693
commit 77a8d931b8

View File

@ -241,11 +241,20 @@ func verbosePrintf(message string, args ...interface{}) {
fmt.Printf("build: "+message, args...) fmt.Printf("build: "+message, args...)
} }
// cleanEnv returns a clean environment with GOPATH and GOBIN removed (if // cleanEnv returns a clean environment with GOPATH, GOBIN and GO111MODULE
// present). // removed (if present).
func cleanEnv() (env []string) { func cleanEnv() (env []string) {
removeKeys := map[string]struct{}{
"GOPATH": struct{}{},
"GOBIN": struct{}{},
"GO111MODULE": struct{}{},
}
for _, v := range os.Environ() { 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 continue
} }
@ -554,7 +563,7 @@ func main() {
if !keepGopath { if !keepGopath {
verbosePrintf("remove %v\n", gopath) verbosePrintf("remove %v\n", gopath)
if err = os.RemoveAll(gopath); err != nil { 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 { } else {
verbosePrintf("leaving temporary GOPATH at %v\n", gopath) verbosePrintf("leaving temporary GOPATH at %v\n", gopath)
@ -599,7 +608,7 @@ func main() {
if runTests { if runTests {
verbosePrintf("running tests\n") verbosePrintf("running tests\n")
err = test(cwd, gopath, config.Tests...) err = test(filepath.Join(gopath, "src"), gopath, config.Tests...)
if err != nil { if err != nil {
die("running tests failed: %v\n", err) die("running tests failed: %v\n", err)
} }