formatcode.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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-8 2> /dev/null ; then
  19. CLANG_FORMAT=clang-format-8
  20. else
  21. CLANG_FORMAT=clang-format
  22. fi
  23. find . -type d \( -path ./deps \
  24. -o -path ./cmake \
  25. -o -path ./plugins/decklink/win/decklink-sdk \
  26. -o -path ./plugins/decklink/mac/decklink-sdk \
  27. -o -path ./plugins/decklink/linux/decklink-sdk \
  28. -o -path ./plugins/enc-amf \
  29. -o -path ./plugins/mac-syphon/syphon-framework \
  30. -o -path ./plugins/obs-outputs/ftl-sdk \
  31. -o -path ./plugins/obs-vst \
  32. -o -path ./build \) -prune -type f -o -name '*.h' -or -name '*.hpp' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \
  33. | xargs -I{} -P ${NPROC} ${CLANG_FORMAT} -i -style=file -fallback-style=none {}