From c75db8d0825ff816cb05e9e46b7017b03a6b100d Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 8 Feb 2021 18:10:51 -0500 Subject: [PATCH] scripts: clean up various shellcheck warnings Should hopefully not break anything :). --- bootstrap.sh | 2 +- cmake/distclean.sh | 2 +- docs/naturaldocs/run_docs.sh | 16 +++++----- tests/source/run.sh | 13 ++++---- travis/lib.sh | 4 +-- travis/main.sh | 33 +++++++++++---------- windows/msys/run_tests.sh | 57 ++++++++++++++++++------------------ 7 files changed, 64 insertions(+), 63 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index fe7dd0f..9dda8cf 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -9,7 +9,7 @@ v() { echo "$@"; "$@"; } # so that random hackers don't need it just to build the code. v docs/naturaldocs/run_docs.sh --nonfatal -if echo "${OSTYPE:-$(uname)}" | grep -q '^darwin' ; then +if uname | grep -qi '^darwin' ; then echo "Having trouble on OS X? Try: brew install autoconf libtool automake gettext pkg-config cmake" fi diff --git a/cmake/distclean.sh b/cmake/distclean.sh index 0124dd1..c47a6be 100755 --- a/cmake/distclean.sh +++ b/cmake/distclean.sh @@ -12,7 +12,7 @@ Clean all the cmake generated output files. Options: --automake Do not clean files autotools also creates EOF - exit ${1:-0} + exit "${1:-0}" } AUTOMAKE="false" diff --git a/docs/naturaldocs/run_docs.sh b/docs/naturaldocs/run_docs.sh index 950d66d..d868e54 100755 --- a/docs/naturaldocs/run_docs.sh +++ b/docs/naturaldocs/run_docs.sh @@ -15,9 +15,9 @@ usage() { nd() { # Figure out the name of this tool. - if which naturaldocs 2>/dev/null ; then + if command -v naturaldocs >/dev/null ; then return - elif which NaturalDocs 2>/dev/null ; then + elif command -v NaturalDocs >/dev/null ; then return else return 1 @@ -46,7 +46,7 @@ elif [ $# -ne 0 ] ; then fi # Version number -VERSION=`(cd ../../; perl config/getver.pl)` +VERSION=$(cd ../../; perl config/getver.pl) # Clear away old docs and ensure the doc dir. is present. rm -rf html @@ -66,11 +66,11 @@ sed -e "s/@VERSION@/$VERSION/g" preamble.txt > tmp/preamble.txt # Run naturaldocs to create the manual. $(nd) --rebuild --rebuild-output --documented-only \ - -i tmp/ \ - -img images/ \ - -o html html \ - --project project/ \ - -s Default libgd + -i tmp/ \ + -img images/ \ + -o html html \ + --project project/ \ + -s Default libgd # And cleanup the temp files. rm -rf Data tmp diff --git a/tests/source/run.sh b/tests/source/run.sh index b1c89eb..1945ae1 100755 --- a/tests/source/run.sh +++ b/tests/source/run.sh @@ -15,11 +15,10 @@ export GIT_PAGER=cat export LC_ALL=C # List all the non-binary files we know about in the tree. -files=".tmp.files" -trap 'rm -f "${files}"' EXIT -git ls-tree -r --name-only HEAD | \ - grep -Ev '\.(bin|bmp|gd|gd2|gif|jpg|jpeg|png|pic|sgi|tga|tiff|ttf|xbm|xpm)$' \ - > "${files}" +read -r -d'\n' -a files < <( + git ls-tree -r --name-only HEAD | \ + grep -Ev '\.(bin|bmp|gd|gd2|gif|jpg|jpeg|png|pic|sgi|tga|tiff|ttf|xbm|xpm)$' +) || : banner() { echo @@ -28,7 +27,7 @@ banner() { do_grep() { # Use -a so UTF-8 files don't get flagged as binary & skipped. - if git grep -aHnE "$@" $(<"${files}") ; then + if git grep -aHnE "$@" "${files[@]}" ; then ret=1 fi } @@ -42,6 +41,6 @@ banner "Check for Windows line endings." do_grep $'\r$' banner "Checking trailing lines." -"${TEST_DIR}"/whitespace.py $(<"${files}") +"${TEST_DIR}"/whitespace.py "${files[@]}" exit ${ret} diff --git a/travis/lib.sh b/travis/lib.sh index 687ed41..7fd0e2c 100644 --- a/travis/lib.sh +++ b/travis/lib.sh @@ -13,7 +13,7 @@ if [[ -n ${TRAVIS_OS_NAME} ]] ; then normal=$(tput sgr0) else whitebg= - blackbg= + blackfg= normal= fi v() { @@ -34,5 +34,5 @@ v() { ncpus=$(getconf _NPROCESSORS_ONLN) m() { - v make -j${ncpus} "$@" + v make -j"${ncpus}" "$@" } diff --git a/travis/main.sh b/travis/main.sh index f843a8a..2d29b5d 100755 --- a/travis/main.sh +++ b/travis/main.sh @@ -4,6 +4,7 @@ # TODO: Add support for building/testing w/ASAN/etc... enabled. +# shellcheck source=travis/lib.sh . "${0%/*}"/lib.sh # We have to do this by hand rather than use the coverity addon because of @@ -78,18 +79,18 @@ build_autotools() { } cmake_args=( - -DBUILD_SHARED_LIBS=1 - -DBUILD_STATIC_LIBS=1 - -DBUILD_TEST=1 - -DCMAKE_INSTALL_PREFIX=/usr/local - -DCMAKE_INSTALL_LIBDIR=/usr/local/lib - -DENABLE_GD_FORMATS=1 - -DENABLE_FONTCONFIG=1 - -DENABLE_FREETYPE=1 - -DENABLE_JPEG=1 - -DENABLE_PNG=1 - -DENABLE_TIFF=1 - -DENABLE_WEBP=1 + "-DBUILD_SHARED_LIBS=1" + "-DBUILD_STATIC_LIBS=1" + "-DBUILD_TEST=1" + "-DCMAKE_INSTALL_PREFIX=/usr/local" + "-DCMAKE_INSTALL_LIBDIR=/usr/local/lib" + "-DENABLE_GD_FORMATS=1" + "-DENABLE_FONTCONFIG=1" + "-DENABLE_FREETYPE=1" + "-DENABLE_JPEG=1" + "-DENABLE_PNG=1" + "-DENABLE_TIFF=1" + "-DENABLE_WEBP=1" ) # libxpm-dev is unavaible in brew repo @@ -104,15 +105,15 @@ build_cmake() { cd build v cmake "${cmake_args[@]}" .. m - v ctest -j${ncpus} + v ctest -j"${ncpus}" cd .. rm -rf build # Then build in-tree. v cmake "${cmake_args[@]}" . m - v ctest -j${ncpus} - m install DESTDIR=$PWD/install-cmake + v ctest -j"${ncpus}" + m install DESTDIR="${PWD}/install-cmake" } compare_builds() { @@ -148,7 +149,7 @@ build_codecov() { export CFLAGS="-fprofile-arcs -ftest-coverage" v cmake "${cmake_args[@]}" .. m - v ctest -j${ncpus} + v ctest -j"${ncpus}" bash <(curl -s https://codecov.io/bash) } diff --git a/windows/msys/run_tests.sh b/windows/msys/run_tests.sh index f7c4b44..0856d96 100755 --- a/windows/msys/run_tests.sh +++ b/windows/msys/run_tests.sh @@ -13,14 +13,15 @@ CFLAGS="-g -Igdtest/ -I. -I../src/ -D_WIN32 -DHAVE_SYS_STAT_H $CFLAGS_EXTRA" LDFLAGS='-L../src -llibgd' DLLPATH=../src:$DLLPATH_EXTRA -function run_gcc { - if msg=`gcc $* 2>&1`; then - true - else - echo "COMMAND: gcc $*" >> $LOG - echo $msg >> $LOG - false - fi +run_gcc() { + local msg + if msg=$(gcc "$@" 2>&1); then + true + else + echo "COMMAND: gcc $*" >> "${LOG}" + echo "${msg}" >> "${LOG}" + false + fi } # Switch to the working directory @@ -29,7 +30,7 @@ cd ../../tests # Initial setup echo "Setting up..." -[ -f $LOG ] && rm -f $LOG +rm -f "${LOG}" [ -f test_config.h ] || echo '#define GDTEST_TOP_DIR "."' > test_config.h run_gcc -c $CFLAGS gdtest/gdtest.c @@ -38,27 +39,27 @@ echo "Running tests:" count=0 failures=0 compile_failures=0 -for test in `find . -name \*.c | grep -vE '^./(fontconfig|gdtest|gdhelpers|xpm)'`; do - count=`expr $count + 1` +for test in $(find . -name '*.c' | grep -vE '^./(fontconfig|gdtest|gdhelpers|xpm)'); do + : $(( count += 1 )) - exe=${test%.c}.exe - if run_gcc -o $exe $CFLAGS $LDFLAGS $test gdtest.o; then - true; - else - echo "COMPILE_FAIL: $test" - compile_failures=`expr $compile_failures + 1` - continue - fi + exe=${test%.c}.exe + if run_gcc -o "${exe}" ${CFLAGS} ${LDFLAGS} "${test}" gdtest.o; then + true + else + echo "COMPILE_FAIL: $test" + : $(( compile_failures += 1 )) + continue + fi - echo "Running $exe:" >> $LOG - if $exe 2>&1 >> $LOG; then - echo "PASS: $test" - else - failures=`expr $failures + 1` - echo "FAIL: $test" - fi - echo >> $LOG + echo "Running $exe:" >> "${LOG}" + if $exe >> "${LOG}" 2>&1; then + echo "PASS: $test" + else + : $(( failures += 1 )) + echo "FAIL: $test" + fi + echo >> "${LOG}" done echo "$failures failures and $compile_failures compile failures out of $count tests." -echo "Error messages in $LOG" +echo "Error messages in ${LOG}"