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: vendor is ignored for packages inside $GOPATH #22712

Closed
juliandroid opened this issue Nov 14, 2017 · 3 comments
Closed

cmd/go: vendor is ignored for packages inside $GOPATH #22712

juliandroid opened this issue Nov 14, 2017 · 3 comments

Comments

@juliandroid
Copy link

What version of Go are you using (go version)?

go version go1.9.1 linux/amd64

What did you do?

gopath.tar.gz

I have the following structure:

/tmp/go/src/app$ tree -L 3 ../

../
├── app
│   ├── main.go
│   └── vendor
│       └── github.com
└── shared
    └── toml
        └── toml.go

$ echo $GOPATH
/tmp/go

When building:
/tmp/go/src/app$ go build main.go
../shared/toml/toml.go:4:9: cannot find package "github.com/BurntSushi/toml" in any of:
/usr/lib/go/src/github.com/BurntSushi/toml (from $GOROOT)
/tmp/go/src/github.com/BurntSushi/toml (from $GOPATH)

vendor/ directory contains needed package.

main.go imports "shared/toml" package which in turn uses the needed vendored package.

The only way to build main.go is by copying the same "vendor" dependency inside shared/toml/ which seems overkill and duplication.

Does the compiler ignore the vendor directory? I.e. some sort of "lexical" scope since the parsed file at the moment (shared/toml) don't have a sub-directory vendor, but the initial compilation process starts from main.go.

If that is a current limitation and not my misuse, then that means if I want to have a complete insulation from "system" $GOPATH (and use my own) and keep all dependencies (normally collected with "go dep" / dep ensure) means I have to copy that vendor directory to all $GOPATH/src/modules

What did you expect to see?

Using the vendor path for building the app and imported packages inside $GOPATH

What did you see instead?

Missing package, already available in the vendor directory

/tmp/go/src/app$ go build main.go
../shared/toml/toml.go:4:9: cannot find package "github.com/BurntSushi/toml" in any of:
/usr/lib/go/src/github.com/BurntSushi/toml (from $GOROOT)
/tmp/go/src/github.com/BurntSushi/toml (from $GOPATH)

@ianlancetaylor
Copy link
Contributor

Thanks for providing a complete test case.

Quoting https://golang.org/cmd/go:

Code below a directory named "vendor" is importable only by code in the directory tree rooted at the parent of "vendor", and only using an import path that omits the prefix up to and including the vendor element.

In this case shared/toml/toml.go is trying to import github.com/BurntSushi/toml, but that directory is only available in app/vendor, not in shared/vendor.

Closing because this is working as designed.

@juliandroid
Copy link
Author

My real case is:

company.com/protobuf-idl
site.org/app1

I have "shared" contract/interface package(s) and go applications that are using them.
Since I want to vendor my app1, I have a vendor directory inside site.org/app1, however to build app1 executable I also need to have vendor, which contains the same packages (github.com/golang/protobuf).

So, the expected behavior is to do "dep init" and "dep ensure" in each of the packages, right?

@ianlancetaylor
Copy link
Contributor

We use the issue tracker for bugs and proposals, not discussion. Let's take questions to the mailing list, where you find better answers anyhow. See https://golang.org/wiki/Questions . Thanks.

@golang golang locked and limited conversation to collaborators Nov 14, 2018
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