-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
run-clang-tidy.sh
executable file
·72 lines (56 loc) · 1.93 KB
/
run-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
#!/bin/sh
if [ $# -ne 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "$0 <build-path>"
echo "Set env var 'base_sha' to upstream/next hash and 'head_sha' and your current HEAD hash."
exit 1
fi
if [ -z $base_sha ] || [ -z $head_sha ]; then
echo "Set env var 'base_sha' to upstream/next hash and 'head_sha' and your current HEAD hash."
exit 0
fi
echo "Running with version:"
clang-tidy --version
BUILD_PATH="$1"
check_list="clang-analyzer-*,-clang-analyzer-cplusplus*,-clang-analyzer-optin.performance.Padding"
if $(hash clang-tidy-18); then
echo -e "#############\nProduced by\n$(clang-tidy-18 --version)\n#############\n\n" > ct-warnings.txt
clang-tidy-18 $(find ./arch ./*.c -type f -iregex ".*\.[c]") -p "$BUILD_PATH" -checks="$check_list" >> ct-warnings.txt
else
echo -e "#############\nProduced by\n$(clang-tidy --version)\n#############\n\n" > ct-warnings.txt
clang-tidy $(find ./arch ./*.c -type f -iregex ".*\.[c]") -p "$BUILD_PATH" -checks="$check_list" >> ct-warnings.txt
fi
if [ $? -ne 0 ]; then
echo "clang-tidy failed"
exit 1
fi
tmp=$(mktemp)
grep ": warning" ct-warnings.txt | grep -oE "^[/a-zA-Z0-9]*\.[ch]" | sort | uniq > $tmp
top_level=$(git rev-parse --show-toplevel)
echo "\n\n###### REPORT\n\n"
changed_files=$(git diff --name-only $base_sha..$head_sha)
if [ $? -ne 0 ]; then
echo "Failed to get changed files."
exit 1
fi
faulty_files=""
for modified in $changed_files; do
files_changed=1
full_path="$top_level/$modified"
if grep -q "$full_path" $tmp; then
faulty_files="$faulty_files $modified"
echo "$full_path as warnings. Please fix them."
needs_fixes=1
fi
done
if [ -z $files_changed ]; then
echo "No files changed."
exit 0
fi
if [ -z $needs_fixes ]; then
echo "None of the changed files has clang-tidy warnings."
exit 0
fi
cat ct-warnings.txt
echo -e "\n\nclang-tidy warnings for: $faulty_files\n"
echo "Please fix them. Or, if completely unrelated, let us know."
exit 1