Skip to content

Commit 5bbc7c8

Browse files
committed
Merge bitcoin/bitcoin#33810: ci: Add IWYU job
56750c4 iwyu, clang-format: Sort includes (Hennadii Stepanov) 2c78814 ci: Add IWYU job (Hennadii Stepanov) 94e4f04 cmake: Fix target name (Hennadii Stepanov) 0f81e00 cmake: Make `codegen` target dependent on `generate_build_info` (Hennadii Stepanov) 73f7844 iwyu: Add patch to prefer C++ headers over C counterparts (Hennadii Stepanov) 7a65437 iwyu: Add patch to prefer angled brackets over quotes for includes (Hennadii Stepanov) Pull request description: This PR separates the IWYU checks into its own CI job to provide faster feedback to developers. No other changes are made to the treatment of IWYU warnings. The existing “tidy” CI job will no longer run IWYU. See also the discussion of bitcoin/bitcoin#33779, specifically this [comment](bitcoin/bitcoin#33779 (comment)): > Maybe a better approach would be to run the enforced sections in a separate, faster job? Some of the linters are already a bit annoying to invoke locally, so I usually just run the lint job. Doing the same for the includes seems fine to me. Based on ideas from bitcoin/bitcoin#32953. ACKs for top commit: maflcko: review ACK 56750c4 🌄 sedited: ACK 56750c4 Tree-SHA512: af15326b6d0c5d1e11346ac64939644936c65eb9466cd1a17ab5da347d39aef10f7ab33b39fbca31ad291b0b4b54639b147b24410f4f86197e4a776049882694
2 parents 695e2b9 + 56750c4 commit 5bbc7c8

File tree

12 files changed

+653
-12
lines changed

12 files changed

+653
-12
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,12 @@ jobs:
522522
fail-fast: false
523523
matrix:
524524
include:
525+
- name: 'iwyu'
526+
cirrus-runner: 'ghcr.io/cirruslabs/ubuntu-runner-amd64:24.04-md'
527+
fallback-runner: 'ubuntu-24.04'
528+
timeout-minutes: 120
529+
file-env: './ci/test/00_setup_env_native_iwyu.sh'
530+
525531
- name: '32 bit ARM'
526532
cirrus-runner: 'ubuntu-24.04-arm' # Cirrus' Arm runners are Apple (with virtual Linux aarch64), which doesn't support 32-bit mode
527533
fallback-runner: 'ubuntu-24.04-arm'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
# Only ignore unexpected patches
1414
*.patch
15+
!ci/test/*.patch
1516
!contrib/guix/patches/*.patch
1617
!depends/patches/**/*.patch
1718

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2023-present The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
7+
export LC_ALL=C.UTF-8
8+
9+
export CI_IMAGE_NAME_TAG="mirror.gcr.io/debian:trixie" # To build codegen, CMake must be 3.31 or newer.
10+
export CONTAINER_NAME=ci_native_iwyu
11+
export TIDY_LLVM_V="21"
12+
export APT_LLVM_V="${TIDY_LLVM_V}"
13+
export PACKAGES="clang-${TIDY_LLVM_V} clang-format-${TIDY_LLVM_V} libclang-${TIDY_LLVM_V}-dev llvm-${TIDY_LLVM_V}-dev jq libevent-dev libboost-dev libzmq3-dev systemtap-sdt-dev qt6-base-dev qt6-tools-dev qt6-l10n-tools libqrencode-dev libsqlite3-dev libcapnp-dev capnproto"
14+
export NO_DEPENDS=1
15+
export RUN_UNIT_TESTS=false
16+
export RUN_FUNCTIONAL_TESTS=false
17+
export RUN_FUZZ_TESTS=false
18+
export RUN_CHECK_DEPS=false
19+
export RUN_IWYU=true
20+
export GOAL="codegen"
21+
export BITCOIN_CONFIG="\
22+
--preset dev-mode -DBUILD_GUI=OFF \
23+
-DCMAKE_C_COMPILER=clang-${TIDY_LLVM_V} \
24+
-DCMAKE_CXX_COMPILER=clang++-${TIDY_LLVM_V} \
25+
"

ci/test/01_base_install.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ if [[ -n "${USE_INSTRUMENTED_LIBCPP}" ]]; then
7979
rm -rf /llvm-project
8080
fi
8181

82-
if [[ "${RUN_TIDY}" == "true" ]]; then
82+
if [[ "${RUN_IWYU}" == true ]]; then
8383
${CI_RETRY_EXE} git clone --depth=1 https://github.com/include-what-you-use/include-what-you-use -b clang_"${TIDY_LLVM_V}" /include-what-you-use
84+
(cd /include-what-you-use && patch -p1 < /ci_container_base/ci/test/01_iwyu.patch)
8485
cmake -B /iwyu-build/ -G 'Unix Makefiles' -DCMAKE_PREFIX_PATH=/usr/lib/llvm-"${TIDY_LLVM_V}" -S /include-what-you-use
8586
make -C /iwyu-build/ install "$MAKEJOBS"
8687
fi

ci/test/01_iwyu.patch

Lines changed: 598 additions & 0 deletions
Large diffs are not rendered by default.

ci/test/03_test_script.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ echo "=== BEGIN env ==="
4444
env
4545
echo "=== END env ==="
4646

