formatcode.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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" || $OS = "Darwin" ]] ; then
  15. NPROC=$(getconf _NPROCESSORS_ONLN)
  16. fi
  17. # Discover clang-format
  18. if type clang-format-12 2> /dev/null ; then
  19. CLANG_FORMAT=clang-format-12
  20. elif type clang-format-10 2> /dev/null ; then
  21. CLANG_FORMAT=clang-format-10
  22. elif type clang-format-8 2> /dev/null ; then
  23. CLANG_FORMAT=clang-format-8
  24. else
  25. CLANG_FORMAT=clang-format
  26. fi
  27. find . -type d \( -path ./deps \
  28. -o -path ./cmake \
  29. -o -path ./plugins/decklink/win/decklink-sdk \
  30. -o -path ./plugins/decklink/mac/decklink-sdk \
  31. -o -path ./plugins/decklink/linux/decklink-sdk \
  32. -o -path ./plugins/enc-amf \
  33. -o -path ./plugins/mac-syphon/syphon-framework \
  34. -o -path ./plugins/obs-outputs/ftl-sdk \
  35. -o -path ./plugins/obs-vst \
  36. -o -path ./plugins/aja/sdk \
  37. -o -path ./build \) -prune -type f -o -name '*.h' -or -name '*.hpp' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \
  38. | xargs -L100 -P${NPROC} ${CLANG_FORMAT} -i -style=file -fallback-style=none