diff options
| author | nicole mazzuca <83086508+strega-nil-ms@users.noreply.github.com> | 2021-07-14 14:45:18 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-14 12:45:18 -0700 |
| commit | d369df7ecf194005eaca46f07368779cd486badd (patch) | |
| tree | 419f9861b796a7dc6e53646df13642c6c71108f2 /scripts/cmake/vcpkg_execute_required_process.cmake | |
| parent | 932df5b8ede16b73fc5508445140d5b360ea0c68 (diff) | |
| download | vcpkg-d369df7ecf194005eaca46f07368779cd486badd.tar.gz vcpkg-d369df7ecf194005eaca46f07368779cd486badd.zip | |
[rollup:2021-07-06] Rollup PR (#18838)
* [rollup:2021-07-06 1/8] PR #18272 (@strega-nil)
[scripts-audit] vcpkg_from_*
* [rollup:2021-07-06 2/8] PR #18319 (@strega-nil)
[scripts-audit] add guidelines for cmake
* [rollup 2021-07-06 3/8] PR #18410 (@mheyman)
[vcpkg-cmake-config] documentation fix
* [rollup:2021-07-06 4/8] PR #18488 (@strega-nil)
[scripts-audit] vcpkg_execute_*
* [rollup:2021-07-06 5/8] PR #18517 (@strega-nil)
[scripts-audit] vcpkg_extract_source_archive
* [rollup:2021-07-06 6/8] PR #18674 (@NancyLi1013)
[vcpkg doc] Update examples
* [rollup:2021-07-06 7/8] PR #18695 (@JackBoosY)
[vcpkg] Update the minimum version of vcpkg
* [rollup:2021-07-06 8/8] PR #18758 (@ras0219-msft)
[vcpkg_from_git] Fix error if downloads folder does not exist
* build docs!
* fix bond:*-windows
* fix nmap
Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
Co-authored-by: Michael Heyman <Michael.Heyman@jhuapl.edu>
Co-authored-by: NancyLi1013 <lirui09@beyondsoft.com>
Co-authored-by: JackBoosY <yuzaiyang@beyondsoft.com>
Co-authored-by: Robert Schumacher <ras0219@outlook.com>
Diffstat (limited to 'scripts/cmake/vcpkg_execute_required_process.cmake')
| -rw-r--r-- | scripts/cmake/vcpkg_execute_required_process.cmake | 121 |
1 files changed, 73 insertions, 48 deletions
diff --git a/scripts/cmake/vcpkg_execute_required_process.cmake b/scripts/cmake/vcpkg_execute_required_process.cmake index c38fd2ed8..27024fecf 100644 --- a/scripts/cmake/vcpkg_execute_required_process.cmake +++ b/scripts/cmake/vcpkg_execute_required_process.cmake @@ -48,28 +48,27 @@ This should be a unique name for different triplets so that the logs don't confl #]===] function(vcpkg_execute_required_process) - # parse parameters such that semicolons in options arguments to COMMAND don't get erased - cmake_parse_arguments(PARSE_ARGV 0 vcpkg_execute_required_process "ALLOW_IN_DOWNLOAD_MODE" "WORKING_DIRECTORY;LOGNAME;TIMEOUT;OUTPUT_VARIABLE;ERROR_VARIABLE" "COMMAND") - set(LOG_OUT "${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-out.log") - set(LOG_ERR "${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_LOGNAME}-err.log") + cmake_parse_arguments(PARSE_ARGV 0 arg + "ALLOW_IN_DOWNLOAD_MODE" + "WORKING_DIRECTORY;LOGNAME;TIMEOUT;OUTPUT_VARIABLE;ERROR_VARIABLE" + "COMMAND" + ) - if(vcpkg_execute_required_process_TIMEOUT) - set(TIMEOUT_PARAM "TIMEOUT;${vcpkg_execute_required_process_TIMEOUT}") - else() - set(TIMEOUT_PARAM "") - endif() - if(vcpkg_execute_required_process_OUTPUT_VARIABLE) - set(OUTPUT_VARIABLE_PARAM "OUTPUT_VARIABLE;${vcpkg_execute_required_process_OUTPUT_VARIABLE}") - else() - set(OUTPUT_VARIABLE_PARAM "") + if(DEFINED arg_UNPARSED_ARGUMENTS) + message(WARNING "${CMAKE_CURRENT_FUNCTION} was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") endif() - if(vcpkg_execute_required_process_ERROR_VARIABLE) - set(ERROR_VARIABLE_PARAM "ERROR_VARIABLE;${vcpkg_execute_required_process_ERROR_VARIABLE}") - else() - set(ERROR_VARIABLE_PARAM "") + 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") endif() - if (DEFINED VCPKG_DOWNLOAD_MODE AND NOT vcpkg_execute_required_process_ALLOW_IN_DOWNLOAD_MODE) + if (VCPKG_DOWNLOAD_MODE AND NOT arg_ALLOW_IN_DOWNLOAD_MODE) message(FATAL_ERROR [[ This command cannot be executed in Download Mode. @@ -77,43 +76,69 @@ Halting portfile execution. ]]) endif() - vcpkg_execute_in_download_mode( - COMMAND ${vcpkg_execute_required_process_COMMAND} - OUTPUT_FILE ${LOG_OUT} - ERROR_FILE ${LOG_ERR} - RESULT_VARIABLE error_code - WORKING_DIRECTORY ${vcpkg_execute_required_process_WORKING_DIRECTORY} - ${TIMEOUT_PARAM} - ${OUTPUT_VARIABLE_PARAM} - ${ERROR_VARIABLE_PARAM}) - if(error_code) - set(LOGS) - file(READ "${LOG_OUT}" out_contents) - file(READ "${LOG_ERR}" err_contents) - if(out_contents) - list(APPEND LOGS "${LOG_OUT}") + 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) endif() - if(err_contents) - list(APPEND LOGS "${LOG_ERR}") + if(DEFINED arg_ERROR_VARIABLE) + set(error_variable_param ERROR_VARIABLE err_var) endif() - set(STRINGIFIED_LOGS) - foreach(LOG ${LOGS}) - file(TO_NATIVE_PATH "${LOG}" NATIVE_LOG) - list(APPEND STRINGIFIED_LOGS " ${NATIVE_LOG}\n") + endif() + + 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} + ) + if(NOT error_code EQUAL 0) + set(stringified_logs "") + foreach(log IN ITEMS "${log_out}" "${log_err}") + 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") + endif() endforeach() - z_vcpkg_prettify_command_line(vcpkg_execute_required_process_COMMAND_PRETTY ${vcpkg_execute_required_process_COMMAND}) + + z_vcpkg_prettify_command_line(pretty_command ${arg_COMMAND}) message(FATAL_ERROR - " Command failed: ${vcpkg_execute_required_process_COMMAND_PRETTY}\n" - " Working Directory: ${vcpkg_execute_required_process_WORKING_DIRECTORY}\n" + " Command failed: ${pretty_command}\n" + " Working Directory: ${arg_WORKING_DIRECTORY}\n" " Error code: ${error_code}\n" " See logs for more information:\n" - ${STRINGIFIED_LOGS} + "${stringified_logs}" ) endif() + # pass output parameters back to caller's scope - foreach(arg OUTPUT_VARIABLE ERROR_VARIABLE) - if(vcpkg_execute_required_process_${arg}) - set(${vcpkg_execute_required_process_${arg}} ${${vcpkg_execute_required_process_${arg}}} PARENT_SCOPE) - endif() - endforeach() + 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() endfunction() |
