mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-26 10:48:38 -06:00
ExternalProject: add LOG_OUTPUT_ON_FAILURE option
This option only has an effect if at least one of the other LOG_<step> options is enabled. If an error occurs for a step which has logging to file enabled, that step's output will be printed to the console. For cases where a large amount of output is recorded, just the end of that output may be printed to the console.
This commit is contained in:
committed by
Craig Scott
parent
772edffbf0
commit
19d86e26e3
@@ -877,6 +877,7 @@ syn keyword cmakeKWExternalProject contained
|
|||||||
\ LOG_DOWNLOAD
|
\ LOG_DOWNLOAD
|
||||||
\ LOG_INSTALL
|
\ LOG_INSTALL
|
||||||
\ LOG_MERGED_STDOUTERR
|
\ LOG_MERGED_STDOUTERR
|
||||||
|
\ LOG_OUTPUT_ON_FAILURE
|
||||||
\ LOG_PATCH
|
\ LOG_PATCH
|
||||||
\ LOG_TEST
|
\ LOG_TEST
|
||||||
\ LOG_UPDATE
|
\ LOG_UPDATE
|
||||||
|
|||||||
@@ -550,6 +550,14 @@ External Project Definition
|
|||||||
``LOG_MERGED_STDOUTERR <bool>``
|
``LOG_MERGED_STDOUTERR <bool>``
|
||||||
When enabled, the output the step is not split by stdout and stderr.
|
When enabled, the output the step is not split by stdout and stderr.
|
||||||
|
|
||||||
|
``LOG_OUTPUT_ON_FAILURE <bool>``
|
||||||
|
This option only has an effect if at least one of the other ``LOG_<step>``
|
||||||
|
options is enabled. If an error occurs for a step which has logging to
|
||||||
|
file enabled, that step's output will be printed to the console if
|
||||||
|
``LOG_OUTPUT_ON_FAILURE`` is set to true. For cases where a large amount
|
||||||
|
of output is recorded, just the end of that output may be printed to the
|
||||||
|
console.
|
||||||
|
|
||||||
**Terminal Access Options:**
|
**Terminal Access Options:**
|
||||||
Steps can be given direct access to the terminal in some cases. Giving a
|
Steps can be given direct access to the terminal in some cases. Giving a
|
||||||
step access to the terminal may allow it to receive terminal input if
|
step access to the terminal may allow it to receive terminal input if
|
||||||
@@ -1953,6 +1961,7 @@ endif()
|
|||||||
set(script ${stamp_dir}/${name}-${step}-$<CONFIG>.cmake)
|
set(script ${stamp_dir}/${name}-${step}-$<CONFIG>.cmake)
|
||||||
set(logbase ${log_dir}/${name}-${step})
|
set(logbase ${log_dir}/${name}-${step})
|
||||||
get_property(log_merged TARGET ${name} PROPERTY _EP_LOG_MERGED_STDOUTERR)
|
get_property(log_merged TARGET ${name} PROPERTY _EP_LOG_MERGED_STDOUTERR)
|
||||||
|
get_property(log_output_on_failure TARGET ${name} PROPERTY _EP_LOG_OUTPUT_ON_FAILURE)
|
||||||
if (log_merged)
|
if (log_merged)
|
||||||
set(stdout_log "${logbase}.log")
|
set(stdout_log "${logbase}.log")
|
||||||
set(stderr_log "${logbase}.log")
|
set(stderr_log "${logbase}.log")
|
||||||
@@ -1961,21 +1970,55 @@ endif()
|
|||||||
set(stderr_log "${logbase}-err.log")
|
set(stderr_log "${logbase}-err.log")
|
||||||
endif()
|
endif()
|
||||||
set(code "
|
set(code "
|
||||||
|
cmake_minimum_required(VERSION 3.13)
|
||||||
${code_cygpath_make}
|
${code_cygpath_make}
|
||||||
set(command \"${command}\")
|
set(command \"${command}\")
|
||||||
|
set(log_merged \"${log_merged}\")
|
||||||
|
set(log_output_on_failure \"${log_output_on_failure}\")
|
||||||
|
set(stdout_log \"${stdout_log}\")
|
||||||
|
set(stderr_log \"${stderr_log}\")
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND \${command}
|
COMMAND \${command}
|
||||||
RESULT_VARIABLE result
|
RESULT_VARIABLE result
|
||||||
OUTPUT_FILE \"${stdout_log}\"
|
OUTPUT_FILE \"\${stdout_log}\"
|
||||||
ERROR_FILE \"${stderr_log}\"
|
ERROR_FILE \"\${stderr_log}\"
|
||||||
)
|
)
|
||||||
|
macro(read_up_to_max_size log_file output_var)
|
||||||
|
file(SIZE \${log_file} determined_size)
|
||||||
|
set(max_size 10240)
|
||||||
|
if (determined_size GREATER max_size)
|
||||||
|
math(EXPR seek_position \"\${determined_size} - \${max_size}\")
|
||||||
|
file(READ \${log_file} \${output_var} OFFSET \${seek_position})
|
||||||
|
set(\${output_var} \"...skipping to end...\\n\${\${output_var}}\")
|
||||||
|
else()
|
||||||
|
file(READ \${log_file} \${output_var})
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
if(result)
|
if(result)
|
||||||
set(msg \"Command failed: \${result}\\n\")
|
set(msg \"Command failed: \${result}\\n\")
|
||||||
foreach(arg IN LISTS command)
|
foreach(arg IN LISTS command)
|
||||||
set(msg \"\${msg} '\${arg}'\")
|
set(msg \"\${msg} '\${arg}'\")
|
||||||
endforeach()
|
endforeach()
|
||||||
set(msg \"\${msg}\\nSee also\\n ${stderr_log}\")
|
if (\${log_merged})
|
||||||
message(FATAL_ERROR \"\${msg}\")
|
set(msg \"\${msg}\\nSee also\\n \${stderr_log}\")
|
||||||
|
else()
|
||||||
|
set(msg \"\${msg}\\nSee also\\n ${logbase}-*.log\")
|
||||||
|
endif()
|
||||||
|
if (\${log_output_on_failure})
|
||||||
|
message(SEND_ERROR \"\${msg}\")
|
||||||
|
if (\${log_merged})
|
||||||
|
read_up_to_max_size(\"\${stderr_log}\" error_log_contents)
|
||||||
|
message(STATUS \"Log output is:\\n\${error_log_contents}\")
|
||||||
|
else()
|
||||||
|
read_up_to_max_size(\"\${stdout_log}\" out_log_contents)
|
||||||
|
read_up_to_max_size(\"\${stderr_log}\" err_log_contents)
|
||||||
|
message(STATUS \"stdout output is:\\n\${out_log_contents}\")
|
||||||
|
message(STATUS \"stderr output is:\\n\${err_log_contents}\")
|
||||||
|
endif()
|
||||||
|
message(FATAL_ERROR \"Stopping after outputting logs.\")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR \"\${msg}\")
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
set(msg \"${name} ${step} command succeeded. See also ${logbase}-*.log\")
|
set(msg \"${name} ${step} command succeeded. See also ${logbase}-*.log\")
|
||||||
message(STATUS \"\${msg}\")
|
message(STATUS \"\${msg}\")
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
^[^0]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
.*
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
( )?-- stdout output is:
|
||||||
|
( )?This is some dummy output with some long lines to ensure formatting is preserved
|
||||||
|
( )? Including lines with leading spaces
|
||||||
|
( )?
|
||||||
|
( )?And also blank lines[
|
||||||
|
]+
|
||||||
|
( )?-- stderr output is:
|
||||||
|
( )?cmake -E env: no command given
|
||||||
20
Tests/RunCMake/ExternalProject/LogOutputOnFailure.cmake
Normal file
20
Tests/RunCMake/ExternalProject/LogOutputOnFailure.cmake
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
include(ExternalProject)
|
||||||
|
|
||||||
|
set(dummyOutput [[
|
||||||
|
This is some dummy output with some long lines to ensure formatting is preserved
|
||||||
|
Including lines with leading spaces
|
||||||
|
|
||||||
|
And also blank lines
|
||||||
|
]])
|
||||||
|
|
||||||
|
ExternalProject_Add(FailsWithOutput
|
||||||
|
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
CONFIGURE_COMMAND ""
|
||||||
|
BUILD_COMMAND ${CMAKE_COMMAND} -E echo ${dummyOutput}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E env # missing command, forces fail
|
||||||
|
TEST_COMMAND ""
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
LOG_BUILD YES
|
||||||
|
LOG_OUTPUT_ON_FAILURE YES
|
||||||
|
USES_TERMINAL_BUILD YES
|
||||||
|
)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
^[^0]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
.*
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
( )?-- Log output is:
|
||||||
|
( )?This is some dummy output with some long lines to ensure formatting is preserved
|
||||||
|
( )? Including lines with leading spaces
|
||||||
|
( )?
|
||||||
|
( )?And also blank lines[
|
||||||
|
]+
|
||||||
|
( )?cmake -E env: no command given
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
include(ExternalProject)
|
||||||
|
|
||||||
|
set(dummyOutput [[
|
||||||
|
This is some dummy output with some long lines to ensure formatting is preserved
|
||||||
|
Including lines with leading spaces
|
||||||
|
|
||||||
|
And also blank lines
|
||||||
|
]])
|
||||||
|
|
||||||
|
ExternalProject_Add(FailsWithOutput
|
||||||
|
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
CONFIGURE_COMMAND ""
|
||||||
|
BUILD_COMMAND ${CMAKE_COMMAND} -E echo ${dummyOutput}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E env # missing command, forces fail
|
||||||
|
TEST_COMMAND ""
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
LOG_BUILD YES
|
||||||
|
LOG_OUTPUT_ON_FAILURE YES
|
||||||
|
LOG_MERGED_STDOUTERR YES
|
||||||
|
USES_TERMINAL_BUILD YES
|
||||||
|
)
|
||||||
@@ -29,6 +29,13 @@ endfunction()
|
|||||||
|
|
||||||
__ep_test_with_build(MultiCommand)
|
__ep_test_with_build(MultiCommand)
|
||||||
|
|
||||||
|
# Output is not predictable enough to be able to verify it reliably
|
||||||
|
# when using the various different Visual Studio generators
|
||||||
|
if(NOT RunCMake_GENERATOR MATCHES "Visual Studio")
|
||||||
|
__ep_test_with_build(LogOutputOnFailure)
|
||||||
|
__ep_test_with_build(LogOutputOnFailureMerged)
|
||||||
|
endif()
|
||||||
|
|
||||||
# We can't test the substitution when using the old MSYS due to
|
# We can't test the substitution when using the old MSYS due to
|
||||||
# make/sh mangling the paths (substitution is performed correctly,
|
# make/sh mangling the paths (substitution is performed correctly,
|
||||||
# but the mangling means we can't reliably test the output).
|
# but the mangling means we can't reliably test the output).
|
||||||
|
|||||||
Reference in New Issue
Block a user