Skip to content

Commit 5c9caba

Browse files
fanquakeClaude Code
authored andcommitted
Merge bitcoin#27616: ci: Remove CI_EXEC bloat
fa01c3c ci: Remove CI_EXEC bloat (MarcoFalke) fa8a428 move-only: Move almost all CI_EXEC code to 06_script_b.sh (MarcoFalke) Pull request description: `CI_EXEC` has many issues: * It is roughly equivalent to `bash -c "$*"`, meaning that the full command will be treated as a single string, ignoring tokens. * It must be put in front of (almost) every command, making it easy to forget, hard to debug the resulting failure, and the code verbose. Fix all issues by removing it almost completely. ACKs for top commit: TheCharlatan: ACK fa01c3c Tree-SHA512: 4a65d61f5c35ca945d31f270dba3e96305fd83333a7713f0452c67f02a78e1901113e9f18d21e1dc016403c0033eb32038a9308d0a0ded7ee6b970d18381a1c2
1 parent 9f3e4fa commit 5c9caba

File tree

4 files changed

+229
-98
lines changed

4 files changed

+229
-98
lines changed

ci/test/04_install.sh

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -75,65 +75,3 @@ export -f CI_EXEC
7575
export -f CI_EXEC_ROOT
7676

7777
CI_EXEC mkdir -p "${BINS_SCRATCH_DIR}"
78-
79-
if [ -n "$DPKG_ADD_ARCH" ]; then
80-
CI_EXEC_ROOT dpkg --add-architecture "$DPKG_ADD_ARCH"
81-
fi
82-
83-
if [[ $DOCKER_NAME_TAG == *centos* ]]; then
84-
CI_EXEC_ROOT yum -y install epel-release
85-
CI_EXEC_ROOT yum -y install "$DOCKER_PACKAGES" "$PACKAGES"
86-
elif [ "$CI_USE_APT_INSTALL" != "no" ]; then
87-
${CI_RETRY_EXE} CI_EXEC_ROOT apt-get update
88-
${CI_RETRY_EXE} CI_EXEC_ROOT apt-get install --no-install-recommends --no-upgrade -y "$PACKAGES" "$DOCKER_PACKAGES"
89-
if [ -n "$PIP_PACKAGES" ]; then
90-
# shellcheck disable=SC2086
91-
${CI_RETRY_EXE} pip3 install --user $PIP_PACKAGES
92-
fi
93-
fi
94-
95-
if [ "$CI_OS_NAME" == "macos" ]; then
96-
top -l 1 -s 0 | awk ' /PhysMem/ {print}'
97-
echo "Number of CPUs: $(sysctl -n hw.logicalcpu)"
98-
else
99-
CI_EXEC free -m -h
100-
CI_EXEC echo "Number of CPUs \(nproc\):" \$\(nproc\)
101-
CI_EXEC echo "$(lscpu | grep Endian)"
102-
fi
103-
CI_EXEC echo "Free disk space:"
104-
CI_EXEC df -h
105-
106-
if [ "$RUN_FUZZ_TESTS" = "true" ]; then
107-
export DIR_FUZZ_IN=${DIR_QA_ASSETS}/fuzz_seed_corpus/
108-
if [ ! -d "$DIR_FUZZ_IN" ]; then
109-
CI_EXEC git clone --depth=1 https://github.com/bitcoin-core/qa-assets "${DIR_QA_ASSETS}"
110-
fi
111-
(
112-
CI_EXEC cd "${DIR_QA_ASSETS}"
113-
CI_EXEC echo "Using qa-assets repo from commit ..."
114-
CI_EXEC git log -1
115-
)
116-
elif [ "$RUN_UNIT_TESTS" = "true" ] || [ "$RUN_UNIT_TESTS_SEQUENTIAL" = "true" ]; then
117-
export DIR_UNIT_TEST_DATA=${DIR_QA_ASSETS}/unit_test_data/
118-
if [ ! -d "$DIR_UNIT_TEST_DATA" ]; then
119-
CI_EXEC mkdir -p "$DIR_UNIT_TEST_DATA"
120-
CI_EXEC curl --location --fail https://github.com/bitcoin-core/qa-assets/raw/main/unit_test_data/script_assets_test.json -o "${DIR_UNIT_TEST_DATA}/script_assets_test.json"
121-
fi
122-
fi
123-
124-
CI_EXEC mkdir -p "${BASE_SCRATCH_DIR}/sanitizer-output/"
125-
126-
if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
127-
echo "Create $BASE_ROOT_DIR"
128-
CI_EXEC rsync -a /ro_base/ "$BASE_ROOT_DIR"
129-
fi
130-
131-
if [ "$USE_BUSY_BOX" = "true" ]; then
132-
echo "Setup to use BusyBox utils"
133-
# tar excluded for now because it requires passing in the exact archive type in ./depends (fixed in later BusyBox version)
134-
# ar excluded for now because it does not recognize the -q option in ./depends (unknown if fixed)
135-
# shellcheck disable=SC1010
136-
CI_EXEC for util in \$\(busybox --list \| grep -v "^ar$" \| grep -v "^tar$" \)\; do ln -s \$\(command -v busybox\) "${BINS_SCRATCH_DIR}/\$util"\; done
137-
# Print BusyBox version
138-
CI_EXEC patch --help
139-
fi

