check-style.sh 625 B

1234567891011121314151617181920212223
  1. #!/bin/bash
  2. function clang_format() {
  3. echo "verifying 'clang-format --output-replacements-xml --style=Google $@'"
  4. if clang-format --output-replacements-xml --style=Google "$@" | grep -q '<replacement '; then
  5. echo "ERROR:" "$@" "not in Google C/C++ style"
  6. echo "To fix formatting run"
  7. echo "$ clang-format -i --style=Google" "$@"
  8. return 255
  9. fi
  10. }
  11. tmpfile="tmpfile.$RANDOM"
  12. find src include examples tests -iname "*.cc" -o -iname "*.h" > "$tmpfile"
  13. ec=0
  14. while read -r file; do
  15. if ! clang_format "$file"; then
  16. ec=255
  17. fi
  18. done < "$tmpfile"
  19. rm -f "$tmpfile"
  20. exit "$ec"