fix_style.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. # Command line arguments
  3. run_clang_format=false
  4. run_fix_headers=false
  5. usage="Invalid argument. Usage:\n$0 <option>\n\t--clang-format|-c\n\t--headers|-h\n\t--all|-a"
  6. if [ -z "$1" ]; then
  7. echo -e $usage
  8. exit 0
  9. fi
  10. while [ $# -gt 0 ]; do
  11. case "$1" in
  12. --clang-format|-c)
  13. run_clang_format=true
  14. ;;
  15. --headers|-h)
  16. run_fix_headers=true
  17. ;;
  18. --all|-a)
  19. run_clang_format=true
  20. run_fix_headers=true
  21. ;;
  22. *)
  23. echo -e $usage
  24. exit 0
  25. esac
  26. shift
  27. done
  28. echo "Removing generated files, some have binary data and make clang-format freeze."
  29. find -name "*.gen.*" -delete
  30. # Apply clang-format
  31. if $run_clang_format; then
  32. # Sync list with pre-commit hook
  33. FILE_EXTS=".c .h .cpp .hpp .cc .hh .cxx .m .mm .inc .java .glsl"
  34. for extension in ${FILE_EXTS}; do
  35. echo -e "Formatting ${extension} files..."
  36. find \( -path "./.git" \
  37. -o -path "./thirdparty" \
  38. -o -path "./platform/android/java/lib/src/com/google" \
  39. \) -prune \
  40. -o -name "*${extension}" \
  41. -exec clang-format -i {} \;
  42. done
  43. fi
  44. # Add missing copyright headers
  45. if $run_fix_headers; then
  46. echo "Fixing copyright headers in Godot code files..."
  47. find \( -path "./.git" -o -path "./thirdparty" \) -prune \
  48. -o -regex '.*\.\(c\|h\|cpp\|hpp\|cc\|hh\|cxx\|m\|mm\|java\)' \
  49. > tmp-files
  50. cat tmp-files | grep -v ".git\|thirdparty\|theme_data.h\|platform/android/java/lib/src/com/google\|platform/android/java/lib/src/org/godotengine/godot/input/InputManager" > files
  51. python misc/scripts/fix_headers.py
  52. rm -f tmp-files files
  53. fi