formatcode.sh 974 B

12345678910111213141516171819202122232425262728293031
  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 -o -path ./cmake -o -path ./plugins/decklink/win -o -path ./plugins/decklink/mac -o -path ./plugins/decklink/linux -o -path ./build \) -prune -type f -o -name '*.h' -or -name '*.hpp' -or -name '*.m' -or -name '*.mm' -or -name '*.c' -or -name '*.cpp' \
  26. | xargs -I{} -P ${NPROC} ${CLANG_FORMAT} -i -style=file -fallback-style=none {}