2016-02-01 09:36:08 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2016-10-18 17:05:20 -04:00
|
|
|
set -o errexit
|
|
|
|
set -o pipefail
|
|
|
|
set -o nounset
|
|
|
|
|
2016-02-01 09:36:08 -05:00
|
|
|
# Runs the Clang Formatter in parallel on the code base.
|
|
|
|
# Return codes:
|
|
|
|
# - 1 there are files to be formatted
|
|
|
|
# - 0 everything looks fine
|
|
|
|
|
2016-07-20 15:10:07 -04:00
|
|
|
# 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
|
2020-11-26 10:21:39 -05:00
|
|
|
if type clang-format-10.0.0 2> /dev/null ; then
|
|
|
|
CLANG_FORMAT=clang-format-10.0.0
|
2016-07-20 15:10:07 -04:00
|
|
|
elif type clang-format 2> /dev/null ; then
|
|
|
|
# Clang format found, but need to check version
|
|
|
|
CLANG_FORMAT=clang-format
|
|
|
|
V=$(clang-format --version)
|
2020-11-26 10:21:39 -05:00
|
|
|
if [[ $V != *10.0* ]] ; then
|
|
|
|
echo "clang-format is not 10.0 (returned ${V})"
|
2017-01-05 17:38:48 -05:00
|
|
|
#exit 1
|
2016-07-20 15:10:07 -04:00
|
|
|
fi
|
|
|
|
else
|
2020-11-26 10:21:39 -05:00
|
|
|
echo "No appropriate clang-format found (expected clang-format-10.0.0, or clang-format)"
|
2016-07-20 15:10:07 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-02-01 09:36:08 -05:00
|
|
|
find src include unit_tests example -type f -name '*.hpp' -o -name '*.cpp' \
|
2016-07-20 15:10:07 -04:00
|
|
|
| xargs -I{} -P ${NPROC} ${CLANG_FORMAT} -i -style=file {}
|