]> git.lizzy.rs Git - dragonfireclient.git/blob - util/travis/lint.sh
Fix clang-format binary selection
[dragonfireclient.git] / util / travis / lint.sh
1 #! /bin/bash
2 function perform_lint() {
3         echo "Performing LINT..."
4         if hash clang-format-3.9 2>/dev/null; then
5                 CLANG_FORMAT=clang-format-3.9
6         else
7                 CLANG_FORMAT=clang-format
8         fi
9         CLANG_FORMAT_WHITELIST="util/travis/clang-format-whitelist.txt"
10
11         if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
12                 # Get list of every file modified in this pull request
13                 files_to_lint="$(git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE | grep '^src/[^.]*[.]\(cpp\|h\)$' | true)"
14         else
15                 # Check everything for branch pushes
16                 files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
17         fi
18
19         local errorcount=0
20         local fail=0
21         for f in ${files_to_lint}; do
22                 d=$(diff -u "$f" <(${CLANG_FORMAT} "$f") || true)
23
24                 if ! [ -z "$d" ]; then
25                         whitelisted=$(egrep -c "^${f}" "${CLANG_FORMAT_WHITELIST}")
26
27                         # If file is not whitelisted, mark a failure
28                         if [ ${whitelisted} -eq 0 ]; then
29                                 errorcount=$((errorcount+1))
30
31                                 printf "The file %s is not compliant with the coding style" "$f"
32                                 if [ ${errorcount} -gt 50 ]; then
33                                         printf "\nToo many errors encountered previously, this diff is hidden.\n"
34                                 else
35                                         printf ":\n%s\n" "$d"
36                                 fi
37
38                                 fail=1
39                         fi
40                 fi
41         done
42
43         if [ "$fail" = 1 ]; then
44                 echo "LINT reports failure."
45                 exit 1
46         fi
47
48         echo "LINT OK"
49 }
50