-
Notifications
You must be signed in to change notification settings - Fork 18k
Proposal: cmd/go: scan Go assembly files for go:generate directives #25737
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
Comments
So in a sentence, the proposal is to also look for “go:generate” comments in Go assembly files? |
Yes. But also in all other source files that can be part of a Go package, which would include |
I think it should be in Go files only, since the go:generate syntax is actually a form of Go comment. If you want to generate something in another file, check in a Go file called generate.go that contains nothing but a package clause and various go:generate commands. |
True, although to push back a bit, Go assembly is Go-specific, and the comment form is identical. (I'm personally a bit less clear about And part of the reason that go:generate comments may be located anywhere is that the go:generate comment can be placed somewhere semantically appropriate, which seems just as relevant to assembly as Go. |
I'm not opposed to looking at .s files, but I'd draw the line there. |
The The only difference is that
To give some numbers for build constraint comments in this git repository:
On one hand, yes, only adding support for assembly files would be a step forward. On the other, it wouldn't solve my issue completely.
Like Josh said, it's all about keeping the directives in the right places. That makes them much easier to write, find, and maintain. If one is forced to put a single generate directive per package that uses this generator, some problems arise, such as:
I'll grant that none of these are dealbreakers, but they do make |
I've changed my mind about the generator after all, so I'm going to use separate generate directives. So, as far as I am concerned, I'm happy if this proposal only covers assembly files. Extending the rules to apply to other source files can be done as another proposal building on this one. I'm going to edit the title, but I'm going to leave the original post untouched, to leave the discussion untouched. |
Especially given the last comment, this doesn't seem like a necessary feature. While occasionally it might be nice to put a go:generate comment in an assembler file, they can always be put in a corresponding Go file, and it doesn't seem like a common problem in any case. Supporting go:generate comments in assembler file invites the question of why they are not supported in other files. Supporting them only in Go files is easy to explain. Proposal declined -- iant for @golang/proposal-review |
go help generate
shows:It seems clear that
go generate
only scans Go files by design, as can be seen by the first paragraph. However, it seems like the tool could support other source files, such as assembly files, just fine - since it reads lines, and doesn't parse Go source code.In particular, I need this for
x/tools/cmd/buildtags
, a build tag line generator I'm trying to write to solve #25348. The idea is that the same files that need the build tags would containgo:generate
files to generate them. Which works great for Go files, but not assembly files.The alternatives are all a bit hacky - such as forcing the user to use one single
go:generate
line in a Go file per package, separate from the build tags, or to have every invocation of the generator generate all the files in its package.I can't think of any downside to doing this. Since the line prefix contains the keyword
go
, I doubt this will cause false positives with other languages or within strings in those other files.Another point in this proposal's favor is that we already scan all source files for build constraints, so there's already some precedent:
/cc @myitcv @josharian
The text was updated successfully, but these errors were encountered: