-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/go: go generate should be more resilient to source changes #36068
Comments
/cc @bcmills @jayconrod |
@rogpeppe, it seems very odd for I'm assuming that you ran into this with a more realistic example somewhere. Can you give some more detail about the concrete case? |
In this particular case, I was writing tests for a code generator. The generator generates code in a package, and the The advantage of doing this is that I can check in the resulting test code, which serves as unit tests for the imported package used by the generated code. It also means that I can easily obtain coverage info for the code covered by the test cases. There's nothing about |
So the It still seems like the solution here belongs on the caller side: if OTOH, if the package |
I don't really see how this is so different from running
If I did that, I couldn't run the generated tests by running |
A smaller testscript that reproduces the error:
Output
|
This change allows go generate to process packages where files may disappear during code generation. See also golang#36422. Fixes golang#36068
Change https://golang.org/cl/311531 mentions this issue: |
Another solution is to put opposite build tags on the generator and the generated file. So the generated file will be excluded from building the generator. |
@nightlyone not sure how that’d help. E.g. gotd/td recently stumbled upon this issue because it puts types from Telegram’s TL schema in a separate files when generating |
This change allows go generate to process packages where files may disappear during code generation. See also golang#36422. Updates golang#36068
Just wanted to mention that we are running into the same issue in https://github.com/open-telemetry/opentelemetry-collector-contrib. The use case is to generate a file in an internal sub-package It works fine for creating new files and replacing them. But if we want to change the filename from the generator, e.g. remove
|
When
go generate
runs, it's quite likely to add and remove source files.This can result in errors which are inappropriate.
Here's a testscript command script that demonstrates the issue. It's a pared-down version of some real code:
When I run it, I see this:
That is, the second time that
go generate
runs, it fails.It seems that
go generate
is evaluating all the files when it runs, and not being resilient when they change (in this case a file changed name).Perhaps it should be silent in cases like this.
There may also be other cases where
go generate
could be quieter about errors (for example when there's a package name mismatch in files in a package, which can be caused when a package is renamed andgo generate
is called again to regenerate the new files).One possible approach might be for
go generate
to ignore any errors on files which contain the standard "DO NOT EDIT" comment.The text was updated successfully, but these errors were encountered: