From aebf6fa0b15bc2502e681e4608727d2784c47a54 Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Wed, 20 Jul 2016 21:10:07 +0200 Subject: [PATCH] [skip ci] Update format script to enforce clang-format version, and work on OSX --- scripts/format.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/scripts/format.sh b/scripts/format.sh index 561db8756..f95f8735a 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -7,8 +7,33 @@ set -eu -o pipefail +# Get CPU count +OS=$(uname) +NPROC=1 +if [[ $OS = "Linux" ]] ; then + NPROC=$(nproc) +elif [[ ${OS} = "Darwin" ]] ; then + NPROC=$(sysctl -n hw.physicalcpu) +fi + +# Discover clang-format +if type clang-format-3.8 2> /dev/null ; then + CLANG_FORMAT=clang-format-3.8 +elif type clang-format 2> /dev/null ; then + # Clang format found, but need to check version + CLANG_FORMAT=clang-format + V=$(clang-format --version) + if [[ $V != *3.8* ]] ; then + echo "clang-format is not 3.8 (returned ${V})" + exit 1 + fi +else + echo "No appropriate clang-format found (expected clang-format-3.8, or clang-format)" + exit 1 +fi + find src include unit_tests example -type f -name '*.hpp' -o -name '*.cpp' \ - | xargs -I{} -P $(nproc) clang-format -i -style=file {} + | xargs -I{} -P ${NPROC} ${CLANG_FORMAT} -i -style=file {} dirty=$(git ls-files --modified)