Improve generated BUILD handling and postprocessin - #21
Conversation
Sometime you might have multiple command that generates different files in the same group of command and previous implementation was not picking all the commands leaving some files ungenerated.
After refactoring the way we parse commands for genrule we exposed a bug in the way some relation existed in the graph we have to fix them.
…buf libs and grpc libs
* preserve load(...) lines understand loaded rule symbols * emit BUILD rules with more Bazel-like formatting, add ordered attribute printing, sorted list values * correct string formatting including triple-quoted strings * avoid emitting the same rule more than once * narrow the companion _hdrs rule behavior to cc_library rules * fixes a missing-dependency bookkeeping bug with missing.setdefault(...).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #21 +/- ##
==========================================
+ Coverage 77.39% 77.86% +0.46%
==========================================
Files 23 25 +2
Lines 4575 5368 +793
==========================================
+ Hits 3541 4180 +639
- Misses 1034 1188 +154 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@codex review |
|
To use Codex here, create a Codex account and connect to github. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2113e5abef
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if ( | ||
| self._commandGroupMentionsTarget(command_group, output, workDir) | ||
| and output not in split_inputs | ||
| ): | ||
| split_inputs.append(output) |
There was a problem hiding this comment.
Avoid revisiting split generated inputs under a genrule
For multi-output CUSTOM_COMMANDs where a later command consumes an earlier generated output, such as gen a.txt && gen a.txt -> b.txt, appending the earlier output to split_inputs makes visitGraph visit a.txt while ctx.current is still the BazelGenRuleTarget created for b.txt. For non-C/C++ outputs, _handleCustomCommandForBazelGen then hits assert isinstance(ctx.current, BazelTarget), so converting these chained generated outputs crashes instead of producing dependent genrules.
Useful? React with 👍 / 👎.
This PR improves how ninja2bazel handles generated files, protobuf/grpc rule relationships, and postprocessed BUILD output. It fixes custom command parsing so multiple
generated outputs in grouped commands are discovered, makes protobuf and grpc library srcs/deps population independent of rule ordering, and ensures cc_proto_library loads are
emitted when needed. It also strengthens the postprocess script with better BUILD formatting, ordered attributes, sorted list values, preserved triple-quoted strings, duplicate
rule suppression, and correct preservation of both single-line and multi-line load(...) blocks.