zephyr/cmake/sca/sparse/sparse.template
Marc Herbert d4b0273ab0 cmake: sparse.template: add COMMAND_ERROR_IS_FATAL
There are some situations like #67035 where sparse aborts and returns an
error code before the compiler has generated the .obj file; without any
clear indication that the .obj is missing (in normal situations sparse
prints warnings and _does_ creates the .obj file)

Also, builds are parallel by default and sparse runs tend to be massive
walls of text which all conspires to make it totally impossible to find
the relevant error message. Instead, we get an link-time error.

The only clear indication is the exit code. So catch it and abort the
build ASAP thanks to COMMAND_ERROR_IS_FATAL.

More generally speaking, the default behavior of execute_process() to
ignore errors is crazy. How frequently does a build system run commands
that do NOT matter?

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2024-01-15 11:32:44 +00:00

22 lines
774 B
Plaintext

# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) 2022, Nordic Semiconductor ASA
# Everything before `--` are arguments for cmake invocation, those must be ignored.
# First argument after `--` is the real compiler, but that is defined in REAL_CC
# as environment variable for cgcc, hence that must also be ignored, thus first
# argument to be passed to sparse is 2nd argument after `--`.
foreach(i RANGE ${CMAKE_ARGC})
if("${CMAKE_ARGV${i}}" STREQUAL "--")
math(EXPR end_of_options "${i} + 2")
break()
endif()
endforeach()
foreach(i RANGE ${end_of_options} ${CMAKE_ARGC})
list(APPEND ARGS ${CMAKE_ARGV${i}})
endforeach()
execute_process(COMMAND @CMAKE_COMMAND@ -E env REAL_CC=@CMAKE_C_COMPILER@ @SPARSE_COMPILER@ ${ARGS}
COMMAND_ERROR_IS_FATAL ANY
)