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/cmd/stringer: replicate build tags in output file #47179

Open
josharian opened this issue Jul 13, 2021 · 1 comment
Open

x/tools/cmd/stringer: replicate build tags in output file #47179

josharian opened this issue Jul 13, 2021 · 1 comment
Labels
FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@josharian
Copy link
Contributor

We use stringer in some platform-specific code. In order to keep the code compiling, we need the code that stringer outputs to be protected by a build tag.

I propose that stringer replicates into its output any build tags present in the file in which the type is defined. The type will only be defined when those build tags are present, so not doing this replication generates broken code.

We are currently manually editing the code after generation, which breaks our attempt to have CI check that go generate has been run. We put in this CI check after failure to run go generate caused bugs. Alas, not all code generation is amenable to tricks making such a CI check unnecessary.

Alternatives to this suggestion:

  • Add a -header flag that accepts text to be used. (Maybe also a -headerfile flag?) This would be useful for build tags as well as license header injection, but it requires manual maintenance.
  • Write a separate utility to inject headers. go generate doesn't define the order in which the generate commands run, and go generate supports running only a subset of generation commands, so for best effect this would have to be a single generate line, like //go:generate injectheader -header "some build tag" -run stringer -type=T, which is a bit of a mouthful.

These alternatives might be independently useful, but it seems to me that getting build tags right automatically is a good place to start.

cc @robpike @bradfitz

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jul 13, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jul 13, 2021
@cherrymui cherrymui added FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Jul 13, 2021
@cherrymui
Copy link
Member

cc @mvdan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants