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: go list and rooted paths #14177

Closed
perillo opened this issue Feb 1, 2016 · 14 comments
Closed

cmd/go: go list and rooted paths #14177

perillo opened this issue Feb 1, 2016 · 14 comments

Comments

@perillo
Copy link
Contributor

perillo commented Feb 1, 2016

go help packages says:

An import path that is a rooted path or that begins with
a . or .. element is interpreted as a file system path and
denotes the package in that directory.

The way I interpret it is that

go list /home/manlio/go/github/perillo/goprint

should list the goprint package; however go list reports an error:

can't load package: package /home/manlio/go/src/github.com/perillo/goprint: import "/home/manlio/go/src/github.com/perillo/goprint": cannot import absolute path
@bradfitz bradfitz added this to the Unplanned milestone Feb 1, 2016
@bradfitz bradfitz changed the title go list and rooted paths cmd/go: go list and rooted paths Feb 1, 2016
@bradfitz
Copy link
Contributor

bradfitz commented Feb 1, 2016

/cc @rsc @robpike for words.

@robpike
Copy link
Contributor

robpike commented Feb 1, 2016

I don't think the problem is wordsmithing, it's that the go tool doesn't accept rooted paths.

@adg
Copy link
Contributor

adg commented Feb 8, 2016

Yeah agree, it's a go tool bug.

@yaegashi
Copy link

I'm searching for the reason why go tool doesn't accept absolute (rooted?) import paths. So far I couldn't find any rationale for that behavior, and just found this issue. Is this actually a bug of go tool? It affects other actions like install, build, etc.

$ tree $GOPATH
/home/yaegashi/go
└── src
    └── hello
        └── hello.go

2 directories, 1 file
$ cd $GOPATH
$ rm -rf bin && go install -v ./src/hello             
hello
$ rm -rf bin && go install -v ./src/...
hello
$ rm -rf bin && go install -v $GOPATH/src/hello
can't load package: package /home/yaegashi/go/src/hello: import "/home/yaegashi/go/src/hello": cannot import absolute path
$ rm -rf bin && go install -v $GOPATH/src/...
warning: "/home/yaegashi/go/src/..." matched no packages

@adg
Copy link
Contributor

adg commented Apr 18, 2016

Well, import declarations in files cannot use rooted paths, and the go tool takes import paths on the command line, so that is at least consistent.

@jeffreydwalter
Copy link

jeffreydwalter commented Aug 7, 2017

Is this going to get fixed?

$ go list ./src/blah/pkg/...
blah/pkg/test0
blah/pkg/test1
blah/pkg/test2

$ go list src/blah/pkg/...
warning: "src/blah/pkg/..." matched no packages

kinda sucks.

@ianlancetaylor
Copy link
Contributor

@jeffreydwalter I think that is a different problem. go list will look for packages in GOPATH unless explicitly told otherwise.

@jeffreydwalter
Copy link

@ianlancetaylor, I don't really follow.

How does $GOPATH come into play in my example?

./foo/... is a relative path, just like foo/..., isn't it? I assume the issue is that the path that starts with . is being treated as a relative path and the one without is not, but that seems wrong to me.

ls ./foo/ and ls foo/ are functionally equivalent (both relative paths) in shell parlance, I guess I expect that go list would treat them the same.

@dominikh
Copy link
Member

dominikh commented Aug 8, 2017

go is not ls. The arguments to go list are package paths, which may be relative (starting with a ./), or absolute. Absolute paths are looked up in GOPATH. Package paths are not POSIX paths.

@jeffreydwalter
Copy link

@dominikh, thanks for the explanation. I just read the go help packages documentation and what you're saying now makes sense, although I'd still argue that the go help list and go list documentation should make it more clear, instead of burying it in go help packages.

@matloob
Copy link
Contributor

matloob commented Jul 30, 2018

cc @bcmills

I vote for fixing this rather than changing the documentation. My conception of go list is not that it takes package paths on the command line, but patterns that resolve to package paths. For instance, ./foo/... is not a package path but a pattern that resolves to all the subpackages of foo. Similarly, in my model at least, an absolute path should resolve to the package in the given directory.

Of course that package should either be contained in GOPATH, GOROOT, or in the transitive set of modules depended on by the current module.

@matloob
Copy link
Contributor

matloob commented Jul 30, 2018

cc @suzmue Thanks!

@rsc
Copy link
Contributor

rsc commented Jul 31, 2018

Fixed by golang.org/cl/126715.

@gopherbot
Copy link

Change https://golang.org/cl/126715 mentions this issue: cmd/go: allow list of absolute directory path

@golang golang locked and limited conversation to collaborators Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests