check-format.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. # Original source https://github.com/Project-OSRM/osrm-backend/blob/master/scripts/format.sh
  3. set -o errexit
  4. set -o pipefail
  5. set -o nounset
  6. if [ ${#} -eq 1 ]; then
  7. VERBOSITY="--verbose"
  8. else
  9. VERBOSITY=""
  10. fi
  11. # Runs the Clang Formatter in parallel on the code base.
  12. # Return codes:
  13. # - 1 there are files to be formatted
  14. # - 0 everything looks fine
  15. # Get CPU count
  16. OS=$(uname)
  17. NPROC=1
  18. if [[ ${OS} = "Linux" ]] ; then
  19. NPROC=$(nproc)
  20. elif [[ ${OS} = "Darwin" ]] ; then
  21. NPROC=$(sysctl -n hw.physicalcpu)
  22. fi
  23. # Discover clang-format
  24. if type clang-format-13 2> /dev/null ; then
  25. CLANG_FORMAT=clang-format-13
  26. elif type clang-format 2> /dev/null ; then
  27. # Clang format found, but need to check version
  28. CLANG_FORMAT=clang-format
  29. V=$(clang-format --version)
  30. if [[ $V != *"version 13.0"* ]]; then
  31. echo "clang-format is not 13.0 (returned ${V})"
  32. exit 1
  33. fi
  34. else
  35. echo "No appropriate clang-format found (expected clang-format-13.0.0, or clang-format)"
  36. exit 1
  37. fi
  38. find . -type d \( \
  39. -path ./\*build\* -o \
  40. -path ./release -o \
  41. -path ./cmake -o \
  42. -path ./plugins/decklink/\*/decklink-sdk -o \
  43. -path ./plugins/enc-amf -o \
  44. -path ./plugins/mac-syphon/syphon-framework -o \
  45. -path ./plugins/obs-outputs/ftl-sdk -o \
  46. -path ./plugins/obs-websocket/deps \
  47. \) -prune -false -type f -o \
  48. -name '*.h' -or \
  49. -name '*.hpp' -or \
  50. -name '*.m' -or \
  51. -name '*.mm' -or \
  52. -name '*.c' -or \
  53. -name '*.cpp' \
  54. | xargs -L100 -P ${NPROC} "${CLANG_FORMAT}" ${VERBOSITY} -i -style=file -fallback-style=none