From 4f84719a807e3a747e8347179a3a45d21b65194c Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Fri, 25 Oct 2024 10:47:26 +0200 Subject: [PATCH] GitHub Actions: Run clang-tidy via CMake instead of run-clang-tidy, fix #2446 --- .github/workflows/linux.yml | 20 ++++++++------------ CMakeLists.txt | 6 ++++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 9cbc8a79cd..07431bf797 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -14,26 +14,26 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install dependencies - run: dnf install -y ninja-build cmake gtest-devel re2c clang util-linux + run: dnf install -y ninja-build cmake gtest-devel re2c clang util-linux clang-tools-extra - name: Linting run: misc/ci.py - name: Configure with CMake - run: cmake -Bbuild -G"Ninja Multi-Config" + run: cmake -Bbuild -G"Ninja Multi-Config" -DNINJA_CLANG_TIDY=1 - name: Build debug ninja - run: ninja + run: CLICOLOR_FORCE=1 ninja working-directory: build - name: Test debug ninja working-directory: build/Debug run: | - ./ninja_test + ./ninja_test --gtest_color=yes ../../misc/output_test.py - name: Build release ninja - run: ninja -f build-Release.ninja + run: CLICOLOR_FORCE=1 ninja -f build-Release.ninja working-directory: build - name: Test release ninja working-directory: build/Release run: | - ./ninja_test + ./ninja_test --gtest_color=yes ../../misc/output_test.py build: @@ -107,7 +107,7 @@ jobs: - name: Install dependencies run: | apt update - apt install -y python3-pytest ninja-build clang-tidy python3-pip clang libgtest-dev + apt install -y python3-pytest ninja-build python3-pip clang libgtest-dev pip3 install cmake==3.17.* - name: Configure (GCC) run: cmake -Bbuild-gcc -DCMAKE_BUILD_TYPE=Debug -G'Ninja Multi-Config' @@ -129,7 +129,7 @@ jobs: working-directory: build-gcc/Release - name: Configure (Clang) - run: CC=clang CXX=clang++ cmake -Bbuild-clang -DCMAKE_BUILD_TYPE=Debug -G'Ninja Multi-Config' -DCMAKE_EXPORT_COMPILE_COMMANDS=1 + run: CC=clang CXX=clang++ cmake -Bbuild-clang -DCMAKE_BUILD_TYPE=Debug -G'Ninja Multi-Config' - name: Build (Clang, Debug) run: cmake --build build-clang --config Debug @@ -147,10 +147,6 @@ jobs: run: pytest-3 --color=yes ../.. working-directory: build-clang/Release - - name: clang-tidy - run: /usr/lib/llvm-10/share/clang/run-clang-tidy.py -header-filter=src - working-directory: build-clang - build-with-python: runs-on: [ubuntu-latest] container: diff --git a/CMakeLists.txt b/CMakeLists.txt index 47b1f9c117..04214f95d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,6 +206,12 @@ if(NINJA_BUILD_BINARY) if(WIN32) target_sources(ninja PRIVATE windows/ninja.manifest) endif() + + option(NINJA_CLANG_TIDY "Run clang-tidy on source files" OFF) + if(NINJA_CLANG_TIDY) + set_target_properties(libninja PROPERTIES CXX_CLANG_TIDY "clang-tidy;--use-color") + set_target_properties(ninja PROPERTIES CXX_CLANG_TIDY "clang-tidy;--use-color") + endif() endif() # Adds browse mode into the ninja binary if it's supported by the host platform.