Repository navigation
refactor(ci/fbuild-static-analysis): drop default param, plumb project_root explicitly - #2345
Conversation
#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]>
📝 WalkthroughWalkthroughThe PR threads Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ci/util/fbuild_adapter.py (1)
33-63: Consider also plumbingproject_rootthroughget_compile_commandsfor API symmetry.The PR rationale for making
build_rootrequired ("callers always know their repo root / build root — don't derive it here") applies equally toproject_root: every caller (ci-iwyu.py,ci-cppcheck.py) already has_PROJECT_ROOT/project_rootlocally, and all public functions inci/util/fbuild_compiledb.pynow take it explicitly. Deriving it here viaPath(__file__).resolve().parent.parent.parentleaves 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
📒 Files selected for processing (4)
ci/ci-cppcheck.pyci/ci-iwyu.pyci/util/fbuild_adapter.pyci/util/fbuild_compiledb.py
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.
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.`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
Related
🤖 Generated with Claude Code
Summary by CodeRabbit