2
0

clang_format.sh 1.2 KB

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