clang_format.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. while read -r f; do
  9. # Run clang-format.
  10. clang-format --Wno-error=unknown -i "$f"
  11. # Fix copyright headers, but not all files get them.
  12. if [[ "$f" == *"inc" ]]; then
  13. continue
  14. elif [[ "$f" == *"glsl" ]]; then
  15. continue
  16. elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/gl/GLSurfaceView"* ]]; then
  17. continue
  18. elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/gl/EGLLogWrapper"* ]]; then
  19. continue
  20. elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix"* ]]; then
  21. continue
  22. fi
  23. python misc/scripts/copyright_headers.py "$f"
  24. done
  25. diff=$(git diff --color)
  26. # If no diff has been generated all is OK, clean up, and exit.
  27. if [ -z "$diff" ] ; then
  28. printf "Files in this commit comply with the clang-format style rules.\n"
  29. exit 0
  30. fi
  31. # A diff has been created, notify the user, clean up, and exit.
  32. printf "\n*** The following changes have been made to comply with the formatting rules:\n\n"
  33. echo "$diff"
  34. printf "\n*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
  35. exit 1