-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtidy.sh
executable file
·41 lines (32 loc) · 1.29 KB
/
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
#!/usr/bin/env bash
readonly SCRIPT_DIR="$(dirname "$0")"
cd ${SCRIPT_DIR}
# Find only test files (absolute paths)
TESTS="hpm/hpm/.*test\.c.*"
# Find all .c++ files except test files (absolute paths)
APPLICATION_CODE="hpm/hpm/([a-z]|-|_|[A-Z]|[0-9])+\.c"
# If there's an argument, use it and assume it is application code
if [ $1 ]; then
# Convert a relative path to an absolute path
APPLICATION_CODE=$(find hpm/ -name "*$1*")
# Cut away trailing ++ because run-clang-tidy will interpret them as a regex
APPLICATION_CODE=${APPLICATION_CODE%++}
echo $APPLICATION_CODE
fi
CHECKS="-*,cppcoreguidelines-*,modernize-*,bugprone-*,clang-analyzer-*,misc-*,performance-*,readability-*"
./make-compilation-database.sh
echo "Tidy application code"
CLANG_TIDY_COMMAND="run-clang-tidy-10"
if ! clang_tidy_loc="$(type -p "$CLANG_TIDY_COMMAND")" || [[ -z $clang_tidy_loc ]]; then
echo "Did not find run-clang-tidy-10. Trying run-clang-tidy-11 instead."
CLANG_TIDY_COMMAND="run-clang-tidy-11"
fi
$CLANG_TIDY_COMMAND -p=. -checks=$CHECKS -quiet $APPLICATION_CODE 2>/dev/null
if [ -z "$1" ]; then
# Allow magic numbers in test code
CHECKS="$CHECKS,-readability-magic-numbers,-cppcoreguidelines-avoid-magic-numbers"
echo ""
echo "Tidy test code"
$CLANG_TIDY_COMMAND -p=. -checks=$CHECKS -quiet $TESTS 2>/dev/null
fi
cd -