From 28a46c11df40676edcb481f80be1f00a85a906da Mon Sep 17 00:00:00 2001 From: Giacomo Vercesi Date: Mon, 4 Apr 2022 16:57:37 +0200 Subject: [PATCH] revng-check-conventions: add bash script check Add bash script checks with shellshock + 'set' rule Fix existing bash scripts --- scripts/revng-check-conventions | 21 +++++++++++++++++++ tests/abi/test.sh | 3 +-- tests/tools/pipeline/MultiStepPipelineTest.sh | 3 +-- .../python-wrappers/multiple-versions/test.sh | 3 +-- .../run-serialization-roundtrip-test.sh | 5 +---- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/scripts/revng-check-conventions b/scripts/revng-check-conventions index 03fe04d27..756e90005 100755 --- a/scripts/revng-check-conventions +++ b/scripts/revng-check-conventions @@ -187,6 +187,7 @@ readarray -t FILES < <(grep -E '\.(c|cc|cpp|h|hpp)$' <<< "$ALL_FILES_N") FILES_N=$(printf '%s\n' "${FILES[@]}") readarray -t PYTHON_FILES < <(find_by_ext_or_shebang py python) +readarray -t BASH_FILES < <(find_by_ext_or_shebang sh bash) readarray -t CMAKE_FILES < <(grep -i cmake <<< "$ALL_FILES_N") @@ -220,6 +221,25 @@ function run_cmake_format() { fi } +# Run shellcheck + check for set -euo pipefail +function run_bash_check() { + local NO_SET_FILES + if [[ ${#BASH_FILES[@]} -eq 0 ]]; then return; fi + shellcheck "${BASH_FILES[@]}" + + NO_SET_FILES=() + for FILE in "${BASH_FILES[@]}"; do + if ! head -n 10 "$FILE" | grep -qFe 'set -euo pipefail'; then + NO_SET_FILES+=("$FILE") + fi + done + if [[ ${#NO_SET_FILES[@]} -gt 0 ]]; then + echo "There are script files without 'set -euo pipefail':" + printf ' %s\n' "${NO_SET_FILES[@]}" + fi +} + + # Run revng-specific checks on files function run_revng_checks() { if [[ ${#FILES[@]} -eq 0 ]]; then return; fi @@ -312,6 +332,7 @@ EXIT_CODE=0 run_clang_format || EXIT_CODE=$? run_black || EXIT_CODE=$? run_cmake_format || EXIT_CODE=$? +run_bash_check || EXIT_CODE=$? run_revng_checks || EXIT_CODE=$? if [[ $(wc -c < "$TMP_FILE") -ne 0 || $EXIT_CODE -ne 0 ]]; then diff --git a/tests/abi/test.sh b/tests/abi/test.sh index 1ba3bcef8..20a615d51 100755 --- a/tests/abi/test.sh +++ b/tests/abi/test.sh @@ -4,8 +4,7 @@ # This file is distributed under the MIT License. See LICENSE.md for details. # -set -eu -set -o pipefail +set -euo pipefail ABI_NAME="$1" RUNTIME_ABI_ANALYSIS_RESULT="$2" diff --git a/tests/tools/pipeline/MultiStepPipelineTest.sh b/tests/tools/pipeline/MultiStepPipelineTest.sh index f3f2c9269..4c6a93b26 100755 --- a/tests/tools/pipeline/MultiStepPipelineTest.sh +++ b/tests/tools/pipeline/MultiStepPipelineTest.sh @@ -1,7 +1,6 @@ #!/bin/bash -set -e -set -o pipefail +set -euo pipefail SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) diff --git a/tests/tuple-tree-generator/python-wrappers/multiple-versions/test.sh b/tests/tuple-tree-generator/python-wrappers/multiple-versions/test.sh index 6ce6409a0..45fbc74ad 100755 --- a/tests/tuple-tree-generator/python-wrappers/multiple-versions/test.sh +++ b/tests/tuple-tree-generator/python-wrappers/multiple-versions/test.sh @@ -1,7 +1,6 @@ #!/bin/bash -set -e -set -o pipefail +set -euo pipefail function log() { echo "$1" > /dev/stderr diff --git a/tests/tuple-tree-generator/run-serialization-roundtrip-test.sh b/tests/tuple-tree-generator/run-serialization-roundtrip-test.sh index 4aebb0083..573978e7e 100755 --- a/tests/tuple-tree-generator/run-serialization-roundtrip-test.sh +++ b/tests/tuple-tree-generator/run-serialization-roundtrip-test.sh @@ -1,9 +1,6 @@ #!/bin/bash -set -o errexit -set -o pipefail - -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +set -euo pipefail PARSE_MODEL_SCRIPT=$(cat << "EOF" import sys