Skip to content

Commit

Permalink
[ci] Enable cppcheck code quality report.
Browse files Browse the repository at this point in the history
  • Loading branch information
bilke committed Jul 16, 2020
1 parent e2ef867 commit 7055e06
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "2"
exclude_patterns:
- "ThirdParty/"
- "Tests/Data/"
- "Tests/"
plugins:
markdownlint:
enabled: true
duplication:
enabled: false
16 changes: 16 additions & 0 deletions scripts/ci/jobs/code-quality.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
cppcheck:
stage: check
image: $CONTAINER_GCC_IMAGE
needs: []
before_script:
- mkdir -p build
- cd build
script: >-
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DOGS_USE_CONAN=OFF \
-DOGS_USE_UNITY_BUILDS=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
bash cppcheck.sh
artifacts:
reports:
codequality: build/cppcheck.json
expire_in: 1 week

code_quality:
stage: check
tags: [docker, envinf1]
Expand Down
8 changes: 6 additions & 2 deletions scripts/cmake/CppCheck.cmake
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
if(NOT CPPCHECK_TOOL_PATH)
return()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
configure_file(${PROJECT_SOURCE_DIR}/scripts/test/cppcheck.in.sh ${PROJECT_BINARY_DIR}/cppcheck.sh)

if(DEFINED ENV{NUM_THREADS})
set(CPPCHECK_THREADS -j $ENV{NUM_THREADS})
endif()

add_custom_target(cppcheck
COMMAND ${CPPCHECK_TOOL_PATH}
--force
--project=${PROJECT_BINARY_DIR}/compile_commands.json
--language=c++
--std=c++17
--enable=all
# --inconclusive
--inconclusive
${CPPCHECK_THREADS}
-i ${PROJECT_BINARY_DIR}/CMakeFiles
-i ${PROJECT_SOURCE_DIR}/ThirdParty
Expand Down
28 changes: 28 additions & 0 deletions scripts/test/cppcheck.in.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Runs cppcheck with GitLab CI (CodeClimate) output
OUTPUT_FILE=${PROJECT_BINARY_DIR}/cppcheck.json
${CPPCHECK_TOOL_PATH} \
--project=${PROJECT_BINARY_DIR}/compile_commands.json \
--language=c++ \
--std=c++17 \
--enable=all \
--inconclusive \
-j 4 \
-i ${PROJECT_BINARY_DIR}/CMakeFiles \
-i ${PROJECT_SOURCE_DIR}/ThirdParty \
-i ${PROJECT_SOURCE_DIR}/Applications/DataExplorer \
-i ${PROJECT_SOURCE_DIR}/Tests \
--template='{\n "description": "{message}",\n "location": {\n "path": "{file}",\n "lines": {\n "begin": {line}\n }\n }\n},' \
--output-file=$OUTPUT_FILE \

echo "$( \
# add brackets
printf '[\n'; \
cat $OUTPUT_FILE | \
# strip source code absolute path
sed 's|${PROJECT_SOURCE_DIR}/||' | \
# escape strings
sed 's/string literal "\(.*\)" to/string literal \\"\1\\" to/g' | \
# remove last comma
sed '$s/,$//'; \
printf ']\n')" \
> $OUTPUT_FILE

0 comments on commit 7055e06

Please sign in to comment.