Repository navigation
fix(meson): move zccache wrapping to build.ninja post-patch (#2714) - #2811
Conversation
…2714) The meson native file previously emitted compiler entries of the form ``[zccache.exe, ctc-clang++.exe]``. Meson's ``BinaryTable.parse_entry`` only strips the literal strings ``ccache``/``sccache`` from the head of a compiler list (``mesonbuild/envconfig.py:465-470``), so the full-path zccache survived ``get_exelist(ccache=False)`` and the configure-phase include-dir probe (``<cc> -xc++ -E -v -``) ran wrapped in zccache. On the bug reporter's box that probe hung >90s instead of the bare compiler's <1s, producing "No include directory found" warnings followed by failing capability probes ("does not support -std=c++11"). This change splits responsibility: * ``_resolve_fast_native_entries`` (``ci/meson/native_launchers.py``) now emits the BARE ctc-clang/ctc-clang++ entries. The ``cache_binary`` parameter is removed. * New ``inject_zccache_wrapping`` in ``ci/meson/meson_markers.py`` is a sibling to the existing ``inject_ar_optimization_patches``. After ``meson setup`` produces ``build.ninja``, it rewrites the ``cpp_COMPILER``, ``cpp_LINKER``, ``c_COMPILER``, ``c_LINKER`` rule command lines to prepend the zccache binary. STATIC_LINKER is excluded since it is already wrapped by ``ar_content_preserving.py``. * Both call sites of ``inject_ar_optimization_patches`` in ``ci/meson/meson_setup_execute.py`` (``handle_skip_meson_setup`` and ``run_meson_setup_command``) gain a paired ``inject_zccache_wrapping`` call. The build phase still goes through zccache exactly as before. Only the configure phase now sees the bare compiler. Cache-version invalidation continues to work via the existing ``zccache_version`` marker. Verified on Windows 10: * Configure phase: <1s (was hanging >90s before this fix). * meson-log.txt reports ``-std=c++11: YES`` with no "No include directory found" warnings. * In-place reconfigure triggered by a test-file content change completes in ~1.1s for the configure phase. * Full ``bash test --cpp`` passes 309/309 in ~50s on a warm cache. * Generated ``build.ninja`` shows zccache wrapping on ``cpp_COMPILER``/``cpp_LINKER`` rules so build-phase caching is preserved. Investigation: #2714 (comment) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThis PR relocates zccache integration from native launcher resolution to post-setup build.ninja injection. It introduces build.ninja wrapping logic, refactors native launcher resolution to remove cache binary composition, and orchestrates zccache injection across both meson setup paths. ChangesZccache architecture refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
Actionable comments posted: 2
🧹 Nitpick comments (2)
ci/meson/meson_setup_execute.py (1)
328-328: ⚡ Quick winConsider checking return value from inject_zccache_wrapping for observability.
Both call sites invoke
inject_zccache_wrapping()but don't check the return value. The function returnsFalsewhen injection fails due to I/O errors or missingbuild.ninja, meaning the build would continue with unwrapped compiler commands (no caching). This failure mode is currently silent.While consistent with the existing pattern for
inject_ar_optimization_patches()(lines 327, 639), logging injection failures would improve observability—especially since zccache is expected whencompiler.cache_binaryis set.📊 Suggested observability improvement
- inject_zccache_wrapping(build_dir, compiler.cache_binary) + if compiler.cache_binary and not inject_zccache_wrapping(build_dir, compiler.cache_binary): + _ts_print("[MESON] Warning: Failed to inject zccache wrapping into build.ninja")Apply to both call sites (lines 328 and 640).
Also applies to: 640-640
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ci/meson/meson_setup_execute.py` at line 328, Call-site should check inject_zccache_wrapping(build_dir, compiler.cache_binary) return and log failures for observability; specifically, after calling inject_zccache_wrapping in the functions that also call inject_ar_optimization_patches, examine its boolean result and emit a clear warning/error via the existing logger when it returns False (include build_dir and compiler.cache_binary context), so a failed injection due to I/O or missing build.ninja is visible instead of silently continuing.ci/meson/native_launchers.py (1)
337-341: 💤 Low valueConsider escaping single quotes in path formatting for Meson native file.
The paths are formatted as single-quoted strings within list notation (e.g.,
['/path/to/ctc-clang']) without escaping single quotes. While extremely rare in practice—especially for paths in.cached/clang-native/—a path containing a single quote would produce malformed Meson list syntax.🛡️ Optional defensive escaping
return FastNativeEntries( - cc=f"['{ctc_c}']", - cxx=f"['{ctc_cpp}']", + cc=f"['{ctc_c.replace(chr(39), chr(92) + chr(39))}']", + cxx=f"['{ctc_cpp.replace(chr(39), chr(92) + chr(39))}']", ar=f"['{ar_path}']", )Alternatively, consider using Python's
shlex.quote()or Meson's native list-of-strings format instead of manually constructing quoted strings.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ci/meson/native_launchers.py` around lines 337 - 341, The Meson string construction uses f"['{ctc_c}']" (and similar for ctc_cpp and ar_path) which breaks if a path contains a single quote; update the return of FastNativeEntries to safely quote/escape each path (ctc_c, ctc_cpp, ar_path) before embedding into the "['...']" string—e.g., import shlex and use shlex.quote(ctc_c), shlex.quote(ctc_cpp), shlex.quote(ar_path) (or explicitly replace single quotes with escaped versions) so the generated Meson list-of-strings remains valid.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ci/meson/meson_markers.py`:
- Around line 322-325: The try/except blocks that call
build_ninja_path.read_text(...) and the corresponding write block
(build_ninja_path.write_text(...)) must handle KeyboardInterrupt before OSError;
update each block to first catch KeyboardInterrupt and invoke
handle_keyboard_interrupt() (or re-raise) and then catch OSError to return False
or handle the error; ensure you reference the existing symbols
build_ninja_path.read_text and build_ninja_path.write_text and call
handle_keyboard_interrupt() in the KeyboardInterrupt except branch while leaving
the OSError handling intact.
- Around line 327-355: The idempotency check fails on Windows because
zccache_path may contain backslashes while Meson uses forward slashes; normalize
zccache_path to use forward slashes before building zccache_quoted and
performing the startswith check. In practice, transform
zccache_path.replace("\\", "/") (or Path.as_posix()) and then set zccache_quoted
= f'"{normalized_path}"' so the existing_value.startswith(zccache_quoted + " ")
comparison (and the string inserted into new_content) use the same normalized
separator style; update references to zccache_path when constructing
zccache_quoted and doing the idempotency check in the loop over
_ZCCACHE_TARGET_RULES and existing_value.
---
Nitpick comments:
In `@ci/meson/meson_setup_execute.py`:
- Line 328: Call-site should check inject_zccache_wrapping(build_dir,
compiler.cache_binary) return and log failures for observability; specifically,
after calling inject_zccache_wrapping in the functions that also call
inject_ar_optimization_patches, examine its boolean result and emit a clear
warning/error via the existing logger when it returns False (include build_dir
and compiler.cache_binary context), so a failed injection due to I/O or missing
build.ninja is visible instead of silently continuing.
In `@ci/meson/native_launchers.py`:
- Around line 337-341: The Meson string construction uses f"['{ctc_c}']" (and
similar for ctc_cpp and ar_path) which breaks if a path contains a single quote;
update the return of FastNativeEntries to safely quote/escape each path (ctc_c,
ctc_cpp, ar_path) before embedding into the "['...']" string—e.g., import shlex
and use shlex.quote(ctc_c), shlex.quote(ctc_cpp), shlex.quote(ar_path) (or
explicitly replace single quotes with escaped versions) so the generated Meson
list-of-strings remains valid.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b7df5355-9878-459d-8a94-11afb23e2eb2
📒 Files selected for processing (3)
ci/meson/meson_markers.pyci/meson/meson_setup_execute.pyci/meson/native_launchers.py
Addresses all four findings from the CodeRabbit review: 1. KeyboardInterrupt before OSError in inject_zccache_wrapping (meson_markers.py read+write blocks). Both blocks now catch KeyboardInterrupt first, invoke handle_keyboard_interrupt(), and re-raise -- matching the policy already enforced elsewhere in ci/meson and documented in agents/docs/python-standards.md. 2. Path-separator normalization for Windows idempotency (meson_markers.py). _find_zccache_binary() returns paths with backslashes on Windows, but meson emits forward slashes in build.ninja. Without normalization the startswith() idempotency check would miss its own prior injection and double-wrap on the second invocation. Verified by re-injecting with a backslashed input path on a build.ninja produced by the forward-slashed first injection -- the count stays at 2 wrappings. 3. Observable failure of inject_zccache_wrapping (meson_setup_execute.py, both call sites). Each call now checks the return value and emits a warning to stderr when injection fails with cache_binary configured, so a silent fall-through to an unwrapped (no-caching) build no longer goes unnoticed. 4. Defensive single-quote escaping in fast native-file entries (native_launchers.py). The generated meson list-of-strings now escapes any embedded single quote. Paths under .cached/clang-native/ never contain a quote in practice, but the escaping costs nothing and prevents a hard-to-debug parse failure in pathological setups. Verification: - bash lint passes - inject_zccache_wrapping smoke test confirms idempotency on Windows with a backslashed input path - the configure phase fix for #2714 continues to hold Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
@coderabbitai All four review findings addressed in a2f2004. Actionable (2):
Nitpicks (2) — both applied:
Verification: |
|
Tip For best results, initiate chat on the files or code changes.
Quick recap:
The implementation looks solid. 🐇 ✨ If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
Summary
Fixes #2714. The meson in-place reconfigure hangs / fails on Windows because the configure-phase compiler probe (
<cc> -xc++ -E -v -) runs wrapped in zccache, which hangs >90s on some boxes (the bug reporter's environment included). Closes #2714.Root cause
The meson native file emitted compiler entries of the form
[zccache.exe, ctc-clang++.exe]. Meson'sBinaryTable.parse_entry(mesonbuild/envconfig.py:465-470) only strips the literal stringsccache/sccachefrom the head of a compiler list, so the full-path zccache survivedget_exelist(ccache=False)(compilers/mixins/gnu.py:401) and the probe ran wrapped. On the reporter's box (and reproduced here) that wrapped probe hung indefinitely instead of the bare compiler's <1s, producingNo include directory foundwarnings followed by failing capability probes (Compiler does not support -std=c++11) and an aborted setup.Full investigation: #2714 (comment)
Fix
Split configure-phase and build-phase responsibility:
ci/meson/native_launchers.py-_resolve_fast_native_entriesnow emits the BAREctc-clang/ctc-clang++entries. Thecache_binaryparameter is removed. Meson sees what it can parse, so probes run natively.ci/meson/meson_markers.py- newinject_zccache_wrapping(build_dir, zccache_path)helper, sibling to the existinginject_ar_optimization_patches. After the setup step producesbuild.ninja, it rewrites thecpp_COMPILER,cpp_LINKER,c_COMPILER,c_LINKERrule command lines to prepend the zccache binary.STATIC_LINKERis intentionally excluded since it is already wrapped byar_content_preserving.py. Idempotent, read-once / write-at-most-once, same pattern as the existing helper.ci/meson/meson_setup_execute.py- both call sites ofinject_ar_optimization_patches(handle_skip_meson_setupandrun_meson_setup_command) gain a pairedinject_zccache_wrapping(build_dir, compiler.cache_binary)call.Build-phase behaviour is unchanged: zccache still wraps every compile and link command. Only the configure-phase probes now run against the bare compiler. The existing
zccache_versionmarker (build_config.py:279-299) continues to force reconfigure on zccache upgrades, which then re-runs the post-patch with the new path.Files touched
Before / after (Windows 10, bug reporter's environment)
<cc> -xc++ -E -v -ctc-clang++.exe)C++ Compiler does not support -std=c++11-std=c++11: YESbuild.ninjacpp_COMPILERruleNote: the bug reporter's box also has a separate pre-existing zccache-daemon-health issue (daemon-side
recv timed out after 300sfor every compile) that is independent of this fix. Verification above was performed withFASTLED_DOCKER=1to bypass zccache and isolate the configure-phase fix; the configure phase itself works identically with and without zccache.Test plan
.build/meson-quick, runbash test --cpp- configure completes <1s, full run 50s, 309/309 passbash test --cpp- the build system auto-detects test changes, reconfigures in 1.13s, then 309/309 passbuild.ninja-cpp_COMPILERandcpp_LINKERrules carryzccache.exeprefix;STATIC_LINKERretains itsar_content_preserving.pywrapper untouchedmeson-log.txt- noNo include directory foundwarnings;-std=c++11: YESbash lintpasses🤖 Generated with Claude Code
Summary by CodeRabbit