-
Notifications
You must be signed in to change notification settings - Fork 5k
201 lines (183 loc) · 7.49 KB
/
Copy pathclang-tidy.yml
File metadata and controls
201 lines (183 loc) · 7.49 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Clang-Tidy CI
on:
push:
branches: ['**']
pull_request:
branches: ['**']
jobs:
clang-tidy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install clang tidy dependencies
run: |
sudo apt update
sudo apt install -y clang clang-tidy cmake g++ ninja-build jq
- name: Install SDK dependencies
run: |
sudo apt update
sudo apt-get install -qq build-essential xorg-dev libgl1-mesa-dev libglu1-mesa-dev libglew-dev libglm-dev;
sudo apt-get install -qq libusb-1.0-0-dev;
sudo apt-get install -qq libgtk-3-dev;
sudo apt-get install libglfw3-dev libglfw3;
- name: Configure project with CMake
run: |
cmake -S . -B build \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCHECK_FOR_UPDATES=OFF \
-DBUILD_EXAMPLES=ON \
-DBUILD_TOOLS=ON \
-DCMAKE_BUILD_TYPE=Release
- name: Build project
run: cmake --build build -j$(nproc)
- name: Create .clang-tidy config
run: |
cat <<'EOF' > .clang-tidy
Checks: >
-*,
bugprone-string-compare,
bugprone-suspicious-string-compare,
bugprone-string-literal-with-embedded-nul,
bugprone-compare-pointer-to-member-virtual-function,
bugprone-signed-char-misuse,
bugprone-bool-pointer-implicit-conversion,
bugprone-argument-comment,
bugprone-assert-side-effect,
bugprone-branch-clone,
bugprone-copy-constructor-init,
bugprone-dangling-handle,
bugprone-exception-escape,
bugprone-fold-init-type,
bugprone-forward-declaration-namespace,
bugprone-forwarding-reference-overload,
bugprone-inaccurate-erase,
bugprone-incorrect-roundings,
bugprone-infinite-loop,
bugprone-integer-division,
bugprone-lambda-function-name,
bugprone-macro-parentheses,
bugprone-macro-repeated-side-effects,
bugprone-misplaced-operator-in-strlen-in-alloc,
bugprone-misplaced-pointer-arithmetic-in-alloc,
bugprone-misplaced-widening-cast,
bugprone-move-forwarding-reference,
bugprone-multiple-statement-macro,
bugprone-parent-virtual-call,
bugprone-posix-return,
bugprone-sizeof-container,
bugprone-sizeof-expression,
bugprone-string-constructor,
bugprone-string-integer-assignment,
bugprone-suspicious-enum-usage,
bugprone-suspicious-memset-usage,
bugprone-suspicious-missing-comma,
bugprone-suspicious-semicolon,
bugprone-swapped-arguments,
bugprone-terminating-continue,
bugprone-throw-keyword-missing,
bugprone-too-small-loop-variable,
bugprone-undefined-memory-manipulation,
bugprone-undelegated-constructor,
bugprone-unhandled-self-assignment,
bugprone-unused-raii,
bugprone-unused-return-value,
bugprone-use-after-move,
bugprone-virtual-near-miss,
cert-dcl21-cpp,
cert-dcl58-cpp,
cert-err34-c,
cert-err52-cpp,
cert-err60-cpp,
cert-flp30-c,
cert-msc50-cpp,
cert-msc51-cpp,
cert-oop58-cpp,
readability-string-compare,
readability-implicit-bool-conversion,
modernize-use-nullptr,
performance-inefficient-string-concatenation
WarningsAsErrors: ''
HeaderFilterRegex: '^((?!third-party/).)*$|third-party/(realdds|rsutils)/.*'
FormatStyle: none
CheckOptions:
- key: readability-implicit-bool-conversion.AllowIntegerConditions
value: 'false'
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: 'false'
EOF
echo "Created .clang-tidy configuration:"
cat .clang-tidy
- name: Run clang-tidy
run: |
echo "Running clang-tidy..."
cp build/compile_commands.json .
# Run clang-tidy only on files that are in compile_commands.json
# This avoids "Error while processing" for files not in the build
echo "Files in compile database:"
jq -r '.[].file' compile_commands.json | head -20
# Find only .cpp files that exist in compile_commands.json
# Exclude third-party files except realdds and rsutils
FILES_TO_CHECK=$(jq -r '.[].file' compile_commands.json | \
grep -E '\.(cpp|cc|cxx)$' | \
grep -v 'third-party/' | \
sort -u)
# Add back third-party/realdds and third-party/rsutils
FILES_TO_CHECK_THIRD_PARTY=$(jq -r '.[].file' compile_commands.json | \
grep -E '\.(cpp|cc|cxx)$' | \
grep -E 'third-party/(realdds|rsutils)/' | \
sort -u)
FILES_TO_CHECK=$(echo -e "$FILES_TO_CHECK\n$FILES_TO_CHECK_THIRD_PARTY" | grep -v '^$' | sort -u)
if [ -z "$FILES_TO_CHECK" ]; then
echo "No files found in compile_commands.json"
exit 1
fi
echo "Running clang-tidy on $(echo "$FILES_TO_CHECK" | wc -l) files..."
echo "Sample files to check:"
echo "$FILES_TO_CHECK" | head -10
echo "$FILES_TO_CHECK" | xargs clang-tidy -p . 2>&1 | tee clang-tidy.log
# Show summary of issues found
echo ""
echo "=== Summary of issues found ==="
grep -E 'warning:|error:' clang-tidy.log | grep -v '\[clang-diagnostic' | wc -l || echo "0 issues found"
# === NEW: Extract errors only to a separate log ===
- name: Extract errors from clang-tidy log
run: |
# Extract actual clang-tidy warnings/errors, excluding:
# - clang-diagnostic-* (compilation errors)
# - "Error while processing" messages
grep -E 'warning:|error:' clang-tidy.log | \
grep -v '\[clang-diagnostic' | \
grep -v 'Error while processing' > clang-tidy-errors.log || true
# === NEW: Summarize only errors at the end ===
- name: Errors Only Summary
run: |
echo "Clang-Tidy Errors Only Summary:"
total_errors=$(cat clang-tidy-errors.log | wc -l)
echo ""
echo "Total errors found: $total_errors"
echo ""
if (( total_errors > 0 )); then
echo "Top error types:"
grep -oE '\[[^][]+\]' clang-tidy-errors.log | sort | uniq -c | sort -nr | head -20
echo ""
echo "CI failed due to errors. See clang-tidy-errors.log for details."
exit 1
else
echo "✅ No clang-tidy errors found."
fi
- name: Upload full clang-tidy log as Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: clang-tidy-log
path: clang-tidy.log
# === NEW: Upload errors-only log as artifact ===
- name: Upload clang-tidy errors-only log as Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: clang-tidy-errors-log
path: clang-tidy-errors.log