47-
# Don't apply patches in the tidy job, because it relies on the `git diff`
48-
# command to detect IWYU errors. It is safe to skip this patch in the tidy job
47+
# Don't apply patches in the iwyu job, because it relies on the `git diff`
48+
# command to detect IWYU errors. It is safe to skip this patch in the iwyu job
4949
# because it doesn't run a UB detector.
50-
if [ "$RUN_TIDY" != "true" ]; then
50+
if [[ "${RUN_IWYU}" != true ]]; then
5151
# compact->outputs[i].file_size is uninitialized memory, so reading it is UB.
5252
# The statistic bytes_written is only used for logging, which is disabled in
5353
# CI, so as a temporary minimal fix to work around UB and CI failures, leave
@@ -123,7 +123,7 @@ BASE_BUILD_DIR=${BASE_BUILD_DIR:-$BASE_SCRATCH_DIR/build-$HOST}
123123

124124
BITCOIN_CONFIG_ALL="$BITCOIN_CONFIG_ALL -DCMAKE_INSTALL_PREFIX=$BASE_OUTDIR -Werror=dev"
125125

126-
if [[ "${RUN_TIDY}" == "true" ]]; then
126+
if [[ "${RUN_IWYU}" == true || "${RUN_TIDY}" == true ]]; then
127127
BITCOIN_CONFIG_ALL="$BITCOIN_CONFIG_ALL -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
128128
fi
129129

@@ -135,11 +135,15 @@ cmake -S "$BASE_ROOT_DIR" -B "$BASE_BUILD_DIR" "${CMAKE_ARGS[@]}" || (
135135
false
136136
)
137137

138+
if [[ "${GOAL}" != all && "${GOAL}" != codegen ]]; then
139+
GOAL="all ${GOAL}"
140+
fi
141+
138142
# shellcheck disable=SC2086
139-
cmake --build "${BASE_BUILD_DIR}" "$MAKEJOBS" --target all $GOAL || (
143+
cmake --build "${BASE_BUILD_DIR}" "$MAKEJOBS" --target $GOAL || (
140144
echo "Build failure. Verbose build follows."
141145
# shellcheck disable=SC2086
142-
cmake --build "${BASE_BUILD_DIR}" -j1 --target all $GOAL --verbose
146+
cmake --build "${BASE_BUILD_DIR}" -j1 --target $GOAL --verbose
143147
false
144148
)
145149

@@ -207,7 +211,9 @@ if [ "${RUN_TIDY}" = "true" ]; then
207211
echo "^^^ ⚠️ Failure generated from clang-tidy"
208212
false
209213
fi
214+
fi
210215

216+
if [[ "${RUN_IWYU}" == true ]]; then
211217
# TODO: Consider enforcing IWYU across the entire codebase.
212218
FILES_WITH_ENFORCED_IWYU="/src/((crypto|index)/.*\\.cpp|node/blockstorage.cpp|node/utxo_snapshot.cpp|core_read.cpp|signet.cpp|kernel/chain.cpp)"
213219
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"
@@ -223,6 +229,7 @@ if [ "${RUN_TIDY}" = "true" ]; then
223229
-Xiwyu --max_line_length=160 \
224230
2>&1 | tee /tmp/iwyu_ci.out
225231
python3 "/include-what-you-use/fix_includes.py" --nosafe_headers < /tmp/iwyu_ci.out
232+
git diff -U0 | ./contrib/devtools/clang-format-diff.py -binary="clang-format-${TIDY_LLVM_V}" -p1 -i -v
226233
}
227234

228235
run_iwyu "compile_commands_iwyu_errors.json"

ci/test_imagefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ENV BASE_ROOT_DIR=${BASE_ROOT_DIR}
1616

1717
# Make retry available in PATH, needed for CI_RETRY_EXE
1818
COPY ./ci/retry/retry /usr/bin/retry
19-
COPY ./ci/test/00_setup_env.sh ./${FILE_ENV} ./ci/test/01_base_install.sh /ci_container_base/ci/test/
19+
COPY ./ci/test/00_setup_env.sh ./${FILE_ENV} ./ci/test/01_base_install.sh ./ci/test/01_iwyu.patch /ci_container_base/ci/test/
2020

2121
# Bash is required, so install it when missing
2222
RUN sh -c "bash -c 'true' || ( apk update && apk add --no-cache bash )"

cmake/libmultiprocess.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function(add_libmultiprocess subdir)
2727
mark_as_advanced(CapnProto_kj-tls_IMPORTED_LOCATION)
2828
if(BUILD_TESTS)
2929
# Add tests to "all" target so ctest can run them
30-
set_target_properties(mptests PROPERTIES EXCLUDE_FROM_ALL OFF)
30+
set_target_properties(mptest PROPERTIES EXCLUDE_FROM_ALL OFF)
3131
endif()
3232
# Exclude examples from compilation database, because the examples are not
3333
# built by default, and they contain generated c++ code. Without this

contrib/devtools/iwyu/bitcoin.core.imp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313
{ "symbol": ["SEEK_CUR", "private", "<cstdio>", "public"] },
1414
{ "symbol": ["SEEK_END", "private", "<cstdio>", "public"] },
1515
{ "symbol": ["SEEK_SET", "private", "<cstdio>", "public"] },
16+
17+
# IWYU bug.
18+
# See: https://github.com/include-what-you-use/include-what-you-use/issues/1863.
19+
{ "symbol": ["std::vector", "private", "<vector>", "public"] },
1620
]

src/.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ ForEachMacros:
9797
- BOOST_FOREACH
9898
IfMacros:
9999
- KJ_IF_MAYBE
100-
IncludeBlocks: Preserve
100+
IncludeBlocks: Regroup
101101
IncludeCategories:
102102
- Regex: '^<bitcoin-build-config\.h>'
103103
Priority: -1

0 commit comments

Comments
 (0)