From d3411bf10cc5e7beba44f9efa788edaef50e4a1d Mon Sep 17 00:00:00 2001 From: Jacob Merson Date: Tue, 13 Jan 2026 13:35:41 -0500 Subject: [PATCH 1/5] test cmake-based approach to run clang-tidy --- .github/workflows/clang-tidy.yml | 22 ++-------------------- CMakeLists.txt | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 94231301..0037fe48 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -191,9 +191,6 @@ jobs: - name: Install fftw3 run: sudo apt-get install -yq libfftw3-dev pkg-config - - - name: Install Bear - run: sudo apt-get install -yq bear - name: configure pcms run : | @@ -219,27 +216,12 @@ jobs: -DKokkosKernels_DIR=${{ runner.temp }}/build-kokkos-kernels-openmpi/install/lib/cmake/KokkosKernels/ \ -DPCMS_TEST_DATA_DIR=$PWD/pcms_testcases - - name: Configure pcms with Bear - run: | - cd ${{ runner.temp }}/build-pcms - bear -- make - - name: Install clang-tidy run: | sudo apt-get update sudo apt-get install -yq clang-tidy-18 + # TODO need to capture the error code from this - name: Run clang-tidy run: | - EXIT_CODE=0 - while read file; do - if ! clang-tidy -p ${{ runner.temp }}/build-pcms "$file" --quiet; then - echo "$file has clang-tidy issues" - EXIT_CODE=1 - fi - done < <(find src -name "*.cpp" -o -name "*.hpp" -o -name "*.c" -o -name "*.h" -o -name "*.cc" -o -name "*.cxx" | grep -v 'src/pcms/capi/' | grep -v 'src/pcms/fortranapi/') - if [ $EXIT_CODE -eq 1 ]; then - echo "Some C/C++ files have clang-tidy issues. Please fix them with clang-tidy-18." - exit 1 - fi - echo "All C/C++ files pass clang-tidy checks" + cmake --build ${{ runner.temp }}/build-pcms -t run-clang-tidy diff --git a/CMakeLists.txt b/CMakeLists.txt index d9c519ca..3cf5fa68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,28 @@ if(PCMS_ENABLE_ASAN AND CMAKE_COMPILER_IS_GNUCXX MATCHES 1) set(PCMS_HAS_ASAN ON) endif() +# based on Professional CMake: A Practical Guide +# this approach works around some issues with CMakes internal handling using co-compilation +# this approach affords a separate clang-tidy run step in the CI +if(PROJECT_IS_TOP_LEVEL) + set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) + + find_program(CLANG_TIDY_EXECUTABLE clang-tidy REQUIRED) + find_program(RUN_CLANG_TIDY_EXECUTABLE run-clang-tidy REQUIRED) + + set(CLANG_TIDY_CONFIG_FILE ${CMAKE_CURRENT_LIST_DIR}/.clang-tidy) + + message(STATUS "CLANG_TIDY_EXECUTABLE=${CLANG_TIDY_EXECUTABLE}") + message(STATUS "RUN_CLANG_TIDY_EXECUTABLE= ${RUN_CLANG_TIDY_EXECUTABLE}") + message(STATUS "CLANG_TIDY_CONFIG_FILE=${CLANG_TIDY_CONFIG_FILE}") + add_custom_target(run-clang-tidy + COMMAND ${RUN_CLANG_TIDY_EXECUTABLE} + -clang-tidy-binary ${CLANG_TIDY_EXECUTABLE} + -p ${CMAKE_BINARY_DIR} + -config-file ${CLANG_TIDY_CONFIG_FILE} + ) +endif() + option(PCMS_ENABLE_SERVER "enable the coupling server implementation" ON) option(PCMS_ENABLE_CLIENT "enable the coupling client implementation" ON) From 836bc838193a75cdc3aa7dafc2d5deb5c339638b Mon Sep 17 00:00:00 2001 From: Jacob Merson Date: Wed, 11 Feb 2026 10:29:37 -0500 Subject: [PATCH 2/5] add source filter for c and fortran files --- .clang-tidy | 6 +++++- CMakeLists.txt | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 0cffe771..4dc20745 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -14,6 +14,10 @@ Checks: > modernize-use-using WarningsAsErrors: '*' -HeaderFilterRegex: 'src/.*' +# capi and fortran api headers are c headers and clang-tidy produces not useful errors +ExcludeHeaderFilterRegex: '.*(capi|fortranapi).*' +# skip c, fortran, and interface creation files +# this is actually needed by run-clang-tidy, so it cannot be included here :( +#ExcludeSourceFilterRegex: '\.(c|i|f90)$' FormatStyle: none InheritParentConfig: true \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cf5fa68..62953219 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,15 +28,19 @@ if(PROJECT_IS_TOP_LEVEL) find_program(RUN_CLANG_TIDY_EXECUTABLE run-clang-tidy REQUIRED) set(CLANG_TIDY_CONFIG_FILE ${CMAKE_CURRENT_LIST_DIR}/.clang-tidy) + set(CLANG_TIDY_SOURCE_FILTER [=[^(?!.*(\.c|\.i|\.f90)$).*$]=]) message(STATUS "CLANG_TIDY_EXECUTABLE=${CLANG_TIDY_EXECUTABLE}") message(STATUS "RUN_CLANG_TIDY_EXECUTABLE= ${RUN_CLANG_TIDY_EXECUTABLE}") message(STATUS "CLANG_TIDY_CONFIG_FILE=${CLANG_TIDY_CONFIG_FILE}") + message(STATUS "CLANG_TIDY_SOURCE_FILTER=${CLANG_TIDY_SOURCE_FILTER}") + add_custom_target(run-clang-tidy - COMMAND ${RUN_CLANG_TIDY_EXECUTABLE} + VERBATIM COMMAND ${RUN_CLANG_TIDY_EXECUTABLE} -clang-tidy-binary ${CLANG_TIDY_EXECUTABLE} -p ${CMAKE_BINARY_DIR} -config-file ${CLANG_TIDY_CONFIG_FILE} + -source-filter ${CLANG_TIDY_SOURCE_FILTER} ) endif() From 11b0250a514dd3ad7252e3f325ee5f84745d3a90 Mon Sep 17 00:00:00 2001 From: Jacob Merson Date: Wed, 11 Feb 2026 11:56:22 -0500 Subject: [PATCH 3/5] try updating clang-tidy version --- .github/workflows/clang-tidy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 0037fe48..045124fa 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -219,7 +219,7 @@ jobs: - name: Install clang-tidy run: | sudo apt-get update - sudo apt-get install -yq clang-tidy-18 + sudo apt-get install -yq clang-tidy-20 # TODO need to capture the error code from this - name: Run clang-tidy From eb7749d2410a143de04825643d20956e10403109 Mon Sep 17 00:00:00 2001 From: Jacob Merson Date: Wed, 11 Feb 2026 12:03:31 -0500 Subject: [PATCH 4/5] add verbose for debugging --- .github/workflows/clang-tidy.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 045124fa..46574a36 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -41,6 +41,11 @@ jobs: - name: Install cmake run: sudo apt-get install -yq cmake + - name: Install clang-tidy + run: | + sudo apt-get update + sudo apt-get install -yq clang-tidy-20 + - uses: actions/checkout@v4 - name: build Catch2 @@ -215,13 +220,8 @@ jobs: -DKokkos_DIR=${{ runner.temp }}/build-kokkos-openmpi/install/lib/cmake/Kokkos \ -DKokkosKernels_DIR=${{ runner.temp }}/build-kokkos-kernels-openmpi/install/lib/cmake/KokkosKernels/ \ -DPCMS_TEST_DATA_DIR=$PWD/pcms_testcases - - - name: Install clang-tidy - run: | - sudo apt-get update - sudo apt-get install -yq clang-tidy-20 - + # TODO need to capture the error code from this - name: Run clang-tidy run: | - cmake --build ${{ runner.temp }}/build-pcms -t run-clang-tidy + VERBOSE=1 cmake --build ${{ runner.temp }}/build-pcms -t run-clang-tidy From 3119ba86d7795b8001fb090afa2ea77ccc5eabb1 Mon Sep 17 00:00:00 2001 From: Jacob Merson Date: Wed, 11 Feb 2026 12:12:49 -0500 Subject: [PATCH 5/5] add additional debugging output --- .github/workflows/clang-tidy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 46574a36..0a4485aa 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -224,4 +224,5 @@ jobs: # TODO need to capture the error code from this - name: Run clang-tidy run: | + clang-tidy --version VERBOSE=1 cmake --build ${{ runner.temp }}/build-pcms -t run-clang-tidy