ci/test/05_before_script.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

ci/test/06_script_b.sh

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2018-2022 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+
set -ex
10+
11+
if [ "$CI_OS_NAME" == "macos" ]; then
12+
top -l 1 -s 0 | awk ' /PhysMem/ {print}'
13+
echo "Number of CPUs: $(sysctl -n hw.logicalcpu)"
14+
else
15+
free -m -h
16+
echo "Number of CPUs \(nproc\):" \$\(nproc\)
17+
lscpu | grep Endian
18+
fi
19+
echo "Free disk space:"
20+
df -h
21+
22+
if [ "$RUN_FUZZ_TESTS" = "true" ]; then
23+
export DIR_FUZZ_IN=${DIR_QA_ASSETS}/fuzz_seed_corpus/
24+
if [ ! -d "$DIR_FUZZ_IN" ]; then
25+
git clone --depth=1 https://github.com/bitcoin-core/qa-assets "${DIR_QA_ASSETS}"
26+
fi
27+
elif [ "$RUN_UNIT_TESTS" = "true" ] || [ "$RUN_UNIT_TESTS_SEQUENTIAL" = "true" ]; then
28+
export DIR_UNIT_TEST_DATA=${DIR_QA_ASSETS}/unit_test_data/
29+
if [ ! -d "$DIR_UNIT_TEST_DATA" ]; then
30+
mkdir -p "$DIR_UNIT_TEST_DATA"
31+
curl --location --fail https://github.com/bitcoin-core/qa-assets/raw/main/unit_test_data/script_assets_test.json -o "${DIR_UNIT_TEST_DATA}/script_assets_test.json"
32+
fi
33+
fi
34+
35+
mkdir -p "${BASE_SCRATCH_DIR}/sanitizer-output/"
36+
37+
if [ "$USE_BUSY_BOX" = "true" ]; then
38+
echo "Setup to use BusyBox utils"
39+
# tar excluded for now because it requires passing in the exact archive type in ./depends (fixed in later BusyBox version)
40+
# ar excluded for now because it does not recognize the -q option in ./depends (unknown if fixed)
41+
for util in $(busybox --list | grep -v "^ar$" | grep -v "^tar$" ); do ln -s "$(command -v busybox)" "${BINS_SCRATCH_DIR}/$util"; done
42+
# Print BusyBox version
43+
patch --help
44+
fi
45+
46+
# Make sure default datadir does not exist and is never read by creating a dummy file
47+
if [ "$CI_OS_NAME" == "macos" ]; then
48+
echo > "${HOME}/Library/Application Support/Bitcoin"
49+
else
50+
echo > "${HOME}/.bitcoin"
51+
fi
52+
53+
if [ -z "$NO_DEPENDS" ]; then
54+
if [[ $CI_IMAGE_NAME_TAG == *centos* ]]; then
55+
# CentOS has problems building the depends if the config shell is not explicitly set
56+
# (i.e. for libevent a Makefile with an empty SHELL variable is generated, leading to
57+
# an error as the first command is executed)
58+
SHELL_OPTS="LC_ALL=en_US.UTF-8 CONFIG_SHELL=/bin/dash"
59+
else
60+
SHELL_OPTS="CONFIG_SHELL="
61+
fi
62+
bash -c "$SHELL_OPTS make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS LOG=1"
63+
fi
64+
if [ "$DOWNLOAD_PREVIOUS_RELEASES" = "true" ]; then
65+
test/get_previous_releases.py -b -t "$PREVIOUS_RELEASES_DIR"
66+
fi
67+
68+
BITCOIN_CONFIG_ALL="--enable-suppress-external-warnings --disable-dependency-tracking"
69+
if [ -z "$NO_DEPENDS" ]; then
70+
BITCOIN_CONFIG_ALL="${BITCOIN_CONFIG_ALL} CONFIG_SITE=$DEPENDS_DIR/$HOST/share/config.site"
71+
fi
72+
if [ -z "$NO_WERROR" ]; then
73+
BITCOIN_CONFIG_ALL="${BITCOIN_CONFIG_ALL} --enable-werror"
74+
fi
75+
76+
ccache --zero-stats --max-size="${CCACHE_SIZE}"
77+
PRINT_CCACHE_STATISTICS="ccache --version | head -n 1 && ccache --show-stats"
78+
79+
if [ -n "$ANDROID_TOOLS_URL" ]; then
80+
make distclean || true
81+
./autogen.sh
82+
bash -c "./configure $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG" || ( (cat config.log) && false)
83+
make "${MAKEJOBS}" && cd src/qt && ANDROID_HOME=${ANDROID_HOME} ANDROID_NDK_HOME=${ANDROID_NDK_HOME} make apk
84+
bash -c "${PRINT_CCACHE_STATISTICS}"
85+
exit 0
86+
fi
87+
88+
BITCOIN_CONFIG_ALL="${BITCOIN_CONFIG_ALL} --enable-external-signer --prefix=$BASE_OUTDIR"
89+
90+
if [ -n "$CONFIG_SHELL" ]; then
91+
"$CONFIG_SHELL" -c "./autogen.sh"
92+
else
93+
./autogen.sh
94+
fi
95+
96+
mkdir -p "${BASE_BUILD_DIR}"
97+
cd "${BASE_BUILD_DIR}"
98+
99+
bash -c "${BASE_ROOT_DIR}/configure --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG" || ( (cat config.log) && false)
100+
101+
make distdir VERSION="$HOST"
102+
103+
cd "${BASE_BUILD_DIR}/bitcoin-$HOST"
104+
105+
bash -c "./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG" || ( (cat config.log) && false)
106+
107+
set -o errtrace
108+
trap 'bash -c "cat ${BASE_SCRATCH_DIR}/sanitizer-output/* 2> /dev/null"' ERR
109+
110+
if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then
111+
# MemorySanitizer (MSAN) does not support tracking memory initialization done by
112+
# using the Linux getrandom syscall. Avoid using getrandom by undefining
113+
# HAVE_SYS_GETRANDOM. See https://github.com/google/sanitizers/issues/852 for
114+
# details.
115+
grep -v HAVE_SYS_GETRANDOM src/config/bitcoin-config.h > src/config/bitcoin-config.h.tmp && mv src/config/bitcoin-config.h.tmp src/config/bitcoin-config.h
116+
fi
117+
118+
if [[ "${RUN_TIDY}" == "true" ]]; then
119+
MAYBE_BEAR="bear --config src/.bear-tidy-config"
120+
MAYBE_TOKEN="--"
121+
fi
122+
123+
bash -c "${MAYBE_BEAR} ${MAYBE_TOKEN} make $MAKEJOBS $GOAL" || ( echo "Build failure. Verbose build follows." && make "$GOAL" V=1 ; false )
124+
125+
bash -c "${PRINT_CCACHE_STATISTICS}"
126+
du -sh "${DEPENDS_DIR}"/*/
127+
du -sh "${PREVIOUS_RELEASES_DIR}"
128+
129+
if [[ $HOST = *-mingw32 ]]; then
130+
# Generate all binaries, so that they can be wrapped
131+
make "$MAKEJOBS" -C src/secp256k1 VERBOSE=1
132+
make "$MAKEJOBS" -C src minisketch/test.exe VERBOSE=1
133+
"${BASE_ROOT_DIR}/ci/test/wrap-wine.sh"
134+
fi
135+
136+
if [ -n "$QEMU_USER_CMD" ]; then
137+
# Generate all binaries, so that they can be wrapped
138+
make "$MAKEJOBS" -C src/secp256k1 VERBOSE=1
139+
make "$MAKEJOBS" -C src minisketch/test VERBOSE=1
140+
"${BASE_ROOT_DIR}/ci/test/wrap-qemu.sh"
141+
fi
142+
143+
if [ -n "$USE_VALGRIND" ]; then
144+
"${BASE_ROOT_DIR}/ci/test/wrap-valgrind.sh"
145+
fi
146+
147+
if [ "$RUN_UNIT_TESTS" = "true" ]; then
148+
bash -c "${TEST_RUNNER_ENV} DIR_UNIT_TEST_DATA=${DIR_UNIT_TEST_DATA} LD_LIBRARY_PATH=${DEPENDS_DIR}/${HOST}/lib make $MAKEJOBS check VERBOSE=1"
149+
fi
150+
151+
if [ "$RUN_UNIT_TESTS_SEQUENTIAL" = "true" ]; then
152+
bash -c "${TEST_RUNNER_ENV} DIR_UNIT_TEST_DATA=${DIR_UNIT_TEST_DATA} LD_LIBRARY_PATH=${DEPENDS_DIR}/${HOST}/lib ${BASE_OUTDIR}/bin/test_bitcoin --catch_system_errors=no -l test_suite"
153+
fi
154+
155+
if [ "$RUN_FUNCTIONAL_TESTS" = "true" ]; then
156+
bash -c "LD_LIBRARY_PATH=${DEPENDS_DIR}/${HOST}/lib ${TEST_RUNNER_ENV} test/functional/test_runner.py --ci $MAKEJOBS --tmpdirprefix ${BASE_SCRATCH_DIR}/test_runner/ --ansi --combinedlogslen=99999999 --timeout-factor=${TEST_RUNNER_TIMEOUT_FACTOR} ${TEST_RUNNER_EXTRA} --quiet --failfast"
157+
fi
158+
159+
if [ "${RUN_TIDY}" = "true" ]; then
160+
set -eo pipefail
161+
cd "${BASE_BUILD_DIR}/bitcoin-$HOST/src/"
162+
( run-clang-tidy-16 -quiet "${MAKEJOBS}" ) | grep -C5 "error"
163+
cd "${BASE_BUILD_DIR}/bitcoin-$HOST/"
164+
python3 "${DIR_IWYU}/include-what-you-use/iwyu_tool.py" \
165+
src/common/args.cpp \
166+
src/common/config.cpp \
167+
src/common/init.cpp \
168+
src/common/url.cpp \
169+
src/compat \
170+
src/dbwrapper.cpp \
171+
src/init \
172+
src/kernel \
173+
src/node/blockmanager_args.cpp \
174+
src/node/chainstate.cpp \
175+
src/node/chainstatemanager_args.cpp \
176+
src/node/mempool_args.cpp \
177+
src/node/minisketchwrapper.cpp \
178+
src/node/utxo_snapshot.cpp \
179+
src/node/validation_cache_args.cpp \
180+
src/policy/feerate.cpp \
181+
src/policy/packages.cpp \
182+
src/policy/settings.cpp \
183+
src/primitives/transaction.cpp \
184+
src/random.cpp \
185+
src/rpc/fees.cpp \
186+
src/rpc/signmessage.cpp \
187+
src/test/fuzz/string.cpp \
188+
src/test/fuzz/txorphan.cpp \
189+
src/test/fuzz/util \
190+
src/test/util/coins.cpp \
191+
src/uint256.cpp \
192+
src/util/bip32.cpp \
193+
src/util/bytevectorhash.cpp \
194+
src/util/check.cpp \
195+
src/util/error.cpp \
196+
src/util/exception.cpp \
197+
src/util/getuniquepath.cpp \
198+
src/util/hasher.cpp \
199+
src/util/message.cpp \
200+
src/util/moneystr.cpp \
201+
src/util/serfloat.cpp \
202+
src/util/spanparsing.cpp \
203+
src/util/strencodings.cpp \
204+
src/util/string.cpp \
205+
src/util/syserror.cpp \
206+
src/util/threadinterrupt.cpp \
207+
src/zmq \
208+
-p . "${MAKEJOBS}" \
209+
-- -Xiwyu --cxx17ns -Xiwyu --mapping_file="${BASE_BUILD_DIR}/bitcoin-$HOST/contrib/devtools/iwyu/bitcoin.core.imp" \
210+
2>&1 | tee /tmp/iwyu_ci.out
211+
cd "${BASE_ROOT_DIR}/src"
212+
python3 "${DIR_IWYU}/include-what-you-use/fix_includes.py" --nosafe_headers < /tmp/iwyu_ci.out
213+
git --no-pager diff
214+
fi
215+
216+
if [ "$RUN_SECURITY_TESTS" = "true" ]; then
217+
make test-security-check
218+
fi
219+
220+
if [ "$RUN_FUZZ_TESTS" = "true" ]; then
221+
bash -c "LD_LIBRARY_PATH=${DEPENDS_DIR}/${HOST}/lib test/fuzz/test_runner.py ${FUZZ_TESTS_CONFIG} $MAKEJOBS -l DEBUG ${DIR_FUZZ_IN}"
222+
fi

ci/test_run_all.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ export LC_ALL=C.UTF-8
88

99
set -o errexit; source ./ci/test/00_setup_env.sh
1010
set -o errexit; source ./ci/test/04_install.sh
11-
set -o errexit; source ./ci/test/05_before_script.sh
11+
set -o errexit
12+
CI_EXEC "${BASE_ROOT_DIR}/ci/test/06_script_b.sh"
13+
14+
if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
15+
echo "Stop and remove CI container by ID"
16+
docker container kill "${CI_CONTAINER_ID}"
17+
fi

0 commit comments

Comments
 (0)