revng-check-conventions: add bash script check

Add bash script checks with shellshock + 'set' rule
Fix existing bash scripts
This commit is contained in:
Giacomo Vercesi
2022-04-04 16:57:37 +02:00
parent 97d46eb708
commit 28a46c11df
5 changed files with 25 additions and 10 deletions
+21
View File
@@ -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
+1 -2
View File
@@ -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"
@@ -1,7 +1,6 @@
#!/bin/bash
set -e
set -o pipefail
set -euo pipefail
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
@@ -1,7 +1,6 @@
#!/bin/bash
set -e
set -o pipefail
set -euo pipefail
function log() {
echo "$1" > /dev/stderr
@@ -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