2021-07-15 03:45:18 +08:00
|
|
|
set(Z_VCPKG_EXECUTE_BUILD_PROCESS_RETRY_ERROR_MESSAGES
|
|
|
|
"LINK : fatal error LNK1102:"
|
|
|
|
" fatal error C1060: "
|
|
|
|
# The linker ran out of memory during execution. We will try continuing once more, with parallelism disabled.
|
|
|
|
"LINK : fatal error LNK1318:"
|
|
|
|
"LINK : fatal error LNK1104:"
|
|
|
|
"LINK : fatal error LNK1201:"
|
2022-01-12 06:29:24 +08:00
|
|
|
"ld terminated with signal 9"
|
2022-01-20 01:01:47 +08:00
|
|
|
"Killed signal terminated program"
|
2021-07-15 03:45:18 +08:00
|
|
|
# Multiple threads using the same directory at the same time cause conflicts, will try again.
|
|
|
|
"Cannot create parent directory"
|
|
|
|
"Cannot write file"
|
|
|
|
# Multiple threads caused the wrong order of creating folders and creating files in folders
|
|
|
|
"Can't open"
|
2022-10-09 12:36:46 +08:00
|
|
|
# `make install` may stumble over concurrency, in particular with `mkdir` on osx.
|
|
|
|
"mkdir [^:]*: File exists"
|
2021-07-15 03:45:18 +08:00
|
|
|
)
|
|
|
|
list(JOIN Z_VCPKG_EXECUTE_BUILD_PROCESS_RETRY_ERROR_MESSAGES "|" Z_VCPKG_EXECUTE_BUILD_PROCESS_RETRY_ERROR_MESSAGES)
|
|
|
|
|
2019-06-13 05:18:43 +08:00
|
|
|
function(vcpkg_execute_build_process)
|
2021-07-15 03:45:18 +08:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 0 arg "" "WORKING_DIRECTORY;LOGNAME" "COMMAND;NO_PARALLEL_COMMAND")
|
|
|
|
|
|
|
|
if(DEFINED arg_UNPARSED_ARGUMENTS)
|
|
|
|
message(WARNING "${CMAKE_CURRENT_FUNCTION} was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
|
|
|
|
endif()
|
|
|
|
foreach(required_arg IN ITEMS WORKING_DIRECTORY COMMAND)
|
|
|
|
if(NOT DEFINED arg_${required_arg})
|
|
|
|
message(FATAL_ERROR "${required_arg} must be specified.")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-06-13 05:18:43 +08:00
|
|
|
|
2021-07-15 03:45:18 +08:00
|
|
|
if(NOT DEFINED arg_LOGNAME)
|
|
|
|
message(WARNING "LOGNAME should be specified.")
|
|
|
|
set(arg_LOGNAME "build")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(log_prefix "${CURRENT_BUILDTREES_DIR}/${arg_LOGNAME}")
|
|
|
|
set(log_out "${log_prefix}-out.log")
|
|
|
|
set(log_err "${log_prefix}-err.log")
|
|
|
|
set(all_logs "${log_out}" "${log_err}")
|
2019-06-13 05:18:43 +08:00
|
|
|
|
2022-06-11 01:56:44 +08:00
|
|
|
if(X_PORT_PROFILE)
|
|
|
|
vcpkg_list(PREPEND arg_COMMAND "${CMAKE_COMMAND}" "-E" "time")
|
|
|
|
if(DEFINED arg_NO_PARALLEL_COMMAND)
|
|
|
|
vcpkg_list(PREPEND arg_NO_PARALLEL_COMMAND "${CMAKE_COMMAND}" "-E" "time")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-06-13 05:18:43 +08:00
|
|
|
execute_process(
|
2021-07-15 03:45:18 +08:00
|
|
|
COMMAND ${arg_COMMAND}
|
|
|
|
WORKING_DIRECTORY "${arg_WORKING_DIRECTORY}"
|
|
|
|
OUTPUT_FILE "${log_out}"
|
|
|
|
ERROR_FILE "${log_err}"
|
2019-06-13 05:18:43 +08:00
|
|
|
RESULT_VARIABLE error_code
|
|
|
|
)
|
2023-01-12 08:13:00 +08:00
|
|
|
if (NOT error_code MATCHES "^[0-9]+$")
|
|
|
|
list(JOIN arg_COMMAND " " command)
|
|
|
|
message(FATAL_ERROR "Failed to execute command \"${command}\" in working directory \"${arg_WORKING_DIRECTORY}\": ${error_code}")
|
|
|
|
endif()
|
2021-07-15 03:45:18 +08:00
|
|
|
if(NOT error_code EQUAL "0")
|
|
|
|
file(READ "${log_out}" out_contents)
|
|
|
|
file(READ "${log_err}" err_contents)
|
|
|
|
set(all_contents "${out_contents}${err_contents}")
|
|
|
|
if(all_contents MATCHES "${Z_VCPKG_EXECUTE_BUILD_PROCESS_RETRY_ERROR_MESSAGES}")
|
2022-01-12 06:29:24 +08:00
|
|
|
message(WARNING "Please ensure your system has sufficient memory.")
|
2021-07-15 03:45:18 +08:00
|
|
|
set(log_out "${log_prefix}-out-1.log")
|
|
|
|
set(log_err "${log_prefix}-err-1.log")
|
|
|
|
list(APPEND all_logs "${log_out}" "${log_err}")
|
2019-06-13 05:18:43 +08:00
|
|
|
|
2021-07-15 03:45:18 +08:00
|
|
|
if(DEFINED arg_NO_PARALLEL_COMMAND)
|
2022-01-12 06:29:24 +08:00
|
|
|
message(STATUS "Restarting build without parallelism")
|
2019-06-13 05:18:43 +08:00
|
|
|
execute_process(
|
2021-07-15 03:45:18 +08:00
|
|
|
COMMAND ${arg_NO_PARALLEL_COMMAND}
|
|
|
|
WORKING_DIRECTORY "${arg_WORKING_DIRECTORY}"
|
|
|
|
OUTPUT_FILE "${log_out}"
|
|
|
|
ERROR_FILE "${log_err}"
|
2019-06-13 05:18:43 +08:00
|
|
|
RESULT_VARIABLE error_code
|
|
|
|
)
|
|
|
|
else()
|
2022-01-12 06:29:24 +08:00
|
|
|
message(STATUS "Restarting build")
|
2019-06-13 05:18:43 +08:00
|
|
|
execute_process(
|
2021-07-15 03:45:18 +08:00
|
|
|
COMMAND ${arg_COMMAND}
|
|
|
|
WORKING_DIRECTORY "${arg_WORKING_DIRECTORY}"
|
|
|
|
OUTPUT_FILE "${log_out}"
|
|
|
|
ERROR_FILE "${log_err}"
|
2019-06-13 05:18:43 +08:00
|
|
|
RESULT_VARIABLE error_code
|
|
|
|
)
|
|
|
|
endif()
|
2021-07-15 03:45:18 +08:00
|
|
|
elseif(all_contents MATCHES "mt : general error c101008d: ")
|
2019-06-13 05:18:43 +08:00
|
|
|
# Antivirus workaround - occasionally files are locked and cause mt.exe to fail
|
|
|
|
message(STATUS "mt.exe has failed. This may be the result of anti-virus. Disabling anti-virus on the buildtree folder may improve build speed")
|
2021-07-15 03:45:18 +08:00
|
|
|
foreach(iteration RANGE 1 3)
|
|
|
|
message(STATUS "Restarting Build ${TARGET_TRIPLET}-${SHORT_BUILDTYPE} because of mt.exe file locking issue. Iteration: ${iteration}")
|
|
|
|
|
|
|
|
set(log_out "${log_prefix}-out-${iteration}.log")
|
|
|
|
set(log_err "${log_prefix}-err-${iteration}.log")
|
|
|
|
list(APPEND all_logs "${log_out}" "${log_err}")
|
2019-06-13 05:18:43 +08:00
|
|
|
execute_process(
|
2021-07-15 03:45:18 +08:00
|
|
|
COMMAND ${arg_COMMAND}
|
|
|
|
WORKING_DIRECTORY "${arg_WORKING_DIRECTORY}"
|
|
|
|
OUTPUT_FILE "${log_out}"
|
|
|
|
ERROR_FILE "${log_err}"
|
2019-06-13 05:18:43 +08:00
|
|
|
RESULT_VARIABLE error_code
|
2021-07-15 03:45:18 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if(error_code EQUAL "0")
|
2019-06-13 05:18:43 +08:00
|
|
|
break()
|
|
|
|
endif()
|
2021-07-15 03:45:18 +08:00
|
|
|
|
|
|
|
file(READ "${log_out}" out_contents)
|
|
|
|
file(READ "${log_err}" err_contents)
|
|
|
|
set(all_contents "${out_contents}${err_contents}")
|
|
|
|
if(NOT all_contents MATCHES "mt : general error c101008d: ")
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-06-13 05:18:43 +08:00
|
|
|
endif()
|
2021-07-15 03:45:18 +08:00
|
|
|
endif()
|
2019-06-13 05:18:43 +08:00
|
|
|
|
2021-07-15 03:45:18 +08:00
|
|
|
if(NOT error_code EQUAL "0")
|
|
|
|
set(stringified_logs "")
|
|
|
|
foreach(log IN LISTS all_logs)
|
|
|
|
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-29 03:30:49 +08:00
|
|
|
file(APPEND "${Z_VCPKG_ERROR_LOG_COLLECTION_FILE}" "${native_log}\n")
|
2021-07-15 03:45:18 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
z_vcpkg_prettify_command_line(pretty_command ${arg_COMMAND})
|
|
|
|
message(FATAL_ERROR
|
|
|
|
" Command failed: ${pretty_command}\n"
|
|
|
|
" Working Directory: ${arg_WORKING_DIRECTORY}\n"
|
|
|
|
" See logs for more information:\n"
|
|
|
|
"${stringified_logs}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endfunction()
|