formatcode.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env bash
  2. # Original source https://github.com/Project-OSRM/osrm-backend/blob/master/scripts/format.sh
  3. set +x
  4. set -o errexit
  5. set -o pipefail
  6. set -o nounset
  7. # Runs the Clang Formatter in parallel on the code base.
  8. # Return codes:
  9. # - 1 there are files to be formatted
  10. # - 0 everything looks fine
  11. # Get CPU count
  12. OS=$(uname)
  13. NPROC=1
  14. if [[ $OS = "Linux" ]] ; then
  15. NPROC=$(nproc)
  16. elif [[ ${OS} = "Darwin" ]] ; then
  17. NPROC=$(sysctl -n hw.physicalcpu)
  18. fi
  19. # Discover clang-format
  20. if type clang-format-8 2> /dev/null ; then
  21. CLANG_FORMAT=clang-format-8
  22. else
  23. CLANG_FORMAT=clang-format
  24. fi
  25. find . -type d \( -path ./deps \
  26. -o -path ./cmake \
  27. -o -path ./plugins/decklink/win \
  28. -o -path ./plugins/decklink/mac \
  29. -o -path ./plugins/decklink/linux \
  30. -o -path ./plugins/enc-amf \
  31. -o -path ./plugins/mac-syphon/syphon-framework \
  32. -o -path ./plugins/obs-outputs/ftl-sdk \
  33. -o -path ./plugins/obs-vst \
  34. -o -path ./build \) -prune -type f -o -name '*.h' -or -name '*.hpp' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \
  35. | xargs -I{} -P ${NPROC} ${CLANG_FORMAT} -i -style=file -fallback-style=none {}