Skip to content

Commit 228110c

Browse files
authored
Use a clang-tidy configuration file (#488)
* Improve GitHub workflow for clang-tidy * Improve clang-tidy configuration * Further improve clang-tidy ignore list of warnings * Add cert warnings to clang-tidy
1 parent fbd9e6e commit 228110c

File tree

2 files changed

+106
-27
lines changed

2 files changed

+106
-27
lines changed

.clang-tidy

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Checks:
2+
- cert-*
3+
- clang-analyzer-*
4+
- bugprone-*
5+
- performance-*
6+
- readability-*
7+
- modernize-*
8+
- cppcoreguidelines-*
9+
- misc-*
10+
- '-altera-unroll-loops'
11+
- '-bugprone-easily-swappable-parameters'
12+
- '-bugprone-sizeof-expression'
13+
- '-cppcoreguidelines-avoid-do-while'
14+
- '-cppcoreguidelines-macro-usage'
15+
- '-cppcoreguidelines-no-malloc'
16+
- '-cppcoreguidelines-owning-memory'
17+
- '-cppcoreguidelines-pro-bounds-array-to-pointer-decay'
18+
- '-cppcoreguidelines-pro-bounds-constant-array-index'
19+
- '-cppcoreguidelines-pro-bounds-pointer-arithmetic'
20+
- '-cppcoreguidelines-pro-type-union-access'
21+
- '-cppcoreguidelines-pro-type-vararg'
22+
- '-llvmlibc-implementation-in-namespace'
23+
- '-llvmlibc-restrict-system-libc-headers'
24+
- '-misc-const-correctness'
25+
- '-misc-definitions-in-headers'
26+
- '-misc-no-recursion'
27+
- '-misc-static-assert'
28+
- '-misc-unused-parameters'
29+
- '-modernize-use-auto'
30+
- '-modernize-use-nodiscard'
31+
- '-modernize-use-using'
32+
- '-modernize-use-trailing-return-type'
33+
- '-performance-enum-size'
34+
- '-readability-braces-around-statements'
35+
- '-readability-function-cognitive-complexity'
36+
- '-readability-implicit-bool-conversion'
37+
- '-readability-simplify-boolean-expr'
38+
- '-readability-static-accessed-through-instance'
39+
- '-readability-identifier-naming'
40+
- '-readability-identifier-length'
41+
42+
HeaderFilterRegex: '.*\.(cpp|h)$'
43+
FormatStyle: file
44+
45+
CheckOptions:
46+
- key: 'modernize-loop-convert.MaxCopySize'
47+
value: '16'
48+
- key: 'readability-identifier-naming.VariableCase'
49+
value: 'camelBack'
50+
- key: 'readability-identifier-naming.ClassCase'
51+
value: 'CamelCase'
52+
- key: 'readability-identifier-naming.FunctionCase'
53+
value: 'camelBack'
54+
- key: 'cppcoreguidelines-avoid-magic-numbers.IgnoreEnums'
55+
value: '1'
56+
- key: 'cppcoreguidelines-avoid-magic-numbers.IgnoreOctalLiterals'
57+
value: '1'
+49-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Static code analysis (clang-tidy)
1+
name: Static code analysis (clang-tidy)
22

33
on:
44
push:
@@ -12,26 +12,39 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v4
1414

15-
- name: Install dependencies
15+
# Cache Vulkan SDK
16+
- name: Cache Vulkan SDK
17+
id: cache-vulkan
18+
uses: actions/cache@v4
19+
with:
20+
path: vulkan_sdk
21+
key: vulkan-sdk-1.4.309.0
22+
23+
# Install system dependencies
24+
- name: Install system dependencies
1625
run: |
1726
sudo apt update
18-
sudo apt install -y clang-15 clang-tidy-15 cmake ninja-build libc++-15-dev libc++abi-15-dev
19-
20-
- name: Set clang-tidy version
21-
run: echo "CLANG_TIDY=clang-tidy-15" >> $GITHUB_ENV
27+
sudo apt install -y clang-15 clang-tidy-15 cmake parallel libc++-15-dev libc++abi-15-dev
2228
23-
- name: Prepare Vulkan SDK
29+
# Download Vulkan SDK only if not cached
30+
- name: Download Vulkan SDK
31+
if: steps.cache-vulkan.outputs.cache-hit != 'true'
2432
run: |
2533
curl -LS -o vulkansdk.tar.xz https://sdk.lunarg.com/sdk/download/1.4.309.0/linux/vulkansdk-linux-x86_64-1.4.309.0.tar.xz
2634
mkdir -p vulkan_sdk
2735
tar xf vulkansdk.tar.xz -C vulkan_sdk
28-
export VULKAN_SDK=$GITHUB_WORKSPACE/vulkan_sdk/1.4.309.0/x86_64
29-
echo "VULKAN_SDK=$VULKAN_SDK" >> $GITHUB_ENV
30-
echo "PATH=$VULKAN_SDK/bin:$PATH" >> $GITHUB_ENV
31-
echo "LD_LIBRARY_PATH=$VULKAN_SDK/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
32-
echo "VK_ICD_FILENAMES=$VULKAN_SDK/etc/vulkan/icd.d" >> $GITHUB_ENV
33-
echo "VK_LAYER_PATH=$VULKAN_SDK/etc/vulkan/layer.d" >> $GITHUB_ENV
3436
37+
# Set environment variables for Clang and Vulkan SDK
38+
- name: Set environment variables
39+
run: |
40+
echo "CLANG_TIDY=clang-tidy-15" >> $GITHUB_ENV
41+
echo "VULKAN_SDK=${GITHUB_WORKSPACE}/vulkan_sdk/1.4.309.0/x86_64" >> $GITHUB_ENV
42+
echo "PATH=${GITHUB_WORKSPACE}/vulkan_sdk/1.4.309.0/x86_64/bin:$PATH" >> $GITHUB_ENV
43+
echo "LD_LIBRARY_PATH=${GITHUB_WORKSPACE}/vulkan_sdk/1.4.309.0/x86_64/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
44+
echo "VK_ICD_FILENAMES=${GITHUB_WORKSPACE}/vulkan_sdk/1.4.309.0/x86_64/etc/vulkan/icd.d" >> $GITHUB_ENV
45+
echo "VK_LAYER_PATH=${GITHUB_WORKSPACE}/vulkan_sdk/1.4.309.0/x86_64/etc/vulkan/layer.d" >> $GITHUB_ENV
46+
47+
# Configure the project with CMake
3548
- name: Configure with CMake
3649
run: |
3750
cmake -S . -B build \
@@ -40,18 +53,27 @@ jobs:
4053
-DCMAKE_C_COMPILER=clang-15 \
4154
-DVMA_BUILD_SAMPLES=YES
4255
43-
- name: Run Clang-Tidy
56+
# List files to analyze
57+
- name: Check the files found for clang-tidy
58+
run: |
59+
find src include \
60+
-path '*/_deps/*' -prune -o \
61+
-path '*/build/*' -prune -o \
62+
\( -name '*.cpp' -o -name '*.hpp' \) -print
63+
64+
# Run clang-tidy in parallel
65+
- name: Run clang-tidy
66+
run: |
67+
find src include \
68+
-path '*/_deps/*' -prune -o \
69+
-path '*/build/*' -prune -o \
70+
\( -name '*.cpp' -o -name '*.hpp' \) -print0 |
71+
parallel -0 clang-tidy -p build {} |
72+
tee output || true
73+
74+
# Summarize warnings
75+
- name: Summarize clang-tidy warnings
4476
run: |
45-
find . -name '*.cpp' | xargs clang-tidy-15 -checks='*, \
46-
-modernize-use-trailing-return-type, \
47-
-cppcoreguidelines-macro-usage, \
48-
-modernize-use-auto, \
49-
-modernize-use-using \
50-
-modernize-use-nodiscard \
51-
-altera-unroll-loops \
52-
-misc-definitions-in-headers \
53-
-cppcoreguidelines-pro-bounds-pointer-arithmetic \
54-
-readability-function-cognitive-complexity \
55-
-llvmlibc-restrict-system-libc-headers \
56-
-cppcoreguidelines-pro-type-union-access' \
57-
-header-filter='.*vk_mem_alloc\.h' -p build || true
77+
grep -hEo '\[[a-z0-9]+-[a-z0-9-]+\]' output \
78+
| sort | uniq -c | sort -nr \
79+
| sed 's/[][]//g' || true

0 commit comments

Comments
 (0)