-
Notifications
You must be signed in to change notification settings - Fork 444
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
Add support for a clang-tidy linter to CMake. Add a files utility function to P4CUtils.cmake. #4254
Conversation
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.
Generally looks good.
43278c0
to
d68e7e2
Compare
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've just now realized that you did not enable clang-tidy for any files. I think it would make more sense to enable it for the same set of files as cpplint and just run it from time to time. Otherwise there is not much point in having the infrastructure for it if it has no files to run on.
# TODO: Add files here once clang-tidy is fast enough. | ||
# file( | ||
# GLOB_RECURSE P4C_CLANG_TIDY_LINT_LIST FOLLOW_SYMLINKS | ||
# ) | ||
# add_clang_tidy_files(${P4C_SOURCE_DIR} "${P4C_CLANG_TIDY_LINT_LIST}") |
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.
Hmm, I understand that clang-tidy is slow, but having the target does not mean it will have to run. I think it would be best to add the same set as is used of cpplint and just let the programmers decide if they run it or not.
add_clang_tidy_files(${P4C_SOURCE_DIR} "${P4C_LINT_LIST}")
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 problem is that, until we have figured out this slowness issue, we can only apply clang-tidy selectively. If we added all the cpplint files the amount we would have to check would be overwhelming, when you just want to check a local set of files in your target.
I have been spot-checking files by adding add_clang_tidy_files(${P4C_SOURCE_DIR} "${P4C_LINT_LIST}")
for a smaller subset of code I am interested in. I have not yet contributed these automated fixes because I am still tweaking rules etc.
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.
Hmm, this is also made worse by using the xargs
which prevents running clang-tidy
in parallel. This can be side-stepped by the following construction:
- Use empty
add_custom_target
to add the actual targetclang-tidy
. - Use
add_custom_command(TARGET clang-tidy POST_BUILD COMMAND ...
for each file
But I still wonder if there is a better way of doing this then just manually adding files one wants to check (I would not expect clang-tidy to get significantly faster any time soon...). How long does it take to run clang-tidy over the all the CPPLINT-linted files?
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 xargs is necessary because of a shell quirk. At some point the number of files as arguments grew too large.
There is a parallel runner but not sure it helps much when it takes ~10-30 second to analyze a single file.
I think the underlying problem is that clang-tidy checks system-files by default. Once we find a workaround for that it should be significantly faster.
Currently, checking all the CPPLINT files would a day at least.
8164bb2
to
18b9c5b
Compare
18b9c5b
to
940238d
Compare
@asl This might help in applying clang-tidy in broader strokes. If you have any advice on how to improve the performance of the analyser please let me know. |
@fruffy By "performance" you mean that it is currently slow? |
Yes, clang-tidy requires many seconds to analyse a single file. This makes it a non-option for CI. |
940238d
to
6446e24
Compare
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.
Let's get this in. In the end, it will be useful even if we can't run in in the P4C CI for now.
Add the ability to run clang-tidy across P4C files via CMake. This is not enabled yet for CI because clang-tidy is quite slow still.
However, one can still use it to run clang-tidy across one's files in bulk.
Supersedes #4253 if merged before it.