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: vendoring a package with the same name as a package in GOROOT leads to inconsistent imports #12172

Closed
azylman opened this issue Aug 17, 2015 · 1 comment

Comments

@azylman
Copy link

azylman commented Aug 17, 2015

go version: go 1.5rc1
architecture: linux-amd64

When you have a vendored package with the same name as a package in GOROOT (e.g. net/http), behavior is inconsistent. It seems like other packages within GOROOT get the package in GOROOT, but things not in GOROOT (e.g. your app, other vendored packages) get the vendored version.

Here's a gist: https://gist.github.com/azylman/305ad6172dd884aaaed4
In this gist, we have a vendored "net/http" and import "net/http" and can use our vendored version, but importing "net/http/httptest" or "net/http/httputil" still work

Here's a Google Group discussion for context: https://groups.google.com/forum/#!topic/golang-nuts/PFaB0hon6ug

I'm not sure what the expected behavior is - if vendoring a package that's the same as GOROOT should work or not, but I'm guessing this inconsistent behavior is not expected.

@azylman azylman changed the title cmd/go: vendoring a package with the same name as a package in GOROOT leads to inconsistent results cmd/go: vendoring a package with the same name as a package in GOROOT leads to inconsistent imports Aug 18, 2015
@rsc
Copy link
Contributor

rsc commented Oct 23, 2015

When you have a vendored package with the same name as a package in
GOROOT (e.g. net/http), behavior is inconsistent. It seems like
other packages within GOROOT get the package in GOROOT, but things
not in GOROOT (e.g. your app, other vendored packages) get the
vendored version.

This is exactly what is supposed to happen. Vendoring affects imports in the directory tree rooted just above the vendor directory. It does NOT reach out and change imports elsewhere in your program.

You can control which net/http your code uses. You cannot control which net/http other people's code uses.

In general this is a very hard problem: what if two different packages you are importing both vendored their own net/http? If the semantics were that vendoring replaced every instance in the whole binary, which one should be used? Not having those semantics avoids that question.

Quoting golang.org/s/go15vendor:

The second is that this does not attempt to solve the problem of vendoring resulting in multiple copies of a package being linked into a single binary. Sometimes having multiple copies of a library is not a problem; sometimes it is. At least for now, it doesn’t seem that the go command should be in charge of policing or solving that problem.

@rsc rsc closed this as completed Oct 23, 2015
@golang golang locked and limited conversation to collaborators Oct 24, 2016
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

3 participants