bazel_clang_tidy icon indicating copy to clipboard operation
bazel_clang_tidy copied to clipboard

Add global option to disable running clang-tidy on headers

Open johnor opened this issue 1 year ago • 8 comments

johnor avatar Nov 15 '24 11:11 johnor

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 avatar Nov 18 '24 16:11 erenon

@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!

johnor avatar Nov 27 '24 09:11 johnor

Fixed usage with bzlmod also, I had missed that first.

johnor avatar Nov 27 '24 10:11 johnor

Hi, thanks for the update. I still do not understand: why doesn't exclude-header-filter work in this case?

erenon avatar Dec 30 '24 10:12 erenon

What is no-clang-tidy-headers? Can that be specified somehow by users of bazel_clang_tidy?

nickdesaulniers avatar Mar 19 '25 20:03 nickdesaulniers

ah, I can add tags = ["noclangtidy"], to my bazel build rules for headers I'm trying to ignore! Is that documented anywhere?

nickdesaulniers avatar Mar 19 '25 21:03 nickdesaulniers

It is in the readme: https://github.com/erenon/bazel_clang_tidy?tab=readme-ov-file#use-a-non-system-clang-tidy

erenon avatar Mar 23 '25 12:03 erenon

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).

johnor avatar Mar 31 '25 17:03 johnor