2020-12-02 05:37:26 +08:00
|
|
|
#[===[.md:
|
|
|
|
# vcpkg_execute_required_process
|
|
|
|
|
|
|
|
Execute a process with logging and fail the build if the command fails.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
```cmake
|
|
|
|
vcpkg_execute_required_process(
|
|
|
|
COMMAND <${PERL}> [<arguments>...]
|
|
|
|
WORKING_DIRECTORY <${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg>
|
|
|
|
LOGNAME <build-${TARGET_TRIPLET}-dbg>
|
|
|
|
[TIMEOUT <seconds>]
|
|
|
|
[OUTPUT_VARIABLE <var>]
|
|
|
|
[ERROR_VARIABLE <var>]
|
|
|
|
)
|
|
|
|
```
|
|
|
|
## Parameters
|
|
|
|
### ALLOW_IN_DOWNLOAD_MODE
|
2021-02-10 07:53:36 +08:00
|
|
|
Allows the command to execute in Download Mode.
|
2020-12-02 05:37:26 +08:00
|
|
|
[See execute_process() override](../../scripts/cmake/execute_process.cmake).
|
|
|
|
|
|
|
|
### COMMAND
|
|
|
|
The command to be executed, along with its arguments.
|
|
|
|
|
|
|
|
### WORKING_DIRECTORY
|
|
|
|
The directory to execute the command in.
|
|
|
|
|
|
|
|
### LOGNAME
|
|
|
|
The prefix to use for the log files.
|
|
|
|
|
|
|
|
### TIMEOUT
|
|
|
|
Optional timeout after which to terminate the command.
|
|
|
|
|
|
|
|
### OUTPUT_VARIABLE
|
|
|
|
Optional variable to receive stdout of the command.
|
|
|
|
|
|
|
|
### ERROR_VARIABLE
|
|
|
|
Optional variable to receive stderr of the command.
|
|
|
|
|
|
|
|
This should be a unique name for different triplets so that the logs don't conflict when building multiple at once.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
* [ffmpeg](https://github.com/Microsoft/vcpkg/blob/master/ports/ffmpeg/portfile.cmake)
|
|
|
|
* [openssl](https://github.com/Microsoft/vcpkg/blob/master/ports/openssl/portfile.cmake)
|
|
|
|
* [boost](https://github.com/Microsoft/vcpkg/blob/master/ports/boost/portfile.cmake)
|
|
|
|
* [qt5](https://github.com/Microsoft/vcpkg/blob/master/ports/qt5/portfile.cmake)
|
|
|
|
#]===]
|
2020-09-10 01:36:58 +08:00
|
|
|
|
2016-09-19 11:50:08 +08:00
|
|
|
function(vcpkg_execute_required_process)
|
2020-10-27 10:30:27 +08:00
|
|
|
# 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")
|
2017-10-20 08:19:11 +08:00
|
|
|
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")
|
2019-08-29 04:49:29 +08:00
|
|
|
|
2020-08-28 10:28:20 +08:00
|
|
|
if(vcpkg_execute_required_process_TIMEOUT)
|
2020-10-27 10:30:27 +08:00
|
|
|
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}")
|
2020-08-28 10:28:20 +08:00
|
|
|
else()
|
2020-10-27 10:30:27 +08:00
|
|
|
set(OUTPUT_VARIABLE_PARAM "")
|
|
|
|
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 "")
|
2020-08-28 10:28:20 +08:00
|
|
|
endif()
|
|
|
|
|
2019-08-29 04:49:29 +08:00
|
|
|
if (DEFINED VCPKG_DOWNLOAD_MODE AND NOT vcpkg_execute_required_process_ALLOW_IN_DOWNLOAD_MODE)
|
2021-02-10 07:53:36 +08:00
|
|
|
message(FATAL_ERROR
|
2019-08-29 04:49:29 +08:00
|
|
|
[[
|
|
|
|
This command cannot be executed in Download Mode.
|
|
|
|
Halting portfile execution.
|
|
|
|
]])
|
|
|
|
endif()
|
|
|
|
|
2020-09-10 01:36:58 +08:00
|
|
|
vcpkg_execute_in_download_mode(
|
2016-09-19 11:50:08 +08:00
|
|
|
COMMAND ${vcpkg_execute_required_process_COMMAND}
|
2017-10-20 08:19:11 +08:00
|
|
|
OUTPUT_FILE ${LOG_OUT}
|
|
|
|
ERROR_FILE ${LOG_ERR}
|
2016-09-19 11:50:08 +08:00
|
|
|
RESULT_VARIABLE error_code
|
2020-08-28 10:28:20 +08:00
|
|
|
WORKING_DIRECTORY ${vcpkg_execute_required_process_WORKING_DIRECTORY}
|
2020-10-27 10:30:27 +08:00
|
|
|
${TIMEOUT_PARAM}
|
|
|
|
${OUTPUT_VARIABLE_PARAM}
|
|
|
|
${ERROR_VARIABLE_PARAM})
|
2016-09-19 11:50:08 +08:00
|
|
|
if(error_code)
|
2017-10-20 08:19:11 +08:00
|
|
|
set(LOGS)
|
|
|
|
file(READ "${LOG_OUT}" out_contents)
|
|
|
|
file(READ "${LOG_ERR}" err_contents)
|
|
|
|
if(out_contents)
|
|
|
|
list(APPEND LOGS "${LOG_OUT}")
|
|
|
|
endif()
|
|
|
|
if(err_contents)
|
|
|
|
list(APPEND LOGS "${LOG_ERR}")
|
|
|
|
endif()
|
|
|
|
set(STRINGIFIED_LOGS)
|
|
|
|
foreach(LOG ${LOGS})
|
|
|
|
file(TO_NATIVE_PATH "${LOG}" NATIVE_LOG)
|
|
|
|
list(APPEND STRINGIFIED_LOGS " ${NATIVE_LOG}\n")
|
|
|
|
endforeach()
|
2021-02-10 07:53:36 +08:00
|
|
|
z_vcpkg_prettify_command_line(vcpkg_execute_required_process_COMMAND_PRETTY ${vcpkg_execute_required_process_COMMAND})
|
2016-09-19 11:50:08 +08:00
|
|
|
message(FATAL_ERROR
|
2019-07-02 04:30:24 +08:00
|
|
|
" Command failed: ${vcpkg_execute_required_process_COMMAND_PRETTY}\n"
|
2016-10-21 06:46:32 +08:00
|
|
|
" Working Directory: ${vcpkg_execute_required_process_WORKING_DIRECTORY}\n"
|
2019-03-07 15:37:24 +08:00
|
|
|
" Error code: ${error_code}\n"
|
2016-10-21 06:46:32 +08:00
|
|
|
" See logs for more information:\n"
|
2017-10-20 08:19:11 +08:00
|
|
|
${STRINGIFIED_LOGS}
|
|
|
|
)
|
2016-09-19 11:50:08 +08:00
|
|
|
endif()
|
2020-10-27 10:30:27 +08:00
|
|
|
# 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()
|
2016-09-19 11:50:08 +08:00
|
|
|
endfunction()
|