-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: relative "files=" query path are not relative to Config.Dir #65965
Comments
Most filenames in the go/packages API are specified as absolute, and relative paths are (implicitly) relative to the application's working directory, as usual. The documentation for Config.Dir says only that it is the working directory of the query tool, not the base for all relative paths in the API. So I think this is really a problem of documentation, and that we should clarify that file= patterns follow the usual convention. |
I think what makes it confusing and non-intuitive is that the base of the
I would expect a consistent behavior in all these cases. The current directory Documenting this different behavior would help a lot. I think making it |
Add a testcase for the gosource resolver that specifies as file query pattern cmd/**/main.go and runs the goresolver from a different directory then the test (aka app dir) directory. This testcase currently fails because the relative file query patterns are not relative to the specified working dir (app dir) but to the cwd (golang/go#65965). The existing testcase query_main_file is refactored for this purpose The test_config.json files got a new field WorkingDir, the $WORKDIR test_config.json variable is renamed to $TESTDIR.
Add a testcase for the gosource resolver that specifies as file query pattern cmd/**/main.go and runs the goresolver from a different directory then the test (aka app dir) directory. This testcase currently fails because the relative file query patterns are not relative to the specified working dir (app dir) but to the cwd (golang/go#65965). The existing testcase query_main_file is refactored for this purpose The test_config.json files got a new field WorkingDir, the $WORKDIR test_config.json variable is renamed to $TESTDIR.
Go version
go version go1.22.0 linux/amd64
Output of
go env
in your module/workspace:What did you do?
packages.Load accepts file paths via the
file=
pattern.The *packages.Config parameter has a
Dir
field that is documented as:Therefore I expect that relative file query paths are relative to cfg.Dir.
I wrote a small tool to reproduce the issue.
The first command-line argument is used as cfg.Dir parameter, the second command line argument is passed as file= query pattern.
Tool + package to test the query can be found in: https://github.com/fho/golist_rel_file_query
What did you see happen?
When a relative path is specified as
file=
pattern, the path is made absolute to the current working directory instead of to cfg.Dir.The go list query results in 0 packages:
What did you expect to see?
When a relative path is specified as
file=
pattern, the path is made absolute to thecfg.Dir
field.Same results for running in the directory
/tmp/repro
:and running in the directory
/tmp/repro/oneprinter
This might be the cause for: #58726
Thanks to @barash-simplesurance for discovering the issue.
The text was updated successfully, but these errors were encountered: