Commit 392d5feb authored by Jonathan Nieder's avatar Jonathan Nieder Committed by Russ Cox

go/build: allow ~ in middle of path, just not at beginning

CL 7799045 relaxed the restriction in cmd/go on ~ in GOPATH
to allow paths with ~ in the middle while continuing to
protect against the common mistake of using GOPATH='~/home'
instead of GOPATH=~/home.  Unfortunately go/build still
filters these paths out:

        $ GOPATH=/tmp/test~ing go build
        test.go:22:2: cannot find package "test" in any of:
                /usr/lib/go/test (from $GOROOT)
                ($GOPATH not set)

So relax the requirement in go/build, too.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7826043
parent b12c299a
...@@ -212,8 +212,8 @@ func (ctxt *Context) gopath() []string { ...@@ -212,8 +212,8 @@ func (ctxt *Context) gopath() []string {
// Do not get confused by this common mistake. // Do not get confused by this common mistake.
continue continue
} }
if strings.Contains(p, "~") && runtime.GOOS != "windows" { if strings.HasPrefix(p, "~") {
// Path segments containing ~ on Unix are almost always // Path segments starting with ~ on Unix are almost always
// users who have incorrectly quoted ~ while setting GOPATH, // users who have incorrectly quoted ~ while setting GOPATH,
// preventing it from expanding to $HOME. // preventing it from expanding to $HOME.
// The situation is made more confusing by the fact that // The situation is made more confusing by the fact that
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment