Skip to content

Commit bb46968

Browse files
4009777 refactor: apply IWYU to `rpc/{fees,signmessage}.cpp` (Kittywhiskers Van Gogh) 85d96c2 merge bitcoin#25047: add readability-redundant-declaration (Kittywhiskers Van Gogh) 71b400d merge bitcoin#24971: modernize-use-nullptr (Kittywhiskers Van Gogh) 104ba87 merge bitcoin#25713: run clang-tidy in quiet mode (Kittywhiskers Van Gogh) 5647652 merge bitcoin#27012: Print iwyu patch in git diff format (Kittywhiskers Van Gogh) 2980992 merge bitcoin#28240: Remove unused boost signals2 from torcontrol (Kittywhiskers Van Gogh) 8e8faa2 merge bitcoin#24831: add include-what-you-use (Kittywhiskers Van Gogh) c673048 merge bitcoin#24753: Add clang-tidy task (Kittywhiskers Van Gogh) a6e80ec merge bitcoin#22903: Enable clang-tidy bugprone-argument-comment and fix violations (Kittywhiskers Van Gogh) Pull request description: ## Additional Information * While linting is generally reserved for our `arm_linux` build variant, utilizing IWYU (which in turns relies on `bear` for the compilation database, also relied upon by `clang-tidy`) requires a version paired to the Clang version ([source](https://github.com/dashpay/dash/blob/0b42caa2e84636e9a2901b485ea87627014a013b/contrib/containers/ci/Dockerfile#L139)) used to build the target codebase. This means it has to be run on a build variant that uses Clang. We have opted to use `linux64_multiprocess` as it the most lightweight Clang build variant available (compared to fuzz, UBSan and TSan variants which come with sanitizers tacked on). * An earlier version of this PR ([source](https://github.com/dashpay/dash/tree/2676eb914d7a1ca6a0f194fe5c573294c3ebee2f)) attempted to apply IWYU to Dash-specific code. This attempt was aborted because IWYU was found to behave non-deterministically. Furthermore, while IWYU will tell you what headers to use, it will not do the following: * Respect the usage of angle brackets for source headers (it will almost always suggest quotation marks) * Use C++-style headers (it will prefer `string.h` over `cstring` and changing it is a manual errand) * Apply its suggestions in alphabetical order (they will pool up at the bottom) * Respect newlines meant to separate sets of headers * Remain consistent (even if IWYU passes locally, there is no guarantee that it would translate to a green CI run) But it will do the following: * Change its suggestions based on the ordering of headers * Make suggestions to add headers/forward declarations and then when run a second time, urge you to remove them * Pull in implementation headers that shouldn't be directly included. IWYU currently ships with mappings to avoid this for the standard library ([source](https://github.com/include-what-you-use/include-what-you-use/blob/f88f045131bfa0ac709d1e0c103580666254b2c6/gcc.libc.imp)), Qt ([source](https://github.com/include-what-you-use/include-what-you-use/blob/f88f045131bfa0ac709d1e0c103580666254b2c6/qt5_11.imp)) and Boost ([source](https://github.com/include-what-you-use/include-what-you-use/blob/f88f045131bfa0ac709d1e0c103580666254b2c6/boost-all.imp)) but for all else, you're on your own. It was determined for now that we will simply take guidance from upstream on the matter and extend it to Dash code at some point in the future. * Both [bitcoin#25029](bitcoin#25029) and [bitcoin#25013](bitcoin#25013) made sure they pass IWYU, changes needed to ensure that the linter is satisfied were made in this PR. ## Breaking Changes None expected. ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests **(note: N/A)** - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK 4009777 PastaPastaPasta: utACK 4009777 Tree-SHA512: 0dae87abfd1f309300a3caadff565da831122591611cb0f6a7dc620e3edc775aeef954935b19035e2fd5b8334bd2281fb05b193a3bdb0844cd0f03890f506212
2 parents 96972a0 + 4009777 commit bb46968

37 files changed

+160
-82
lines changed

ci/dash/build_src.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ make distdir VERSION=$BUILD_TARGET
5151
cd dashcore-$BUILD_TARGET
5252
bash -c "./configure $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG" || ( cat config.log && false)
5353

54-
make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false )
54+
if [ "${RUN_TIDY}" = "true" ]; then
55+
MAYBE_BEAR="bear --config src/.bear-tidy-config"
56+
MAYBE_TOKEN="--"
57+
fi
58+
59+
bash -c "${MAYBE_BEAR} ${MAYBE_TOKEN} make ${MAKEJOBS} ${GOAL}" || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false )
5560

