CodeChecker support

CodeChecker is a static analysis infrastructure. It executes analysis tools available on the build system, such as Clang-Tidy, Clang Static Analyzer and Cppcheck. Refer to the analyzer’s websites for installation instructions.

Installing CodeChecker

CodeChecker itself is a python package available on pypi.

pip install codechecker

Running with CodeChecker

To run CodeChecker, west build should be called with a -DZEPHYR_SCA_VARIANT=codechecker parameter, e.g.

west build -b mimxrt1064_evk samples/basic/blinky -- -DZEPHYR_SCA_VARIANT=codechecker

Configuring CodeChecker

To configure CodeChecker or analyzers used, arguments can be passed using the CODECHECKER_ANALYZE_OPTS parameter, e.g.

west build -b mimxrt1064_evk samples/basic/blinky -- -DZEPHYR_SCA_VARIANT=codechecker \
-DCODECHECKER_ANALYZE_OPTS="--config;$CODECHECKER_CONFIG_FILE;--timeout;60"

Storing CodeChecker results

If a CodeChecker server is active the results can be uploaded and stored for tracking purposes. Storing is done using the optional CODECHECKER_STORE=y or CODECHECKER_STORE_OPTS="arg;list" parameters, e.g.

west build -b mimxrt1064_evk samples/basic/blinky -- -DZEPHYR_SCA_VARIANT=codechecker \
-DCODECHECKER_STORE_OPTS="--name;build;--url;localhost:8001/Default"

Note

If --name isn’t passed to either CODECHECKER_ANALYZE_OPTS or CODECHECKER_STORE_OPTS, the default zephyr is used.

Exporting CodeChecker reports

Optional reports can be generated using the CodeChecker results, when passing a -DCODECHECKER_EXPORT=<type> parameter. Allowed types are: html,json,codeclimate,gerrit,baseline. Multiple types can be passed as comma-separated arguments.

Optional parser configuration arguments can be passed using the CODECHECKER_PARSE_OPTS parameter, e.g.

west build -b mimxrt1064_evk samples/basic/blinky -- -DZEPHYR_SCA_VARIANT=codechecker \
-DCODECHECKER_EXPORT=html,json -DCODECHECKER_PARSE_OPTS="--trim-path-prefix;$PWD"

Failing the build on CodeChecker issues

By default, CodeChecker identified issues will not fail the build, only generate a report. To fail the build if any issues are found (for example, for use in CI), pass the CODECHECKER_PARSE_EXIT_STATUS=y parameter, e.g.

west build -b mimxrt1064_evk samples/basic/blinky -- -DZEPHYR_SCA_VARIANT=codechecker \
-DCODECHECKER_PARSE_EXIT_STATUS=y