]> Cypherpunks repositories - gostls13.git/commit
cmd/go: use os.Executable to find GOROOT
authorDavid Crawshaw <crawshaw@golang.org>
Wed, 3 May 2017 18:46:28 +0000 (14:46 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Thu, 4 May 2017 13:23:23 +0000 (13:23 +0000)
commitb8c7fddd58432b6cbe12af221d275935a1ffc8f0
tree5fa88a04d1cbae4b9e141a28ef13bdb9c68f3848
parentec0ee7d35737ef137175e92d563c8c4315820204
cmd/go: use os.Executable to find GOROOT

Before this change, building a GOROOT using make.bash, and then
moving the entire to a new path confused the go tool. Correct
operation of the go tool under these conditions required either
running make.bash again (not always possible if the new location
was owned by a different system user) or setting the GOROOT
environment variable. Setting GOROOT is unfortunate and
discouraged, as it makes it too easy to use the go tool from
one GOROOT and the compiler from another GOROOT.

With this change, the go tool finds its GOROOT relative to its
own location, using os.Executable. It checks it is in a GOROOT
by searching for the GOROOT/pkg/tool directory, to avoid two
plausible situations:

ln -s $GOROOT/bin/go /usr/local/bin/go

and

PATH=$HOME/bin:$PATH
GOPATH=$HOME
ln -s $GOROOT/bin/go $HOME/bin/go

Additionally, if the current executable path is not in a GOROOT,
the tool will follow any symlinks for the executable and check
to see if its original path is a GOROOT.

Fixes #18678

Change-Id: I151d7d449d213164f98193cc176b616849e6332c
Reviewed-on: https://go-review.googlesource.com/42533
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/cfg/cfg.go