Skip to content

Commit e6796f2

Browse files
committed
Add standalone Cppcheck CI
1 parent 7ca2e79 commit e6796f2

3 files changed

Lines changed: 231 additions & 0 deletions

File tree

.github/workflows/cppcheck.yml

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: Cppcheck
19+
20+
on:
21+
push:
22+
branches:
23+
- develop
24+
- iotdb
25+
- rc/*
26+
paths:
27+
- '.github/workflows/cppcheck.yml'
28+
- '.mvn/**'
29+
- 'cpp/**'
30+
- 'mvnw'
31+
- 'pom.xml'
32+
pull_request:
33+
branches:
34+
- develop
35+
- dev/*
36+
- iotdb
37+
- rc/*
38+
paths:
39+
- '.github/workflows/cppcheck.yml'
40+
- '.mvn/**'
41+
- 'cpp/**'
42+
- 'mvnw'
43+
- 'pom.xml'
44+
workflow_dispatch:
45+
46+
concurrency:
47+
group: ${{ github.workflow }}-${{ github.ref }}
48+
cancel-in-progress: true
49+
50+
permissions:
51+
contents: read
52+
53+
env:
54+
CPPCHECK_VERSION: 2.17.1
55+
CPPCHECK_SOURCE_SHA256: bfd681868248ec03855ca7c2aea7bcb1f39b8b18860d76aec805a92a967b966c
56+
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3
57+
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
58+
59+
jobs:
60+
cppcheck:
61+
runs-on: ubuntu-24.04
62+
timeout-minutes: 30
63+
64+
steps:
65+
- name: Checkout repository
66+
uses: actions/checkout@v7
67+
68+
- name: Set up JDK 17
69+
uses: actions/setup-java@v5.6.0
70+
with:
71+
distribution: corretto
72+
java-version: 17
73+
74+
- name: Cache Maven packages
75+
uses: actions/cache@v6
76+
with:
77+
path: ~/.m2
78+
key: ${{ runner.os }}-m2-cppcheck-${{ hashFiles('**/pom.xml') }}
79+
restore-keys: ${{ runner.os }}-m2-
80+
81+
- name: Cache Cppcheck
82+
uses: actions/cache@v6
83+
with:
84+
path: ~/.cache/cppcheck/${{ env.CPPCHECK_VERSION }}
85+
key: cppcheck-${{ runner.os }}-${{ runner.arch }}-${{ env.CPPCHECK_VERSION }}-${{ env.CPPCHECK_SOURCE_SHA256 }}
86+
87+
- name: Install dependencies
88+
run: |
89+
sudo apt-get update
90+
sudo apt-get install -y uuid-dev
91+
92+
- name: Install Cppcheck
93+
shell: bash
94+
run: |
95+
set -euo pipefail
96+
97+
cppcheck_home="${HOME}/.cache/cppcheck/${CPPCHECK_VERSION}"
98+
if [[ ! -x "${cppcheck_home}/bin/cppcheck" ]]; then
99+
build_root="$(mktemp -d)"
100+
archive="${build_root}/cppcheck.tar.gz"
101+
source_dir="${build_root}/source"
102+
build_dir="${build_root}/build"
103+
104+
mkdir -p "${source_dir}" "${build_dir}" "${cppcheck_home}"
105+
curl --fail --location --retry 3 \
106+
"https://github.com/cppcheck-opensource/cppcheck/archive/refs/tags/${CPPCHECK_VERSION}.tar.gz" \
107+
--output "${archive}"
108+
echo "${CPPCHECK_SOURCE_SHA256} ${archive}" | sha256sum --check -
109+
tar -xzf "${archive}" --strip-components=1 -C "${source_dir}"
110+
111+
cmake -S "${source_dir}" -B "${build_dir}" \
112+
-DCMAKE_BUILD_TYPE=Release \
113+
-DUSE_MATCHCOMPILER=ON \
114+
-DBUILD_GUI=OFF \
115+
-DBUILD_TESTS=OFF \
116+
-DCMAKE_INSTALL_PREFIX="${cppcheck_home}"
117+
cmake --build "${build_dir}" --parallel "$(nproc)"
118+
cmake --install "${build_dir}"
119+
fi
120+
121+
echo "${cppcheck_home}/bin" >> "${GITHUB_PATH}"
122+
"${cppcheck_home}/bin/cppcheck" --version
123+
124+
- name: Generate compilation database with Maven
125+
run: |
126+
./mvnw -P with-cpp,with-cppcheck -pl cpp \
127+
-Dbuild.test=OFF \
128+
cmake:generate@cmake-generate-test-compile
129+
test -s cpp/target/build/compile_commands.json
130+
131+
- name: Run Cppcheck
132+
shell: bash
133+
run: |
134+
mkdir -p cpp/target/cppcheck
135+
136+
set +e
137+
cppcheck \
138+
--project=cpp/target/build/compile_commands.json \
139+
--file-filter='*cpp/src/*' \
140+
--file-filter='*cpp/tools/*' \
141+
--file-filter='*cpp/examples/*' \
142+
--enable=warning,performance,portability \
143+
--check-level=exhaustive \
144+
--inline-suppr \
145+
--suppress=missingIncludeSystem \
146+
--suppress=unusedFunction \
147+
--suppress='*:*/third_party/*' \
148+
--suppress='*:*/target/*' \
149+
--suppress='*:*/parser/generated/*' \
150+
--exitcode-suppressions=cpp/cppcheck-baseline.txt \
151+
--error-exitcode=2 \
152+
--template=gcc \
153+
--output-file=cpp/target/cppcheck/cppcheck.txt \
154+
--quiet \
155+
-j "$(nproc)"
156+
cppcheck_status=$?
157+
set -e
158+
159+
cat cpp/target/cppcheck/cppcheck.txt
160+
exit "${cppcheck_status}"
161+
162+
- name: Upload Cppcheck report
163+
if: always()
164+
uses: actions/upload-artifact@v7
165+
with:
166+
name: cppcheck-report
167+
path: cpp/target/cppcheck/cppcheck.txt
168+
if-no-files-found: ignore

