aboutsummaryrefslogtreecommitdiff
path: root/scripts/cmake/vcpkg_execute_required_process_repeat.cmake
blob: 91b847dc5a23d5fb5dee9b19c4a890b762a3183a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Usage: vcpkg_execute_required_process_repeat(COUNT <num> COMMAND <cmd> [<args>...] WORKING_DIRECTORY </path/to/dir> LOGNAME <my_log_name>)
include(vcpkg_prettify_command)
function(vcpkg_execute_required_process_repeat)
    # parse parameters such that semicolons in options arguments to COMMAND don't get erased
    cmake_parse_arguments(PARSE_ARGV 0 vcpkg_execute_required_process_repeat "ALLOW_IN_DOWNLOAD_MODE" "COUNT;WORKING_DIRECTORY;LOGNAME" "COMMAND")
    #debug_message("vcpkg_execute_required_process_repeat(${vcpkg_execute_required_process_repeat_COMMAND})")
    if (DEFINED VCPKG_DOWNLOAD_MODE AND NOT vcpkg_execute_required_process_repeat_ALLOW_IN_DOWNLOAD_MODE)
        message(FATAL_ERROR 
[[
This command cannot be executed in Download Mode.
Halting portfile execution.
]])
    endif()
    set(SUCCESSFUL_EXECUTION FALSE)
    foreach(loop_count RANGE ${vcpkg_execute_required_process_repeat_COUNT})
        vcpkg_execute_in_download_mode(
            COMMAND ${vcpkg_execute_required_process_repeat_COMMAND}
            OUTPUT_FILE ${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_repeat_LOGNAME}-out-${loop_count}.log
            ERROR_FILE ${CURRENT_BUILDTREES_DIR}/${vcpkg_execute_required_process_repeat_LOGNAME}-err-${loop_count}.log
            RESULT_VARIABLE error_code
            WORKING_DIRECTORY ${vcpkg_execute_required_process_repeat_WORKING_DIRECTORY})
        #debug_message("error_code=${error_code}")
        file(TO_NATIVE_PATH "${CURRENT_BUILDTREES_DIR}" NATIVE_BUILDTREES_DIR)
        if(NOT error_code)
            set(SUCCESSFUL_EXECUTION TRUE)
            break()
        endif()
    endforeach(loop_count)
    if (NOT SUCCESSFUL_EXECUTION)
        vcpkg_prettify_command(vcpkg_execute_required_process_repeat_COMMAND vcpkg_execute_required_process_repeat_COMMAND_PRETTY)
        message(FATAL_ERROR
            "  Command failed: ${vcpkg_execute_required_process_repeat_COMMAND_PRETTY}\n"
            "  Working Directory: ${vcpkg_execute_required_process_repeat_WORKING_DIRECTORY}\n"
            "  See logs for more information:\n"
            "    ${NATIVE_BUILDTREES_DIR}\\${vcpkg_execute_required_process_repeat_LOGNAME}-out.log\n"
            "    ${NATIVE_BUILDTREES_DIR}\\${vcpkg_execute_required_process_repeat_LOGNAME}-err.log\n"
        )
    endif()
endfunction()