script.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash -ex
  2. # SPDX-FileCopyrightText: 2019 yuzu Emulator Project
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. if grep -nrI '\s$' src *.yml *.txt *.md Doxyfile .gitignore .gitmodules .ci* dist/*.desktop \
  5. dist/*.svg dist/*.xml; then
  6. echo Trailing whitespace found, aborting
  7. exit 1
  8. fi
  9. # Default clang-format points to default 3.5 version one
  10. CLANG_FORMAT=clang-format-12
  11. $CLANG_FORMAT --version
  12. if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
  13. # Get list of every file modified in this pull request
  14. files_to_lint="$(git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE | grep '^src/[^.]*[.]\(cpp\|h\)$' || true)"
  15. else
  16. # Check everything for branch pushes
  17. files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
  18. fi
  19. # Turn off tracing for this because it's too verbose
  20. set +x
  21. for f in $files_to_lint; do
  22. d=$(diff -u "$f" <($CLANG_FORMAT "$f") || true)
  23. if ! [ -z "$d" ]; then
  24. echo "!!! $f not compliant to coding style, here is the fix:"
  25. echo "$d"
  26. fail=1
  27. fi
  28. done
  29. set -x
  30. if [ "$fail" = 1 ]; then
  31. exit 1
  32. fi