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/loader: working directory affects resolution of vendored imports #16580
Comments
I've been able to fix this by setting Cwd to "." in the loader.Config, which seems to work by disabling some parts of the loader package which I don't entirely understand. I traced usage of loader.Config.Cwd through the golang.org/x/tools/go/loader package and found a somewhat relevant TODO, though it still doesn't explain what's going on. It looks like this issue is less about the /cc @adonovan |
CL https://golang.org/cl/29446 mentions this issue. |
While this is annoying, I'm not sure that it's really a bug. Half of the behavior (now fixed) is due to #17247, and the other half is due to the loader drawing a distinction between package "bar" and package "foo/vendor/bar". That's an annoying distinction when an eg rewrite causes a project to depend on a package for the first time, but it's not an incorrect one. |
The meaning of that TODO is that the package's directory (for vendoring purposes) should be the parent directory of its files, not the current directory. This logic is only invoked for xtest packages (of which there are none in your example) and for "created" (not "imported") packages such as the one containing template.go. I would expect that the loader resolves template.go's imports relative to the working directory, so if you run eg beneath vendor, you'll get a different result. That's clearly a vendoring bug in go/loader that I need to fix. I am surprised that using "." instead of Cwd changes the behavior at all, though. |
CL https://golang.org/cl/33589 mentions this issue. |
CL https://golang.org/cl/33673 mentions this issue. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.7rc4, with golang/tools@9e74590
What operating system and processor architecture are you using (
go env
)?darwin/amd64
What did you do?
I have an
eg
template that replaces calls to a function in one package ("dep1" below) with calls to a similar function in a second package ("dep2"). I raneg
with the template in a repo with a vendor directory that includes only the first package.What did you expect to see?
I expected
eg
to successfully run, updating the function call if present.What did you see instead?
The
eg
invocation fails when my current working directory is in the directory containing the vendor directory, or a subdirectory of it. The invocation succeeds if Icd
to anywhere else.Here are the contents of the GOPATH where I've reproduced the issue:
./src/dep1/dep1.go:
./src/dep2/dep2.go:
./src/prog/vendor/dep1/dep1.go:
./src/prog/main.go:
./src/prog/tmpl.go:
The text was updated successfully, but these errors were encountered: