clang_format.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. fi
  21. python misc/scripts/copyright_headers.py "$f"
  22. done
  23. diff=$(git diff --color)
  24. # If no patch has been generated all is OK, clean up, and exit.
  25. if [ -z "$diff" ] ; then
  26. printf "Files in this commit comply with the clang-tidy style rules.\n"
  27. exit 0
  28. fi
  29. # A patch has been created, notify the user, clean up, and exit.
  30. printf "\n*** The following changes have been made to comply with the formatting rules:\n\n"
  31. echo "$diff"
  32. printf "\n*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
  33. exit 1