cpp/cppcheck-baseline.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# Existing diagnostics remain visible in CI but do not fail the job. Keep each
19+
# entry scoped to an exact file and line so newly introduced diagnostics fail.
20+
ignoredReturnValue:cpp/src/parser/path_visitor.cpp:106
21+
returnByReference:cpp/src/common/tsblock/tuple_desc.h:100
22+
passedByValue:cpp/src/common/tsblock/tuple_desc.h:65
23+
invalidPointerCast:cpp/src/common/tsblock/tsblock.h:165
24+
invalidPointerCast:cpp/src/common/tsblock/tsblock.cc:86
25+
invalidPointerCast:cpp/src/common/tsblock/tsblock.cc:92
26+
uninitMemberVar:cpp/src/compress/gzip_compressor.cc:26
27+
uninitMemberVar:cpp/src/compress/gzip_compressor.cc:143
28+
returnByReference:cpp/src/file/write_file.h:49
29+
uninitMemberVar:cpp/src/reader/filter/binary_filter.h:28
30+
useInitializationList:cpp/src/common/path.h:44
31+
containerOutOfBounds:cpp/src/reader/expression.cc:115
32+
uninitMemberVar:cpp/src/common/row_record.h:191
33+
noCopyConstructor:cpp/src/common/row_record.h:201
34+
noOperatorEq:cpp/src/common/row_record.h:201
35+
invalidPointerCast:cpp/src/reader/table_result_set.cc:152
36+
invalidPointerCast:cpp/src/reader/table_result_set.cc:156
37+
memleak:cpp/examples/c_examples/demo_write.c:71

cpp/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,32 @@
292292
</plugins>
293293
</build>
294294
</profile>
295+
<!--
296+
Generate compile_commands.json for the standalone Cppcheck CI job.
297+
This profile only changes the CMake configure step; it does not run
298+
Cppcheck or add static analysis to normal C++ builds.
299+
-->
300+
<profile>
301+
<id>with-cppcheck</id>
302+
<build>
303+
<plugins>
304+
<plugin>
305+
<groupId>com.googlecode.cmake-maven-project</groupId>
306+
<artifactId>cmake-maven-plugin</artifactId>
307+
<executions>
308+
<execution>
309+
<id>cmake-generate-test-compile</id>
310+
<configuration>
311+
<options combine.children="append">
312+
<option>-DCMAKE_EXPORT_COMPILE_COMMANDS=ON</option>
313+
</options>
314+
</configuration>
315+
</execution>
316+
</executions>
317+
</plugin>
318+
</plugins>
319+
</build>
320+
</profile>
295321
<profile>
296322
<id>.java-9-and-above</id>
297323
<activation>

0 commit comments

Comments
 (0)