]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: set $GOROOT during 'go tool' invocations
authorRuss Cox <rsc@golang.org>
Sat, 17 Jan 2015 03:15:01 +0000 (22:15 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 19 Jan 2015 02:19:01 +0000 (02:19 +0000)
cmd/dist now requires $GOROOT to be set explicitly.
Set it when invoking via 'go tool dist' so that users are unaffected.

Also, change go tool -n to drop trailing space in output
for 'go tool -n <anything>'.

Change-Id: I9b2c020e0a2f3fa7c9c339fadcc22cc5b6cb7cac
Reviewed-on: https://go-review.googlesource.com/3011
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/go/tool.go

index 3f11c3e3d44a4c9cb70d56749f72570c7c4a3324..dc8d34ba089738b10c33882deb357bcd43df99b6 100644 (file)
@@ -92,7 +92,11 @@ func runTool(cmd *Command, args []string) {
                return
        }
        if toolN {
-               fmt.Printf("%s %s\n", toolPath, strings.Join(args[1:], " "))
+               cmd := toolPath
+               if len(args) > 1 {
+                       cmd += " " + strings.Join(args[1:], " ")
+               }
+               fmt.Printf("%s\n", cmd)
                return
        }
        toolCmd := &exec.Cmd{
@@ -101,6 +105,8 @@ func runTool(cmd *Command, args []string) {
                Stdin:  os.Stdin,
                Stdout: os.Stdout,
                Stderr: os.Stderr,
+               // Set $GOROOT, mainly for go tool dist.
+               Env: mergeEnvLists([]string{"GOROOT=" + goroot}, os.Environ()),
        }
        err := toolCmd.Run()
        if err != nil {