ci, iwyu: Treat warnings as errors for specific directories
What changed, and why it matters
This commit changes a Bitcoin Core continuous integration (CI) script so that a code-cleanup tool called Include What You Use (IWYU) treats its findings as hard errors for two source directories (`crypto` and `index`), while keeping them as warnings everywhere else. It is a build/development hygiene change, not a fix for a security vulnerability or a change to the Bitcoin protocol or wallet code.
No security action required. This is a CI quality-of-life change. Reviewers may want to confirm the regex `FILES_WITH_ENFORCED_IWYU` matches the intended directories and that the temporary `compile_commands.json` swap does not affect later CI steps.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies ci/test/03_test_script.sh to split compile_commands.json into two filtered files: one containing only src/crypto and src/index .cpp files, and another containing everything else. IWYU is then run twice: first on the filtered set with a git diff --exit-code check that fails the build if any include changes are generated, and then on the rest of the codebase as non-fatal warnings. This enforces stricter include hygiene in the selected directories without expanding enforcement to the whole repository.
Changed components
ci/test/03_test_script.shInspect captured patch +23 / −7
diff --git a/ci/test/03_test_script.sh b/ci/test/03_test_script.sh
index 3e07f1c8..3c540cb8 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
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.