From e5f021c10e7bee782fb2e81da88775557b369ec8 Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Thu, 14 May 2020 10:21:31 +0200 Subject: [PATCH] scripts/check_format: auto-detect shfmt binary A newer version of shfmt was released, but the script still looked explicitly for the older one. Make it execute the first binary '^shfmt.*' in PATH whose --version returns at least v3.1.0. Change-Id: If621abfa4d995a9dc985e6bab8c33aa36c327fae Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2428 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki --- scripts/check_format.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/check_format.sh b/scripts/check_format.sh index bc724fb9b..3e52f76a9 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -227,8 +227,16 @@ else echo "You do not have pycodestyle or pep8 installed so your Python style is not being checked!" fi -shfmt="shfmt-3.1.0" -if hash "$shfmt" 2> /dev/null; then +# find compatible shfmt binary +shfmt_bins=$(compgen -c | grep '^shfmt' || true) +for bin in $shfmt_bins; do + if [[ "$("$bin" --version)" > "v3.0.9" ]]; then + shfmt=$bin + break + fi +done + +if [ -n "$shfmt" ]; then shfmt_cmdline=() silly_plural=() silly_plural[1]="s" @@ -302,7 +310,7 @@ if hash "$shfmt" 2> /dev/null; then fi fi else - printf '%s not detected, Bash style formatting check is skipped\n' "$shfmt" + echo "shfmt not detected, Bash style formatting check is skipped" fi if hash shellcheck 2> /dev/null; then