Repository navigation
buffa-build: add Config::exclude_package knob - #383
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
[claude code] Thanks, this is the right shape: one Rebase. Silent no-op. Tests for the two claims the PR makes. Nothing exercises the "before context build" ordering: a test with Validation timing and message. A malformed entry currently fails inside Docs. The build.rs Smaller: the three Happy to re-review as soon as it's pushed; this is on the 0.9.2 list. |
Expose the package-filtering capability that protoc-gen-buffa already had as a first-class Config builder method on buffa-build. Closes anthropics#293. Key changes: - buffa-codegen: add `CodeGenConfig::exclude_packages: Vec<String>` and move filtering into `generate_with_diagnostics`, called before building the codegen context so that WKT extern-path auto-injection and other context decisions see the already-filtered file list. Normalization (leading-dot strip, validation) is routed through the existing `normalize_exclude_package`, removing the inline duplicate. - buffa-build: add `Config::exclude_package(impl Into<String>) -> Self`, storing the raw value for deferred normalization and validation inside `generate_with_diagnostics` / `compile()`. - protoc-gen-buffa: remove `filter_excluded_files` and the separate `PluginConfig::exclude_packages` field; push directly into `codegen.exclude_packages` so a single code path handles all callers. - docs/guide.md: correct the statement that `exclude_package` is a plugin-only option.
- Add CodeGenWarning::ExcludePackageMatchedNothing { package }, emitted
when an exclude_packages entry matches no proto package in the full
descriptor set (typo or stale entry); buffa-build forwards it to
cargo:warning= automatically.
- Add test pinning the "filter before context build" ordering: excluding
google.protobuf while a kept file holds a Timestamp field must produce
the ::buffa_types extern path, not a dangling local path.
- Add test for ExcludePackageMatchedNothing warning (typo'd package
name produces a warning rather than a silent no-op).
- Rebase on main (picks up anthropics#352 and the shared_descriptor_pool PRs);
resolve docs/guide.md conflict keeping anthropics#352's ExcludedPackageFieldRef
warning sentence and replacing only the "plugin-only" clause.
- Add .exclude_package(pkg) row to the buffa-build Config table in
docs/guide.md.
d72433f to
b506a3c
Compare
|
Thanks for the thorough review — all points addressed in the latest push: Rebase — Rebased on main; the Silent no-op — Added Tests — Added Validation timing / error message — Docs — Added The smaller items ( |
…sage, test compile() end to end - buffa-build rejects malformed entries at the top of compile(), ahead of protoc, with the normalizer's own message; codegen forwards that message instead of re-wording it - end-to-end compile() test through a synthetic descriptor set: the excluded package produces no module and no include entry; a second test pins that validation runs before any input is read - the before-context-build test asserts the exact extern path and the absence of a local one, instead of a disjunct any buffa_types mention satisfies - docs: leading-dot rule stated once, ExcludedPackageFieldRef remedy names .exclude_package(), the guide row says what puts an excluded file in files(), fragment mentions the new warning
|
[claude code] Thanks for the second round. The warning, the guide rebase, and the before-context-build test were in, but two items from the list were not: validation still ran after protoc (the reply said it used |
Summary
Closes #293.
protoc-gen-buffahas hadexclude_package=buf.validatesince v0.6.0, butbuffa-buildusers had no equivalent — they could only approximate it by omitting files from the.files()list, which doesn't help when directory globbing or transitive descriptor resolution pulls in option-only packages (e.g.buf/validate/validate.protovia--include_imports).This PR:
Config::exclude_package("buf.validate")tobuffa-build(a leading dot is accepted and stripped, matching the plugin).CodeGenConfig::exclude_packages: Vec<String>tobuffa-codegenas the shared backing field, so the knob is available to direct codegen users too.generate_with_diagnostics, applied before the codegen context is built — ensuring that WKT extern-path auto-injection and other context decisions that key onfiles_to_generatemembership see the already-filtered list.filter_excluded_filesfromprotoc-gen-buffa(the logic is now ingenerate_with_diagnostics); the plugin's parse layer pushes directly intocodegen.exclude_packages.normalize_exclude_packagefor all callers, so leading-dot stripping and validation cannot drift between front-ends.docs/guide.mdto reflect thatexclude_packageis now available on both the plugin andbuffa-buildpaths.Usage
The same plugin option string syntax continues to work unchanged:
Test plan
task lintpasses (clippy clean, fmt clean, markdownlint clean)task testpasses — 603 buffa-codegen unit tests including 5 newtest_exclude_packages_*tests and 2 newbuffa-buildbuilder testsFileNotFoundwhen a file without a descriptor passes the filter unchanged, and rejection of malformed entries