Skip to content

Commit f61950a

Browse files
noahpnashif
authored andcommitted
cmake: sca: Enable CodeChecker error exit status
Normally the return code of `CodeChecker analyze` and `CodeChecker parse` is suppressed, so all the enabled commands can execute instead of crashing the build. Add a new option, `CODECHECKER_PARSE_EXIT_STATUS`, to permit failing the build if `CodeChecker parse` returns non-zero. Signed-off-by: Noah Pendleton <[email protected]>
1 parent 555c07e commit f61950a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

cmake/sca/codechecker/sca.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ add_custom_command(
4040
COMMAND ${CMAKE_COMMAND} -E rm ${output_dir}/codechecker.ready
4141
)
4242

43+
# If 'codechecker parse' returns an exit status of '2', it means more than 0
44+
# issues were detected. Suppress the exit status by default, but permit opting
45+
# in to the failure.
46+
if(NOT CODECHECKER_PARSE_EXIT_STATUS)
47+
set(CODECHECKER_PARSE_OPTS ${CODECHECKER_PARSE_OPTS} || ${CMAKE_COMMAND} -E true)
48+
endif()
49+
50+
4351
if(CODECHECKER_EXPORT)
4452
string(REPLACE "," ";" export_list ${CODECHECKER_EXPORT})
4553

@@ -53,7 +61,6 @@ if(CODECHECKER_EXPORT)
5361
--export ${export_item}
5462
--output ${output_dir}/codechecker.${export_item}
5563
${CODECHECKER_PARSE_OPTS}
56-
|| ${CMAKE_COMMAND} -E true # parse has exit code 2 if a report is emitted by an analyzer
5764
BYPRODUCTS ${output_dir}/codechecker.${export_item}
5865
VERBATIM
5966
USES_TERMINAL
@@ -67,7 +74,6 @@ else()
6774
COMMAND ${CODECHECKER_EXE} parse
6875
${output_dir}/codechecker.plist
6976
${CODECHECKER_PARSE_OPTS}
70-
|| ${CMAKE_COMMAND} -E true # parse has exit code 2 if a report is emitted by an analyzer
7177
VERBATIM
7278
USES_TERMINAL
7379
COMMAND_EXPAND_LISTS

doc/develop/sca/codechecker.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,15 @@ Optional parser configuration arguments can be passed using the
7474
7575
west build -b mimxrt1064_evk samples/basic/blinky -- -DZEPHYR_SCA_VARIANT=codechecker \
7676
-DCODECHECKER_EXPORT=html,json -DCODECHECKER_PARSE_OPTS="--trim-path-prefix;$PWD"
77+
78+
Failing the build on CodeChecker issues
79+
***************************************
80+
81+
By default, CodeChecker identified issues will not fail the build, only generate
82+
a report. To fail the build if any issues are found (for example, for use in
83+
CI), pass the ``CODECHECKER_PARSE_EXIT_STATUS=y`` parameter, e.g.
84+
85+
.. code-block:: shell
86+
87+
west build -b mimxrt1064_evk samples/basic/blinky -- -DZEPHYR_SCA_VARIANT=codechecker \
88+
-DCODECHECKER_PARSE_EXIT_STATUS=y

0 commit comments

Comments
 (0)