tooling: extract the compile DB in the develop config (--config=clang-tidy) - #420
Merged
Conversation
…-tidy) Adopt helly25/mbo#280's approach: extract compile_commands.json in the exact configuration we develop in, rather than the default build config with a post-hoc compiler substitution. A new .bazelrc `clang-tidy` config layers the hermetic clang toolchain (--config=clang) plus an explicit libc++ (std + link), and compile_commands-update.sh runs the extractor's internal aquery under it (passed as a runtime flag, which the fork forwards to aquery). So clang-tidy / clangd parse with the compiler, standard library, include paths and feature macros the real --config=clang builds use, on every platform. Two xff-specific deviations from mbo#280: - Keep --bcce-compiler: xff's toolchain names `cc_wrapper.sh` in the extracted command, not a real clang++. clang-tidy reads that leading token to derive the driver target + resource dir, and a shell script leaves it with the wrong builtins (SDK / libc++ headers fail to parse). Substituting the hermetic clang++ binary fixes that; all OTHER flags still come from the config. - macOS: drop the SDK libc++ redirection. On macOS toolchains_llvm emits `-nostdinc++ -cxx-isystem <SDK>/usr/include/c++/v1` (Xcode's libc++) while -resource-dir is the hermetic clang's; that mismatch silently degrades clang-tidy's analysis (spurious unused-variable / const-correctness findings). The hermetic clang++ finds its own libc++ by default, so a gated post-filter drops just those two flags; -isysroot stays for the system C headers. Linux never emits the SDK -cxx-isystem, so the filter is a no-op there. Also materialize the generated / virtual-include headers in the SAME config (bazel build --config=clang-tidy //...) so the forests land where the DB points, and drop the now-redundant ~15-line default-config header-build note. Verified: DB names the hermetic clang++ with libc++, and clang-tidy parses the tree clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adopts helly25/mbo#280's root-cause approach: extract
compile_commands.jsonin the exact configuration we develop in, instead of the default build config with a post-hoc compiler substitution.Change
.bazelrcclang-tidyconfig:--config=clang+ explicit--cxxopt=-stdlib=libc++/--linkopt=-stdlib=libc++.compile_commands-update.shextracts under it (--config=clang-tidypassed as a runtime flag; the hedron fork forwards non---bcce-*runtime args to its internalaquery), and materializes generated / virtual-include headers in the same config so the forests land where the DB points.So clang-tidy / clangd parse with the compiler, standard library, include paths and feature macros the real
--config=clangbuilds use - not whatever toolchain bazel would autodetect (libc++ on macOS, system libstdc++ on Linux).Two xff-specific deviations from mbo#280
--bcce-compiler. xff's toolchain namescc_wrapper.shas the compiler in the extracted command, not a realclang++. clang-tidy reads that leading token to derive the driver's target + resource dir; a shell script leaves it with the wrong builtins, so SDK / libc++ headers fail to parse. Substituting the hermeticclang++binary fixes it - all other flags still come from the config.toolchains_llvmemits-nostdinc++ -cxx-isystem <SDK>/usr/include/c++/v1(Xcode's libc++) while-resource-diris the hermetic clang's. That mismatch silently degrades clang-tidy's analysis (spuriousunused-variable/ const-correctness findings on clearly-used variables). The hermeticclang++finds its own libc++ by default, so auname-gated post-filter drops just those two flags;-isysrootstays for the system C headers. Linux never emits the SDK-cxx-isystem, so the filter is a no-op there.Test
clang++,-stdlib=libc++and-isysrootpresent, SDK-cxx-isystem/-nostdinc++gone.pre-commit run clang-tidyparses the tree clean (the const/internal-linkage findings that appeared mid-investigation were artifacts of the broken parse and are gone once the DB is healthy).pre-commit rungreen on the changed files (shfmt / shellcheck / actionlint / yaml).The CI compile-DB build step exercises the Linux path of the new script (the macOS filter is gated off there).