From 1dbffd0798679c0c6b466e620725135944cfddea Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 9 May 2017 12:41:43 -0700 Subject: [PATCH] cmd/toolstash: use "go env GOROOT" instead of runtime.GOROOT() The GOROOT of whatever tool build toolstash is irrelevant. We want the goroot of the "go" command we're testing. Change-Id: Ie7e11c74cb445ea694d88c743dbc239a55d47864 Reviewed-on: https://go-review.googlesource.com/43033 Run-TryBot: Keith Randall Reviewed-by: Josh Bleecher Snyder TryBot-Result: Gobot Gobot --- cmd/toolstash/main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/toolstash/main.go b/cmd/toolstash/main.go index e5d226d0ac..0b4cbc50e7 100644 --- a/cmd/toolstash/main.go +++ b/cmd/toolstash/main.go @@ -156,6 +156,7 @@ func usage() { } var ( + goCmd = flag.String("go", "go", "path to \"go\" command") norun = flag.Bool("n", false, "print but do not run commands") verbose = flag.Bool("v", false, "print commands being run") cmp = flag.Bool("cmp", false, "compare tool object files") @@ -199,7 +200,11 @@ func main() { usage() } - goroot = runtime.GOROOT() + s, err := exec.Command(*goCmd, "env", "GOROOT").CombinedOutput() + if err != nil { + log.Fatalf("%s env GOROOT: %v", *goCmd, err) + } + goroot = strings.TrimSpace(string(s)) toolDir = filepath.Join(goroot, fmt.Sprintf("pkg/tool/%s_%s", runtime.GOOS, runtime.GOARCH)) stashDir = filepath.Join(goroot, "pkg/toolstash") @@ -248,7 +253,7 @@ func main() { xcmd.Stdin = os.Stdin xcmd.Stdout = os.Stdout xcmd.Stderr = os.Stderr - err := xcmd.Run() + err = xcmd.Run() if err != nil { log.Fatal(err) }