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

x/tools/go/gopackages: add Dir field to the Package struct #36730

Closed
perillo opened this issue Jan 24, 2020 · 4 comments
Closed

x/tools/go/gopackages: add Dir field to the Package struct #36730

perillo opened this issue Jan 24, 2020 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@perillo
Copy link
Contributor

perillo commented Jan 24, 2020

Currently, the Package struct does not have a Dir field, but instead there is a Dir field in the Config struct, specifying the directory in which to run the build system's query tool.

With relative queries, like . or ./... it is possible to get a relative path to a .go source file.
However with queries like fmt or golang.org/x/time/rate, the caller has no way to obtain relative file names.

This may be a problem for some tools, like my https://github.com/perillo/goprint.
Showing something like golang.org/x/time/rate ... /home/manlio/.local/lib/go/pkg/mod/golang.org/x/time@v0.0.0-20191024005414-555d28b269f0/rate/rate.go instead of golang.org/x/time/rate ... rate.go on the page top header is a bit problematic.

@gopherbot gopherbot added this to the Unreleased milestone Jan 24, 2020
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 24, 2020
@toothrot
Copy link
Contributor

/cc @ianthehat @matloob

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 24, 2020
@matloob
Copy link
Contributor

matloob commented Jan 24, 2020

We don't plan to add a Dir field to the Package struct because not all build systems have a concept of a directory for the package.

So in a sense, the concept of a relative file name to a package doesn't exist in general, for all build systems.

But I'd like to understand your example better, by asking a question to help me understand: Is golang.org/x/time/rate ... rate.go, in the format of <package path> ... <package-relative file name> ? If so, why wouldn't it work to emit <package path> ... <file base name>? It should be what you want almost all of the time. Could we do something else to make it work ?

@perillo
Copy link
Contributor Author

perillo commented Jan 25, 2020

@matloob The file base name should be fine. I did not think about it since I was fixated on using the Dir field. Thanks.

However probably I will still have to use go list directly instead of gopackages, since I may need to include the ignored files and test files in the generated document.

@matloob
Copy link
Contributor

matloob commented Jan 27, 2020

Okay, that's reasonable. I'll close this issue.

@matloob matloob closed this as completed Jan 27, 2020
@stamblerre stamblerre changed the title x/tools/go/gopackage: add Dir field to the Package struct x/tools/go/gopackages: add Dir field to the Package struct Apr 14, 2020
@golang golang locked and limited conversation to collaborators Apr 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants