Skip to content

Commit aec631b

Browse files
committed
Merge bitcoin/bitcoin#23462: test: Enable SC2046 and SC2086 shellcheck rules
fe0ff56 test: Enable SC2046 shellcheck rule (Hennadii Stepanov) 9a1ad7b test: Enable SC2086 shellcheck rule (Hennadii Stepanov) Pull request description: Closes #20879. Replaces #22695. **Note for reviewers**. Some touched shell scripts are not being run in CI, therefore they require more thorough reviewing: - `contrib/devtools/gen-manpages.sh` - `contrib/macdeploy/detached-sig-apply.sh` - `contrib/windeploy/detached-sig-create.sh` - `src/qt/res/animation/makespinner.sh` ACKs for top commit: laanwj: Code review re-ACK fe0ff56 Tree-SHA512: 73619b9a7bcb6cf0dfc4189a753ef550d40c82a3432bb9d8d8a994310d42594576038daac7e0c2fc004d716976bb1413b9a77848ecf088b25b69ed0773b77e8e
2 parents 2efc8c0 + fe0ff56 commit aec631b

26 files changed

+76
-67
lines changed

ci/lint/04_install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export LC_ALL=C
88

99
${CI_RETRY_EXE} apt-get update
1010
${CI_RETRY_EXE} apt-get install -y clang-format-9 python3-pip curl git gawk jq
11-
update-alternatives --install /usr/bin/clang-format clang-format $(which clang-format-9 ) 100
12-
update-alternatives --install /usr/bin/clang-format-diff clang-format-diff $(which clang-format-diff-9) 100
11+
update-alternatives --install /usr/bin/clang-format clang-format "$(which clang-format-9 )" 100
12+
update-alternatives --install /usr/bin/clang-format-diff clang-format-diff "$(which clang-format-diff-9)" 100
1313

1414
${CI_RETRY_EXE} pip3 install codespell==2.0.0
1515
${CI_RETRY_EXE} pip3 install flake8==3.8.3

ci/lint/06_script.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ if [ "$CIRRUS_REPO_FULL_NAME" = "bitcoin/bitcoin" ] && [ "$CIRRUS_PR" = "" ] ; t
3131
# sanity checking only a few (10) commits seems sufficient and cheap.
3232
git log HEAD~10 -1 --format='%H' > ./contrib/verify-commits/trusted-sha512-root-commit
3333
git log HEAD~10 -1 --format='%H' > ./contrib/verify-commits/trusted-git-root
34-
${CI_RETRY_EXE} gpg --keyserver hkps://keys.openpgp.org --recv-keys $(<contrib/verify-commits/trusted-keys) &&
34+
mapfile -t KEYS < contrib/verify-commits/trusted-keys
35+
${CI_RETRY_EXE} gpg --keyserver hkps://keys.openpgp.org --recv-keys "${KEYS[@]}" &&
3536
./contrib/verify-commits/verify-commits.py;
3637
fi
3738

ci/test/00_setup_env_native_qt5.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export RUN_UNIT_TESTS_SEQUENTIAL="true"
1515
export RUN_UNIT_TESTS="false"
1616
export GOAL="install"
1717
export PREVIOUS_RELEASES_TO_DOWNLOAD="v0.15.2 v0.16.3 v0.17.2 v0.18.1 v0.19.1 v0.20.1"
18-
export BITCOIN_CONFIG="--enable-zmq --with-libs=no --with-gui=qt5 --enable-reduce-exports
18+
export BITCOIN_CONFIG="--enable-zmq --with-libs=no --with-gui=qt5 --enable-reduce-exports \
1919
--enable-debug --disable-fuzz-binary CFLAGS=\"-g0 -O2 -funsigned-char\" CXXFLAGS=\"-g0 -O2 -funsigned-char\" CC=gcc-8 CXX=g++-8"

ci/test/04_install.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fi
1212

1313
if [ "$CI_OS_NAME" == "macos" ]; then
1414
sudo -H pip3 install --upgrade pip
15+
# shellcheck disable=SC2086
1516
IN_GETOPT_BIN="/usr/local/opt/gnu-getopt/bin/getopt" ${CI_RETRY_EXE} pip3 install --user $PIP_PACKAGES
1617
fi
1718

