forked from MinyazevR/clazy-standalone-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclazy.sh
executable file
·124 lines (98 loc) · 3.96 KB
/
clazy.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
clazy_options=()
for arg in $EXTRA_ARG; do
clazy_options+=( "-extra-arg=$arg" )
done
for arg in $EXTRA_ARG_BEFORE; do
clazy_options+=( "-extra-arg-before=$arg" )
done
if [[ $ONLY_QT == "true" ]]; then
clazy_options+=( "--only-qt" )
fi
if [[ $QT4_COMPAT == "true" ]]; then
clazy_options+=( "--qt4-compat" )
fi
if [[ $VISIT_IMPLICIT_CODE == "true" ]]; then
clazy_options+=( "--visit-implicit-code" )
fi
args=(
-clang-tidy-binary "$GITHUB_ACTION_PATH/clazy-unbuffer.sh"
-checks="$CHECKS"
-warnings-as-errors="$WARNINGS_AS_ERRORS"
-p="$DATABASE"
-header-filter="$HEADER_FILTER"
--
"$PATH_REGEX"
)
exec 5>&1
output=$(CLAZY_OPTIONS=${clazy_options[*]} run-clang-tidy "${args[@]}" 2>&1 | tee /dev/fd/5)
warnings_file=$(mktemp)
errors_file=$(mktemp)
trap 'rm -f "$warnings_file" "$errors_file"' EXIT
echo 0 > "$warnings_file"
echo 0 > "$errors_file"
declare -A warnings_seen
pattern='^(.*?):([0-9]+):([0-9]+): (.+): (.+) \[(.*)\]$'
echo "$output" | grep -E "$pattern" | while IFS= read -r line; do
if [[ $line =~ $pattern ]]; then
relative_path="${BASH_REMATCH[1]}"
line_number="${BASH_REMATCH[2]}"
column_number="${BASH_REMATCH[3]}"
warning_type="${BASH_REMATCH[4]}"
warning_message="${BASH_REMATCH[5]}"
warning_code="${BASH_REMATCH[6]}"
if [[ "$relative_path" == /* ]]; then
absolute_path=$relative_path
else
absolute_path=$(realpath "$DATABASE/$relative_path")
fi
warning_key="${absolute_path}:${line_number}:${column_number}:${warning_code}"
if [[ -n "${warnings_seen[$warning_key]}" ]]; then
continue
fi
warnings_seen["$warning_key"]=1
if [ "$IGNORE_HEADERS" != "true" ]; then
if [[ "$warning_type" == "warning" ]]; then
echo "warning file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
current_warnings=$(<"$warnings_file")
((current_warnings++))
echo "$current_warnings" > "$warnings_file"
fi
if [[ "$warning_type" == "error" ]]; then
echo "error file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
current_errors=$(<"$errors_file")
((current_errors++))
echo "$current_errors" > "$errors_file"
fi
elif [[ "${files[@]}" =~ "$absolute_path" ]]; then
if [[ "$warning_type" == "warning" ]]; then
echo "warning file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
current_warnings=$(<"$warnings_file")
((current_warnings++))
echo "$current_warnings" > "$warnings_file"
fi
if [[ "$warning_type" == "error" ]]; then
echo "error file=$absolute_path,line=$line_number,col=$column_number,$warning_message [$warning_code]"
current_errors=$(<"$errors_file")
((current_errors++))
echo "$current_errors" > "$errors_file"
fi
fi
if [[ "${files[@]}" =~ "$absolute_path" ]]; then
if [[ "$warning_type" == "warning" ]]; then
echo "::warning file=$absolute_path,line=$line_number,col=$column_number::$warning_message [$warning_code]"
fi
if [[ "$warning_type" == "error" ]]; then
echo "::error file=$absolute_path,line=$line_number,col=$column_number::$warning_message [$warning_code]"
fi
fi
fi
done
warnings_count=$(<"$warnings_file")
errors_count=$(<"$errors_file")
echo "::set-output name=errors-count::$errors_count"
echo "::set-output name=warnings-count::$warnings_count"
if [ "$IGNORE_HEADERS" == "true" ] && [ -n "$DATABASE" ]; then
mv $DATABASE/compile_commands_backup.json $DATABASE/compile_commands.json
fi
rm -f "$warnings_file" "$errors_file"