Skip to content

refactor(ci/fbuild-static-analysis): drop default param, plumb project_root explicitly - #2345

Merged
zackees merged 1 commit into
masterfrom
feat/iwyu-nits-2331
Apr 19, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/iwyu-nits-2331

Conversation

@zackees

@zackees zackees commented Apr 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Addresses the two outstanding CodeRabbit nitpicks from the original #2331 review that were deferred pending follow-up. Both tighten the public API for fbuild-backed static analysis.

  1. ci/util/fbuild_adapter.py: drop the default on `get_compile_commands(board, build_root: Path | None = None)`. Repo style says parameters don't have defaults; the sole caller already passes build_root explicitly, so making it required is a no-op at call sites.

  2. `ci/util/fbuild_compiledb.py`: replace the fragile `repo_root = build_root.parent if build_root.name == ".build" else build_root` heuristic in `_candidate_fbuild_release_dirs` with an explicit `project_root` parameter. The heuristic silently collapsed two of the three candidate release-dirs into one whenever a caller passed a `build_root` not literally named `.build/` — a surprise waiting to happen as callers multiply.

    `project_root` now flows through the public API: `fbuild_release_dir`, `was_compiled_with_fbuild`, `_find_existing_compile_db`, `ensure_compile_commands`. Callers updated: `ci/ci-iwyu.py` (`_PROJECT_ROOT`), `ci/ci-cppcheck.py` (`project_root`), `ci/util/fbuild_adapter.py` (already computed).

Test plan

  • `bash lint` on all four touched files passes
  • `uv run python ci/ci-iwyu.py --help` and `ci-cppcheck.py --help` both boot (import chain intact)
  • No behavioral change on conventionally-named `.build/` roots (all three candidates resolve to the same paths as before)

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Updated internal build detection and compilation database retrieval logic to explicitly pass the project root directory to fbuild utility functions, removing reliance on naming heuristics.
    • Made the build root parameter required instead of optional in compile database retrieval functions for clearer API contracts.

#2331

Two outstanding nitpicks from the original #2331 review that were deferred
pending follow-up. Both tighten up the public API the IWYU/cppcheck front-
ends use.

1. ci/util/fbuild_adapter.py — drop default `build_root: Path | None = None`
   on `get_compile_commands`. Repo style: parameters don't have defaults.
   Sole caller (ci/ci-iwyu.py) already passes build_root explicitly, so
   making it required is a no-op at call sites. The doc now explains
   why the default was removed.

2. ci/util/fbuild_compiledb.py — replace the fragile
   `repo_root = build_root.parent if build_root.name == ".build" else
   build_root` heuristic in `_candidate_fbuild_release_dirs` with an
   explicit `project_root` parameter. The heuristic silently collapsed
   two of the three candidates into one whenever a caller passed a
   build_root not literally named ".build/" (a surprise waiting to
   happen once callers multiply).

   Plumb `project_root` through the public API:
   - `fbuild_release_dir`     (project_root, build_root, board_name)
   - `was_compiled_with_fbuild` (project_root, build_root, board_name)
   - internal `_find_existing_compile_db` and `ensure_compile_commands`

   Callers updated:
   - ci/ci-iwyu.py: pass `_PROJECT_ROOT` (already defined locally)
   - ci/ci-cppcheck.py: pass `project_root` (already computed locally)
   - ci/util/fbuild_adapter.py: already computes project_root for
     `ensure_compile_commands`; no change beyond the default removal.

Imports and `--help` verified on both ci-iwyu.py and ci-cppcheck.py.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 19, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR threads project_root as an explicit parameter through fbuild compile-database detection and retrieval functions. Function signatures across ci/util/fbuild_compiledb.py are updated along with their callers in ci/ci-cppcheck.py and ci/ci-iwyu.py. The optional build_root parameter in get_compile_commands() is made mandatory, removing internal fallback logic.

Changes

