Skip to content

Commit 518f321

Browse files
committed
try copilot way
1 parent 2b6990c commit 518f321

File tree

1 file changed

+108
-13
lines changed

1 file changed

+108
-13
lines changed

.github/workflows/clang-tidy.yml

Lines changed: 108 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Install clang tidy dependencies
1818
run: |
1919
sudo apt update
20-
sudo apt install -y clang clang-tidy cmake g++ ninja-build
20+
sudo apt install -y clang clang-tidy cmake g++ ninja-build jq
2121
- name: Install SDK dependencies
2222
run: |
2323
sudo apt update
@@ -30,8 +30,11 @@ jobs:
3030
run: |
3131
cmake -S . -B build \
3232
-DCMAKE_CXX_COMPILER=clang++ \
33+
-DCMAKE_C_COMPILER=clang \
3334
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
3435
-DCHECK_FOR_UPDATES=OFF \
36+
-DBUILD_EXAMPLES=ON \
37+
-DBUILD_TOOLS=ON \
3538
-DCMAKE_BUILD_TYPE=Release
3639
3740
- name: Build project
@@ -42,35 +45,127 @@ jobs:
4245
cat <<'EOF' > .clang-tidy
4346
Checks: >
4447
-*,
45-
readability-string-compare,
48+
bugprone-string-compare,
4649
bugprone-suspicious-string-compare,
47-
bugprone-*,
50+
bugprone-string-literal-with-embedded-nul,
51+
bugprone-compare-pointer-to-member-virtual-function,
52+
bugprone-signed-char-misuse,
53+
bugprone-bool-pointer-implicit-conversion,
54+
bugprone-argument-comment,
55+
bugprone-assert-side-effect,
56+
bugprone-branch-clone,
57+
bugprone-copy-constructor-init,
58+
bugprone-dangling-handle,
59+
bugprone-exception-escape,
60+
bugprone-fold-init-type,
61+
bugprone-forward-declaration-namespace,
62+
bugprone-forwarding-reference-overload,
63+
bugprone-inaccurate-erase,
64+
bugprone-incorrect-roundings,
65+
bugprone-infinite-loop,
66+
bugprone-integer-division,
67+
bugprone-lambda-function-name,
68+
bugprone-macro-parentheses,
69+
bugprone-macro-repeated-side-effects,
70+
bugprone-misplaced-operator-in-strlen-in-alloc,
71+
bugprone-misplaced-pointer-arithmetic-in-alloc,
72+
bugprone-misplaced-widening-cast,
73+
bugprone-move-forwarding-reference,
74+
bugprone-multiple-statement-macro,
75+
bugprone-parent-virtual-call,
76+
bugprone-posix-return,
77+
bugprone-sizeof-container,
78+
bugprone-sizeof-expression,
79+
bugprone-string-constructor,
80+
bugprone-string-integer-assignment,
81+
bugprone-suspicious-enum-usage,
82+
bugprone-suspicious-memset-usage,
83+
bugprone-suspicious-missing-comma,
84+
bugprone-suspicious-semicolon,
85+
bugprone-swapped-arguments,
86+
bugprone-terminating-continue,
87+
bugprone-throw-keyword-missing,
88+
bugprone-too-small-loop-variable,
89+
bugprone-undefined-memory-manipulation,
90+
bugprone-undelegated-constructor,
91+
bugprone-unhandled-self-assignment,
92+
bugprone-unused-raii,
93+
bugprone-unused-return-value,
94+
bugprone-use-after-move,
95+
bugprone-virtual-near-miss,
96+
cert-dcl21-cpp,
97+
cert-dcl58-cpp,
98+
cert-err34-c,
99+
cert-err52-cpp,
100+
cert-err60-cpp,
101+
cert-flp30-c,
102+
cert-msc50-cpp,
103+
cert-msc51-cpp,
104+
cert-oop58-cpp,
105+
readability-string-compare,
48106
readability-implicit-bool-conversion,
49-
performance-inefficient-string-concatenation,
50107
modernize-use-nullptr,
51-
modernize-use-override,
52-
modernize-use-auto,
53-
misc-unused-parameters,
54-
misc-strcmp
55-
# WarningsAsErrors: '*' # <-- Commented out to not fail on all warnings
56-
#HeaderFilterRegex: 'src/(?!third-party).*' # consider adding some third party that are not actually third party like realdds
108+
performance-inefficient-string-concatenation
109+
WarningsAsErrors: ''
110+
HeaderFilterRegex: '(src|include|common|tools|examples)/.*\.(h|hpp)$'
57111
FormatStyle: none
58112
CheckOptions:
59113
- key: readability-implicit-bool-conversion.AllowIntegerConditions
60114
value: 'false'
115+
- key: readability-implicit-bool-conversion.AllowPointerConditions
116+
value: 'false'
61117
EOF
118+
echo "Created .clang-tidy configuration:"
119+
cat .clang-tidy
62120
63121
- name: Run clang-tidy
64122
run: |
65123
echo "Running clang-tidy..."
66124
cp build/compile_commands.json .
67-
#clang-tidy -p . $(find src -name '*.cpp') 2>&1 | tee clang-tidy.log
68-
clang-tidy -p . $(find common examples tools wrappers/python src third-party/rsutils third-party/realdds -name '*.cpp') 2>&1 | tee clang-tidy.log
125+
# Run clang-tidy only on files that are in compile_commands.json
126+
# This avoids "Error while processing" for files not in the build
127+
echo "Files in compile database:"
128+
jq -r '.[].file' compile_commands.json | head -20
129+
130+
# Find only .cpp files that exist in compile_commands.json
131+
# Exclude third-party files except realdds and rsutils
132+
FILES_TO_CHECK=$(jq -r '.[].file' compile_commands.json | \
133+
grep -E '\.(cpp|cc|cxx)$' | \
134+
grep -v 'third-party/' | \
135+
sort -u)
136+
137+
# Add back third-party/realdds and third-party/rsutils
138+
FILES_TO_CHECK_THIRD_PARTY=$(jq -r '.[].file' compile_commands.json | \
139+
grep -E '\.(cpp|cc|cxx)$' | \
140+
grep -E 'third-party/(realdds|rsutils)/' | \
141+
sort -u)
142+
143+
FILES_TO_CHECK=$(echo -e "$FILES_TO_CHECK\n$FILES_TO_CHECK_THIRD_PARTY" | grep -v '^$' | sort -u)
144+
145+
if [ -z "$FILES_TO_CHECK" ]; then
146+
echo "No files found in compile_commands.json"
147+
exit 1
148+
fi
149+
150+
echo "Running clang-tidy on $(echo "$FILES_TO_CHECK" | wc -l) files..."
151+
echo "Sample files to check:"
152+
echo "$FILES_TO_CHECK" | head -10
153+
echo "$FILES_TO_CHECK" | xargs clang-tidy -p . 2>&1 | tee clang-tidy.log
154+
155+
# Show summary of issues found
156+
echo ""
157+
echo "=== Summary of issues found ==="
158+
grep -E 'warning:|error:' clang-tidy.log | grep -v '\[clang-diagnostic' | wc -l || echo "0 issues found"
69159
70160
# === NEW: Extract errors only to a separate log ===
71161
- name: Extract errors from clang-tidy log
72162
run: |
73-
awk '/error:/ && !/\[clang-diagnostic-error\]/' clang-tidy.log > clang-tidy-errors.log
163+
# Extract actual clang-tidy warnings/errors, excluding:
164+
# - clang-diagnostic-* (compilation errors)
165+
# - "Error while processing" messages
166+
grep -E 'warning:|error:' clang-tidy.log | \
167+
grep -v '\[clang-diagnostic' | \
168+
grep -v 'Error while processing' > clang-tidy-errors.log || true
74169
75170
# === NEW: Summarize only errors at the end ===
76171
- name: Errors Only Summary

0 commit comments

Comments
 (0)