-
Notifications
You must be signed in to change notification settings - Fork 467
/
clang_check.sh
35 lines (31 loc) · 723 Bytes
/
clang_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
CLANG_FORMAT="clang-format-5.0"
if hash $CLANG_FORMAT 2>/dev/null; then
echo "clang-format hashed"
elif hash clang-format 2>/dev/null; then
echo "Cannot find $CLANG_FORMAT, using clang-format"
CLANG_FORMAT="clang-format"
else
echo "Cannot find clang-format"
exit 1
fi
if [ ! -f ".clang-format" ]; then
echo ".clang-format file not found!"
exit 1
fi
RETURN=0
:
for FILE in `ls *.[ch] */*.[ch]`; do
DIFF=`diff $FILE <($CLANG_FORMAT $FILE)`
if [ $? -ne 0 ]; then
if [ -z "$TRAVIS" ]; then
echo "Formatting $FILE" >&2
$CLANG_FORMAT -i $FILE
else
echo -e "\e[31m$FILE has formatting errors:\e[30m" >&2
echo "$DIFF" >&2
fi
RETURN=1
fi
done
exit $RETURN