ExternalProject: Add support for multiple alternative URLs
Now it is possible to pass multiple URLs as a list that will be tried in and foreach(). So it will try next URL if the previous failed. Fixes #15749.
This commit is contained in:
parent
41c3c9a495
commit
2eec433f98
|
@ -114,48 +114,56 @@ endif()
|
||||||
|
|
||||||
set(retry_number 5)
|
set(retry_number 5)
|
||||||
|
|
||||||
|
message(STATUS "Downloading...
|
||||||
|
dst='@LOCAL@'
|
||||||
|
timeout='@TIMEOUT_MSG@'"
|
||||||
|
)
|
||||||
|
|
||||||
foreach(i RANGE ${retry_number})
|
foreach(i RANGE ${retry_number})
|
||||||
sleep_before_download(${i})
|
sleep_before_download(${i})
|
||||||
|
|
||||||
message(STATUS "downloading...
|
foreach(url @REMOTE@)
|
||||||
src='@REMOTE@'
|
message(STATUS "Using src='${url}'")
|
||||||
dst='@LOCAL@'
|
|
||||||
timeout='@TIMEOUT_MSG@'")
|
|
||||||
|
|
||||||
@TLS_VERIFY_CODE@
|
@TLS_VERIFY_CODE@
|
||||||
@TLS_CAINFO_CODE@
|
@TLS_CAINFO_CODE@
|
||||||
|
|
||||||
file(
|
file(
|
||||||
DOWNLOAD
|
DOWNLOAD
|
||||||
"@REMOTE@" "@LOCAL@"
|
"${url}" "@LOCAL@"
|
||||||
@SHOW_PROGRESS@
|
@SHOW_PROGRESS@
|
||||||
@TIMEOUT_ARGS@
|
@TIMEOUT_ARGS@
|
||||||
STATUS status
|
STATUS status
|
||||||
LOG log
|
LOG log
|
||||||
)
|
|
||||||
|
|
||||||
list(GET status 0 status_code)
|
|
||||||
list(GET status 1 status_string)
|
|
||||||
|
|
||||||
if(status_code EQUAL 0)
|
|
||||||
check_file_hash(has_hash hash_is_good)
|
|
||||||
if(has_hash AND NOT hash_is_good)
|
|
||||||
message(STATUS "Hash mismatch, removing...")
|
|
||||||
file(REMOVE "@LOCAL@")
|
|
||||||
else()
|
|
||||||
message(STATUS "Downloading... done")
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
message("error: downloading '@REMOTE@' failed
|
|
||||||
status_code: ${status_code}
|
|
||||||
status_string: ${status_string}
|
|
||||||
log:
|
|
||||||
--- LOG BEGIN ---
|
|
||||||
${log}
|
|
||||||
--- LOG END ---"
|
|
||||||
)
|
)
|
||||||
endif()
|
|
||||||
|
list(GET status 0 status_code)
|
||||||
|
list(GET status 1 status_string)
|
||||||
|
|
||||||
|
if(status_code EQUAL 0)
|
||||||
|
check_file_hash(has_hash hash_is_good)
|
||||||
|
if(has_hash AND NOT hash_is_good)
|
||||||
|
message(STATUS "Hash mismatch, removing...")
|
||||||
|
file(REMOVE "@LOCAL@")
|
||||||
|
else()
|
||||||
|
message(STATUS "Downloading... done")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
string(APPEND logFailedURLs "error: downloading '${url}' failed
|
||||||
|
status_code: ${status_code}
|
||||||
|
status_string: ${status_string}
|
||||||
|
log:
|
||||||
|
--- LOG BEGIN ---
|
||||||
|
${log}
|
||||||
|
--- LOG END ---
|
||||||
|
"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
message(FATAL_ERROR "Downloading failed")
|
message(FATAL_ERROR "Each download failed!
|
||||||
|
${logFailedURLs}
|
||||||
|
"
|
||||||
|
)
|
||||||
|
|
|
@ -69,8 +69,8 @@ Create custom targets to build projects in external trees
|
||||||
URL of mercurial repo
|
URL of mercurial repo
|
||||||
``HG_TAG <tag>``
|
``HG_TAG <tag>``
|
||||||
Mercurial branch name, commit id or tag
|
Mercurial branch name, commit id or tag
|
||||||
``URL /.../src.tgz``
|
``URL /.../src.tgz [/.../src.tgz]...``
|
||||||
Full path or URL of source
|
Full path or URL(s) of source. Multiple URLs are allowed as mirrors.
|
||||||
``URL_HASH ALGO=value``
|
``URL_HASH ALGO=value``
|
||||||
Hash of file at URL
|
Hash of file at URL
|
||||||
``URL_MD5 md5``
|
``URL_MD5 md5``
|
||||||
|
@ -1667,7 +1667,7 @@ function(_ep_add_download_command name)
|
||||||
get_property(fname TARGET ${name} PROPERTY _EP_DOWNLOAD_NAME)
|
get_property(fname TARGET ${name} PROPERTY _EP_DOWNLOAD_NAME)
|
||||||
|
|
||||||
# TODO: Perhaps file:// should be copied to download dir before extraction.
|
# TODO: Perhaps file:// should be copied to download dir before extraction.
|
||||||
string(REGEX REPLACE "^file://" "" url "${url}")
|
string(REGEX REPLACE "file://" "" url "${url}")
|
||||||
|
|
||||||
set(depends)
|
set(depends)
|
||||||
set(comment)
|
set(comment)
|
||||||
|
@ -1861,6 +1861,19 @@ function(_ep_add_download_command name)
|
||||||
@ONLY
|
@ONLY
|
||||||
)
|
)
|
||||||
list(APPEND depends ${stamp_dir}/${name}-urlinfo.txt)
|
list(APPEND depends ${stamp_dir}/${name}-urlinfo.txt)
|
||||||
|
|
||||||
|
list(LENGTH url url_list_length)
|
||||||
|
if(NOT "${url_list_length}" STREQUAL "1")
|
||||||
|
foreach(entry ${url})
|
||||||
|
if(NOT "${entry}" MATCHES "^[a-z]+://")
|
||||||
|
message(FATAL_ERROR "At least one entry of URL is a path (invalid in a list)")
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
if("x${fname}" STREQUAL "x")
|
||||||
|
list(GET url 0 fname)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
if(IS_DIRECTORY "${url}")
|
if(IS_DIRECTORY "${url}")
|
||||||
get_filename_component(abs_dir "${url}" ABSOLUTE)
|
get_filename_component(abs_dir "${url}" ABSOLUTE)
|
||||||
set(comment "Performing download step (DIR copy) for '${name}'")
|
set(comment "Performing download step (DIR copy) for '${name}'")
|
||||||
|
|
Loading…
Reference in New Issue