From db7e74696087edefd03162583cc8d45ad5bd2f06 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 25 Mar 2019 22:57:27 +0000 Subject: [PATCH] cmd/vet/all: don't use the x/tools vet in GOPATH Updates golang/go#31040 Change-Id: I76e3044b2cc992e63194654a825e70307075eff3 Reviewed-on: https://go-review.googlesource.com/c/go/+/169237 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Dmitri Shuralyov --- src/cmd/vet/all/main.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/cmd/vet/all/main.go b/src/cmd/vet/all/main.go index 6e4a4e297e..e4f8eccd8c 100644 --- a/src/cmd/vet/all/main.go +++ b/src/cmd/vet/all/main.go @@ -243,7 +243,17 @@ func (p platform) vet() { } cmd := exec.Command(cmdGoPath, "build", "-o", vetTool, "golang.org/x/tools/go/analysis/cmd/vet") - cmd.Env = os.Environ() + cmd.Env = append(os.Environ(), + // Setting GO111MODULE to on is redundant in master + // (Go 1.13), but not if we backport this to Go 1.11/1.12 + // release branches (for our own builder usage) or if + // master ends up reverting its GO111MODULE default. If + // that happens, we want to force it on here anyway, as + // we're now depending on it. + "GO111MODULE=on", + ) + // Use the module that cmd/vet/all is a part of: + cmd.Dir = filepath.Join(runtime.GOROOT(), "src", "cmd", "vet", "all") // golang.org/x/tools does not have a vendor directory, so don't try to use // one in module mode. @@ -259,19 +269,6 @@ func (p platform) vet() { } } - // The coordinator places a copy of golang.org/x/tools in GOPATH. - // If we can find it there, use that specific version. - for _, gp := range filepath.SplitList(os.Getenv("GOPATH")) { - gopathDir := filepath.Join(gp, "src", "golang.org", "x", "tools", "go", "analysis", "cmd", "vet") - if _, err := os.Stat(gopathDir); err == nil { - cmd.Dir = gopathDir - } - } - if cmd.Dir == "" { - // Otherwise, move to tmpdir and let the module loader resolve the latest version. - cmd.Dir = tmpdir - } - cmd.Stderr = os.Stderr cmd.Stdout = os.Stderr if err := cmd.Run(); err != nil { -- 2.48.1