Skip to content

Add global option to disable running clang-tidy on headers #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

johnor
Copy link
Contributor

@johnor johnor commented Nov 15, 2024

No description provided.

@erenon
Copy link
Owner

erenon commented Nov 18, 2024

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/

@johnor
Copy link
Contributor Author

johnor commented Nov 27, 2024

@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
Copy link
Contributor Author

johnor commented Nov 27, 2024

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

@erenon
Copy link
Owner

erenon commented Dec 30, 2024

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

@nickdesaulniers
Copy link

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

@nickdesaulniers
Copy link

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

@erenon
Copy link
Owner

erenon commented Mar 23, 2025

* Commit f43f9d6 added support to run
  clang-tidy on headers. After that commit, all headers will be checked
  by clang-tidy.
* Commit a01e5e2 added a tag to make it
  possible to not run clang-tidy on specific libraries.
* For projects that only want to run clang-tidy on source files, the
  only way to disable running clang-tidy on headers is to add the above
  mentioned tag to all libraries. For large projects this requires
  changing all BUILD files. This commit adds a global option instead to
  always disable running clang-tidy on headers.
@johnor
Copy link
Contributor Author

johnor commented Mar 31, 2025

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

Before commit f43f9d6, 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 f43f9d6, 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 a01e5e2, 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants