mirror of
https://github.com/microsoft/vcpkg
synced 2024-11-21 16:09:03 -07:00
[world rebuild][vcpkg scripts] Test, fix, extend vcpkg_execute_required_process (#39445)
Fixes `OUTPUT_VARIABLE`, `ERROR_VARIABLE`. vcpkg always wants logfiles. CMake (`execute_process`) doesn't send stdout/stderr to files and variables at the same time, and even "the precedence is not specified". So simultaneous output has to be handled in `vcpkg_execute_required_process`. At this occasion, port the arguments for stripping trailing whitespace. `tensorflow-common` implicitly relied on the broken behavior. I chose the minimal fix: drop the pointless calls, just set the empty value.
This commit is contained in:
parent
a6cad7a165
commit
5a5242aee4
8 changed files with 236 additions and 23 deletions
|
@ -39,7 +39,6 @@ if(CMAKE_HOST_WIN32)
|
|||
set(ENV{BAZEL_VC_FULL_VERSION} $ENV{VCToolsVersion})
|
||||
|
||||
set(PYTHON3 "${MSYS_ROOT}/mingw64/bin/python3.exe")
|
||||
vcpkg_execute_required_process(COMMAND ${PYTHON3} -c "import site; print(site.getsitepackages()[0])" WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR} LOGNAME prerequisites-pypath-${TARGET_TRIPLET} OUTPUT_VARIABLE PYTHON_LIB_PATH)
|
||||
else()
|
||||
vcpkg_find_acquire_program(PYTHON3)
|
||||
|
||||
|
@ -72,11 +71,9 @@ else()
|
|||
else()
|
||||
vcpkg_execute_required_process(COMMAND ${PYTHON3} -m pip install -U pip numpy WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR} LOGNAME prerequisites-pip-${TARGET_TRIPLET})
|
||||
endif()
|
||||
|
||||
vcpkg_execute_required_process(COMMAND ${PYTHON3} -c "import site; print(site.getusersitepackages())" WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR} LOGNAME prerequisites-pypath-${TARGET_TRIPLET} OUTPUT_VARIABLE PYTHON_LIB_PATH)
|
||||
endif()
|
||||
set(ENV{PYTHON_BIN_PATH} "${PYTHON3}")
|
||||
set(ENV{PYTHON_LIB_PATH} "${PYTHON_LIB_PATH}")
|
||||
set(ENV{PYTHON_LIB_PATH} "")
|
||||
|
||||
# check if numpy can be loaded
|
||||
vcpkg_execute_required_process(COMMAND ${PYTHON3} -c "import numpy" WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR} LOGNAME prerequisites-numpy-${TARGET_TRIPLET})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "tensorflow-common",
|
||||
"version-semver": "2.10.0",
|
||||
"port-version": 2,
|
||||
"port-version": 3,
|
||||
"description": "This meta package holds common files for the C [tensorflow] and the C++ [tensorflow-cc] API version of TensorFlow but is not installable on its own.",
|
||||
"homepage": "https://github.com/tensorflow/tensorflow",
|
||||
"license": "Apache-2.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
function(vcpkg_execute_required_process)
|
||||
cmake_parse_arguments(PARSE_ARGV 0 arg
|
||||
"ALLOW_IN_DOWNLOAD_MODE"
|
||||
"ALLOW_IN_DOWNLOAD_MODE;OUTPUT_STRIP_TRAILING_WHITESPACE;ERROR_STRIP_TRAILING_WHITESPACE"
|
||||
"WORKING_DIRECTORY;LOGNAME;TIMEOUT;OUTPUT_VARIABLE;ERROR_VARIABLE"
|
||||
"COMMAND;SAVE_LOG_FILES"
|
||||
)
|
||||
|
@ -27,29 +27,34 @@ Halting portfile execution.
|
|||
]])
|
||||
endif()
|
||||
|
||||
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()
|
||||
|
||||
set(log_out "${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-out.log")
|
||||
set(log_err "${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}-err.log")
|
||||
set(output_param OUTPUT_FILE "${log_out}")
|
||||
set(error_param ERROR_FILE "${log_err}")
|
||||
set(output_and_error_same OFF)
|
||||
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_param OUTPUT_VARIABLE out_err_var)
|
||||
set(error_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)
|
||||
set(output_param OUTPUT_VARIABLE out_var)
|
||||
endif()
|
||||
if(DEFINED arg_ERROR_VARIABLE)
|
||||
set(error_variable_param ERROR_VARIABLE err_var)
|
||||
set(error_param ERROR_VARIABLE err_var)
|
||||
endif()
|
||||
endif()
|
||||
if(arg_OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
list(APPEND output_param OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
endif()
|
||||
if(arg_ERROR_STRIP_TRAILING_WHITESPACE)
|
||||
list(APPEND error_param ERROR_STRIP_TRAILING_WHITESPACE)
|
||||
endif()
|
||||
|
||||
if(X_PORT_PROFILE AND NOT arg_ALLOW_IN_DOWNLOAD_MODE)
|
||||
vcpkg_list(PREPEND arg_COMMAND "${CMAKE_COMMAND}" "-E" "time")
|
||||
|
@ -57,14 +62,24 @@ Halting portfile execution.
|
|||
|
||||
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}
|
||||
${output_param}
|
||||
${error_param}
|
||||
)
|
||||
|
||||
if(output_and_error_same)
|
||||
file(WRITE "${log_out}" "${out_err_var}")
|
||||
file(WRITE "${log_err}" "")
|
||||
else()
|
||||
if(DEFINED arg_OUTPUT_VARIABLE)
|
||||
file(WRITE "${log_out}" "${out_var}")
|
||||
endif()
|
||||
if(DEFINED arg_ERROR_VARIABLE)
|
||||
file(WRITE "${log_err}" "${err_var}")
|
||||
endif()
|
||||
endif()
|
||||
vcpkg_list(SET logfiles)
|
||||
vcpkg_list(SET logfile_copies)
|
||||
set(expect_alias FALSE)
|
||||
|
|
|
@ -192,6 +192,9 @@ if("fixup-rpath" IN_LIST FEATURES)
|
|||
include("${CMAKE_CURRENT_LIST_DIR}/test-z_vcpkg_calculate_corrected_rpath.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/test-z_vcpkg_calculate_corrected_rpath_macho.cmake")
|
||||
endif()
|
||||
if("execute-required-process" IN_LIST FEATURES)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/test-vcpkg_execute_required_process.cmake")
|
||||
endif()
|
||||
|
||||
if(Z_VCPKG_UNIT_TEST_HAS_ERROR)
|
||||
_message(FATAL_ERROR "At least one test failed")
|
||||
|
|
|
@ -0,0 +1,189 @@
|
|||
# vcpkg_execute_required_process
|
||||
#[[
|
||||
"ALLOW_IN_DOWNLOAD_MODE;OUTPUT_STRIP_TRAILING_WHITESPACE;ERROR_STRIP_TRAILING_WHITESPACE"
|
||||
"WORKING_DIRECTORY;LOGNAME;TIMEOUT;OUTPUT_VARIABLE;ERROR_VARIABLE"
|
||||
"COMMAND;SAVE_LOG_FILES"
|
||||
]]
|
||||
|
||||
block(SCOPE_FOR VARIABLES)
|
||||
|
||||
set(logname "test-vcpkg_execute_required_process")
|
||||
|
||||
function(count_log_files out_var)
|
||||
set(count 0)
|
||||
if(EXISTS "${CURRENT_BUILDTREES_DIR}/${logname}-out.log")
|
||||
math(EXPR count "${count} + 1")
|
||||
endif()
|
||||
if(EXISTS "${CURRENT_BUILDTREES_DIR}/${logname}-err.log")
|
||||
math(EXPR count "${count} + 1")
|
||||
endif()
|
||||
if(EXISTS "${CURRENT_BUILDTREES_DIR}/${logname}-extra.log")
|
||||
math(EXPR count "${count} + 1")
|
||||
endif()
|
||||
set("${out_var}" "${count}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(reset_log_files)
|
||||
file(REMOVE "${CURRENT_BUILDTREES_DIR}/${logname}-out.log")
|
||||
file(REMOVE "${CURRENT_BUILDTREES_DIR}/${logname}-err.log")
|
||||
file(REMOVE "${CURRENT_BUILDTREES_DIR}/${logname}-extra.log")
|
||||
endfunction()
|
||||
|
||||
|
||||
# ALLOW_IN_DOWNLOAD_MODE
|
||||
|
||||
set(VCPKG_DOWNLOAD_MODE 1)
|
||||
unit_test_ensure_success([[
|
||||
vcpkg_execute_required_process(
|
||||
COMMAND "${CMAKE_COMMAND}" -E echo Success
|
||||
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
|
||||
LOGNAME "${logname}"
|
||||
ALLOW_IN_DOWNLOAD_MODE
|
||||
)]]
|
||||
)
|
||||
unit_test_ensure_fatal_error([[
|
||||
vcpkg_execute_required_process(
|
||||
COMMAND "${CMAKE_COMMAND}" -E echo Success
|
||||
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
|
||||
LOGNAME "${logname}"
|
||||
)]]
|
||||
)
|
||||
|
||||
set(VCPKG_DOWNLOAD_MODE "")
|
||||
unit_test_ensure_success([[
|
||||
vcpkg_execute_required_process(
|
||||
COMMAND "${CMAKE_COMMAND}" -E echo Success
|
||||
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
|
||||
LOGNAME "${logname}"
|
||||
ALLOW_IN_DOWNLOAD_MODE
|
||||
)]]
|
||||
)
|
||||
unit_test_ensure_success([[
|
||||
vcpkg_execute_required_process(
|
||||
COMMAND "${CMAKE_COMMAND}" -E echo Success
|
||||
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
|
||||
LOGNAME "${logname}"
|
||||
)]]
|
||||
)
|
||||
|
||||
|
||||
# COMMAND, LOGNAME
|
||||
|
||||
reset_log_files()
|
||||
unit_test_check_variable_equal([[count_log_files(count)]] count 0)
|
||||
|
||||
unit_test_ensure_success([[
|
||||
vcpkg_execute_required_process(
|
||||
COMMAND "${CMAKE_COMMAND}" -E echo Hello world
|
||||
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
|
||||
LOGNAME "${logname}"
|
||||
)]]
|
||||
)
|
||||
unit_test_check_variable_equal([[ count_log_files(count) ]] count 2)
|
||||
unit_test_check_variable_equal([[ file(STRINGS "${CURRENT_BUILDTREES_DIR}/${logname}-out.log" stdout) ]] stdout "Hello world")
|
||||
|
||||
|
||||
# WORKING_DIRECTORY, SAVE_LOG_FILES
|
||||
|
||||
file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/vcpkg_execute_required_process-dir/subdir")
|
||||
file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/vcpkg_execute_required_process-dir/subdir")
|
||||
file(WRITE "${CURRENT_BUILDTREES_DIR}/vcpkg_execute_required_process-dir/source" "extra log")
|
||||
file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/subdir")
|
||||
|
||||
reset_log_files()
|
||||
unit_test_check_variable_equal([[count_log_files(count)]] count 0)
|
||||
|
||||
unit_test_ensure_success([[
|
||||
vcpkg_execute_required_process(
|
||||
COMMAND "${CMAKE_COMMAND}" -E rename source subdir/extra.log
|
||||
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/vcpkg_execute_required_process-dir"
|
||||
LOGNAME "${logname}"
|
||||
SAVE_LOG_FILES "subdir/extra.log"
|
||||
)]]
|
||||
)
|
||||
unit_test_check_variable_equal([[ count_log_files(count) ]] count 3)
|
||||
unit_test_check_variable_equal([[ file(STRINGS "${CURRENT_BUILDTREES_DIR}/${logname}-extra.log" extra) ]] extra "extra log")
|
||||
|
||||
|
||||
# OUTPUT_VARIABLE, OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
|
||||
reset_log_files()
|
||||
unit_test_check_variable_equal([[count_log_files(count)]] count 0)
|
||||
|
||||
unit_test_check_variable_equal([[
|
||||
vcpkg_execute_required_process(
|
||||
COMMAND "${CMAKE_COMMAND}" -E echo Hello world
|
||||
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
|
||||
LOGNAME "${logname}"
|
||||
OUTPUT_VARIABLE outvar
|
||||
)]]
|
||||
outvar "Hello world\n"
|
||||
)
|
||||
unit_test_check_variable_equal([[
|
||||
vcpkg_execute_required_process(
|
||||
COMMAND "${CMAKE_COMMAND}" -E echo Hello world
|
||||
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
|
||||
LOGNAME "${logname}"
|
||||
OUTPUT_VARIABLE outvar
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)]]
|
||||
outvar "Hello world"
|
||||
)
|
||||
unit_test_check_variable_equal([[ count_log_files(count) ]] count 2)
|
||||
|
||||
|
||||
# ERROR_VARIABLE
|
||||
|
||||
reset_log_files()
|
||||
unit_test_check_variable_equal([[count_log_files(count)]] count 0)
|
||||
|
||||
file(WRITE "${CURRENT_BUILDTREES_DIR}/vcpkg_execute_required_process-dir/stderr.cmake" "message(WARNING on-stderr)\n")
|
||||
unit_test_check_variable_not_equal([[
|
||||
vcpkg_execute_required_process(
|
||||
COMMAND "${CMAKE_COMMAND}" -P "${CURRENT_BUILDTREES_DIR}/vcpkg_execute_required_process-dir/stderr.cmake"
|
||||
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
|
||||
LOGNAME "${logname}"
|
||||
ERROR_VARIABLE outvar
|
||||
)
|
||||
string(FIND "${outvar}" "on-stderr" pos)
|
||||
]] pos -1
|
||||
)
|
||||
unit_test_check_variable_equal([[ count_log_files(count) ]] count 2)
|
||||
|
||||
|
||||
# OUTPUT_VARIABLE == ERROR_VARIABLE
|
||||
|
||||
reset_log_files()
|
||||
unit_test_check_variable_equal([[count_log_files(count)]] count 0)
|
||||
|
||||
file(WRITE "${CURRENT_BUILDTREES_DIR}/vcpkg_execute_required_process-dir/combined.cmake" [[
|
||||
message(WARNING on-stderr)
|
||||
message(STATUS on-stdout)
|
||||
]])
|
||||
unit_test_check_variable_not_equal([[
|
||||
vcpkg_execute_required_process(
|
||||
COMMAND "${CMAKE_COMMAND}" -P "${CURRENT_BUILDTREES_DIR}/vcpkg_execute_required_process-dir/combined.cmake"
|
||||
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
|
||||
LOGNAME "${logname}"
|
||||
OUTPUT_VARIABLE outvar
|
||||
ERROR_VARIABLE outvar
|
||||
)
|
||||
string(REGEX MATCH "on-stderr.*on-stdout" match "${outvar}")
|
||||
]] CMAKE_MATCH_0 ""
|
||||
)
|
||||
unit_test_check_variable_equal([[ count_log_files(count) ]] count 2)
|
||||
|
||||
|
||||
# TIMEOUT (if not flaky)
|
||||
|
||||
unit_test_ensure_fatal_error([[
|
||||
vcpkg_execute_required_process(
|
||||
COMMAND "${CMAKE_COMMAND}" -E sleep 10
|
||||
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}"
|
||||
LOGNAME "${logname}"
|
||||
TIMEOUT 1
|
||||
)]]
|
||||
)
|
||||
|
||||
|
||||
endblock()
|
|
@ -1,11 +1,12 @@
|
|||
{
|
||||
"name": "unit-test-cmake",
|
||||
"version-string": "0",
|
||||
"version-string": "ci",
|
||||
"description": "Ensures that the CMake scripts are unit tested.",
|
||||
"license": "MIT",
|
||||
"supports": "x64",
|
||||
"default-features": [
|
||||
"backup-restore-env-vars",
|
||||
"execute-required-process",
|
||||
"fixup-pkgconfig",
|
||||
{
|
||||
"name": "fixup-rpath",
|
||||
|
@ -22,6 +23,9 @@
|
|||
"backup-restore-env-vars": {
|
||||
"description": "Test the vcpkg_backup/restore_env_vars functions"
|
||||
},
|
||||
"execute-required-process": {
|
||||
"description": "Test the vcpkg_execute_required_process function"
|
||||
},
|
||||
"fixup-pkgconfig": {
|
||||
"description": "Test the vcpkg_fixup_pkgconfig function"
|
||||
},
|
||||
|
|
|
@ -8650,7 +8650,7 @@
|
|||
},
|
||||
"tensorflow-common": {
|
||||
"baseline": "2.10.0",
|
||||
"port-version": 2
|
||||
"port-version": 3
|
||||
},
|
||||
"tensorpipe": {
|
||||
"baseline": "2022-03-16",
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
{
|
||||
"versions": [
|
||||
{
|
||||
"git-tree": "27a6a0026a080b8f5ec19b0092d4f4e20dfa13ed",
|
||||
"version-semver": "2.10.0",
|
||||
"port-version": 3
|
||||
},
|
||||
{
|
||||
"git-tree": "ee613e90128a706972e0acec27abb7fdd18fb9de",
|
||||
"version-semver": "2.10.0",
|
||||
|
|
Loading…
Reference in a new issue