mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-18 08:51:52 +08:00
ExternalProject: retry download on recoverable errors
In order to shorten the download failure of ExternalProject download steps, a download retry is only done when a recoverable network error is encountered.
This commit is contained in:
@@ -107,19 +107,23 @@ message(STATUS "Downloading...
|
|||||||
dst='@LOCAL@'
|
dst='@LOCAL@'
|
||||||
timeout='@TIMEOUT_MSG@'"
|
timeout='@TIMEOUT_MSG@'"
|
||||||
)
|
)
|
||||||
|
set(download_retry_codes 7 6 8 15)
|
||||||
|
set(skip_url_list)
|
||||||
|
set(status_code)
|
||||||
foreach(i RANGE ${retry_number})
|
foreach(i RANGE ${retry_number})
|
||||||
sleep_before_download(${i})
|
if(status_code IN_LIST download_retry_codes)
|
||||||
|
sleep_before_download(${i})
|
||||||
|
endif()
|
||||||
foreach(url @REMOTE@)
|
foreach(url @REMOTE@)
|
||||||
message(STATUS "Using src='${url}'")
|
if(NOT url IN_LIST skip_url_list)
|
||||||
|
message(STATUS "Using src='${url}'")
|
||||||
|
|
||||||
@TLS_VERIFY_CODE@
|
@TLS_VERIFY_CODE@
|
||||||
@TLS_CAINFO_CODE@
|
@TLS_CAINFO_CODE@
|
||||||
@NETRC_CODE@
|
@NETRC_CODE@
|
||||||
@NETRC_FILE_CODE@
|
@NETRC_FILE_CODE@
|
||||||
|
|
||||||
file(
|
file(
|
||||||
DOWNLOAD
|
DOWNLOAD
|
||||||
"${url}" "@LOCAL@"
|
"${url}" "@LOCAL@"
|
||||||
@SHOW_PROGRESS@
|
@SHOW_PROGRESS@
|
||||||
@@ -128,31 +132,36 @@ foreach(i RANGE ${retry_number})
|
|||||||
LOG log
|
LOG log
|
||||||
@USERPWD_ARGS@
|
@USERPWD_ARGS@
|
||||||
@HTTP_HEADERS_ARGS@
|
@HTTP_HEADERS_ARGS@
|
||||||
)
|
)
|
||||||
|
|
||||||
list(GET status 0 status_code)
|
list(GET status 0 status_code)
|
||||||
list(GET status 1 status_string)
|
list(GET status 1 status_string)
|
||||||
|
|
||||||
if(status_code EQUAL 0)
|
if(status_code EQUAL 0)
|
||||||
check_file_hash(has_hash hash_is_good)
|
check_file_hash(has_hash hash_is_good)
|
||||||
if(has_hash AND NOT hash_is_good)
|
if(has_hash AND NOT hash_is_good)
|
||||||
message(STATUS "Hash mismatch, removing...")
|
message(STATUS "Hash mismatch, removing...")
|
||||||
file(REMOVE "@LOCAL@")
|
file(REMOVE "@LOCAL@")
|
||||||
|
else()
|
||||||
|
message(STATUS "Downloading... done")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
message(STATUS "Downloading... done")
|
string(APPEND logFailedURLs "error: downloading '${url}' failed
|
||||||
return()
|
status_code: ${status_code}
|
||||||
|
status_string: ${status_string}
|
||||||
|
log:
|
||||||
|
--- LOG BEGIN ---
|
||||||
|
${log}
|
||||||
|
--- LOG END ---
|
||||||
|
"
|
||||||
|
)
|
||||||
|
if(NOT status_code IN_LIST download_retry_codes)
|
||||||
|
list(APPEND skip_url_list "${url}")
|
||||||
|
break()
|
||||||
endif()
|
endif()
|
||||||
else()
|
|
||||||
string(APPEND logFailedURLs "error: downloading '${url}' failed
|
|
||||||
status_code: ${status_code}
|
|
||||||
status_string: ${status_string}
|
|
||||||
log:
|
|
||||||
--- LOG BEGIN ---
|
|
||||||
${log}
|
|
||||||
--- LOG END ---
|
|
||||||
"
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
^[^0]
|
@@ -0,0 +1 @@
|
|||||||
|
.*
|
5
Tests/RunCMake/ExternalProject/DownloadTimeout.cmake
Normal file
5
Tests/RunCMake/ExternalProject/DownloadTimeout.cmake
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
include(ExternalProject)
|
||||||
|
set(source_dir "${CMAKE_CURRENT_BINARY_DIR}/DownloadTimeout")
|
||||||
|
file(REMOVE_RECURSE "${source_dir}")
|
||||||
|
file(MAKE_DIRECTORY "${source_dir}")
|
||||||
|
ExternalProject_Add(MyProj URL "http://cmake.org/invalid_file.tar.gz")
|
@@ -38,6 +38,7 @@ set(RunCMake_TEST_OUTPUT_MERGE 0)
|
|||||||
if(NOT RunCMake_GENERATOR MATCHES "Visual Studio")
|
if(NOT RunCMake_GENERATOR MATCHES "Visual Studio")
|
||||||
__ep_test_with_build(LogOutputOnFailure)
|
__ep_test_with_build(LogOutputOnFailure)
|
||||||
__ep_test_with_build(LogOutputOnFailureMerged)
|
__ep_test_with_build(LogOutputOnFailureMerged)
|
||||||
|
__ep_test_with_build(DownloadTimeout)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# We can't test the substitution when using the old MSYS due to
|
# We can't test the substitution when using the old MSYS due to
|
||||||
|
Reference in New Issue
Block a user