From 2002d6964e576c003c10b083a1dcc884649833f4 Mon Sep 17 00:00:00 2001 From: Jordan Rome Date: Tue, 14 Apr 2026 07:43:02 -0700 Subject: [PATCH] tests: check: fix iwyu This fixes a few issues: - instead of running iwyu on one file, run it on the whole build if the WITH_IWYU flag is added - use Cmake's native iwyu instead of relying on the path --- .github/fedora-43.Dockerfile | 1 + .github/workflows/ci.yaml | 6 ++++++ CMakeLists.txt | 6 ++++++ tests/check/CMakeLists.txt | 9 +-------- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/fedora-43.Dockerfile b/.github/fedora-43.Dockerfile index 4099b79d1..0bde92787 100644 --- a/.github/fedora-43.Dockerfile +++ b/.github/fedora-43.Dockerfile @@ -32,6 +32,7 @@ RUN dnf --disablerepo=* --enablerepo=fedora,updates --nodocs --setopt=install_we python3-linuxdoc \ python3-scapy \ python3-sphinx \ + include-what-you-use \ sed \ xxd && \ dnf clean all -y diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 04049a330..7f39c3961 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -135,6 +135,12 @@ jobs: run: ctest --test-dir $GITHUB_WORKSPACE/build -L integration --verbose - name: Run checks run: ctest --test-dir $GITHUB_WORKSPACE/build -L check --verbose + + - name: Run IWYU + run: | + git config --global --add safe.directory $GITHUB_WORKSPACE + cmake -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build-iwyu -DWITH_IWYU=1 -DNO_BENCHMARKS=1 + make -C $GITHUB_WORKSPACE/build-iwyu -j `nproc` - name: Generate the coverage report run: make -C $GITHUB_WORKSPACE/build coverage diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e787ed8a..010a57d5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,12 @@ option(NO_TESTS "Disable unit, end-to-end, and integration tests" 0) option(NO_CHECKS "Disable the check target (clang-tidy and clang-format" 0) option(NO_BENCHMARKS "Disable the benchmark" 0) option(WITH_COVERAGE "Build with code coverage support. Disabled by default" 0) +option(WITH_IWYU "Build with include-what-you-use checks. Disabled by default" 0) + +if (WITH_IWYU) + find_program(IWYU_BIN NAMES include-what-you-use iwyu REQUIRED) + set(CMAKE_C_INCLUDE_WHAT_YOU_USE "${IWYU_BIN};-Xiwyu;--error") +endif () set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/tests/check/CMakeLists.txt b/tests/check/CMakeLists.txt index e26f9baf1..73c416fa6 100644 --- a/tests/check/CMakeLists.txt +++ b/tests/check/CMakeLists.txt @@ -27,13 +27,6 @@ add_test(NAME "check.lint" ${bf_srcs} ) -add_test(NAME "check.iwyu" - COMMAND - /usr/bin/iwyu_tool.py - -p ${CMAKE_BINARY_DIR} - ${CMAKE_SOURCE_DIR}/src/libbpfilter/cgen/program.c -) - set_tests_properties("check.lint" PROPERTIES LABELS "check" ) @@ -63,4 +56,4 @@ add_custom_target(fixstyle add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -L check COMMENT "Running check tests" -) \ No newline at end of file +)