Cohort / File(s) Summary
CI Script Call Sites
ci/ci-cppcheck.py, ci/ci-iwyu.py
Updated was_compiled_with_fbuild() calls to pass project_root as the first argument; updated get_compile_commands() call in ci/ci-iwyu.py to pass build directly without keyword argument.
Fbuild Adapter
ci/util/fbuild_adapter.py
Made build_root parameter in get_compile_commands() mandatory by removing the optional default and internal fallback assignment; updated docstring to clarify no default is applied.
Fbuild Compile DB Helpers
ci/util/fbuild_compiledb.py
Refactored helper functions to explicitly accept project_root: _candidate_fbuild_release_dirs(), fbuild_release_dir(), was_compiled_with_fbuild(), and _find_existing_compile_db() signatures updated to include project_root as first parameter; removed name-based heuristic reliance on build_root directory naming.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 Through parameters we weave and thread,
The project root now takes its spread,
No more defaults, just explicit flow—
Each function now precisely knows! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring the fbuild static analysis code to remove a default parameter and explicitly pass project_root throughout the call chain.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/iwyu-nits-2331

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
ci/util/fbuild_adapter.py (1)

33-63: Consider also plumbing project_root through get_compile_commands for API symmetry.

The PR rationale for making build_root required ("callers always know their repo root / build root — don't derive it here") applies equally to project_root: every caller (ci-iwyu.py, ci-cppcheck.py) already has _PROJECT_ROOT / project_root locally, and all public functions in ci/util/fbuild_compiledb.py now take it explicitly. Deriving it here via Path(__file__).resolve().parent.parent.parent leaves this adapter as the lone place still using a file-location heuristic, which silently breaks if the module is ever relocated or vendored.

♻️ Proposed signature
-def get_compile_commands(board: str, build_root: Path) -> Path | None:
+def get_compile_commands(board: str, project_root: Path, build_root: Path) -> Path | None:
     ...
-    project_root = Path(__file__).resolve().parent.parent.parent
     return ensure_compile_commands(project_root, build_root, board)

And at the call site in ci/ci-iwyu.py (line 846):

-        compile_db = get_compile_commands(canonical_board_name, build)
+        compile_db = get_compile_commands(canonical_board_name, _PROJECT_ROOT, build)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ci/util/fbuild_adapter.py` around lines 33 - 63, Update get_compile_commands
to accept a project_root parameter and pass it through to
ci.util.fbuild_compiledb.ensure_compile_commands instead of deriving
project_root from __file__; adjust the function signature and docstring to
document the new required Path parameter, remove the local
Path(__file__).resolve().parent.parent.parent derivation, and update all call
sites (e.g., ci/ci-iwyu.py and ci/ci-cppcheck.py) to supply their existing
project_root/_PROJECT_ROOT when calling get_compile_commands so API symmetry
with build_root is preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@ci/util/fbuild_adapter.py`:
- Around line 33-63: Update get_compile_commands to accept a project_root
parameter and pass it through to
ci.util.fbuild_compiledb.ensure_compile_commands instead of deriving
project_root from __file__; adjust the function signature and docstring to
document the new required Path parameter, remove the local
Path(__file__).resolve().parent.parent.parent derivation, and update all call
sites (e.g., ci/ci-iwyu.py and ci/ci-cppcheck.py) to supply their existing
project_root/_PROJECT_ROOT when calling get_compile_commands so API symmetry
with build_root is preserved.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 52985181-4568-4f8c-9636-b22cd7788ebf

📥 Commits

Reviewing files that changed from the base of the PR and between 06c4019 and 9f51bba.

📒 Files selected for processing (4)
  • ci/ci-cppcheck.py
  • ci/ci-iwyu.py
  • ci/util/fbuild_adapter.py
  • ci/util/fbuild_compiledb.py

@zackees
zackees merged commit ef94ab3 into master Apr 19, 2026
48 of 80 checks passed
@zackees
zackees deleted the feat/iwyu-nits-2331 branch May 30, 2026 20:02
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.

1 participant