-
Notifications
You must be signed in to change notification settings - Fork 535
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
integrating clang-tidy into openal-soft with cmake #1005
Conversation
this changes introduces the integration of Clang-Tidy into the OpenAL-Soft project using CMake. Clang-Tidy is a static code analysis tool that helps identify and fix potential issues in C++ code. The changes in this comment will analyze and apply clang-tidy fixes to the following directories and files: * `al` * `alc` * `common` * `core` * `utils/openal-info.c` (if enabled) * CMake 3.5 or higher [see. CMAKE_EXPORT_COMPILE_COMMANDS](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html). compatible for current project cmake version. * Clang-Tidy (only required if analysis is executed) 1. Configure OpenAL-Soft with CMake using the desired features and add the `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON` flag to the CMake command line. ex. `cmake -G "MinGW Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release ..` 2. Run Clang-Tidy using the target `clang-tidy-check`. ex. `make clang-tidy-check` 1. The fixes applied by clang-tidy are not guaranteed to be correct. Therefore, it is important to re-compile and test the project after running this target. 2. More checks over clang-tidy can be implemented, but this may prevent the project from compiling. A more comprehensive clang-tidy configuration with lint comments to ignore specific cases can be developed in the future.
For pffft, sure. It's already heavily modified, so more changes to fix other issues isn't a problem (so long as it doesn't adversely affect performance).
Currently this is what I have enabled with Qt Creator:
This has a few "false" reports from |
hi @kcat, i added the checks you shared. i tested the changes on ubuntu and Windows. there seems to be no problem, but of course i think a review is necessary. commit was a big :) . |
…yevski/openal-soft into feat/clang-tidy-cmake
Hi @kcat . Sorry I've been MIA with this for a few months. It back from the dead :) .
I've created a patch that highlights the changes made by |
Apologies for being rather non-responsive about this. It's been something I wanted to look at, but kept forgetting as I wanted to avoid doing anything too significant before the release, and I wasn't sure exactly what it was going to do to. Now that the release is out, though, I can take a more focused look at it. I'm not terribly familiar with how clang-tidy itself functions, but I see it's passing the If it instead just outputs something with the fixes without directly modifying the sources, that should be fine. Or perhaps separate targets, one which does the checks and reports the suggested fixes that can be looked at, and another target that can apply those fixes if appropriate. I'm not really sure what the usual method of integrating clang-tidy into the build is for projects. |
Yes, it makes changes directly to the source files for errors it can fix or similar things. You're right about incorrect warnings (although I don't see any I've experienced outside of include ordering for my projects and jobs projects). I think this is a risk that should be taken into account, especially in a project with many mathematical operations, as it can be difficult to detect these false positives. If we prefer to avoid direct modifications to the source tree, we can use clang-tidy solely for feedback. By removing the As the initial developer of the project, you've already modernized it significantly and clang-tidy approved with this approach. However it can serve as a valuable tool for future contributors, helping them ensure code compatibility with modern C++ standards or another things.
That's possible. We could consider redirecting clang-tidy's console output to a file. |
There seems to be an Are you familiar with any other projects that have clang-tidy integrated into their cmake script like this? If so, what do they normally do? |
There are several examples of projects, most do not use modern CMake. I don't know of a popular open source project, I'll look into it. https://github.com/the-risk-taker/cppcheck-clang-tidy-and-cmake If the project is quite large and complex, they may prefer to run it with Python scripts (example llvm project). |
Removing the |
hi @kcat |
this changes introduces the integration of Clang-Tidy into the OpenAL-Soft project using CMake.
Clang-Tidy is a static code analysis tool that helps identify and fix potential issues in C++ code.
The changes in this pull request will analyze and apply clang-tidy fixes to the following directories and files:
al
alc
common
core
utils/openal-info.c
(if enabled)requirements
usage
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
flag to the CMake command line. And you can also set the appropriate clang-tidy program according to the platform, check out the note below.e.g.
cmake -G "MinGW Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release ..
clang-tidy-check
.e.g.
make clang-tidy-check
Note: LLVM toolset is usually installed as
<tool_name>-<version>
. Theclang-tidy
executable file may not be directly on your platform with the clang-tidy name/path. In this case, you can report clang-tidy available on the platform to cmake.The default executable is
clang-tidy
.For Linux based OSs:
export
.E.g.
export CLANG_TIDY_EXECUTABLE=clang-tidy-18
E.g.
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCLANG_TIDY_EXECUTABLE=clang-tidy-18 ..
For Windows OS:
SET
.E.g.
SET CLANG_TIDY_EXECUTABLE=clang-tidy-18
importants
some questions we need to answer
I can make changes based on these two questions.
For the second question i took the basic checks and tested some of them to see if they were compatible with the project. Activating some of them (ex. using explicit in single-argument constructors) requires a lot of time because it requires too many changes. I eliminated these.