@@ -39,6 +40,7 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
3940
systemctl restart docker
4041
fi
4142

43+
# shellcheck disable=SC2086
4244
DOCKER_ID=$(docker run $DOCKER_ADMIN --rm --interactive --detach --tty \
4345
--mount type=bind,src=$BASE_ROOT_DIR,dst=/ro_base,readonly \
4446
--mount type=bind,src=$CCACHE_DIR,dst=$CCACHE_DIR \
@@ -54,7 +56,7 @@ else
5456
fi
5557

5658
DOCKER_EXEC () {
57-
$DOCKER_CI_CMD_PREFIX bash -c "export PATH=$BASE_SCRATCH_DIR/bins/:\$PATH && cd $P_CI_DIR && $*"
59+
$DOCKER_CI_CMD_PREFIX bash -c "export PATH=$BASE_SCRATCH_DIR/bins/:\$PATH && cd \"$P_CI_DIR\" && $*"
5860
}
5961
export -f DOCKER_EXEC
6062

@@ -64,11 +66,12 @@ fi
6466

6567
if [[ $DOCKER_NAME_TAG == centos* ]]; then
6668
${CI_RETRY_EXE} DOCKER_EXEC dnf -y install epel-release
67-
${CI_RETRY_EXE} DOCKER_EXEC dnf -y --allowerasing install $DOCKER_PACKAGES $PACKAGES
69+
${CI_RETRY_EXE} DOCKER_EXEC dnf -y --allowerasing install "$DOCKER_PACKAGES" "$PACKAGES"
6870
elif [ "$CI_USE_APT_INSTALL" != "no" ]; then
6971
${CI_RETRY_EXE} DOCKER_EXEC apt-get update
70-
${CI_RETRY_EXE} DOCKER_EXEC apt-get install --no-install-recommends --no-upgrade -y $PACKAGES $DOCKER_PACKAGES
72+
${CI_RETRY_EXE} DOCKER_EXEC apt-get install --no-install-recommends --no-upgrade -y "$PACKAGES" "$DOCKER_PACKAGES"
7173
if [ -n "$PIP_PACKAGES" ]; then
74+
# shellcheck disable=SC2086
7275
${CI_RETRY_EXE} pip3 install --user $PIP_PACKAGES
7376
fi
7477
fi
@@ -79,14 +82,14 @@ if [ "$CI_OS_NAME" == "macos" ]; then
7982
else
8083
DOCKER_EXEC free -m -h
8184
DOCKER_EXEC echo "Number of CPUs \(nproc\):" \$\(nproc\)
82-
DOCKER_EXEC echo $(lscpu | grep Endian)
85+
DOCKER_EXEC echo "$(lscpu | grep Endian)"
8386
fi
8487
DOCKER_EXEC echo "Free disk space:"
8588
DOCKER_EXEC df -h
8689

8790
if [ "$RUN_FUZZ_TESTS" = "true" ] || [ "$RUN_UNIT_TESTS" = "true" ] || [ "$RUN_UNIT_TESTS_SEQUENTIAL" = "true" ]; then
88-
if [ ! -d ${DIR_QA_ASSETS} ]; then
89-
DOCKER_EXEC git clone --depth=1 https://github.com/bitcoin-core/qa-assets ${DIR_QA_ASSETS}
91+
if [ ! -d "${DIR_QA_ASSETS}" ]; then
92+
DOCKER_EXEC git clone --depth=1 https://github.com/bitcoin-core/qa-assets "${DIR_QA_ASSETS}"
9093
fi
9194

9295
export DIR_FUZZ_IN=${DIR_QA_ASSETS}/fuzz_seed_corpus/
@@ -106,17 +109,17 @@ fi
106109

107110
if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
108111
echo "Create $BASE_ROOT_DIR"
109-
DOCKER_EXEC rsync -a /ro_base/ $BASE_ROOT_DIR
112+
DOCKER_EXEC rsync -a /ro_base/ "$BASE_ROOT_DIR"
110113
fi
111114

112115
if [ "$USE_BUSY_BOX" = "true" ]; then
113116
echo "Setup to use BusyBox utils"
114-
DOCKER_EXEC mkdir -p $BASE_SCRATCH_DIR/bins/
117+
DOCKER_EXEC mkdir -p "${BASE_SCRATCH_DIR}/bins/"
115118
# tar excluded for now because it requires passing in the exact archive type in ./depends (fixed in later BusyBox version)
116119
# find excluded for now because it does not recognize the -delete option in ./depends (fixed in later BusyBox version)
117120
# ar excluded for now because it does not recognize the -q option in ./depends (unknown if fixed)
118121
# shellcheck disable=SC1010
119-
DOCKER_EXEC for util in \$\(busybox --list \| grep -v "^ar$" \| grep -v "^tar$" \| grep -v "^find$"\)\; do ln -s \$\(command -v busybox\) $BASE_SCRATCH_DIR/bins/\$util\; done
122+
DOCKER_EXEC for util in \$\(busybox --list \| grep -v "^ar$" \| grep -v "^tar$" \| grep -v "^find$"\)\; do ln -s \$\(command -v busybox\) "${BASE_SCRATCH_DIR}/bins/\$util"\; done
120123
# Print BusyBox version
121124
DOCKER_EXEC patch --help
122125
fi

ci/test/05_before_script.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export LC_ALL=C.UTF-8
88

99
# Make sure default datadir does not exist and is never read by creating a dummy file
1010
if [ "$CI_OS_NAME" == "macos" ]; then
11-
echo > $HOME/Library/Application\ Support/Bitcoin
11+
echo > "${HOME}/Library/Application Support/Bitcoin"
1212
else
1313
DOCKER_EXEC echo \> \$HOME/.bitcoin
1414
fi
1515

16-
DOCKER_EXEC mkdir -p ${DEPENDS_DIR}/SDKs ${DEPENDS_DIR}/sdk-sources
16+
DOCKER_EXEC mkdir -p "${DEPENDS_DIR}/SDKs" "${DEPENDS_DIR}/sdk-sources"
1717

1818
OSX_SDK_BASENAME="Xcode-${XCODE_VERSION}-${XCODE_BUILD_ID}-extracted-SDK-with-libcxx-headers.tar.gz"
1919
OSX_SDK_PATH="${DEPENDS_DIR}/sdk-sources/${OSX_SDK_BASENAME}"
@@ -42,7 +42,7 @@ if [ -n "$XCODE_VERSION" ] && [ -f "$OSX_SDK_PATH" ]; then
4242
DOCKER_EXEC tar -C "${DEPENDS_DIR}/SDKs" -xf "$OSX_SDK_PATH"
4343
fi
4444
if [[ $HOST = *-mingw32 ]]; then
45-
DOCKER_EXEC update-alternatives --set $HOST-g++ \$\(which $HOST-g++-posix\)
45+
DOCKER_EXEC update-alternatives --set "${HOST}-g++" \$\(which "${HOST}-g++-posix"\)
4646
fi
4747
if [ -z "$NO_DEPENDS" ]; then
4848
if [[ $DOCKER_NAME_TAG == centos* ]]; then
@@ -53,7 +53,7 @@ if [ -z "$NO_DEPENDS" ]; then
5353
else
5454
SHELL_OPTS="CONFIG_SHELL="
5555
fi
56-
DOCKER_EXEC $SHELL_OPTS make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS
56+
DOCKER_EXEC "$SHELL_OPTS" make "$MAKEJOBS" -C depends HOST="$HOST" "$DEP_OPTS"
5757
fi
5858
if [ -n "$PREVIOUS_RELEASES_TO_DOWNLOAD" ]; then
5959
DOCKER_EXEC test/get_previous_releases.py -b -t "$PREVIOUS_RELEASES_DIR" "${PREVIOUS_RELEASES_TO_DOWNLOAD}"

ci/test/06_script_a.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export LC_ALL=C.UTF-8
99
if [ -n "$ANDROID_TOOLS_URL" ]; then
1010
DOCKER_EXEC make distclean || true
1111
DOCKER_EXEC ./autogen.sh
12-
DOCKER_EXEC ./configure $BITCOIN_CONFIG --prefix=$DEPENDS_DIR/aarch64-linux-android || ( (DOCKER_EXEC cat config.log) && false)
12+
DOCKER_EXEC ./configure "$BITCOIN_CONFIG" --prefix="${DEPENDS_DIR}/aarch64-linux-android" || ( (DOCKER_EXEC cat config.log) && false)
1313
DOCKER_EXEC "make $MAKEJOBS && cd src/qt && ANDROID_HOME=${ANDROID_HOME} ANDROID_NDK_HOME=${ANDROID_NDK_HOME} make apk"
1414
exit 0
1515
fi
@@ -29,13 +29,13 @@ fi
2929
DOCKER_EXEC mkdir -p "${BASE_BUILD_DIR}"
3030
export P_CI_DIR="${BASE_BUILD_DIR}"
3131

32-
DOCKER_EXEC "${BASE_ROOT_DIR}/configure" --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( (DOCKER_EXEC cat config.log) && false)
32+
DOCKER_EXEC "${BASE_ROOT_DIR}/configure" --cache-file=config.cache "$BITCOIN_CONFIG_ALL" "$BITCOIN_CONFIG" || ( (DOCKER_EXEC cat config.log) && false)
3333

34-
DOCKER_EXEC make distdir VERSION=$HOST
34+
DOCKER_EXEC make distdir VERSION="$HOST"
3535

3636
export P_CI_DIR="${BASE_BUILD_DIR}/bitcoin-$HOST"
3737

38-
DOCKER_EXEC ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( (DOCKER_EXEC cat config.log) && false)
38+
DOCKER_EXEC ./configure --cache-file=../config.cache "$BITCOIN_CONFIG_ALL" "$BITCOIN_CONFIG" || ( (DOCKER_EXEC cat config.log) && false)
3939

4040
set -o errtrace
4141
trap 'DOCKER_EXEC "cat ${BASE_SCRATCH_DIR}/sanitizer-output/* 2> /dev/null"' ERR
@@ -48,7 +48,7 @@ if [[ ${USE_MEMORY_SANITIZER} == "true" ]]; then
4848
DOCKER_EXEC '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'
4949
fi
5050

51-
DOCKER_EXEC make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && DOCKER_EXEC make $GOAL V=1 ; false )
51+
DOCKER_EXEC make "$MAKEJOBS" "$GOAL" || ( echo "Build failure. Verbose build follows." && DOCKER_EXEC make "$GOAL" V=1 ; false )
5252

5353
DOCKER_EXEC "ccache --version | head -n 1 && ccache --show-stats"
5454
DOCKER_EXEC du -sh "${DEPENDS_DIR}"/*/

ci/test/06_script_b.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ export LC_ALL=C.UTF-8
88

99
if [[ $HOST = *-mingw32 ]]; then
1010
# Generate all binaries, so that they can be wrapped
11-
DOCKER_EXEC make $MAKEJOBS -C src/secp256k1 VERBOSE=1
11+
DOCKER_EXEC make "$MAKEJOBS" -C src/secp256k1 VERBOSE=1
1212
DOCKER_EXEC "${BASE_ROOT_DIR}/ci/test/wrap-wine.sh"
1313
fi
1414

1515
if [ -n "$QEMU_USER_CMD" ]; then
1616
# Generate all binaries, so that they can be wrapped
17-
DOCKER_EXEC make $MAKEJOBS -C src/secp256k1 VERBOSE=1
17+
DOCKER_EXEC make "$MAKEJOBS" -C src/secp256k1 VERBOSE=1
1818
DOCKER_EXEC "${BASE_ROOT_DIR}/ci/test/wrap-qemu.sh"
1919
fi
2020

@@ -23,21 +23,21 @@ if [ -n "$USE_VALGRIND" ]; then
2323
fi
2424

2525
if [ "$RUN_UNIT_TESTS" = "true" ]; then
26-
DOCKER_EXEC ${TEST_RUNNER_ENV} DIR_UNIT_TEST_DATA=${DIR_UNIT_TEST_DATA} LD_LIBRARY_PATH=$DEPENDS_DIR/$HOST/lib make $MAKEJOBS check VERBOSE=1
26+
DOCKER_EXEC "${TEST_RUNNER_ENV}" DIR_UNIT_TEST_DATA="${DIR_UNIT_TEST_DATA}" LD_LIBRARY_PATH="${DEPENDS_DIR}/${HOST}/lib" make "$MAKEJOBS" check VERBOSE=1
2727
fi
2828

2929
if [ "$RUN_UNIT_TESTS_SEQUENTIAL" = "true" ]; then
30-
DOCKER_EXEC ${TEST_RUNNER_ENV} DIR_UNIT_TEST_DATA=${DIR_UNIT_TEST_DATA} LD_LIBRARY_PATH=$DEPENDS_DIR/$HOST/lib "${BASE_BUILD_DIR}/bitcoin-*/src/test/test_bitcoin*" --catch_system_errors=no -l test_suite
30+
DOCKER_EXEC "${TEST_RUNNER_ENV}" DIR_UNIT_TEST_DATA="${DIR_UNIT_TEST_DATA}" LD_LIBRARY_PATH="${DEPENDS_DIR}/${HOST}/lib" "${BASE_BUILD_DIR}/bitcoin-*/src/test/test_bitcoin*" --catch_system_errors=no -l test_suite
3131
fi
3232

3333
if [ "$RUN_FUNCTIONAL_TESTS" = "true" ]; then
34-
DOCKER_EXEC 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=4000 --timeout-factor=${TEST_RUNNER_TIMEOUT_FACTOR} ${TEST_RUNNER_EXTRA} --quiet --failfast
34+
DOCKER_EXEC 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=4000 --timeout-factor="${TEST_RUNNER_TIMEOUT_FACTOR}" "${TEST_RUNNER_EXTRA}" --quiet --failfast
3535
fi
3636

3737
if [ "$RUN_SECURITY_TESTS" = "true" ]; then
3838
DOCKER_EXEC make test-security-check
3939
fi
4040

4141
if [ "$RUN_FUZZ_TESTS" = "true" ]; then
42-
DOCKER_EXEC LD_LIBRARY_PATH=$DEPENDS_DIR/$HOST/lib test/fuzz/test_runner.py ${FUZZ_TESTS_CONFIG} $MAKEJOBS -l DEBUG ${DIR_FUZZ_IN}
42+
DOCKER_EXEC LD_LIBRARY_PATH="${DEPENDS_DIR}/${HOST}/lib" test/fuzz/test_runner.py "${FUZZ_TESTS_CONFIG}" "$MAKEJOBS" -l DEBUG "${DIR_FUZZ_IN}"
4343
fi

ci/test/wrap-qemu.sh

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

99
for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/minisketch/test{,-verify},src/univalue/{no_nul,test_json,unitester,object}}; do
1010
# shellcheck disable=SC2044
11-
for b in $(find "${BASE_ROOT_DIR}" -executable -type f -name $(basename $b_name)); do
11+
for b in $(find "${BASE_ROOT_DIR}" -executable -type f -name "$(basename "$b_name")"); do
1212
echo "Wrap $b ..."
1313
mv "$b" "${b}_orig"
1414
echo '#!/usr/bin/env bash' > "$b"

ci/test/wrap-valgrind.sh

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

99
for b_name in "${BASE_OUTDIR}/bin"/*; do
1010
# shellcheck disable=SC2044
11-
for b in $(find "${BASE_ROOT_DIR}" -executable -type f -name $(basename $b_name)); do
11+
for b in $(find "${BASE_ROOT_DIR}" -executable -type f -name "$(basename "$b_name")"); do
1212
echo "Wrap $b ..."
1313
mv "$b" "${b}_orig"
1414
echo '#!/usr/bin/env bash' > "$b"

ci/test/wrap-wine.sh

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

99
for b_name in {"${BASE_OUTDIR}/bin"/*,src/secp256k1/*tests,src/minisketch/test{,-verify},src/univalue/{no_nul,test_json,unitester,object}}.exe; do
1010
# shellcheck disable=SC2044
11-
for b in $(find "${BASE_ROOT_DIR}" -executable -type f -name "$(basename $b_name)"); do
11+
for b in $(find "${BASE_ROOT_DIR}" -executable -type f -name "$(basename "$b_name")"); do
1212
if (file "$b" | grep "Windows"); then
1313
echo "Wrap $b ..."
1414
mv "$b" "${b}_orig"

0 commit comments

Comments
 (0)