@@ -213,14 +213,30 @@ if [ "${RUN_TIDY}" = "true" ]; then
213213 false
214214 fi
215215
216+ # TODO: Consider enforcing IWYU across the entire codebase.
217+ FILES_WITH_ENFORCED_IWYU=" /src/(crypto|index)/.*\\ .cpp"
218+ 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"
219+ 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"
220+
216221 cd " ${BASE_ROOT_DIR} "
217- python3 " /include-what-you-use/iwyu_tool.py" \
218- -p " ${BASE_BUILD_DIR} " " ${MAKEJOBS} " \
219- -- -Xiwyu --cxx17ns -Xiwyu --mapping_file=" ${BASE_ROOT_DIR} /contrib/devtools/iwyu/bitcoin.core.imp" \
220- -Xiwyu --max_line_length=160 \
221- 2>&1 | tee /tmp/iwyu_ci.out
222- cd " ${BASE_ROOT_DIR} /src"
223- python3 " /include-what-you-use/fix_includes.py" --nosafe_headers < /tmp/iwyu_ci.out
222+
223+ run_iwyu () {
224+ mv " ${BASE_BUILD_DIR} /$1 " " ${BASE_BUILD_DIR} /compile_commands.json"
225+ python3 " /include-what-you-use/iwyu_tool.py" \
226+ -p " ${BASE_BUILD_DIR} " " ${MAKEJOBS} " \
227+ -- -Xiwyu --cxx17ns -Xiwyu --mapping_file=" ${BASE_ROOT_DIR} /contrib/devtools/iwyu/bitcoin.core.imp" \
228+ -Xiwyu --max_line_length=160 \
229+ 2>&1 | tee /tmp/iwyu_ci.out
230+ python3 " /include-what-you-use/fix_includes.py" --nosafe_headers < /tmp/iwyu_ci.out
231+ }
232+
233+ run_iwyu " compile_commands_iwyu_errors.json"
234+ if ! ( git --no-pager diff --exit-code ); then
235+ echo " ^^^ ⚠️ Failure generated from IWYU"
236+ false
237+ fi
238+
239+ run_iwyu " compile_commands_iwyu_warnings.json"
224240 git --no-pager diff
225241fi
226242
0 commit comments