Files
nextepc-oss/misc/static_code_analyze.sh
Bostjan Meglic 114f783d06 [MISC] Add support for static code analysis
Static code analysis can be executed with following commands:
  meson build
  ninja -C build analyze-cppcheck
  ninja -C build analyze-clang-tidy

These commands are available only if additional tools are installed:
  - cppcheck
  - clang-tidy
  - clang-tools is optional if you want to paralelize the clang-tidy

In case of cppcheck analysis, a file called build/cppchecklog.log is
created with the analysis results.

In case of clang-tidy analysis, some checks are disabled. See file
.clang-tidy, and reenable them if you see fit.
Also it does not scan all the files in the project, since some of them
are imported from other sources. It does not scan any sources under:
  - subprojects/
  - lib/asn1c/
  - lib/ipfw/
2022-07-01 21:38:47 +09:00

41 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
ANALYZE_TOOL="${1}" && shift
BUILD_DIR="${1}" && shift
SOURCES_DIR="${1}" && shift
SOURCES=$(find ${SOURCES_DIR}/src ${SOURCES_DIR}/lib -not -path *asn1c* -not -path *ipfw* -name *.c)
#SOURCES=$(find ${SOURCES_DIR}/src ${SOURCES_DIR}/lib ${SOURCES_DIR}/subprojects -name *.c)
if [[ ${ANALYZE_TOOL} == *"clang-tidy"* ]];
then
if [[ ${ANALYZE_TOOL} == *"run-clang-tidy"* ]]; then
OPTS="${OPTS} -j $(nproc)"
fi
OPTS="${OPTS} -quiet"
OPTS="${OPTS} -p=${BUILD_DIR}"
${ANALYZE_TOOL} ${OPTS} ${SOURCES} 2>/dev/null
elif [[ ${ANALYZE_TOOL} == *"cppcheck"* ]];
then
OPTS="${OPTS} -j $(nproc)"
# OPTS="${OPTS} --quiet"
OPTS="${OPTS} --verbose"
OPTS="${OPTS} --enable=all"
OPTS="${OPTS} --verbose"
OPTS="${OPTS} --suppress=variableScope"
OPTS="${OPTS} --suppress=preprocessorErrorDirective"
OPTS="${OPTS} --suppress=unusedVariable"
OPTS="${OPTS} --output-file=cppchecklog.log"
OPTS="${OPTS} --cppcheck-build-dir=${BUILD_DIR}/cppcheck"
OPTS="${OPTS} --project=${BUILD_DIR}/compile_commands.json"
${ANALYZE_TOOL} ${OPTS} ${SOURCES}
else
echo "Unknown static code analysis tool: ${ANALYZE_TOOL}"
exit 1
fi