Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@

# meta-codechecker

A Layer to support CodeChecker as a frontent to clang static analysis

A Layer to support CodeChecker as a frontend to clang static analysis

## usage

This layer exposes a bbclass and the recipes needed to support inclusion of the tooling.
Note that meta-clang is a requirement.

### In a recipe enable:
### enable codechecker feature:

In e.g. conf/local.conf
DISTRO_FEATURES_append += " codechecker"

To enable the layer within a single recipe, do add
To enable the layer within a single recipe, add to the bitbake recipe

inherit codechecker
CODECHECKER_ENABLED = "1"

### In conf/local.conf

### globally enable codechecker for all packages

In e.g. conf/local.conf
INHERIT += "codechecker"
CODECHECKER_ENABLED = "1"

### options:
### options

To generate a static HTML site as report do add:

In e.g. conf/local.conf
CODECHECKER_REPORT_HTML = "1"

To upload the results to the CodeScanner webserver (e.g. docker container) add:
Expand All @@ -34,8 +37,9 @@ To upload the results to the CodeScanner webserver (e.g. docker container) add:
Note: The URL of the product to store the results for, in the format of
'http[s]://]host:port/Endpoint'. (default: localhost:8001/Default)

Note: this was tested against the docker container
docker pull codechecker/codechecker-web:6.13.0
To add arguments to the CodeChecker analyze command (see CodeChecker man), e.g.:

CODECHECKER_ANALYZE_ARGS = "-e sensitive"

### output location

Expand Down
166 changes: 81 additions & 85 deletions classes/codechecker.bbclass
Original file line number Diff line number Diff line change
@@ -1,109 +1,105 @@
inherit python3-dir

python () {
if d.getVar("CODECHECKER_ENABLED") == "1":
if not bb.data.inherits_class('nativesdk', d) \
and not bb.data.inherits_class('native', d) \
and not bb.data.inherits_class('cross', d) \
and not bb.data.inherits_class('crosssdk', d) \
and not bb.data.inherits_class('allarch', d):
d.prependVarFlag("do_compile", 'prefuncs', "do_csprecompile ")
d.appendVarFlag("do_compile", 'postfuncs', " do_cspostcompile")
d.appendVarFlag("do_compile", "postfuncs", " do_codecheckeranalyse")
d.appendVarFlag("do_compile", "postfuncs", " do_codecheckerreport")
d.appendVarFlag("do_compile", 'depends', ' codechecker-native:do_populate_sysroot python3-six-native:do_populate_sysroot python3-thrift-native:do_populate_sysroot python3-codechecker-api-native:do_populate_sysroot python3-codechecker-api-shared-native:do_populate_sysroot clang-native:do_populate_sysroot python3-native:do_populate_sysroot python3-psutil-native:do_populate_sysroot python3-portalocker-native:do_populate_sysroot python3-pyyaml-native:do_populate_sysroot')
}
CODECHECKER_ENABLED ?= "${@bb.utils.contains('DISTRO_FEATURES', 'codechecker', '1', '0', d)}"
CODECHECKER_ENABLED_class-native = ""
CODECHECKER_ENABLED_class-nativesdk = ""
CODECHECKER_ENABLED_class-cross-canadian = ""

SAVEDENV = ""
#_environ = dict(os.environ) # or os.environ.copy()
# os.environ.update(_environ)
CODECHECKER_REPORT_HTML ?= "1"

python do_csprecompile () {
SAVEDENV = os.environ.copy()
os.environ["LD_PRELOAD"] = "" + d.getVar('RECIPE_SYSROOT_NATIVE') + "/usr/local/CodeChecker/ld_logger/lib/x86_64/ldlogger.so"
os.environ["CC_LOGGER_GCC_LIKE"] = "gcc:g++:clang:clang++:cc:c++:ccache"
os.environ["CC_LOGGER_FILE"] = "" + d.getVar("DEPLOY_DIR") + "/CodeChecker/" + d.getVar("PN") + "/codechecker-log.json"
#os.environ["PARALLEL_MAKE"] = "" + d.getVar("PARALLEL_MAKE")
os.makedirs("" + d.getVar("DEPLOY_DIR") + "/CodeChecker/" + d.getVar("PN") , exist_ok=True)
#bb.warn(str(os.environ["LD_PRELOAD"]))
os.environ["CC_LOGGER_FILE"] = "" + d.getVar("B") + "/codechecker-log.json"
os.makedirs("" + d.getVar("DEPLOY_DIR") + "/codechecker/" + d.getVar("PN") , exist_ok=True)
}

python do_cspostcompile () {
if d.getVar("CODECHECKER_ENABLED") == "1":
os.environ["LD_PRELOAD"] = ""
# or restore saved env
# optimization: remove empty files
os.environ["LD_PRELOAD"] = ""
}


###############################################

do_codecheckeranalyse() {

if test x"${CODECHECKER_ENABLED}" = x"1"; then
# optimization - skip empty
#
# need to teach proper PATHs for this run
export PYTHON="${STAGING_BINDIR_NATIVE}/python3-native/python3"
export PYTHONNOUSERSITE="1"
export PYTHONPATH="${RECIPE_SYSROOT_NATIVE}/usr/lib/python${PYTHON_BASEVERSION}/site-packages/"
export PATH="${RECIPE_SYSROOT_NATIVE}/usr/bin:${RECIPE_SYSROOT_NATIVE}/usr/bin/python3-native/:${RECIPE_SYSROOT_NATIVE}/usr/local/CodeChecker/bin:$PATH"

# expose Variable for CodeChecker
export CC_LOGGER_FILE="${DEPLOY_DIR}/CodeChecker/${PN}/codechecker-log.json"
export CC_ANALYSE_OUT="${DEPLOY_DIR}/CodeChecker/${PN}/results/"
do_codechecker_analyze() {
bbnote "codechecker_analyze"
if test -f ${CC_LOGGER_FILE} ; then
CodeChecker analyze ${PARALLEL_MAKE} -o ${CC_ANALYSE_OUT} --report-hash context-free-v2 ${CC_LOGGER_FILE}
CodeChecker analyze ${PARALLEL_MAKE} ${CODECHECKER_ANALYZE_ARGS} -o ${CC_ANALYZE_OUT} --report-hash context-free-v2 ${CC_LOGGER_FILE} || status=$?
if [ ${status} -eq 0 ]; then
bbnote "codechecker analyze ok"
else
bbwarn "codechecker analyze issues found, status=${status}"
status=0
fi
mkdir -p ${CC_DIR}
ln -sfn ${CC_DIR}/${TS} ${CC_DIR}/latest
cp ${CC_LOGGER_FILE} ${CC_DIR}/${TS}/
fi
fi
}

addtask codecheckeranalyse

do_codecheckerreport() {

if test x"${CODECHECKER_ENABLED}" = x"1"; then

# optimization - skip empty

# need to teach proper PATHs for this run
export PYTHON="${STAGING_BINDIR_NATIVE}/python3-native/python3"
export PYTHONNOUSERSITE="1"
export PYTHONPATH="${RECIPE_SYSROOT_NATIVE}/usr/lib/python${PYTHON_BASEVERSION}/site-packages/"
export PATH="${RECIPE_SYSROOT_NATIVE}/usr/bin:${RECIPE_SYSROOT_NATIVE}/usr/bin/python3-native/:${RECIPE_SYSROOT_NATIVE}/usr/local/CodeChecker/bin:$PATH"

# expose variables for CodeChecker
export CC_LOGGER_FILE="${DEPLOY_DIR}/CodeChecker/${PN}/codechecker-log.json"
export CC_ANALYSE_OUT="${DEPLOY_DIR}/CodeChecker/${PN}/results/"
export CC_REPORT_OUT="${DEPLOY_DIR}/CodeChecker/${PN}/report-html/"

if test -d ${CC_ANALYSE_OUT} ; then
if test x"${CODECHECKER_REPORT_HTML}" = x"1"; then
mkdir -p ${CC_REPORT_OUT}
#usage: CodeChecker parse [-h] [-t {plist}] [-e {html,json,codeclimate}]
# [-o OUTPUT_PATH] [--suppress SUPPRESS]
# [--export-source-suppress] [--print-steps]
# [-i SKIPFILE]
# [--trim-path-prefix [TRIM_PATH_PREFIX [TRIM_PATH_PREFIX ...]]]
# [--review-status [REVIEW_STATUS [REVIEW_STATUS ...]]]
# [--verbose {info,debug,debug_analyzer}]
# file/folder [file/folder ...]
CodeChecker parse -e html --trim-path-prefix=${S} ${CC_ANALYSE_OUT} -o ${CC_REPORT_OUT}
do_codechecker_parse() {
bbnote "codechecker_parse"
if test x"${CODECHECKER_REPORT_HTML}" = x"1"; then
mkdir -p ${CC_REPORT_OUT}
CodeChecker parse ${CODECHECKER_PARSE_ARGS} -e html --trim-path-prefix=${S} ${CC_ANALYZE_OUT} -o ${CC_REPORT_OUT} || status=$?
if [ ${status} -eq 0 ]; then
bbdebug 1 "codechecker parse ok"
else
bbwarn "codechecker parse failed, status=${status}"
status=0
fi
if test x"${CODECHECKER_REPORT_STORE}" = x"1"; then
if test ! x"${CODECHECKER_REPORT_HOST}" = x""; then
#usage: CodeChecker store [-h] [-t {plist}] [-n NAME] [--tag TAG]
# [--description DESCRIPTION]
# [--trim-path-prefix [TRIM_PATH_PREFIX [TRIM_PATH_PREFIX ...]]]
# [--config CONFIG_FILE] [-f] [--url PRODUCT_URL]
# [--verbose {info,debug,debug_analyzer}]
# [file/folder [file/folder ...]]
# Todo: credentials
CodeChecker store -n ${PF} --trim-path-prefix=${S} --url ${CODECHECKER_REPORT_HOST} ${CC_ANALYSE_OUT}
fi
}

do_codechecker_store() {
bbnote "codechecker_store"
if test x"${CODECHECKER_REPORT_STORE}" = x"1"; then
if test ! x"${CODECHECKER_REPORT_HOST}" = x""; then
CodeChecker store ${CODECHECKER_STORE_ARGS} -n ${PF} --trim-path-prefix=${S} --url ${CODECHECKER_REPORT_HOST} ${CC_ANALYZE_OUT} || status=$?
if [ ${status} -eq 0 ]; then
bbdebug 1 "codechecker store ok"
else
bbwarn "codechecker store failed, status=${status}"
status=0
fi
fi
fi
fi
}

addtask codecheckerreport
do_codechecker() {
if test x"${CODECHECKER_ENABLED}" = x"1"; then
bbnote "codechecker enabled"

# need to teach proper PATHs for this run
export PYTHON="${STAGING_BINDIR_NATIVE}/python3-native/python3"
export PYTHONNOUSERSITE="1"
export PYTHONPATH="${RECIPE_SYSROOT_NATIVE}/usr/lib/python${PYTHON_BASEVERSION}/site-packages/"
export PATH="${RECIPE_SYSROOT_NATIVE}/usr/bin:${RECIPE_SYSROOT_NATIVE}/usr/bin/python3-native/:${RECIPE_SYSROOT_NATIVE}/usr/local/CodeChecker/bin:$PATH"

# expose variable for codechecker
export TS=$(date +%4Y%2m%2d%2H%2M%2S)
export CC_DIR="${DEPLOY_DIR}/codechecker/${PN}"
export CC_ANALYZE_OUT="${CC_DIR}/${TS}/results/"
export CC_REPORT_OUT="${CC_DIR}/${TS}/report-html/"
export CC_LOGGER_FILE="${B}/codechecker-log.json"
export status=0

do_codechecker_analyze
if test -d ${CC_ANALYZE_OUT} ; then
do_codechecker_parse
do_codechecker_store
fi
fi
}
addtask codechecker after do_compile before do_install

python () {
if d.getVar("CODECHECKER_ENABLED") == "1":
if not bb.data.inherits_class('nativesdk', d) \
and not bb.data.inherits_class('native', d) \
and not bb.data.inherits_class('cross', d) \
and not bb.data.inherits_class('crosssdk', d) \
and not bb.data.inherits_class('allarch', d):
d.prependVarFlag("do_compile", "prefuncs", "do_csprecompile ")
d.appendVarFlag("do_compile", "postfuncs", " do_cspostcompile")
d.appendVarFlag("do_compile", "depends", " codechecker-native:do_populate_sysroot python3-six-native:do_populate_sysroot python3-thrift-native:do_populate_sysroot python3-codechecker-api-native:do_populate_sysroot python3-codechecker-api-shared-native:do_populate_sysroot clang-native:do_populate_sysroot python3-native:do_populate_sysroot python3-psutil-native:do_populate_sysroot python3-portalocker-native:do_populate_sysroot python3-pyyaml-native:do_populate_sysroot")
}
10 changes: 10 additions & 0 deletions conf/documentation.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# DESCRIPTIONS FOR TASKS #
do_codechecker[doc] = "Run codechecker analyse, parse and store."

# DESCRIPTIONS FOR VARIABLES #
CODECHECKER_ANALYZE_ARGS[doc] = "codechecker analyze arguments."
CODECHECKER_PARSE_ARGS[doc] = "codechecker parse arguments."
CODECHECKER_STORE_ARGS[doc] = "codechecker store arguments."
CODECHECKER_REPORT_HTML[doc] = "Print analysis summary and results in a human-readable format."
CODECHECKER_REPORT_STORE[doc] = "Save analysis results to a database."
CODECHECKER_REPORT_HOST[doc] = "URL to codechecker server."
4 changes: 3 additions & 1 deletion conf/layer.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ BBFILE_COLLECTIONS += "codechecker"
BBFILE_PATTERN_codechecker = "^${LAYERDIR}/"
BBFILE_PRIORITY_codechecker = "70"

LAYERSERIES_COMPAT_codechecker = "dunfell"
LAYERSERIES_COMPAT_codechecker = "dunfell gatesgarth hardknott"
LAYERDEPENDS_codechecker = "core clang-layer meta-python"

include documentation.conf
10 changes: 4 additions & 6 deletions recipes-devtools/codechecker/codechecker_git.bb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ LIC_FILES_CHKSUM = "file://LICENSE.TXT;md5=2e982d844baa4df1c80de75470e0c5cb"

DEPENDS = "doxygen-native curl-native git-native nodejs-native python3-native"

SRC_URI = " git://github.com/Ericsson/codechecker.git;protocol=https \
file://0001-Use-python3-for-setuptool-calls.patch "
SRC_URI = "git://github.com/Ericsson/CodeChecker.git;branch=release-v6.15.1"

#SRCREV = "${AUTOREV}"
# last 6.32 api
SRCREV = "f5defa9cb06c8ffdd68160bafa0d130c4b0f3951"
#6.15.1
SRCREV = "692e51ba4be08e97c4b07cc344edca082dc50f63"

S = "${WORKDIR}/git"

Expand All @@ -37,6 +36,5 @@ SYSROOT_DIRS += " ${exec_prefix}/local"
SYSROOT_DIRS_NATIVE += " ${exec_prefix}/local"

RDEPENDS_${PN}_class-native += "clang-native python3-native"
RDEPENDS_${PN}_class-nativesdk += "nativesdk-clang nativesdk-python3"

BBCLASSEXTEND += "native nativesdk"
BBCLASSEXTEND += "native"

This file was deleted.

Loading