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.
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
ci: clang-tidy: speed-up clang-tidy #2758
ci: clang-tidy: speed-up clang-tidy #2758
Changes from 52 commits
68d1925
ede13f2
5759354
d8e9d77
762295d
111ddf1
831a7e2
5f11485
38805df
686f8b8
d912a5b
9d0ab18
2fa2839
e3a065c
412085c
3f24538
372e8f5
5e1eefd
a07a413
856d4c5
f92024d
1c095c5
8b9aa69
17dc79b
01a1969
0a8577a
6b5c370
9fa4861
15041b4
c09a5a7
2cebba2
0d562c9
ee2fe63
06e6eca
e4d61f1
1b5e910
bdb1c9b
233d96b
8691ca1
2e1599c
61a2973
9704533
15b7bc8
09c76b5
40cde4f
3909f95
8acd1bd
b11a0d5
d82f70e
25749ca
bc3590a
f02d978
fdeb823
7fd7f9b
4ad9720
313ca65
bc55e45
42f7ddf
1609c06
1f0ca7a
3a9599d
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Could you please explain this logic? I'm primarily interested in why we need to handle headers separately and what rules you apply to pick the relevant ones.
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.
The reason is compile_commands.json does not contain header files. It only contains c/cpp files which are used in full build. If we want to ensure somehow that we check the "right" header files we need to check full path without file name. For example:
headers:
c/cpp:
This is the main difference between checking c/cpp files and headers. As you can see headers are more tricky because we don't have the list of exact files. Also it seems to provide more visibility when we check c/cpp files only and headers separately, but this is only my opinion :)
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.
Got it, thanks. Documentation for
clang-tidy
indicates that it is expected to run on C/C++ files only. Header files included by sources are analyzed as well if they match the mask defined byHeaderFilterRegex
in .clang-tidy or '--header-filter' option. So it looks like we should not be invokingclang-tidy
on header files at all.With that we have a question of how to make sure that the changed headers are analyzed. In ideal world this should be done by finding a source that includes particular header and running clang-tidy on it, though this may not be practical. For starters we can assume that header is not touched in isolation and see how it goes.
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 think the options for this part are:
Once we are done with addressing hits in headers (2) will become the default behavior.
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.
Upon experimenting I'm leaning towards option (2).
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.
This doesn't seem like a good assumption to me, in my experience this happens relatively frequently, especially for small changes. If we excluded header checks here, we will just hit issues when we later run a full clang-tidy suite.
Ideally, this dependency management would be handled by the build system, but last I was looking into it, there are not tools for this. Although there are a few wrappers scripts floating around that try to cache clang-tidy calls. (see https://gitlab.kitware.com/cmake/cmake/-/issues/21092 for some discussions).
What if we just generate some psuedo-cpp targets which just include the target header via CMake that we can run clang-tidy against for this check? The main thing that clang-tidy needs to know is how to compile the file, which for headers, implies knowing what preprocessor defines are set. Since most of our
#include
are solely a function of the defines set by the compiler, this will get us 99% of the way to being correct without worrying about dependencies. One other minor advantage here is we can avoid duplicated logging when modified cpp files reference the same header.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.
That's an interesting idea to explore. For headers clang-tidy need a bit more then defines alone:
-std
that affect behaviorEffectively this problem boils down to finding a C++ file in
compile_commands.json
that include particular header and running clang-tidy on it.I would suggest to not hold this PR though, as it offers material improvement over what we have now.