New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: relative path argument should not cause search #12385

rsc opened this Issue Aug 28, 2015 · 4 comments


None yet
5 participants

rsc commented Aug 28, 2015

f$ pwd
f$ go install ./jfmt
can't load package: package cannot find package "" in any of:
    /usr/local/google/home/rsc/go/src/ (from $GOROOT)
    /usr/local/google/home/rsc/src/ (from $GOPATH)

There is no ./jfmt directory in this example. That should be the end. It should not figure out that I am in $GOPATH/src/ and go looking for in other work spaces.

@rsc rsc added this to the Go1.6 milestone Aug 28, 2015


This comment has been minimized.


dominikh commented Nov 8, 2015

I've started looking into this.

The underlying issue happens in cmd/go/pkg.go around line 1570. The code attempts to turn something like "./ioutil" into "io/ioutil". The code is problematic because when specifying a path inside GOROOT or GOPATH, go/build will set ImportPath to a plausible import path. Whether the package actually exists isn't checked.

Thus, with GOPATH=/go, ImportDir("/go/src/foo", 1) will unconditionally set ImportPath to "foo".

I am wondering whether the ./ioutil -> io/ioutil rewrite is even a useful feature and whether the logic should be fixed, or removed entirely.


This comment has been minimized.


rsc commented Nov 10, 2015

It's useful, it just shouldn't trigger a search. When you're in src/math and run go test ./rand you want to get math/rand not a relative import.


This comment has been minimized.

gopherbot commented Nov 17, 2015

CL mentions this issue.


This comment has been minimized.


rsc commented May 27, 2016

CL 16944 didn't work and was abandoned. (Writing this because I click on it every time I view this issue.) The actual fix is not obvious.

@rsc rsc modified the milestones: Go1.8, Go1.7 May 27, 2016

@rsc rsc modified the milestones: Go1.9Early, Go1.8 Oct 21, 2016

@bradfitz bradfitz modified the milestones: Go1.10, Go1.9Early May 3, 2017

@rsc rsc modified the milestones: Go1.10, Go1.11 Dec 1, 2017

@gopherbot gopherbot modified the milestones: Go1.11, Unplanned May 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment