From 9dd85507d0c7cc1ca66d3d862d029b797f69507a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 4 Jan 2023 21:35:13 +0100 Subject: [PATCH] core: don't use eval to run commands in scripts This fixes the following shellcheck error: SC2294 (warning): eval negates the benefit of arrays. Drop eval to preserve whitespace/symbols (or eval as string). --- autogen.sh | 22 +++++++++---------- tools/build-test.sh | 52 +++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/autogen.sh b/autogen.sh index c6c872e30..1561c30ff 100755 --- a/autogen.sh +++ b/autogen.sh @@ -41,29 +41,29 @@ err () run () { - printf "Running \"%s\"..." "$@" - if eval "$@" >"$AUTOGEN_LOG" 2>&1 ; then - echo " OK" + printf "Running \"%s\"... " "$*" + if "$@" >"$AUTOGEN_LOG" 2>&1 ; then + echo "OK" else - echo " FAILED" + echo "FAILED" err fi } # remove autotools stuff -run "rm -f config.h.in" -run "rm -f aclocal.m4 configure config.log config.status" -run "rm -rf autom4te*.cache" +run rm -f config.h.in +run rm -f aclocal.m4 configure config.log config.status +run rm -rf "autom4te*.cache" # remove libtool stuff -run "rm -f libtool" +run rm -f libtool # remove gettext stuff -run "rm -f ABOUT-NLS" -run "rm -rf intl" +run rm -f ABOUT-NLS +run rm -rf intl # execute autoreconf cmds -run "autoreconf -vi" +run autoreconf -vi # ending rm -f "$AUTOGEN_LOG" diff --git a/tools/build-test.sh b/tools/build-test.sh index 3a94f6316..7197f268e 100755 --- a/tools/build-test.sh +++ b/tools/build-test.sh @@ -36,14 +36,8 @@ # This script is used to build WeeChat in CI environment. # -run () -{ - echo "Running \"$*\"..." - if ! eval "$@"; then - echo "ERROR" - exit 1 - fi -} +# exit on any error +set -e BUILDDIR="build-tmp-$$" @@ -61,32 +55,40 @@ if [ -z "$BUILDTOOL" ]; then exit 1 fi +run () +{ + "$@" +} + +# display commands +set -x + # create build directory -run "mkdir $BUILDDIR" -run "cd $BUILDDIR" +mkdir "$BUILDDIR" +cd "$BUILDDIR" if [ "$BUILDTOOL" = "cmake" ]; then # build with CMake - run "cmake .. -DENABLE_MAN=ON -DENABLE_DOC=ON -DENABLE_TESTS=ON ${BUILDARGS}" + run cmake .. -DENABLE_MAN=ON -DENABLE_DOC=ON -DENABLE_TESTS=ON "${BUILDARGS}" if [ -f "build.ninja" ]; then - run "ninja -v" - run "ninja -v changelog" - run "ninja -v rn" - run "sudo ninja install" + ninja -v + ninja -v changelog + ninja -v rn + sudo ninja install else - run "make VERBOSE=1 -j$(nproc)" - run "make VERBOSE=1 changelog" - run "make VERBOSE=1 rn" - run "sudo make install" + make VERBOSE=1 --jobs="$(nproc)" + make VERBOSE=1 changelog + make VERBOSE=1 rn + sudo make install fi - run "ctest -V" + ctest -V fi if [ "$BUILDTOOL" = "autotools" ]; then # build with autotools - run "../autogen.sh" - run "../configure --enable-man --enable-doc --enable-tests ${BUILDARGS}" - run "make -j$(nproc)" - run "sudo make install" - run "./tests/tests -v" + ../autogen.sh + run ../configure --enable-man --enable-doc --enable-tests "${BUILDARGS}" + make --jobs="$(nproc)" + sudo make install + ./tests/tests -v fi