From 468755200afc5a3ae887ef760ec5b4745e5816bc Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Wed, 1 Dec 2021 00:36:54 +0000 Subject: [PATCH] check_format.sh: add Darwin/MacOS support check_format.sh requires the following, none of which are supported by default on MacOS and require alternative homebrew installation for GNU variants: * mapfile command not supported by bash * -f option for readlink * -P option for grep Note that SPDK is not supported on MacOS, the changes here are added only for developer convenience. Fixes issue #2255. Signed-off-by: Jim Harris Change-Id: Ic3d4ed49d9bfb4be50a8dd090a34090037f592c0 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10476 Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Reviewed-by: Michal Berger Reviewed-by: Ben Walker Reviewed-by: Tomasz Zawadzki --- scripts/check_format.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/scripts/check_format.sh b/scripts/check_format.sh index 2c31df58c..b60b4914c 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -1,6 +1,34 @@ #!/usr/bin/env bash -rootdir=$(readlink -f "$(dirname "$0")")/.. +if [[ $(uname -s) == Darwin ]]; then + # SPDK is not supported on MacOS, but as a developer + # convenience we support running the check_format.sh + # script on MacOS. + # Running "brew install bash greadlink ggrep" should be + # sufficient to get the correct versions of these utilities. + if [[ $(type -t mapfile) != builtin ]]; then + # We need bash version >= 4.0 for mapfile builtin + echo "Please install bash version >= 4.0" + exit 1 + fi + if ! hash greadlink 2> /dev/null; then + # We need GNU readlink for -f option + echo "Please install GNU readlink" + exit 1 + fi + if ! hash ggrep 2> /dev/null; then + # We need GNU grep for -P option + echo "Please install GNU grep" + exit 1 + fi + GNU_READLINK="greadlink" + GNU_GREP="ggrep" +else + GNU_READLINK="readlink" + GNU_GREP="grep" +fi + +rootdir=$($GNU_READLINK -f "$(dirname "$0")")/.. source "$rootdir/scripts/common.sh" cd "$rootdir" @@ -611,7 +639,7 @@ function check_rpc_args() { local rc=0 echo -n "Checking rpc.py argument option names..." - grep add_argument scripts/rpc.py | grep -oP "(?<=--)[a-z0-9\-\_]*(?=\')" | grep "_" > badargs.log + grep add_argument scripts/rpc.py | $GNU_GREP -oP "(?<=--)[a-z0-9\-\_]*(?=\')" | grep "_" > badargs.log if [[ -s badargs.log ]]; then echo "rpc.py arguments with underscores detected!"