Commit 883ca947 authored by Lars Bilke's avatar Lars Bilke
Browse files

Merge branch 'fix-cppcheck' into 'master'

[ci] Fixed cppcheck exclusions

See merge request ogs/ogs!3288
parents 2c6c0aa8 50aa174b
cppcheck:
stage: check
image: $CONTAINER_GCC_IMAGE
needs: ["pre commit"]
needs: ["pre commit", meta]
before_script:
- mkdir -p build
- cd build
script: >-
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DOGS_USE_CONAN=OFF \
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
- bash cppcheck.sh
artifacts:
reports:
codequality: build/cppcheck.json
expire_in: 1 week
# Disabled, see !3053
.code_quality:
......
......@@ -2,6 +2,12 @@ if(NOT CPPCHECK_TOOL_PATH)
return()
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CPPCHECK_PARALLEL 4)
if(DEFINED ENV{CMAKE_BUILD_PARALLEL_LEVEL})
set(CPPCHECK_PARALLEL $ENV{CMAKE_BUILD_PARALLEL_LEVEL})
elseif(DEFINED CMAKE_BUILD_PARALLEL_LEVEL)
set(CPPCHECK_PARALLEL ${CMAKE_BUILD_PARALLEL_LEVEL})
endif()
configure_file(${PROJECT_SOURCE_DIR}/scripts/test/cppcheck.in.sh ${PROJECT_BINARY_DIR}/cppcheck.sh)
if(DEFINED ENV{NUM_THREADS})
......
......@@ -6,12 +6,11 @@ ${CPPCHECK_TOOL_PATH} \
--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},' \
-j ${CPPCHECK_PARALLEL} \
--suppress=*:*/usr/local\* \
--suppress=*:*ThirdParty\* \
--suppress=*:*Tests\* \
--template='{\n "description": "{message}",\n "severity": "info",\n "location": {\n "path": "{file}",\n "lines": {\n "begin": {line}\n }\n }\n},' \
--output-file=$OUTPUT_FILE \
echo "$( \
......@@ -26,3 +25,7 @@ echo "$( \
sed '$s/,$//'; \
printf ']\n')" \
> $OUTPUT_FILE
if [ -f ${Python3_EXECUTABLE} ]; then
${Python3_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/test/cppcheck_gen_hashes.py $OUTPUT_FILE
fi
# Inserts hashes of description + file path as GitLab code quality fingerprint
import hashlib
import json
import sys
data = None
with open(sys.argv[1]) as json_file:
data = json.load(json_file)
for entry in data:
desc = entry["description"]
path = entry["location"]["path"]
hash = hashlib.sha256((desc + path).encode("utf-8")).hexdigest()
entry["fingerprint"] = hash
with open(sys.argv[1], "w") as outfile:
json.dump(data, outfile)
print("Added cppcheck fingerprints to {}.".format(sys.argv[1]))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment