-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclang-tidy.sh
81 lines (70 loc) · 1.65 KB
/
clang-tidy.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# This script executes clang-tidy on given folder(s) using regular expressions
# Use this command for individual files:
# clang-tidy -p "<BUILD_PATH>" -checks="<CHECKS>" "<SOURCE>" "<SOURCE>" ...
# cgsg forever!
# print message before exit function
message() {
if [ "$#" -ne 0 ]; then
printf "$@\n" >&2;
fi
printf "Usage: $0 [-r REGEX_PATTERN] [-b BUILD_PATH] [-c CHECKS] [-C ADDITIONAL CHECKS] DIRECTORY [DIRECTORIES...]\n" >&2;
}
if [ "${#@}" -eq 0 ]; then
message
exit 1;
fi
# defaul variables values
REGEX_PATTERN='.*\.(h|hpp|hxx|c|cc|cpp|cxx)$'
BUILD_PATH="out"
CHECKS="-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,-cppcoreguidelines-avoid-do-while,-cppcoreguidelines-avoid-goto,modernize-*,-modernize-use-trailing-return-type,perfomance-*,readability-*"
DIRECTORIES=""
# parse command arguments
while [ "$#" -gt 0 ]; do
key="$1"
case "$key" in
-h|--help)
message
exit 0
;;
-r)
REGEX_PATTERN="$2"
shift
shift
;;
-b)
BUILD_PATH="$2"
shift
shift
;;
-c)
CHECKS="$2"
shift
shift
;;
-C)
CHECKS+=",$2"
shift
shift
;;
*)
DIRECTORIES+="$1 "
shift
;;
esac
done
echo "$DIRECTORIES -> $BUILD_PATH"
echo "Enabled checks: $CHECKS"
# obtain source files
if [ -z "$DIRECTORIES" ]; then
message "No directories are provided."
exit 1;
fi
CLANG_TIDY_FILES=$(
find $DIRECTORIES -type f -regextype posix-extended -regex "$REGEX_PATTERN"
)
# execute clang-tidy
for FILE in ${CLANG_TIDY_FILES}; do
echo "$FILE:"
clang-tidy -p "$BUILD_PATH" -checks="$CHECKS" "$FILE"
done