2016-09-18 20:50:08 -07:00
|
|
|
function(vcpkg_execute_required_process)
|
2021-07-14 14:45:18 -05:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 0 arg
|
|
|
|
"ALLOW_IN_DOWNLOAD_MODE"
|
|
|
|
"WORKING_DIRECTORY;LOGNAME;TIMEOUT;OUTPUT_VARIABLE;ERROR_VARIABLE"
|
2022-07-07 23:58:03 +02:00
|
|
|
"COMMAND;SAVE_LOG_FILES"
|
2021-07-14 14:45:18 -05:00
|
|
|
)
|
2019-08-28 13:49:29 -07:00
|
|
|
|
2021-07-14 14:45:18 -05:00
|
|
|
if(DEFINED arg_UNPARSED_ARGUMENTS)
|
|
|
|
message(WARNING "${CMAKE_CURRENT_FUNCTION} was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
|
2020-10-27 03:30:27 +01:00
|
|
|
endif()
|
2021-07-14 14:45:18 -05:00
|
|
|
foreach(required_arg IN ITEMS WORKING_DIRECTORY COMMAND)
|
|
|
|
if(NOT DEFINED arg_${required_arg})
|
|
|
|
message(FATAL_ERROR "${required_arg} must be specified.")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(NOT DEFINED arg_LOGNAME)
|
|
|
|
message(WARNING "LOGNAME should be specified.")
|
|
|
|
set(arg_LOGNAME "required")
|
2020-08-28 04:28:20 +02:00
|
|
|
endif()
|
|
|
|
|
2021-07-14 14:45:18 -05:00
|
|
|
if (VCPKG_DOWNLOAD_MODE AND NOT arg_ALLOW_IN_DOWNLOAD_MODE)
|
2021-02-09 15:53:36 -08:00
|
|
|
message(FATAL_ERROR
|
2019-08-28 13:49:29 -07:00
|
|
|
[[
|
|
|
|
This command cannot be executed in Download Mode.
|
|
|
|
Halting portfile execution.
|
|
|
|
]])
|
|
|
|
endif()
|
|
|
|
|
2021-07-14 14:45:18 -05:00
|
|
|
set(log_out "${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-out.log")
|
|
|
|
set(log_err "${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-err.log")
|
|
|
|
|
|
|
|
set(timeout_param "")
|
|
|
|
set(output_and_error_same OFF)
|
|
|
|
set(output_variable_param "")
|
|
|
|
set(error_variable_param "")
|
|
|
|
|
|
|
|
if(DEFINED arg_TIMEOUT)
|
|
|
|
set(timeout_param TIMEOUT "${arg_TIMEOUT}")
|
|
|
|
endif()
|
|
|
|
if(DEFINED arg_OUTPUT_VARIABLE AND DEFINED arg_ERROR_VARIABLE AND arg_OUTPUT_VARIABLE STREQUAL arg_ERROR_VARIABLE)
|
|
|
|
set(output_variable_param OUTPUT_VARIABLE out_err_var)
|
|
|
|
set(error_variable_param ERROR_VARIABLE out_err_var)
|
|
|
|
set(output_and_error_same ON)
|
|
|
|
else()
|
|
|
|
if(DEFINED arg_OUTPUT_VARIABLE)
|
|
|
|
set(output_variable_param OUTPUT_VARIABLE out_var)
|
2017-10-19 17:19:11 -07:00
|
|
|
endif()
|
2021-07-14 14:45:18 -05:00
|
|
|
if(DEFINED arg_ERROR_VARIABLE)
|
|
|
|
set(error_variable_param ERROR_VARIABLE err_var)
|
2017-10-19 17:19:11 -07:00
|
|
|
endif()
|
2021-07-14 14:45:18 -05:00
|
|
|
endif()
|
|
|
|
|
2022-06-10 20:56:44 +03:00
|
|
|
if(X_PORT_PROFILE AND NOT arg_ALLOW_IN_DOWNLOAD_MODE)
|
|
|
|
vcpkg_list(PREPEND arg_COMMAND "${CMAKE_COMMAND}" "-E" "time")
|
|
|
|
endif()
|
|
|
|
|
2021-07-14 14:45:18 -05:00
|
|
|
vcpkg_execute_in_download_mode(
|
|
|
|
COMMAND ${arg_COMMAND}
|
|
|
|
OUTPUT_FILE "${log_out}"
|
|
|
|
ERROR_FILE "${log_err}"
|
|
|
|
RESULT_VARIABLE error_code
|
|
|
|
WORKING_DIRECTORY "${arg_WORKING_DIRECTORY}"
|
|
|
|
${timeout_param}
|
|
|
|
${output_variable_param}
|
|
|
|
${error_variable_param}
|
|
|
|
)
|
2022-07-07 23:58:03 +02:00
|
|
|
vcpkg_list(SET saved_logs)
|
|
|
|
foreach(logfile IN LISTS arg_SAVE_LOG_FILES)
|
|
|
|
set(filepath "${arg_WORKING_DIRECTORY}/${logfile}")
|
|
|
|
if(NOT EXISTS "${filepath}")
|
|
|
|
continue()
|
|
|
|
endif()
|
|
|
|
cmake_path(GET filepath FILENAME filename)
|
|
|
|
if(NOT filename MATCHES "[.]log\$")
|
|
|
|
string(APPEND filename ".log")
|
|
|
|
endif()
|
|
|
|
configure_file("${filepath}" "${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-${filename}" COPYONLY)
|
|
|
|
vcpkg_list(APPEND saved_logs "${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-${filename}")
|
|
|
|
endforeach()
|
2021-07-14 14:45:18 -05:00
|
|
|
if(NOT error_code EQUAL 0)
|
|
|
|
set(stringified_logs "")
|
2022-07-07 23:58:03 +02:00
|
|
|
foreach(log IN LISTS saved_logs ITEMS "${log_out}" "${log_err}")
|
2021-07-14 14:45:18 -05:00
|
|
|
if(NOT EXISTS "${log}")
|
|
|
|
continue()
|
|
|
|
endif()
|
|
|
|
file(SIZE "${log}" log_size)
|
|
|
|
if(NOT log_size EQUAL "0")
|
|
|
|
file(TO_NATIVE_PATH "${log}" native_log)
|
|
|
|
string(APPEND stringified_logs " ${native_log}\n")
|
2022-01-28 20:30:49 +01:00
|
|
|
file(APPEND "${Z_VCPKG_ERROR_LOG_COLLECTION_FILE}" "${native_log}\n")
|
2021-07-14 14:45:18 -05:00
|
|
|
endif()
|
2017-10-19 17:19:11 -07:00
|
|
|
endforeach()
|
2021-07-14 14:45:18 -05:00
|
|
|
|
|
|
|
z_vcpkg_prettify_command_line(pretty_command ${arg_COMMAND})
|
2016-09-18 20:50:08 -07:00
|
|
|
message(FATAL_ERROR
|
2021-07-14 14:45:18 -05:00
|
|
|
" Command failed: ${pretty_command}\n"
|
|
|
|
" Working Directory: ${arg_WORKING_DIRECTORY}\n"
|
2019-03-07 09:37:24 +02:00
|
|
|
" Error code: ${error_code}\n"
|
2016-10-20 15:46:32 -07:00
|
|
|
" See logs for more information:\n"
|
2021-07-14 14:45:18 -05:00
|
|
|
"${stringified_logs}"
|
2017-10-19 17:19:11 -07:00
|
|
|
)
|
2016-09-18 20:50:08 -07:00
|
|
|
endif()
|
2021-07-14 14:45:18 -05:00
|
|
|
|
2020-10-27 03:30:27 +01:00
|
|
|
# pass output parameters back to caller's scope
|
2021-07-14 14:45:18 -05:00
|
|
|
if(output_and_error_same)
|
|
|
|
z_vcpkg_forward_output_variable(arg_OUTPUT_VARIABLE out_err_var)
|
|
|
|
# arg_ERROR_VARIABLE = arg_OUTPUT_VARIABLE, so no need to set it again
|
|
|
|
else()
|
|
|
|
z_vcpkg_forward_output_variable(arg_OUTPUT_VARIABLE out_var)
|
|
|
|
z_vcpkg_forward_output_variable(arg_ERROR_VARIABLE err_var)
|
|
|
|
endif()
|
2016-09-18 20:50:08 -07:00
|
|
|
endfunction()
|