]> git.lizzy.rs Git - dragonfireclient.git/blob - util/travis/script.sh
clang-format: add a whitelist (#5459)
[dragonfireclient.git] / util / travis / script.sh
1 #!/bin/bash -e
2 . util/travis/common.sh
3
4 needs_compile || exit 0
5
6 function perform_lint() {
7         echo "Performing LINT..."
8         CLANG_FORMAT=clang-format-3.9
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\)$' | egrep -v '^src/(gmp|lua|jsoncpp)/' || true)"
14         else
15                 # Check everything for branch pushes
16                 files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h' | egrep -v '^src/(gmp|lua|jsoncpp)/')"
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                         errorcount=$((errorcount+1))
26
27                         printf "The file %s is not compliant with the coding style" "$f"
28                         if [ ${errorcount} -gt 50 ]; then
29                                 printf "\nToo many errors encountered previously, this diff is hidden.\n"
30                         else
31                                 printf ":\n%s\n" "$d"
32                         fi
33
34                         whitelisted=$(egrep -c "^${f}" "${CLANG_FORMAT_WHITELIST}")
35
36                         # If file is not whitelisted, mark a failure
37                         if [ ${whitelisted} -eq 0 ]; then
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
51 if [[ "$LINT" == "1" ]]; then
52         # Lint with exit CI
53         perform_lint
54         exit 0
55 fi
56
57 if [[ $PLATFORM == "Unix" ]]; then
58         mkdir -p travisbuild
59         cd travisbuild || exit 1
60
61         CMAKE_FLAGS=''
62         if [[ $COMPILER == "g++-6" ]]; then
63                 export CC=gcc-6
64                 export CXX=g++-6
65         fi
66
67         # Clang builds with FreeType fail on Travis
68         if [[ $CC == "clang" ]]; then
69                 CMAKE_FLAGS+=' -DENABLE_FREETYPE=FALSE'
70         fi
71
72         if [[ $TRAVIS_OS_NAME == "osx" ]]; then
73                 CMAKE_FLAGS+=' -DCUSTOM_GETTEXT_PATH=/usr/local/opt/gettext'
74         fi
75
76         cmake -DCMAKE_BUILD_TYPE=Debug \
77                 -DRUN_IN_PLACE=TRUE \
78                 -DENABLE_GETTEXT=TRUE \
79                 -DBUILD_SERVER=TRUE \
80                 $CMAKE_FLAGS ..
81         make -j2
82
83         echo "Running unit tests."
84         CMD="../bin/minetest --run-unittests"
85         if [[ "$VALGRIND" == "1" ]]; then
86                 valgrind --leak-check=full --leak-check-heuristics=all --undef-value-errors=no --error-exitcode=9 ${CMD} && exit 0
87         else
88                 ${CMD} && exit 0
89         fi
90
91 elif [[ $PLATFORM == Win* ]]; then
92         [[ $CC == "clang" ]] && exit 1 # Not supposed to happen
93         # We need to have our build directory outside of the minetest directory because
94         #  CMake will otherwise get very very confused with symlinks and complain that
95         #  something is not a subdirectory of something even if it actually is.
96         # e.g.:
97         # /home/travis/minetest/minetest/travisbuild/minetest
98         # \/  \/  \/
99         # /home/travis/minetest/minetest/travisbuild/minetest/travisbuild/minetest
100         # \/  \/  \/
101         # /home/travis/minetest/minetest/travisbuild/minetest/travisbuild/minetest/travisbuild/minetest
102         # You get the idea.
103         OLDDIR=$(pwd)
104         cd ..
105         export EXISTING_MINETEST_DIR=$OLDDIR
106         export NO_MINETEST_GAME=1
107         if [[ $PLATFORM == "Win32" ]]; then
108                 "$OLDDIR/util/buildbot/buildwin32.sh" travisbuild && exit 0
109         elif [[ $PLATFORM == "Win64" ]]; then
110                 "$OLDDIR/util/buildbot/buildwin64.sh" travisbuild && exit 0
111         fi
112 else
113         echo "Unknown platform \"${PLATFORM}\"."
114         exit 1
115 fi
116