5661
ccache --version | head -n 1 && ccache --show-stats
5762

@@ -60,6 +65,24 @@ if [ -n "$USE_VALGRIND" ]; then
6065
${BASE_ROOT_DIR}/ci/test/wrap-valgrind.sh
6166
fi
6267

68+
if [ "${RUN_TIDY}" = "true" ]; then
69+
set -eo pipefail
70+
cd src
71+
( run-clang-tidy -quiet "${MAKEJOBS}" ) | grep -C5 "error"
72+
cd ..
73+
iwyu_tool.py \
74+
"src/compat" \
75+
"src/init" \
76+
"src/rpc/fees.cpp" \
77+
"src/rpc/signmessage.cpp" \
78+
-p . "${MAKEJOBS}" \
79+
-- -Xiwyu --cxx17ns -Xiwyu --mapping_file="${BASE_ROOT_DIR}/contrib/devtools/iwyu/bitcoin.core.imp" \
80+
|& tee "/tmp/iwyu_ci.out"
81+
cd src
82+
fix_includes.py --nosafe_headers < /tmp/iwyu_ci.out
83+
git --no-pager diff
84+
fi
85+
6386
if [ "$RUN_SECURITY_TESTS" = "true" ]; then
6487
make test-security-check
6588
fi

ci/test/00_setup_env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export USE_BUSY_BOX=${USE_BUSY_BOX:-false}
3838

3939
export RUN_UNIT_TESTS=${RUN_UNIT_TESTS:-true}
4040
export RUN_FUNCTIONAL_TESTS=${RUN_FUNCTIONAL_TESTS:-true}
41+
export RUN_TIDY=${RUN_TIDY:-false}
4142
export RUN_SECURITY_TESTS=${RUN_SECURITY_TESTS:-false}
4243
# By how much to scale the test_runner timeouts (option --timeout-factor).
4344
# This is needed because some ci machines have slow CPU or disk, so sanitizers

