Skip to content

Commit 85d7957

Browse files
committed
[sanitizer] shellcheck fixes
1 parent 68fe000 commit 85d7957

File tree

1 file changed

+47
-40
lines changed

1 file changed

+47
-40
lines changed

zorg/buildbot/builders/sanitizers/buildbot_functions.sh

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eu
44

55
ulimit -Ss 12288
66

7-
ROOT=`pwd`
7+
ROOT=$(pwd)
88
LLVM=$ROOT/llvm-project/llvm
99

1010
BUILDBOT_CLOBBER="${BUILDBOT_CLOBBER:-}"
@@ -25,15 +25,16 @@ fi
2525
SANITIZER_LOG_DIR=$ROOT/sanitizer_logs
2626

2727
function build_step() {
28-
echo "@@@BUILD_STEP ""$@""@@@"
29-
CURRENT_STEP="$@"
28+
echo "@@@BUILD_STEP ${1}@@@"
29+
CURRENT_STEP="${1}"
3030
}
3131

3232
function include_config() {
3333
local P=.
3434
while true ; do
3535
local F=${P}/sanitizer_buildbot_config
3636
if [[ -f ${F} ]] ; then
37+
# shellcheck source=/dev/null
3738
. ${F}
3839
break
3940
fi
@@ -100,7 +101,7 @@ function cleanup() {
100101
rm_dirs llvm_build64
101102
fi
102103
# Workaround the case when a new unittest was reverted, but incremental build continues to execute the leftover binary.
103-
find -path ./llvm-project -prune -o -executable -type f -path '*unittests*' -print -exec rm -f {} \;
104+
find . -path ./llvm-project -prune -o -executable -type f -path '*unittests*' -print -exec rm -f {} \;
104105
du -hs ./* | sort -h
105106
}
106107

@@ -112,7 +113,7 @@ function clobber {
112113
exit 1
113114
fi
114115
# Keep sources in ./llvm-project and ./llvm_build0 for faster builds.
115-
find -maxdepth 1 -mindepth 1 -path ./llvm-project -prune -o -path ./llvm_build0 -prune -o -print -exec rm -rf {} \;
116+
find . -maxdepth 1 -mindepth 1 -path ./llvm-project -prune -o -path ./llvm_build0 -prune -o -print -exec rm -rf {} \;
116117
du -hs ./* | sort -h
117118
return 0
118119
else
@@ -139,7 +140,6 @@ function buildbot_update {
139140
LLVM=$BUILDBOT_MONO_REPO_PATH/llvm
140141
else
141142
(
142-
local DEPTH=100
143143
[[ -d llvm-project ]] || (
144144
mkdir -p llvm-project
145145
cd llvm-project
@@ -170,7 +170,8 @@ function print_sanitizer_logs() {
170170
if compgen -G "${SANITIZER_LOG_DIR}"/* ; then
171171
build_step "sanitizer logs: ${CURRENT_STEP}"
172172
head -n -1 "${SANITIZER_LOG_DIR}"/*
173-
buildbot_build && rm -rf "${SANITIZER_LOG_DIR}"/*
173+
buildbot_build && rm -rf "${SANITIZER_LOG_DIR}"
174+
mkdir -p "${SANITIZER_LOG_DIR}"
174175
build_warning
175176
fi
176177
}
@@ -179,11 +180,11 @@ function print_sanitizer_logs() {
179180
function run_ninja() {
180181
env
181182
local ec=0
182-
/usr/bin/time -o ${ROOT}/time.txt -- ninja "$@" || ec=$?
183+
/usr/bin/time -o "${ROOT}/time.txt" -- ninja "$@" || ec=$?
183184
buildbot_build || print_sanitizer_logs
184185
if [[ $ec -ne 0 ]] ; then
185186
build_failure
186-
rm -f ${ROOT}/time.txt
187+
rm -f "${ROOT}/time.txt"
187188
fi
188189
print_sanitizer_logs
189190
}
@@ -198,7 +199,7 @@ function common_stage1_variables {
198199

199200
function build_stage1_clang_impl {
200201
[[ ! -f "${STAGE1_DIR}/delete_next_time" ]] || rm -rf "${STAGE1_DIR}"
201-
mkdir -p ${STAGE1_DIR}
202+
mkdir -p "${STAGE1_DIR}"
202203
local cmake_stage1_options="${CMAKE_COMMON_OPTIONS}"
203204
cmake_stage1_options+=" -DLLVM_ENABLE_PROJECTS='clang;lld'"
204205
cmake_stage1_options+=" -DLLVM_ENABLE_RUNTIMES='compiler-rt;libunwind;libcxx;libcxxabi'"
@@ -229,16 +230,17 @@ function download_clang_from_chromium {
229230
function build_clang_at_release_tag {
230231
common_stage1_variables
231232

232-
local host_clang_revision=llvmorg-$(
233+
local host_clang_revision
234+
host_clang_revision=llvmorg-$(
233235
git ls-remote --tags https://github.com/llvm/llvm-project.git | \
234236
grep -oE "refs/tags/llvmorg-[0-9.]+$" | \
235237
grep -Eo "[0-9.]+" | \
236238
sort -n | \
237239
tail -n1
238240
)
239241

240-
if [ -r ${STAGE1_DIR}/host_clang_revision ] && \
241-
[ "$(cat ${STAGE1_DIR}/host_clang_revision)" == $host_clang_revision ]
242+
if [ -r "${STAGE1_DIR}/host_clang_revision" ] && \
243+
[ "$(cat "${STAGE1_DIR}/host_clang_revision")" == "$host_clang_revision" ]
242244
then
243245
build_step "using pre-built stage1 clang at r${host_clang_revision}"
244246
else
@@ -249,7 +251,7 @@ function build_clang_at_release_tag {
249251
# PGO, can improve build time by 10%. However bots spend most of the time
250252
# running tests and compilation mostly incremental or CCCACH-ed.
251253
build_stage1_clang_impl && \
252-
( echo $host_clang_revision > ${STAGE1_DIR}/host_clang_revision )
254+
( echo "$host_clang_revision" > "${STAGE1_DIR}/host_clang_revision" )
253255
fi
254256
}
255257

@@ -334,8 +336,8 @@ function build_stage2 {
334336
exit 1
335337
fi
336338

337-
mkdir -p ${libcxx_build_dir}
338-
cmake -B ${libcxx_build_dir} \
339+
mkdir -p "${libcxx_build_dir}"
340+
cmake -B "${libcxx_build_dir}" \
339341
${cmake_stage2_common_options} \
340342
${cmake_options} \
341343
-DCMAKE_INSTALL_PREFIX="${ROOT}/${libcxx_install_dir}" \
@@ -345,14 +347,16 @@ function build_stage2 {
345347
-DLLVM_USE_SANITIZER=${llvm_use_sanitizer} \
346348
-DCMAKE_C_FLAGS="${fsanitize_flag} ${cmake_libcxx_cflags} ${fno_sanitize_flag}" \
347349
-DCMAKE_CXX_FLAGS="${fsanitize_flag} ${cmake_libcxx_cflags} ${fno_sanitize_flag}" \
348-
$LLVM/../runtimes || build_failure
350+
"$LLVM/../runtimes" || build_failure
349351

350-
run_ninja -C ${libcxx_build_dir}
351-
run_ninja -C ${libcxx_build_dir} install
352+
run_ninja -C "${libcxx_build_dir}"
353+
run_ninja -C "${libcxx_build_dir}" install
352354

353-
local libcxx_so_path="$(find "${ROOT}/${libcxx_install_dir}" -name libc++.so)"
355+
local libcxx_so_path
356+
libcxx_so_path="$(find "${ROOT}/${libcxx_install_dir}" -name libc++.so)"
354357
test -f "${libcxx_so_path}" || build_failure
355-
local libcxx_runtime_path=$(dirname "${libcxx_so_path}")
358+
local libcxx_runtime_path
359+
libcxx_runtime_path=$(dirname "${libcxx_so_path}")
356360

357361
local sanitizer_ldflags="-Wl,--rpath=${libcxx_runtime_path} -L${libcxx_runtime_path}"
358362
local sanitizer_cflags="-nostdinc++ -isystem ${ROOT}/${libcxx_install_dir}/include -isystem ${ROOT}/${libcxx_install_dir}/include/c++/v1 $fsanitize_flag"
@@ -362,26 +366,26 @@ function build_stage2 {
362366
# See http://llvm.org/bugs/show_bug.cgi?id=19071, http://www.cmake.org/Bug/view.php?id=15264
363367
sanitizer_cflags+=" $sanitizer_ldflags -w"
364368

365-
mkdir -p ${build_dir}
369+
mkdir -p "${build_dir}"
366370
local cmake_stage2_clang_options="-DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra;mlir'"
367371
if [[ "$(arch)" == "aarch64" ]] ; then
368372
# FIXME: clangd tests fail.
369373
cmake_stage2_clang_options="-DLLVM_ENABLE_PROJECTS='clang;lld;mlir'"
370374
fi
371-
cmake -B ${build_dir} \
375+
cmake -B "${build_dir}" \
372376
${cmake_stage2_common_options} \
373377
${cmake_stage2_clang_options} \
374378
-DLLVM_USE_SANITIZER=${llvm_use_sanitizer} \
375379
-DLLVM_ENABLE_LIBCXX=ON \
376380
-DCMAKE_C_FLAGS="${sanitizer_cflags}" \
377381
-DCMAKE_CXX_FLAGS="${sanitizer_cflags}" \
378382
-DCMAKE_EXE_LINKER_FLAGS="${sanitizer_ldflags}" \
379-
$LLVM || {
383+
"$LLVM" || {
380384
build_failure
381385
# No stats on failure.
382386
return 0
383387
}
384-
run_ninja -C ${build_dir}
388+
run_ninja -C "${build_dir}"
385389

386390
upload_stats stage2
387391
ccache -s || true
@@ -471,12 +475,12 @@ function check_stage2 {
471475
LIT_FILTER_OUT+="|ostream.formatted.print/vprint_nonunicode.pass.cpp"
472476
LIT_FILTER_OUT+="|ostream.formatted.print/vprint_unicode.pass.cpp"
473477
fi
474-
run_ninja -C libcxx_build_${sanitizer_name} check-runtimes
478+
run_ninja -C "libcxx_build_${sanitizer_name}" check-runtimes
475479
)
476480
fi
477481

478482
build_step "stage2/$sanitizer_name check"
479-
run_ninja -C ${STAGE2_DIR} check-all
483+
run_ninja -C "${STAGE2_DIR}" check-all
480484
}
481485

482486
function check_stage2_msan {
@@ -504,33 +508,36 @@ function check_stage2_asan_ubsan {
504508
}
505509

506510
function build_stage3 {
507-
local sanitizer_name=$1
511+
local sanitizer_name
512+
sanitizer_name="${1}"
508513
build_step "build stage3/$sanitizer_name build"
509514

510-
local build_dir=llvm_build2_${sanitizer_name}
515+
local build_dir
516+
build_dir="llvm_build2_${sanitizer_name}"
511517

512-
local clang_path=$ROOT/${STAGE2_DIR}/bin
518+
local clang_path
519+
clang_path="${ROOT}/${STAGE2_DIR}/bin"
513520
local sanitizer_cflags=
514-
mkdir -p ${build_dir}
521+
mkdir -p "${build_dir}"
515522
local stage3_projects='clang;lld;clang-tools-extra'
516523
if [[ "$(arch)" == "aarch64" ]] ; then
517524
# FIXME: clangd tests fail.
518525
stage3_projects='clang;lld'
519526
fi
520527
# -DLLVM_CCACHE_BUILD=OFF to track real build time.
521-
cmake -B ${build_dir} \
528+
cmake -B "${build_dir}" \
522529
${CMAKE_COMMON_OPTIONS} \
523530
-DLLVM_ENABLE_PROJECTS="${stage3_projects}" \
524-
-DCMAKE_C_COMPILER=${clang_path}/clang \
525-
-DCMAKE_CXX_COMPILER=${clang_path}/clang++ \
531+
-DCMAKE_C_COMPILER="${clang_path}/clang" \
532+
-DCMAKE_CXX_COMPILER="${clang_path}/clang++" \
526533
-DCMAKE_CXX_FLAGS="${sanitizer_cflags}" \
527534
-DLLVM_CCACHE_BUILD=OFF \
528-
$LLVM || {
535+
"${LLVM}" || {
529536
build_failure
530537
# No stats on failure.
531538
return 0
532539
}
533-
run_ninja -C ${build_dir}
540+
run_ninja -C "${build_dir}"
534541
upload_stats stage3
535542
}
536543

@@ -560,7 +567,7 @@ function check_stage3 {
560567

561568
local build_dir=llvm_build2_${sanitizer_name}
562569

563-
run_ninja -C ${build_dir} check-all
570+
run_ninja -C "${build_dir}" check-all
564571
}
565572

566573
function check_stage3_msan {
@@ -594,7 +601,7 @@ function build_failure() {
594601
echo
595602

596603
# Repeat, server sometimes ignores failures or warnings.
597-
for i in 0 1 2 ; do
604+
for _ in 0 1 2 ; do
598605
echo
599606
echo "@@@STEP_FAILURE@@@"
600607
sleep 5
@@ -605,7 +612,7 @@ function build_failure() {
605612

606613
function build_exception() {
607614
# Repeat, server sometimes ignores failures or warnings.
608-
for i in 0 1 2 ; do
615+
for _ in 0 1 2 ; do
609616
echo
610617
echo "@@@STEP_EXCEPTION@@@"
611618
sleep 5
@@ -616,7 +623,7 @@ function build_exception() {
616623

617624
function build_warning() {
618625
# Repeat, server sometimes ignores failures or warnings.
619-
for i in 0 1 2 ; do
626+
for _ in 0 1 2 ; do
620627
echo
621628
echo "@@@STEP_WARNINGS@@@"
622629
sleep 5

0 commit comments

Comments
 (0)