build(cmake): skip download if target file exists #14844)

This commit is contained in:
comicfans 2021-07-09 02:16:13 +08:00 committed by GitHub
parent 980d50d90e
commit 9c7e04eb3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,41 +59,48 @@ string(REPLACE ";" "-" fname "${fname}")
set(file ${DOWNLOAD_DIR}/${fname})
message(STATUS "file: ${file}")
message(STATUS "downloading...
src='${URL}'
dst='${file}'
timeout='${timeout_msg}'")
set(EXISTING_SHA256 "")
if(EXISTS ${file})
file(SHA256 ${file} EXISTING_SHA256)
endif()
file(DOWNLOAD ${URL} ${file}
${timeout_args}
${hash_args}
STATUS status
LOG log)
list(GET status 0 status_code)
list(GET status 1 status_string)
if(NOT status_code EQUAL 0)
# Retry on certain errors, e.g. CURLE_COULDNT_RESOLVE_HOST, which is often
# seen with libtermkey (www.leonerd.org.uk).
if((status_code EQUAL 6) # "Couldn't resolve host name"
OR (status_code EQUAL 7)) # "Couldn't connect to server"
message(STATUS "warning: retrying '${URL}' (${status_string}, status ${status_code})")
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 10)
file(DOWNLOAD ${URL} ${file}
${timeout_args}
${hash_args}
STATUS status
LOG log)
list(GET status 0 status_code)
list(GET status 1 status_string)
endif()
if(NOT EXISTING_SHA256 STREQUAL ${EXPECTED_SHA256})
message(STATUS "downloading...
src='${URL}'
dst='${file}'
timeout='${timeout_msg}'")
file(DOWNLOAD ${URL} ${file}
${timeout_args}
${hash_args}
STATUS status
LOG log)
list(GET status 0 status_code)
list(GET status 1 status_string)
if(NOT status_code EQUAL 0)
message(FATAL_ERROR "error: downloading '${URL}' failed
status_code: ${status_code}
status_string: ${status_string}
log: ${log}
")
# Retry on certain errors, e.g. CURLE_COULDNT_RESOLVE_HOST, which is often
# seen with libtermkey (www.leonerd.org.uk).
if((status_code EQUAL 6) # "Couldn't resolve host name"
OR (status_code EQUAL 7)) # "Couldn't connect to server"
message(STATUS "warning: retrying '${URL}' (${status_string}, status ${status_code})")
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 10)
file(DOWNLOAD ${URL} ${file}
${timeout_args}
${hash_args}
STATUS status
LOG log)
list(GET status 0 status_code)
list(GET status 1 status_string)
endif()
if(NOT status_code EQUAL 0)
message(FATAL_ERROR "error: downloading '${URL}' failed
status_code: ${status_code}
status_string: ${status_string}
log: ${log}
")
endif()
endif()
endif()