clang_format.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env bash
  2. # This script runs clang-format and fixes copyright headers on all relevant files in the repo.
  3. # This is the primary script responsible for fixing style violations.
  4. set -uo pipefail
  5. # Loops through all code files tracked by Git.
  6. git ls-files -- '*.c' '*.h' '*.cpp' '*.hpp' '*.cc' '*.hh' '*.cxx' '*.m' '*.mm' '*.inc' '*.java' '*.glsl' \
  7. ':!:.git/*' ':!:thirdparty/*' ':!:platform/android/java/lib/src/com/google/*' ':!:*-so_wrap.*' \
  8. ':!:tests/python_build/*' |
  9. while read -r f; do
  10. # Run clang-format.
  11. clang-format --Wno-error=unknown -i "$f"
  12. # Fix copyright headers, but not all files get them.
  13. if [[ "$f" == *"inc" ]]; then
  14. continue
  15. elif [[ "$f" == *"glsl" ]]; then
  16. continue
  17. elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/gl/GLSurfaceView"* ]]; then
  18. continue
  19. elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/gl/EGLLogWrapper"* ]]; then
  20. continue
  21. elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix"* ]]; then
  22. continue
  23. fi
  24. python misc/scripts/copyright_headers.py "$f"
  25. done
  26. diff=$(git diff --color)
  27. # If no diff has been generated all is OK, clean up, and exit.
  28. if [ -z "$diff" ] ; then
  29. printf "Files in this commit comply with the clang-format style rules.\n"
  30. exit 0
  31. fi
  32. # A diff has been created, notify the user, clean up, and exit.
  33. printf "\n*** The following changes have been made to comply with the formatting rules:\n\n"
  34. echo "$diff"
  35. printf "\n*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
  36. exit 1