Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error printing during Ninja sub-build #3006

Merged
merged 2 commits into from
Nov 5, 2024
Merged
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
17 changes: 13 additions & 4 deletions cmake/utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ endfunction(introspect)
# - **ERROR_MESSAGE**: message to output should an error occurs
####
function(execute_process_or_fail ERROR_MESSAGE)
# Quiet standard output unless we are doing verbose output generate
# Quiet standard output unless we are doing verbose output (handled below)
set(OUTPUT_ARGS OUTPUT_QUIET)
# Print the invocation if debug output is set
if (CMAKE_DEBUG_OUTPUT)
Expand All @@ -571,19 +571,28 @@ function(execute_process_or_fail ERROR_MESSAGE)
foreach(ARG IN LISTS ARGN)
set(COMMAND_AS_STRING "${COMMAND_AS_STRING}\"${ARG}\" ")
endforeach()

#string(REPLACE ";" "\" \"" COMMAND_AS_STRING "${ARGN}")
message(STATUS "[cli] ${COMMAND_AS_STRING}")
endif()
# Ninja pipes stderr to stdout so remove quiet output to see errors
if (CMAKE_GENERATOR MATCHES "Ninja")
set(OUTPUT_ARGS)
endif()
execute_process(
COMMAND ${ARGN}
RESULT_VARIABLE RETURN_CODE
OUTPUT_VARIABLE STANDARD_OUTPUT
ERROR_VARIABLE STANDARD_ERROR
ERROR_STRIP_TRAILING_WHITESPACE
OUTPUT_STRIP_TRAILING_WHITESPACE
${OUTPUT_ARGS}
)
if (NOT RETURN_CODE EQUAL 0)
message(FATAL_ERROR "${ERROR_MESSAGE}:\n${STANDARD_ERROR}")
set(FATAL_MESSAGE "${ERROR_MESSAGE}:\n${STANDARD_ERROR}")
# Ninja pipes stderr to stdout so we have to print stdout to see errors
if (CMAKE_GENERATOR MATCHES "Ninja")
string(APPEND FATAL_MESSAGE "\n${STANDARD_OUTPUT}")
endif()
message(FATAL_ERROR "${FATAL_MESSAGE}")
endif()
endfunction()

Expand Down
Loading