From 02d2b5a11c921ef71c971ee80eb3dfbc75c8cb0d Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 8 Sep 2025 17:46:22 +0100 Subject: [PATCH] ci, iwyu: Treat warnings as errors for specific directories Currently, this applies only to the `crypto` and `index` directories. --- ci/test/03_test_script.sh | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/ci/test/03_test_script.sh b/ci/test/03_test_script.sh index 3e07f1c86d2..3c540cb89e3 100755 --- a/ci/test/03_test_script.sh +++ b/ci/test/03_test_script.sh @@ -213,14 +213,30 @@ if [ "${RUN_TIDY}" = "true" ]; then false fi + # TODO: Consider enforcing IWYU across the entire codebase. + FILES_WITH_ENFORCED_IWYU="/src/(crypto|index)/.*\\.cpp" + jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns)))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_errors.json" + jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns) | not))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_warnings.json" + cd "${BASE_ROOT_DIR}" - python3 "/include-what-you-use/iwyu_tool.py" \ - -p "${BASE_BUILD_DIR}" "${MAKEJOBS}" \ - -- -Xiwyu --cxx17ns -Xiwyu --mapping_file="${BASE_ROOT_DIR}/contrib/devtools/iwyu/bitcoin.core.imp" \ - -Xiwyu --max_line_length=160 \ - 2>&1 | tee /tmp/iwyu_ci.out - cd "${BASE_ROOT_DIR}/src" - python3 "/include-what-you-use/fix_includes.py" --nosafe_headers < /tmp/iwyu_ci.out + + run_iwyu() { + mv "${BASE_BUILD_DIR}/$1" "${BASE_BUILD_DIR}/compile_commands.json" + python3 "/include-what-you-use/iwyu_tool.py" \ + -p "${BASE_BUILD_DIR}" "${MAKEJOBS}" \ + -- -Xiwyu --cxx17ns -Xiwyu --mapping_file="${BASE_ROOT_DIR}/contrib/devtools/iwyu/bitcoin.core.imp" \ + -Xiwyu --max_line_length=160 \ + 2>&1 | tee /tmp/iwyu_ci.out + python3 "/include-what-you-use/fix_includes.py" --nosafe_headers < /tmp/iwyu_ci.out + } + + run_iwyu "compile_commands_iwyu_errors.json" + if ! ( git --no-pager diff --exit-code ); then + echo "^^^ ⚠️ Failure generated from IWYU" + false + fi + + run_iwyu "compile_commands_iwyu_warnings.json" git --no-pager diff fi