Commit 46875520 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

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: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: Ic3d4ed49d9bfb4be50a8dd090a34090037f592c0
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10476


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: default avatarMichal Berger <michalx.berger@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 91bd8744
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
#!/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!"