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

proposal: go/build: add API to return embed patterns #52245

Open
ianlancetaylor opened this issue Apr 8, 2022 · 5 comments
Open

proposal: go/build: add API to return embed patterns #52245

ianlancetaylor opened this issue Apr 8, 2022 · 5 comments

Comments

@ianlancetaylor
Copy link
Contributor

This is similar to #52222.

While most Go programmers use the go tool, there are alternative build systems such as Bazel. In order to build existing Go code, those build systems have to analyze go:embed directives in the same way as the go tool does. This can in principle be done by parsing the file and looking at the comments, but this permits unanticipated deviations from what the go tool does. The go/build package already contains the code that does this for the go tool, but it is not exposed in a usable form; it is only exposed as part of creating a go/build.Package, but that assumes that directory layout used by the go tool but not by Bazel.

I propose that we add a new exported method to go/build similar to a subset of the existing readGoInfo function.

// EmbedPatterns returns the patterns for all go:embed directives found in the Go file read from f.
// If f does not import the "embed" package, EmbedPatterns will not return any patterns.
func EmbedPatterns(f io.Reader) []string

Note that this API doesn't return the locations of the go:embed patterns. I think that is OK in practice because it's easy for the developer to search for the relevant go:embed directive if there is an error locating the files. But if it seems appropriate we could add offset/line/column information to the results.

@ianlancetaylor ianlancetaylor added this to the Proposal milestone Apr 8, 2022
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Apr 8, 2022
@rsc
Copy link
Contributor

rsc commented Apr 13, 2022

/cc @matloob

@rsc
Copy link
Contributor

rsc commented Apr 13, 2022

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc rsc moved this from Incoming to Active in Proposals (old) Apr 13, 2022
@rsc
Copy link
Contributor

rsc commented May 4, 2022

Waiting on @matloob to figure out an API proposal that covers both this and #52222.

@rsc
Copy link
Contributor

rsc commented May 18, 2022

Let's put this on hold for an updated API proposal.

@rsc
Copy link
Contributor

rsc commented May 18, 2022

Placed on hold.
— rsc for the proposal review group

@rsc rsc moved this from Active to Hold in Proposals (old) May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Hold
Development

No branches or pull requests

2 participants