From f1b7f8c83fdb90a833a859feb60108cdba5f0006 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 27 Mar 2025 11:21:33 +0100 Subject: [PATCH] CMake: Add check.cmake to check for errors in commands RunCMake uses SEND_ERROR instead of FATAL_ERROR in run_cmake(), which means that the script will continue to run even if a command fails. This change adds a check.cmake file and modifies run_suite_command to ensure that we exit early if a command fails. Change-Id: I8175ddc91144e3d0dea131857138af7940626208 Reviewed-by: Alexey Edelev --- .../RunCMake/InitRepository/RunCMakeTest.cmake | 14 +++++++++++++- tests/manual/RunCMake/InitRepository/check.cmake | 9 +++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/manual/RunCMake/InitRepository/check.cmake diff --git a/tests/manual/RunCMake/InitRepository/RunCMakeTest.cmake b/tests/manual/RunCMake/InitRepository/RunCMakeTest.cmake index bb18bd1a..4e93dbd3 100644 --- a/tests/manual/RunCMake/InitRepository/RunCMakeTest.cmake +++ b/tests/manual/RunCMake/InitRepository/RunCMakeTest.cmake @@ -12,7 +12,19 @@ include(RunCMake) # Uses prefix set from outside scope. function(run_suite_command name) - run_cmake_command(${prefix}_${name} ${ARGN}) + set(RunCMake_TEST_COMMAND "${ARGN}") + set(RunCMake-check-file "check.cmake") + + set(args ${ARGN}) + list(JOIN args " " args_str) + set(working_dir "${RunCMake_TEST_COMMAND_WORKING_DIRECTORY}") + message(STATUS "Running command: '${args_str}' in dir: '${working_dir}'") + + run_cmake("${prefix}${name}") + # set by the check file above. + if(should_error_out) + message(FATAL_ERROR "Command ${prefix}${name} failed. Exiting early.") + endif() endfunction() macro(read_expected_output test file_name) diff --git a/tests/manual/RunCMake/InitRepository/check.cmake b/tests/manual/RunCMake/InitRepository/check.cmake new file mode 100644 index 00000000..56fbb060 --- /dev/null +++ b/tests/manual/RunCMake/InitRepository/check.cmake @@ -0,0 +1,9 @@ +# This file is include()d by run_cmake right after it calls execute_process. +# The msg var is set to a non-empty value when the was an error of +# some kind. Record failure with a separate variable in the parent scope, +# so we can FATAL_ERROR at the end. +if(NOT "${msg}" STREQUAL "") + set(should_error_out TRUE PARENT_SCOPE) +else() + set(should_error_out FALSE PARENT_SCOPE) +endif()