-
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: add EmbedFiles and EmbedPatterns #50720
Comments
Change https://golang.org/cl/379974 mentions this issue: |
I think this is reasonable and we should go forward with it. The only potential design question is whether the embeds should be guarded with their own Need flag to potentially allow for potentially doing less work in the go command. We probably should, just to be safe, even if it adds a bit of annoyance to the API. |
I'd be happy to do that. I saw in #38445 that an invariant of the packages API is that every build system should be able to produce this information. I assume EmbedFiles and EmbedPatterns are things that bazel can produce? |
Moving this to a proposal, following discussion on the associated CL: since this is an API addition, it must go through the proposal process. With that said this seems like an unambiguous improvement to me, and would be useful for many tools. I think we should do it. |
From
|
Maybe it's not as useful given that EmbedFiles contains all the files that are matched by EmbedPatterns? I personally don't have as much of a use for it, so I could drop it from the proposal. But I also don't see why not to add it.
In my experiments with |
Can |
I saw this in go/ast: https://pkg.go.dev/go/ast#CommentGroup.Text
But I did not check this out in practice. So I expect that it is not possible to get this information from the go/ast package. |
This proposal has been added to the active column of the proposals project |
I don't see much harm in including both EmbedFiles and EmbedPatterns. They are both useful and already provided by the go/build API. It would be weird to throw away the info and make the caller recompute it. One possibility would be a flag to get the patterns without the files, since getting the files is more expensive. |
@rsc Did you mean getting the content of the matching files or the getting the paths to the matching files? |
I meant just deciding which files match the patterns. That can be quite expensive because it can in general require walking around the file system looking for matches. Consider |
I don't have a lot of insight into the other implementations, but at least in the Happy to have a NeedEmbedFiles flag. (Or call it NeedEmbed and guard both EmbedFiles and EmbedPatterns behind it?) |
If we implement field based pruning in go list (#29666) then go/packages would use it based on its flags and gain the performance improvements. |
Then I'm all for the separate flag |
OK, so it sounds like we are talking about:
Does that sounds right? /cc @matloob |
@matloob, does the previous comment sound right to you? |
Yes, that sounds right. Thanks! Separate NeedEmbedFiles and NeedEmbedPatterns seems like the right thing to do. |
They are not in the comment groups as rendered by the |
Based on the discussion above, this proposal seems like a likely accept. |
Thanks Russ and @matloob. Let me know when we're ready to go and I'll pick up my CL again :) |
No change in consensus, so accepted. 🎉 |
Thanks Russ! CL should be ready for review again: https://golang.org/cl/379974 |
What version of Go are you using (
go version
)?Feature Request
x/tools/go/packages has in the
Package
struct fields for GoFiles, OtherFiles, IgnoredFiles, etc, corresponding to (I think) the output ofgo list -json <package>
.Since go:embed support was added in Go 1.16,
go list -json
has also been listing EmbedPatterns and EmbedFiles in its output. I would like for those to be exported in Package asEmbedFiles []string
andEmbedPatterns []string
if possible.The text was updated successfully, but these errors were encountered: