Skip to content
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 and Test Clang-tidy #1710

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

haytham918
Copy link

@haytham918 haytham918 commented Nov 18, 2024

Addressing the issue in #1060. Added clang-tidy check on files inside "libopenage" directory, focusing on "clang-analyzer", "bugprone", "concurrency", and "performance" issues. @heinezen

@haytham918
Copy link
Author

I think make checkall doesn't work for your workflow because it didn't detect installed clang-tidy

@heinezen heinezen added area: buildsystem Related to our cmake/python buildsystem lang: c++ Done in C++ code code quality Does not alter behavior, but beauty of our code labels Nov 18, 2024
@heinezen heinezen linked an issue Nov 18, 2024 that may be closed by this pull request
@heinezen
Copy link
Member

@TheJJ kevin needs clang-tidy to be installed

@heinezen
Copy link
Member

@haytham918 You should add clang-tidy as a sanity check dependency in https://github.com/SFTtech/openage/blob/master/doc/building.md#dependencies

@haytham918
Copy link
Author

@heinezen Thank you for the notice. I have updated it accordingly.

doc/building.md Outdated Show resolved Hide resolved
@heinezen heinezen added the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Nov 20, 2024
@SFTbot SFTbot removed the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Nov 20, 2024
@haytham918 haytham918 requested a review from TheJJ November 24, 2024 08:02
@heinezen
Copy link
Member

heinezen commented Dec 5, 2024

@TheJJ Did you add clang-tidy already?

@haytham918
Copy link
Author

@heinezen @TheJJ , I hope you are doing well with the new year :), any updates on this request?

@heinezen
Copy link
Member

heinezen commented Jan 8, 2025

@haytham918 Happy new year! I'm still waiting for @TheJJ to add clang-tidy to the CI machine.

@TheJJ
Copy link
Member

TheJJ commented Jan 9, 2025

It's in the image now :)

@heinezen heinezen added the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 9, 2025
@SFTbot SFTbot removed the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 9, 2025
@heinezen heinezen added the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 9, 2025
@SFTbot SFTbot removed the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 9, 2025
@heinezen heinezen added the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 11, 2025
@SFTbot SFTbot removed the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 11, 2025
@heinezen heinezen added the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 11, 2025
@SFTbot SFTbot removed the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 11, 2025
@haytham918
Copy link
Author

-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:34 (project):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
Error: Process completed with exit code 1.

This is what I am seeing from the build output, not sure what exactly is going wrong with the configuration? I don't think I have ever modified the CMake files.

@TheJJ TheJJ added the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 14, 2025
@SFTbot SFTbot removed the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 14, 2025
@TheJJ TheJJ added the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 14, 2025
@SFTbot SFTbot removed the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 14, 2025
@TheJJ TheJJ added the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 14, 2025
@SFTbot SFTbot removed the kevin-rebuild-pl0x instruct kevin to rebuild this pull request label Jan 14, 2025
@TheJJ
Copy link
Member

TheJJ commented Jan 14, 2025

Kevin is now able to run clang-tidy, but produces many errors.
The cause of this seems to be the invocation of clang-tidy, which must be integrated into the buildsystem (cmake), because only there the correct compiler invocations are available :)

@haytham918
Copy link
Author

Now clang-tidy seems to be working and generating warnings?

@simonsan
Copy link
Contributor

simonsan commented Jan 17, 2025

I think the compile command database needs to be added like this: https://stackoverflow.com/questions/63944447/how-to-specify-compilation-database-for-clang-tidy#71826250

-p ${CMAKE_BUILD_DIR}, also not -DCMAKE_EXPORT_COMPILE_COMMANDS=ON needs to be set to get the compile_commands.json if not already set.

-p <build-path> is used to read a compile command database.

        For example, it can be a CMake build directory in which a file named
        compile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
        CMake option to get this output). When no build path is specified,
        a search for compile_commands.json will be attempted through all
        parent paths of the first input file . See:
        https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an
        example of setting up Clang Tooling on a source tree.

@TheJJ
Copy link
Member

TheJJ commented Jan 17, 2025

we have the compile command export already. but we need to make clang-tidy to use it, i.e. by integrating it in the buildsystem. it can't run without cmake running before it.

the warnings it currently generates are not helpful since they fail at things like unknown includes, but once it's integrated into the real compile environment, real output is generated :)

@mikonse
Copy link

mikonse commented Jan 17, 2025

Fyi cmake natively supports running clang tidy as part of the normal build.
If the increased compile time is not a problem this is probably the easiest solution.

See https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_CLANG_TIDY.html

@TheJJ
Copy link
Member

TheJJ commented Jan 17, 2025

Thx, indeed. And now I remember: We actually added this already:

cli.add_argument("--clang-tidy", action="store_true",

set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=-*,readability-*")

https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_CLANG_TIDY.html
https://cmake.org/cmake/help/latest/prop_tgt/LANG_CLANG_TIDY.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: buildsystem Related to our cmake/python buildsystem code quality Does not alter behavior, but beauty of our code lang: c++ Done in C++ code
Projects
Status: Review in progress
Development

Successfully merging this pull request may close these issues.

Add clang-tidy to buildsystem checks
6 participants