Wire should not put a go:generate line into wire_gen.go
Is your feature request related to a problem? Please describe.
Wire puts the following line into the generated file:
//go:generate wire
We have a lot of generated files (many megabytes of total size), which is why we don't commit files to git and just require a simple go generate ./... to be run by users or before tests are run.
We define all commands in //go:generate ... comments which are needed to compile the program, so that step is already required in order to compile the program.
Since wire is the only one generating a new //go:generate line into the already generated file, when you run go generate ./... again, the wire code generation gets triggered twice. While this is not the worst thing in the world, I think it would be great if this could be at least configured.
Describe the solution you'd like
Either don't generate this line at all, or add a CLI configuration option --no-go-generate could be introduced, which if present skips this line:
https://github.com/google/wire/blob/f285c073b52078f165ca19f3ceb192f0f50f3934/internal/wire/wire.go#L253
Describe alternatives you've considered
- removing the line with sed
This is unacceptable, since sed has different implementations on different operating systems. It's not worth the trouble and just results in bugs and weird behaviour.
- run
go generate -tags wireinject ./...
This will ignore the generated code because the generated wire_gen.go has a !wireinject flag. However, everyone working on a project needs to run this command.
- ignore
Ignore this, and just let the wire codeine run twice. It's not too slow so it's ok, but it doesn't feel good.
Additional context
https://github.com/google/wire/issues/106 requested a similar feature but for different reasons.
I agree.
This requires github.com/google/wire in go.mod but I think everyone not always manage developer tools in go.mod.(like tools.go)