-
-
Notifications
You must be signed in to change notification settings - Fork 5
Clang tidy separate ci job #1801
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?
Clang tidy separate ci job #1801
Conversation
See: sourcemeta/blaze#429 Signed-off-by: Juan Cruz Viotti <jv@jviotti.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>
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>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
89ec116
to
bdac96c
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>
@jviotti it's ready for your review. |
This supersedes #1754 |
Also supersedes #1640 |
Also supersedes #1702 |
@jviotti PTAL |
.github/workflows/ci.yml
Outdated
- uses: actions/checkout@v4 | ||
- run: cmake --version | ||
- name: Install llvm | ||
run: sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" |
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.
Why do we need this? I thought we tweaked the CMake scripts to conveniently download ClangTidy binaries when configuring?
OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) | ||
message(STATUS "Installed `clang-tidy` pre-built binary to ${CLANG_TIDY_BINARY_OUTPUT}") | ||
function(sourcemeta_enable_clang_tidy) | ||
find_program(CLANG_TIDY_BIN NAMES 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.
We could still download ClangTidy on demand and set CMAKE_CXX_CLANG_TIDY
to the downloaded 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.
Having clang-tidy without rest of the llvm is causing trouble
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.
Also keep in mind that this find_program
invocation succeeds even if clang-tidy
was not found. Maybe worth putting REQUIRED
? Otherwise you might end up setting a non-sense CMAKE_CXX_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.
Having clang-tidy without rest of the llvm is causing trouble
@bavulapati Even when installing clang-tidy
from the Ubuntu packages? Because in theory Ubuntu consumes upstream LLVM.
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 can try that
message(STATUS "Installed `clang-tidy` pre-built binary to ${CLANG_TIDY_BINARY_OUTPUT}") | ||
function(sourcemeta_enable_clang_tidy) | ||
find_program(CLANG_TIDY_BIN NAMES clang-tidy) | ||
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_BIN};--config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy;-header-filter=${CMAKE_CURRENT_SOURCE_DIR}/src/*" PARENT_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.
It's probably fine for all projects right now, but maybe worth taking the -header-filter
as an option to the CMake function? At least so that it is generic enough out of the box for all possible uses?
endif() | ||
|
||
sourcemeta_disable_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.
Interesting. Disabling looks a bit weird though. Now that I see this I wonder if it is possible to set CMAKE_CXX_CLANG_TIDY
on a per-target level. If so, we could have a CLANG_TIDY
option when declaring a library with sourcemeta_library
(or executable with sourcemeta_executable
). Then we don't have to worry about unsetting it, as we literally opt into it for specific things we are about?
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.
Yes, we can do it at the target level
message(STATUS "Installed `clang-tidy` pre-built binary to ${CLANG_TIDY_BINARY_OUTPUT}") | ||
function(sourcemeta_enable_clang_tidy) | ||
find_program(CLANG_TIDY_BIN NAMES clang-tidy) | ||
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_BIN};--config-file=${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy;-header-filter=${CMAKE_CURRENT_SOURCE_DIR}/src/*" PARENT_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.
Also, does this work across compilers? i.e. can I enable this if I have ClangTidy available even if using MSVC? Or does it also require the Clang compiler? If so, it might be worth checking for this, so that nobody can accidentally enable it
It seems to work fine for me with AppleClang. Can you confirm it fails with non-Clang compilers? If so, we should have a check in the CMake function to error out if somebody tries to enable it with an incompatible compiler |
It works but misses the required context like std headers location etc., |
Co-authored-by: Juan Cruz Viotti <jv@jviotti.com> Signed-off-by: Balakrishna Avulapati <bavulapati@gmail.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
…re into clang-tidy-separate-ci-job
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
@jviotti Addressed critical review comments.
|
We use a CMAKE flag to decide if we want to run clang-tidy.
We can run the clang-tidy checks locally using the flag SOURCEMETA_CORE_CLANG_TIDY.
Tested this locally on Mac too. We just need to make sure we are using llvm instead of apple clang++.
Clang-tidy is friendly with clang++ but not with gcc or apple clang++.
This PR makes sure that it runs on a single machine, as we can't have clang used on all the machines.
Choosing ubuntu as its availability and cost on CI might be less(subject to correction).
We are using a single .clang-tidy configuration file. And the configuration file path is explicitly specified.
We are enabling the clang-tidy checks only for sourcemeta source targets. Disabling it for vendor, tests, etc.,
New CI Job installs the llvm package.
Using modernize-use-nodiscard check to demonstrate the proper clang-tidy working.