bazel_clang_tidy
bazel_clang_tidy copied to clipboard
Add global option to disable running clang-tidy on headers
Hi, thanks for the PR. FMI, what's the difference between this approach and using --exclude-header-filter= ? https://clang.llvm.org/extra/clang-tidy/
@erenon Hi, sorry for the late reply. I updated the commit message with some more information. I think it should answer your questions. Let me know otherwise!
Fixed usage with bzlmod also, I had missed that first.
Hi, thanks for the update. I still do not understand: why doesn't exclude-header-filter work in this case?
What is no-clang-tidy-headers? Can that be specified somehow by users of bazel_clang_tidy?
ah, I can add tags = ["noclangtidy"], to my bazel build rules for headers I'm trying to ignore! Is that documented anywhere?
It is in the readme: https://github.com/erenon/bazel_clang_tidy?tab=readme-ov-file#use-a-non-system-clang-tidy
Hi, thanks for the update. I still do not understand: why doesn't exclude-header-filter work in this case?
Before commit f43f9d61c201b314c62a3ebcf2d4a37f1a3b06f7, the following invocation will be made by bazel when running on "//example:lib"
bazel build --config clang-tidy //example:lib --subcommands=pretty_print --enable_workspace:
SUBCOMMAND: # //example:lib [action 'Run clang-tidy on example/lib.cpp', configuration: 3723722276aac1314320ca9a9fb2a278d80e4eb3b422da8939e984231a537159, execution platform: @@platforms//host:host, mnemonic: ClangTidy]
On commit f43f9d61c201b314c62a3ebcf2d4a37f1a3b06f7, we are instead invoking clang-tidy twice, once on the cpp file and once on the header:
SUBCOMMAND: # //example:lib [action 'Run clang-tidy on example/lib.hpp', configuration: 3723722276aac1314320ca9a9fb2a278d80e4eb3b422da8939e984231a537159, execution platform: @@platforms//host:host, mnemonic: ClangTidy]
SUBCOMMAND: # //example:lib [action 'Run clang-tidy on example/lib.cpp', configuration: 3723722276aac1314320ca9a9fb2a278d80e4eb3b422da8939e984231a537159, execution platform: @@platforms//host:host, mnemonic: ClangTidy]
I would like to keep the previous behavior, where clang-tidy is only invoked on .cpp files, as headers are not buildable by themselves in the projects I am working on. The current workaround, introduced in a01e5e262e6d604c21ed11c420a2a245397b995a, requires adding "no-clang-tidy-headers" to all libraries. This is impractical in a large project unfortunately.
This pr introduces a global option to control this behavior, instead of using tags on all libs. "exclude-header-filter" might be possible, but bazel will still invoke clang-tidy on every header (unless I am missing something).