Skip to content
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

Open
rsc opened this issue Aug 28, 2015 · 5 comments

Comments

@rsc
Copy link
Contributor

commented Aug 28, 2015

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

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

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

@dominikh

This comment has been minimized.

Copy link
Member

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.

@rsc

This comment has been minimized.

Copy link
Contributor Author

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.

@gopherbot

This comment has been minimized.

Copy link

commented Nov 17, 2015

CL https://golang.org/cl/16944 mentions this issue.

@rsc

This comment has been minimized.

Copy link
Contributor Author

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

@bcmills

This comment has been minimized.

Copy link
Member

commented Jan 23, 2019

This is fixed in module mode, but not in GOPATH mode.

_gopath/src/example.com$ go env GOPATH
/tmp/tmp.VrFzeLPnb6/_gopath:/tmp/tmp.Nz3gatY2ZI:/tmp/tmp.MZ8FiGUB8Q

_gopath/src/example.com$ GO111MODULE=off go install ./aoeuhtns
can't load package: package example.com/aoeuhtns: cannot find package "example.com/aoeuhtns" in any of:
        /usr/local/google/home/bcmills/go/src/example.com/aoeuhtns (from $GOROOT)
        /tmp/tmp.VrFzeLPnb6/_gopath/src/example.com/aoeuhtns (from $GOPATH)
        /tmp/tmp.Nz3gatY2ZI/src/example.com/aoeuhtns
        /tmp/tmp.MZ8FiGUB8Q/src/example.com/aoeuhtns

_gopath/src/example.com$ GO111MODULE=on go install ./aoeuhtns
can't load package: package example.com/aoeuhtns: unknown import path "example.com/aoeuhtns": cannot find package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.