obs-studio/formatcode.sh
yalpul 6b3479108f CI: Make processor count consistent
Code formatting script was using `sysctl -n hw.physicalcpu` on macOS
machines to get the CPU count. This command returns the physical CPUs.
`nproc`, however, returns logical CPU count on Linux machines. It
should be `sysctl -n hw.logicalcpu` to make it consistent with its
Linux counterpart. But there also another way. `getconf
_NPROCESSORS_ONLN` gives the number of logical CPUs on both Linux and
macOS.
2020-03-26 00:20:07 +03:00

39 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Original source https://github.com/Project-OSRM/osrm-backend/blob/master/scripts/format.sh
set +x
set -o errexit
set -o pipefail
set -o nounset
# Runs the Clang Formatter in parallel on the code base.
# Return codes:
# - 1 there are files to be formatted
# - 0 everything looks fine
# Get CPU count
OS=$(uname)
NPROC=1
if [[ $OS = "Linux" || $OS = "Darwin" ]] ; then
NPROC=$(getconf _NPROCESSORS_ONLN)
fi
# Discover clang-format
if type clang-format-8 2> /dev/null ; then
CLANG_FORMAT=clang-format-8
else
CLANG_FORMAT=clang-format
fi
find . -type d \( -path ./deps \
-o -path ./cmake \
-o -path ./plugins/decklink/win/decklink-sdk \
-o -path ./plugins/decklink/mac/decklink-sdk \
-o -path ./plugins/decklink/linux/decklink-sdk \
-o -path ./plugins/enc-amf \
-o -path ./plugins/mac-syphon/syphon-framework \
-o -path ./plugins/obs-outputs/ftl-sdk \
-o -path ./plugins/obs-vst \
-o -path ./build \) -prune -type f -o -name '*.h' -or -name '*.hpp' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \
| xargs -I{} -P ${NPROC} ${CLANG_FORMAT} -i -style=file -fallback-style=none {}