Skip to content

Improve generated BUILD handling and postprocessin - #21

Open
ekacnet wants to merge 7 commits into
mainfrom
dev/miscfixesmay
Open

Improve generated BUILD handling and postprocessin#21
ekacnet wants to merge 7 commits into
mainfrom
dev/miscfixesmay

Conversation

@ekacnet

@ekacnet ekacnet commented May 10, 2026

Copy link
Copy Markdown
Owner

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.

ekacnet added 5 commits May 10, 2026 11:59
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.
* 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-commenter

codecov-commenter commented May 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.94254% with 132 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.86%. Comparing base (315d59f) to head (2113e5a).

Files with missing lines Patch % Lines
postprocess 36.71% 81 Missing ⚠️
build.py 84.27% 39 Missing ⚠️
ninjabuild.py 81.81% 10 Missing ⚠️
build_visitor.py 85.71% 1 Missing ⚠️
test/test_postprocess.py 95.23% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ekacnet ekacnet changed the title Misc fixes Improve generated BUILD handling and postprocessin Jun 28, 2026
@ekacnet

ekacnet commented Jun 28, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@ekacnet

ekacnet commented Jun 29, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread build.py
Comment on lines +1878 to +1882
if (
self._commandGroupMentionsTarget(command_group, output, workDir)
and output not in split_inputs
):
split_inputs.append(output)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants