Skip to content

Commit 6bd6560

Browse files
authored
refactor(shellcheck): enable for entire repo and fix all warnings (rapidsai#1971)
xref rapidsai/build-planning#135 Authors: - Gil Forsyth (https://github.com/gforsyth) Approvers: - Bradley Dice (https://github.com/bdice) URL: rapidsai#1971
1 parent 17c7545 commit 6bd6560

File tree

11 files changed

+43
-37
lines changed

11 files changed

+43
-37
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ python/ @rapidsai/rmm-python-codeowners
1414
/.github/ @rapidsai/ci-codeowners
1515
/ci/ @rapidsai/ci-codeowners
1616
/.pre-commit-config.yaml @rapidsai/ci-codeowners
17+
/.shellcheckrc @rapidsai/ci-codeowners
1718

1819
#packaging code owners
1920
/.devcontainer/ @rapidsai/packaging-codeowners

.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ repos:
9999
rev: v0.10.0.1
100100
hooks:
101101
- id: shellcheck
102-
args: ["--severity=warning"]
103-
files: ^ci/
104102

105103
default_language_version:
106104
python: python3

.shellcheckrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Disable file checks (otherwise every use of `gha-tools` will get flagged)
2+
disable=SC1091

build.sh

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ARGS=$*
1616

1717
# NOTE: ensure all dir changes are relative to the location of this
1818
# script, and that this script resides in the repo dir!
19-
REPODIR=$(cd $(dirname $0); pwd)
19+
REPODIR=$(cd "$(dirname "$0")"; pwd)
2020

2121
VALIDARGS="clean librmm rmm -v -g -n -s --ptds -h tests benchmarks"
2222
HELP="$0 [clean] [librmm] [rmm] [-v] [-g] [-n] [-s] [--ptds] [--cmake-args=\"<args>\"] [-h]
@@ -61,24 +61,25 @@ function hasArg {
6161

6262
function cmakeArgs {
6363
# Check for multiple cmake args options
64-
if [[ $(echo $ARGS | { grep -Eo "\-\-cmake\-args" || true; } | wc -l ) -gt 1 ]]; then
64+
if [[ $(echo "$ARGS" | { grep -Eo "\-\-cmake\-args" || true; } | wc -l ) -gt 1 ]]; then
6565
echo "Multiple --cmake-args options were provided, please provide only one: ${ARGS}"
6666
exit 1
6767
fi
6868

6969
# Check for cmake args option
70-
if [[ -n $(echo $ARGS | { grep -E "\-\-cmake\-args" || true; } ) ]]; then
70+
if [[ -n $(echo "$ARGS" | { grep -E "\-\-cmake\-args" || true; } ) ]]; then
7171
# There are possible weird edge cases that may cause this regex filter to output nothing and fail silently
7272
# the true pipe will catch any weird edge cases that may happen and will cause the program to fall back
7373
# on the invalid option error
74-
EXTRA_CMAKE_ARGS=$(echo $ARGS | { grep -Eo "\-\-cmake\-args=\".+\"" || true; })
74+
EXTRA_CMAKE_ARGS=$(echo "$ARGS" | { grep -Eo "\-\-cmake\-args=\".+\"" || true; })
7575
if [[ -n ${EXTRA_CMAKE_ARGS} ]]; then
7676
# Remove the full EXTRA_CMAKE_ARGS argument from list of args so that it passes validArgs function
7777
ARGS=${ARGS//$EXTRA_CMAKE_ARGS/}
7878
# Filter the full argument down to just the extra string that will be added to cmake call
79-
EXTRA_CMAKE_ARGS=$(echo $EXTRA_CMAKE_ARGS | grep -Eo "\".+\"" | sed -e 's/^"//' -e 's/"$//')
79+
EXTRA_CMAKE_ARGS=$(echo "$EXTRA_CMAKE_ARGS" | grep -Eo "\".+\"" | sed -e 's/^"//' -e 's/"$//')
8080
fi
8181
fi
82+
read -ra EXTRA_CMAKE_ARGS <<< "$EXTRA_CMAKE_ARGS"
8283
}
8384

8485

@@ -88,14 +89,14 @@ function ensureCMakeRan {
8889
mkdir -p "${LIBRMM_BUILD_DIR}"
8990
if (( RAN_CMAKE == 0 )); then
9091
echo "Executing cmake for librmm..."
91-
cmake -S ${REPODIR}/cpp -B "${LIBRMM_BUILD_DIR}" \
92+
cmake -S "${REPODIR}"/cpp -B "${LIBRMM_BUILD_DIR}" \
9293
-DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
9394
-DCUDA_STATIC_RUNTIME="${CUDA_STATIC_RUNTIME}" \
9495
-DPER_THREAD_DEFAULT_STREAM="${PER_THREAD_DEFAULT_STREAM}" \
9596
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
9697
-DBUILD_TESTS=${BUILD_TESTS} \
9798
-DBUILD_BENCHMARKS=${BUILD_BENCHMARKS} \
98-
${EXTRA_CMAKE_ARGS}
99+
"${EXTRA_CMAKE_ARGS[@]}"
99100
RAN_CMAKE=1
100101
fi
101102
}
@@ -106,7 +107,7 @@ if hasArg -h || hasArg --help; then
106107
fi
107108

108109
# Check for valid usage
109-
if (( ${NUMARGS} != 0 )); then
110+
if (( NUMARGS != 0 )); then
110111
# Check for cmake args
111112
cmakeArgs
112113
for a in ${ARGS}; do
@@ -160,7 +161,7 @@ fi
160161
if (( NUMARGS == 0 )) || hasArg librmm; then
161162
ensureCMakeRan
162163
echo "building librmm..."
163-
cmake --build "${LIBRMM_BUILD_DIR}" -j${PARALLEL_LEVEL} ${VERBOSE_FLAG}
164+
cmake --build "${LIBRMM_BUILD_DIR}" -j"${PARALLEL_LEVEL}" ${VERBOSE_FLAG}
164165
if [[ ${INSTALL_TARGET} != "" ]]; then
165166
echo "installing librmm..."
166167
cmake --build "${LIBRMM_BUILD_DIR}" --target install -v ${VERBOSE_FLAG}
@@ -170,9 +171,9 @@ fi
170171
# Build and install the rmm Python package
171172
if (( NUMARGS == 0 )) || hasArg rmm; then
172173
echo "building and installing rmm..."
173-
SKBUILD_CMAKE_ARGS="-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX};${EXTRA_CMAKE_ARGS}" python -m pip install \
174+
SKBUILD_CMAKE_ARGS="-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX};$(IFS=';'; echo "${EXTRA_CMAKE_ARGS[*]}")" python -m pip install \
174175
--no-build-isolation \
175176
--no-deps \
176177
--config-settings rapidsai.disable-cuda=true \
177-
${REPODIR}/python/rmm
178+
"${REPODIR}"/python/rmm
178179
fi

ci/build_wheel_cpp.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ rapids-telemetry-record sccache-stats.txt sccache --show-adv-stats
2626
python -m auditwheel repair \
2727
--exclude librapids_logger.so \
2828
-w "${RAPIDS_WHEEL_BLD_OUTPUT_DIR}" \
29-
${dist_dir}/*
29+
"${dist_dir}"/*
3030

3131
../../ci/validate_wheel.sh "${RAPIDS_WHEEL_BLD_OUTPUT_DIR}"

ci/build_wheel_python.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ python -m auditwheel repair \
5050
absolute_wheel_dir=$(realpath "${RAPIDS_WHEEL_BLD_OUTPUT_DIR}")
5151
# switch back to the root of the repo and check symbol visibility
5252
popd
53-
ci/check_symbols.sh "$(echo ${absolute_wheel_dir}/rmm_*.whl)"
53+
ci/check_symbols.sh "$(echo "${absolute_wheel_dir}"/rmm_*.whl)"

ci/test_cpp.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ export GTEST_OUTPUT=xml:${RAPIDS_TESTS_DIR}/
3939
./ci/run_ctests.sh -j20 && EXITCODE=$? || EXITCODE=$?;
4040

4141
# Run all examples from librmm-example package
42-
for example in ${CONDA_PREFIX}/bin/examples/librmm/*; do
42+
for example in "${CONDA_PREFIX}"/bin/examples/librmm/*; do
4343
if [ -x "$example" ]; then
4444
rapids-logger "Running example: $(basename "$example")"
4545
"$example" && EXAMPLE_EXITCODE=$? || EXAMPLE_EXITCODE=$?;
46-
if [ $EXAMPLE_EXITCODE -ne 0 ]; then
46+
if [ "$EXAMPLE_EXITCODE" -ne 0 ]; then
4747
rapids-logger "Example $(basename "$example") failed with exit code: $EXAMPLE_EXITCODE"
4848
EXITCODE=$EXAMPLE_EXITCODE
4949
break

cpp/examples/build.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ INSTALL_EXAMPLES=false
1313
# Check for -i or --install flags to enable installation
1414
ARGS=$(getopt -o i --long install -- "$@")
1515
eval set -- "$ARGS"
16+
# shellcheck disable=SC2078
1617
while [ : ]; do
1718
case "$1" in
1819
-i | --install)
@@ -46,12 +47,12 @@ build_example() {
4647
build_dir="${example_dir}/build"
4748

4849
# Configure
49-
cmake -S ${example_dir} -B ${build_dir} -Drmm_ROOT="${LIB_BUILD_DIR}"
50+
cmake -S "${example_dir}" -B "${build_dir}" -Drmm_ROOT="${LIB_BUILD_DIR}"
5051
# Build
51-
cmake --build ${build_dir} -j${PARALLEL_LEVEL}
52+
cmake --build "${build_dir}" -j"${PARALLEL_LEVEL}"
5253
# Install if needed
5354
if [ "$INSTALL_EXAMPLES" = true ]; then
54-
cmake --install ${build_dir} --prefix ${INSTALL_PREFIX:-${example_dir}/install}
55+
cmake --install "${build_dir}" --prefix "${INSTALL_PREFIX:-${example_dir}/install}"
5556
fi
5657
}
5758

cpp/scripts/doxygen.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,25 @@ fi
1414
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
1515

1616
# doxygen supported version 1.9.1
17-
DOXYGEN_VERSION=`doxygen --version`
18-
if [ ! $(version "$DOXYGEN_VERSION") -eq $(version "1.9.1") ] ; then
17+
DOXYGEN_VERSION=$(doxygen --version)
18+
if [ ! "$(version "$DOXYGEN_VERSION")" -eq "$(version "1.9.1")" ] ; then
1919
echo -e "warning: Unsupported doxygen version $DOXYGEN_VERSION"
2020
echo -e "Expecting doxygen version 1.9.1"
2121
exit 0
2222
fi
2323

24-
export RAPIDS_VERSION="$(sed -E -e 's/^([0-9]{2})\.([0-9]{2})\.([0-9]{2}).*$/\1.\2.\3/' VERSION)"
25-
export RAPIDS_VERSION_MAJOR_MINOR="$(sed -E -e 's/^([0-9]{2})\.([0-9]{2})\.([0-9]{2}).*$/\1.\2/' VERSION)"
24+
RAPIDS_VERSION="$(sed -E -e 's/^([0-9]{2})\.([0-9]{2})\.([0-9]{2}).*$/\1.\2.\3/' VERSION)"
25+
RAPIDS_VERSION_MAJOR_MINOR="$(sed -E -e 's/^([0-9]{2})\.([0-9]{2})\.([0-9]{2}).*$/\1.\2/' VERSION)"
26+
export RAPIDS_VERSION
27+
export RAPIDS_VERSION_MAJOR_MINOR
2628

2729
# Run doxygen, ignore missing tag files error
2830
TAG_ERROR1="error: Tag file '.*.tag' does not exist or is not a file. Skipping it..."
2931
TAG_ERROR2="error: cannot open tag file .*.tag for writing"
30-
DOXYGEN_STDERR=`cd cpp/doxygen && { cat Doxyfile ; echo QUIET = YES; echo GENERATE_HTML = NO; } | doxygen - 2>&1 | sed "/\($TAG_ERROR1\|$TAG_ERROR2\)/d"`
32+
DOXYGEN_STDERR=$(cd cpp/doxygen && { cat Doxyfile ; echo QUIET = YES; echo GENERATE_HTML = NO; } | doxygen - 2>&1 | sed "/\($TAG_ERROR1\|$TAG_ERROR2\)/d")
3133
RETVAL=$?
3234

33-
if [ "$RETVAL" != "0" ] || [ ! -z "$DOXYGEN_STDERR" ]; then
35+
if [ "$RETVAL" != "0" ] || [ -n "$DOXYGEN_STDERR" ]; then
3436
echo -e "$DOXYGEN_STDERR"
3537
RETVAL=1 #because return value is not generated by doxygen 1.8.20
3638
fi

cpp/scripts/run-cmake-format.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ if ! [ ${status} -eq 0 ]; then
3737
echo "This script must be run inside the rmm repository, or the RMM_ROOT environment variable must be set."
3838
else
3939
echo "Script failed with unknown error attempting to determine project root:"
40-
echo ${RMM_BUILD_DIR}
40+
echo "${RMM_BUILD_DIR}"
4141
fi
4242
exit 1
4343
fi
@@ -48,8 +48,8 @@ DEFAULT_FORMAT_FILE_LOCATIONS=(
4848
)
4949

5050
if [ -z ${RAPIDS_CMAKE_FORMAT_FILE:+PLACEHOLDER} ]; then
51-
for file_path in ${DEFAULT_FORMAT_FILE_LOCATIONS[@]}; do
52-
if [ -f ${file_path} ]; then
51+
for file_path in "${DEFAULT_FORMAT_FILE_LOCATIONS[@]}"; do
52+
if [ -f "${file_path}" ]; then
5353
RAPIDS_CMAKE_FORMAT_FILE=${file_path}
5454
break
5555
fi
@@ -68,7 +68,7 @@ else
6868
fi
6969

7070
if [[ $1 == "cmake-format" ]]; then
71-
cmake-format -i --config-files cpp/cmake/config.json ${RAPIDS_CMAKE_FORMAT_FILE} -- ${@:2}
71+
cmake-format -i --config-files cpp/cmake/config.json "${RAPIDS_CMAKE_FORMAT_FILE}" -- "${@:2}"
7272
elif [[ $1 == "cmake-lint" ]]; then
73-
cmake-lint --config-files cpp/cmake/config.json ${RAPIDS_CMAKE_FORMAT_FILE} -- ${@:2}
73+
cmake-lint --config-files cpp/cmake/config.json "${RAPIDS_CMAKE_FORMAT_FILE}" -- "${@:2}"
7474
fi

0 commit comments

Comments
 (0)