The go/build package will implicitly set $GOPATH to $HOME. It skips setting an implicit GOPATH if it would set GOPATH/go to GOROOT.
def:=filepath.Join(home, "go")
ifdef==runtime.GOROOT() {
// Don't set the default GOPATH to GOROOT,// as that will trigger warnings from the go tool.return""
}
Note that the comment and the code disagree. I suspect the comment describes the intended behavior (don't set the default GOPATH to GOROOT), not the code.
Discovered when testing something with a GOROOT of ~/go:
# /usr/bin/go: All is good.
$ go test .
? github.com/neild/foo [no test files]
# ~/go/bin/go: Unhappy. Huh?
$ ~/go/bin/go test .
missing $GOPATH
# Explicitly set GOPATH=$HOME: All is good.
$ GOPATH=$HOME ~/go/bin/go test .
? github.com/neild/foo [no test files]
# This is presumably the case the code is trying to avoid: Set GOPATH=GOROOT.
$ GOPATH=$HOME/go ~/go/bin/go test .
warning: GOPATH set to GOROOT (/usr/local/google/home/dneil/go) has no effect
? github.com/neild/foo [no test files]
The text was updated successfully, but these errors were encountered:
The
go/build
package will implicitly set$GOPATH
to$HOME
. It skips setting an implicit GOPATH if it would set GOPATH/go to GOROOT.https://go.googlesource.com/go/+/master/src/go/build/build.go#272
Note that the comment and the code disagree. I suspect the comment describes the intended behavior (don't set the default GOPATH to GOROOT), not the code.
Discovered when testing something with a GOROOT of
~/go
:The text was updated successfully, but these errors were encountered: