-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add best pratice for how to check in generated files #16405
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
Add best pratice for how to check in generated files #16405
Conversation
Best practice here is to have a test that checks if the generated file matches, but that wasn't documented anywhere.
|
r? @weihanglo rustbot has assigned @weihanglo. Use |
| * Sometimes, projects want to check in a generated file, and treat it as | ||
| source code. However, in this case, the file shouldn't be generated from | ||
| `build.rs`. Instead, have a test or similar which checks that the file | ||
| precisely matches the generated version *and fails if the result doesn't | ||
| match*, and run that test as part of your CI. (The test can generate a | ||
| temporary file to compare to, and if you want to update the generated file, | ||
| you can replace the checked-in file with that temporary file.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-blocking: should we point people to libraries like expect-test ad snapbox for doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to point people to snapbox and insta and expect-test, yes.
Update cargo submodule 13 commits in e91b2baa632c0c7e84216c91ecfe107c37d887c1..3861f60f6b58f57524c0e7aab1f5c1ad83e35409 2025-12-13 16:29:21 +0000 to 2025-12-19 21:53:33 +0000 - fix(sbom): Don't set CARGO_SBOM_PATH when empty (like stable) (rust-lang/cargo#16419) - chore(ci): report-timings to upload HTML report (rust-lang/cargo#16416) - fix(report): get the same feature parity of `--timings` (rust-lang/cargo#16414) - fix(docs): Document the only possible values for DEBUG in build scripts (rust-lang/cargo#16413) - fix(log): emit fingeprint log also for no-rebuild unit (rust-lang/cargo#16408) - Fix link to `doc_cfg` docs in cargo book (rust-lang/cargo#16404) - Add best pratice for how to check in generated files (rust-lang/cargo#16405) - test: Use a larger default term width (rust-lang/cargo#16403) - Document more services and permissions of the cargo team (rust-lang/cargo#16402) - fix(new): Improve quality of package name error messages (rust-lang/cargo#16398) - feat(log): add more log events (rust-lang/cargo#16390) - chore: bump to 0.95.0; update changelog (rust-lang/cargo#16395) - Cache submodule into git db (rust-lang/cargo#16246) r? ghost
Update cargo submodule 13 commits in e91b2baa632c0c7e84216c91ecfe107c37d887c1..3861f60f6b58f57524c0e7aab1f5c1ad83e35409 2025-12-13 16:29:21 +0000 to 2025-12-19 21:53:33 +0000 - fix(sbom): Don't set CARGO_SBOM_PATH when empty (like stable) (rust-lang/cargo#16419) - chore(ci): report-timings to upload HTML report (rust-lang/cargo#16416) - fix(report): get the same feature parity of `--timings` (rust-lang/cargo#16414) - fix(docs): Document the only possible values for DEBUG in build scripts (rust-lang/cargo#16413) - fix(log): emit fingeprint log also for no-rebuild unit (rust-lang/cargo#16408) - Fix link to `doc_cfg` docs in cargo book (rust-lang/cargo#16404) - Add best pratice for how to check in generated files (rust-lang/cargo#16405) - test: Use a larger default term width (rust-lang/cargo#16403) - Document more services and permissions of the cargo team (rust-lang/cargo#16402) - fix(new): Improve quality of package name error messages (rust-lang/cargo#16398) - feat(log): add more log events (rust-lang/cargo#16390) - chore: bump to 0.95.0; update changelog (rust-lang/cargo#16395) - Cache submodule into git db (rust-lang/cargo#16246) r? ghost
Best practice here is to have a test that checks if the generated file
matches, but that wasn't documented anywhere.