-
-
Notifications
You must be signed in to change notification settings - Fork 5
style(clang-tidy): modularize clang-tidy config #1754
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
base: main
Are you sure you want to change the base?
style(clang-tidy): modularize clang-tidy config #1754
Conversation
These are reported with sourcemeta#1754 Refs: sourcemeta#1654 Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Reported with sourcemeta#1754 Refs sourcemeta#1654 Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Reported with sourcemeta#1754 Refs sourcemeta#1657 Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Reported with sourcemeta#1754 Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
@jviotti Need your thoughts on this? |
I'm not sure I understand the PR. You have deleted the targets that even call ClangTidy, so what is invoking it now? The CI builds also seem to be failing without being able to execute anything. Also a few comments:
|
CMakeLists.txt
Outdated
endif() | ||
|
||
# Add clang-tidy to the targets. Clang-tidy uses the .clang-tidy file for configuration. | ||
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_BIN}" "--allow-no-checks") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you instead set this variable inside the clang tidy target?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought of using global scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can still affect the global scope from within a function (there are options for that). That way, we keep everything ClangTidy related in a single file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered PARENT_SCOPE
but that didn't sound global.
But I can try to encapsulate it.
CMakeLists.txt
Outdated
src/*.h src/*.cc | ||
benchmark/*.h benchmark/*.cc | ||
test/*.h test/*.cc) | ||
sourcemeta_find_clang_tidy() # Locates CLANG_TIDY program |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does it know what files to run it against? i.e. can we ignore dependencies like vendor/uriparser
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll use the source files of the target
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using .clang-tidy file at the root level to disable the checks outside the src/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder how would that work with nested projects. For example, other projects like Hydra will consume Core, and still have their own external libraries that they probably should not lint (like BearSSL). If we override the ClangTidy config in the child, we still have to retain the blacklist from this repo? I'm just concerned about how re-usability and extensibility of the config file will play when other projects consume this. That's why I had a single config file for everything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering hydra folder structure, core goes vendored along with hydra's external library dependencies.
With this PR's approach, we disable all the clang-tidy checks at root directory and enable the required checks at the src/folder level.
hydra
|_.clang-tidy(-)
|_src/.clang-tidy(performance-)
|_test
|_vendor--|core/.clang-tidy
|... |bearssl
|..
So, having this hierarchy doesn't mess with each other's config.
All the configuration we do for core doesn't have any role in the configuration of hydra.
If we want to have a single configuration, we can consider symlinks.(Re-usability)
This approach gives extensible too by allowing us to control the configuration at the folder level.
Let me know if you see any issues with this approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't tell right now. But let's make it work, and then I can attempt i.e. an upgrade on Hydra pointing at the PR and see how it goes
function(sourcemeta_target_clang_tidy) | ||
cmake_parse_arguments(SOURCEMETA_TARGET_CLANG_TIDY "REQUIRED" "" "SOURCES" ${ARGN}) | ||
|
||
function(sourcemeta_find_clang_tidy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this not only finds ClangTidy but also enables it? Also if we are not making it a target anymore, we should move this file outside of cmake/common/targets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not making it a target anymore. We can move it out of targets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! Probably under cmake/common
This works at the target level. Clang-tidy checks can be enabled/disabled at the target level. We can be explicit about config path. But it picks up the .clang-tidy from the current directory and combines the config from the parent directory. So, specifying just the current dir config file might be misleading. Clang-tidy takes time. So, we can have a variable to disable the clang-tidy check. |
CI builds are failing because of older version of clang-tidy available to them. |
Refs sourcemeta#1754 This makes it use consistent version of clang-tidy on all the platforms. And also uses fairy latest version of clang-tidy, instead of using old versions shipped along with apple llvm and similar distros. Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Refs sourcemeta#1754 Inspired by sourcemeta#1739 This makes it use consistent version of clang-tidy on all the platforms. And also uses fairy latest version of clang-tidy, instead of using old versions shipped along with apple llvm and similar distros. Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Regarding the slow down, I would propose us to try enabling it by default. |
Refs #1754 This makes it use consistent version of clang-tidy on all the platforms. And also uses fairy latest version of clang-tidy, instead of using old versions shipped along with apple llvm and similar distros. Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Sounds good. Let's first make it work, and then we evaluate and polish? |
Reported with #1754 Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
86515ba
to
a974e5e
Compare
Read blogs and played around with [CMAKE_CXX_CLANG_TIDY](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_CLANG_TIDY.html). Also read source code to understand the clang-tidy config of chromium, llvm and other projects. We can provide complete context including headers to the clang-tidy tool for static analyzer by running it while building the code. This also makes static analysis first-class citizen of the project, reporting errors before making commits. For example, `misc-internal-linkage` check was reporting mostly false positives prior to this. With this, it also considered the headers, where methods/functions were declared constant. Refer sourcemeta#1752 And we should also incrementally add the checks. Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
294aaad
to
95ef54c
Compare
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Read blogs and played around with CMAKE_CXX_CLANG_TIDY. Also read source code to understand the clang-tidy config of chromium, llvm and other projects.
We can provide complete context including headers to the clang-tidy tool for static analyzer by running it while building the code. This also makes static analysis first-class citizen of the project, reporting errors before making commits.
For example,
misc-internal-linkage
check was reporting mostly false positives prior to this. With this, it also considered the headers, where methods/functions were declared constant. Refer #1752And we should also incrementally add the checks.