ci/test/00_setup_env_native_multiprocess.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export CONTAINER_NAME=ci_native_multiprocess
1010
export HOST=x86_64-pc-linux-gnu
1111
export PACKAGES="cmake python3 llvm clang"
1212
export DEP_OPTS="MULTIPROCESS=1 CC=clang-18 CXX=clang++-18"
13+
export RUN_TIDY=true
1314
export GOAL="install"
1415
export TEST_RUNNER_EXTRA="--v2transport"
1516
export BITCOIN_CONFIG="--with-boost-process --enable-debug CC=clang-18 CXX=clang++-18" # Use clang to avoid OOM
17+
# Additional flags for RUN_TIDY
18+
export BITCOIN_CONFIG="${BITCOIN_CONFIG} --disable-hardening CFLAGS='-O0 -g0' CXXFLAGS='-O0 -g0'"
1619
export BITCOIND=dash-node # Used in functional tests

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,8 @@ AC_CONFIG_LINKS([contrib/devtools/test-security-check.py:contrib/devtools/test-s
19111911
AC_CONFIG_LINKS([contrib/devtools/symbol-check.py:contrib/devtools/symbol-check.py])
19121912
AC_CONFIG_LINKS([contrib/devtools/test-symbol-check.py:contrib/devtools/test-symbol-check.py])
19131913
AC_CONFIG_LINKS([contrib/filter-lcov.py:contrib/filter-lcov.py])
1914+
AC_CONFIG_LINKS([src/.bear-tidy-config:src/.bear-tidy-config])
1915+
AC_CONFIG_LINKS([src/.clang-tidy:src/.clang-tidy])
19141916
AC_CONFIG_LINKS([test/functional/test_runner.py:test/functional/test_runner.py])
19151917
AC_CONFIG_LINKS([test/fuzz/test_runner.py:test/fuzz/test_runner.py])
19161918
AC_CONFIG_LINKS([test/util/test_runner.py:test/util/test_runner.py])

contrib/containers/ci/Dockerfile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ RUN set -ex; \
3939
autotools-dev \
4040
automake \
4141
autoconf \
42+
bear \
4243
bison \
4344
build-essential \
4445
bsdmainutils \
@@ -83,12 +84,14 @@ RUN set -ex; \
8384
"clang-tidy-${LLVM_VERSION}" \
8485
"libc++-${LLVM_VERSION}-dev" \
8586
"libc++abi-${LLVM_VERSION}-dev" \
87+
"libclang-${LLVM_VERSION}-dev" \
8688
"libclang-rt-${LLVM_VERSION}-dev" \
87-
"lld-${LLVM_VERSION}"; \
89+
"lld-${LLVM_VERSION}" \
90+
"llvm-${LLVM_VERSION}-dev"; \
8891
rm -rf /var/lib/apt/lists/*; \
8992
echo "Setting defaults..."; \
9093
lldbUpdAltArgs="update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-${LLVM_VERSION} 100"; \
91-
for binName in clang clang++ clang-format clang-tidy clangd dsymutil lld lldb lldb-server llvm-ar llvm-cov llvm-nm llvm-objdump llvm-ranlib llvm-strip; do \
94+
for binName in clang clang++ clang-apply-replacements clang-format clang-tidy clangd dsymutil lld lldb lldb-server llvm-ar llvm-cov llvm-nm llvm-objdump llvm-ranlib llvm-strip run-clang-tidy; do \
9295
lldbUpdAltArgs="${lldbUpdAltArgs} --slave /usr/bin/${binName} ${binName} /usr/bin/${binName}-${LLVM_VERSION}"; \
9396
done; \
9497
for binName in ld64.lld ld.lld lld-link wasm-ld; do \
@@ -140,6 +143,14 @@ RUN set -ex; \
140143
cd dash_hash && pip3 install -r requirements.txt .; \
141144
cd .. && rm -rf dash_hash
142145

146+
RUN set -ex; \
147+
git clone --depth=1 "https://github.com/include-what-you-use/include-what-you-use" -b "clang_${LLVM_VERSION}" /opt/iwyu; \
148+
cd /opt/iwyu; \
149+
mkdir build && cd build; \
150+
cmake -G 'Unix Makefiles' -DCMAKE_PREFIX_PATH=/usr/lib/llvm-${LLVM_VERSION} ..; \
151+
make install -j "$(( $(nproc) - 1 ))"; \
152+
cd /opt && rm -rf /opt/iwyu;
153+
143154
ARG SHELLCHECK_VERSION=v0.7.1
144155
RUN set -ex; \
145156
curl -fL "https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" -o /tmp/shellcheck.tar.xz; \
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Fixups / upstreamed changes
2+
[
3+
{ include: [ "<bits/termios-c_lflag.h>", private, "<termios.h>", public ] },
4+
{ include: [ "<bits/termios-struct.h>", private, "<termios.h>", public ] },
5+
{ include: [ "<bits/termios-tcflow.h>", private, "<termios.h>", public ] },
6+
]

src/.bear-tidy-config

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"output": {
3+
"content": {
4+
"include_only_existing_source": true,
5+
"paths_to_include": [],
6+
"paths_to_exclude": [
7+
"src/crc32",
8+
"src/crypto/x11",
9+
"src/dashbls",
10+
"src/gsl",
11+
"src/immer",
12+
"src/leveldb",
13+
"src/minisketch",
14+
"src/univalue",
15+
"src/secp256k1"
16+
]
17+
},
18+
"format": {
19+
"command_as_array": true,
20+
"drop_output_field": false
21+
}
22+
}
23+
}

src/.clang-tidy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Checks: '
2+
-*,
3+
bugprone-argument-comment,
4+
modernize-use-nullptr,
5+
readability-redundant-declaration,
6+
'
7+
WarningsAsErrors: '
8+
bugprone-argument-comment,
9+
modernize-use-nullptr,
10+
readability-redundant-declaration,
11+
'

src/bench/coin_selection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void CoinSelection(benchmark::Bench& bench)
5151
const CoinSelectionParams coin_selection_params(/* change_output_size= */ 34,
5252
/* change_spend_size= */ 148, /* effective_feerate= */ CFeeRate(0),
5353
/* long_term_feerate= */ CFeeRate(0), /* discard_feerate= */ CFeeRate(0),
54-
/* tx_no_inputs_size= */ 0, /* avoid_partial= */ false);
54+
/* tx_noinputs_size= */ 0, /* avoid_partial= */ false);
5555
bench.run([&] {
5656
std::set<CInputCoin> setCoinsRet;
5757
CAmount nValueRet;

src/compat/byteswap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <config/bitcoin-config.h>
1010
#endif
1111

12-
#include <stdint.h>
12+
#include <cstdint>
1313

1414
#if defined(HAVE_BYTESWAP_H)
1515
#include <byteswap.h>

0 commit comments

Comments
 (0)