/
run-clang-tidy.sh
executable file
·60 lines (47 loc) · 1.45 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
#!/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
BUILD_PATH="$1"
clang-tidy $(find ./arch ./*.c -type f -iregex ".*\.[c]") -p "$BUILD_PATH" -checks=clang-analyzer-*,-clang-analyzer-cplusplus* > ct-warnings.txt
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