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 <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/cmd/toolstash/main.go b/cmd/toolstash/main.go
index e5d226d..0b4cbc5 100644
--- a/cmd/toolstash/main.go
+++ b/cmd/toolstash/main.go
@@ -156,6 +156,7 @@
 }
 
 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 @@
 		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 @@
 	xcmd.Stdin = os.Stdin
 	xcmd.Stdout = os.Stdout
 	xcmd.Stderr = os.Stderr
-	err := xcmd.Run()
+	err = xcmd.Run()
 	if err != nil {
 		log.Fatal(err)
 	}