-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
x/tools/go/packages: vendor is not searched in GOPATH mode #30289
Comments
I presume you're running the tool with Also, see https://golang.org/cmd/go/#hdr-Maintaining_module_requirements; Also see #30240, which I believe would make this better and automatic in 1.13. |
No, I'm using Note that in the test I am importing the vendored package directly to prove the go toolchain is happy to resolve this path, its only x/packages that cant find it. |
Interesting - I'm not sure why this would happen, as /cc @matloob @ianthehat |
interestingly this is ok
which is consistent with go build
|
If I add a
So I really don't know where the bug is. Seems to me like |
Ah, I think I'm finally catching up - you can't do I think From https://golang.org/cmd/go/#hdr-Vendor_Directories:
So it seems to me like this is by design; vendor is only meant to satisfy dependencies. Perhaps this will all work better in module mode with the new vendor folder; I'm not sure. /cc @bcmills |
I think that dates back to a bunch of fixes to prevent tools that didn't know about vendoring from accidentally running across all of the vendored code. Hiding it from go list makes sense for the same reason. I don't think this logic should be applied to x/packages, its a new module conceived well after vendoring was added, and its purpose is very different. x/loader used to check vendor, and x/packages checks the module path for dependencies, vendor search seems like a large omision here. At the very least it should have a flag that mirrors ImportMode IgnoreVendor in build. |
Hello @vektah, this is working as intended. go/packages defers to the build system's (in this case, go build's and go list's) understanding of patterns you supply to it. So in your case, go/packages understands packages as go list does. When run in GOPATH mode, go list's output is independent of the directory it's run in (with one exception below). And the way go list is specified in GOPATH mode, there's no way to supply which package you're "importing" a package from. Because we can't specify the importer of a package, go list has no way of knowing which vendor directories to consult to resolve a package. The exception is that you can specify relative and absolute directory paths to go list. And as you noticed you can provide the qualified package paths pointing into the vendor directories. But it doesn't sound like either of those would solve your problem. If you're trying to find a vendored package by its import path, your best bet is to do a deps query of an importer and look through those deps to find the package that you need. |
Ok, that's a little disappointing. What is the intended use case for packages? Maybe I've misunderstood this to be a replacement for x/loader, because x/loader was not going to receive go modules updates? I think not having a viable successor to X/loader is a big contributer to #24661
I can't really do that, the code doesn't exist yet (this is for a codegen tool). I guess I could generate a new file in the right dir with a a bunch of _ imports, but that seems like a lot of work. I might end up having to reproduce the is vendoring check and call go build directly for package resolution, before handing off to packages. |
We do plan for go/packages to be a viable successor to loader, but it can't have all the features loader had because we want it both to be more correct and to be compatible with different build systems. I'd like to know more about your use case to see if there's some other way for your tool to get the information it needs through the go/packages interface. I'm especially interested in how the vendored package name is provided to go/packages (by the user, by a codegen comment, is it created by the code generator?), and what the vendored package's relation is to the generated code. If you'd like, I'd be able to meet via VC to discuss. |
Its a code generator that takes some graphql schema and config that maps it to go types to bridge between the two type systems. There are a heap of builtin graphql types like Int and String that are implemented in gqlgen, so when searching for those types it needs to find them in vendor. There are also often things like UUIDs and api types that are implemented in external libraries and referenced like this. Its complicated, but if that isn't really clear I'm happy to jump on a call. |
Are those types vendored into gqlgen itself? If so, can you use the "fully-qualified" package path to load the package? If not, where is it vendored? |
Those ones are, but they arent all defined by gqlgen, gqlgen is just adding its default implementations to config. End users can also refer directly to other external dependencies, eg well known protobuffer types and these full import paths shouldnt be leaking out. For now we are now converting the standard import path from users to these full paths by calling build.Import before passing it off to x/packages. |
Okay, I think this is a case of "working as intended; unfortunate". go list doesn't provide a way to look up that information, so we can't support it in go/packages. I think the workaround is reasonable for now, until everyone moves over to modules... |
x/tools/go/pacakges does not search inside vendor. Work around by using build.Import first to find the package in vendor. See golang/go#30289
x/tools/go/packages does not search inside vendor. Work around by using build.Import first to find the package in vendor. See golang/go#30289
Closing as working as intended then |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Reproducable on 1.12-rc1
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Trying to load a package using x/tools/go/packages doesn't seem to search vendor directories.
For your convenience this code can be fetched from https://github.com/vektah/packages-vendor-test
packages_test.go
vendor/github.com/external/tool/tool.go
What did you expect to see?
What did you see instead?
This is hurting go modules adoption in http://github.com/99designs/gqlgen, Ideally I should be able to switch to packages to get modules support without losing support for vendor.
The text was updated successfully, but these errors were encountered: