Add retry logic for CMake download operations (#5227)

* Add retry logic for CMake donwload operations

* Remove message

* PR feedback

* Move condition out of the loop

* Another small improvement

* Cleaner diff

---------

Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com>
This commit is contained in:
Anton Kolesnyk 2023-12-13 14:35:35 -08:00 коммит произвёл GitHub
Родитель 2dbaa8a37d
Коммит 370bedc8ae
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 31 добавлений и 4 удалений

Просмотреть файл

@ -73,13 +73,40 @@ macro(DownloadDepVersion DEP_FOLDER DEP_NAME DEP_VERSION)
set(DEP_PREFIX azure-sdk-for-cpp)
if(FETCH_SOURCE_DEPS STREQUAL "LATEST")
message("Downloading latest version of ${DEP_NAME}")
SET(DOWNLOAD_MESSAGE "Downloading latest version of ${DEP_NAME}")
#get the latest version from main
file(DOWNLOAD http://github.com/Azure/azure-sdk-for-cpp/archive/main.zip ${DOWNLOAD_FOLDER}/${DOWNLOAD_FILE})
SET(DOWNLOAD_LINK "http://github.com/Azure/azure-sdk-for-cpp/archive/main.zip")
else()
message("Downloading version ${DEP_VERSION} of ${DEP_NAME}")
SET(DOWNLOAD_MESSAGE "Downloading version ${DEP_VERSION} of ${DEP_NAME}")
# get the zip
file(DOWNLOAD https://github.com/Azure/azure-sdk-for-cpp/archive/refs/tags/${DOWNLOAD_FILE} ${DOWNLOAD_FOLDER}/${DOWNLOAD_FILE})
SET(DOWNLOAD_LINK "https://github.com/Azure/azure-sdk-for-cpp/archive/refs/tags/${DOWNLOAD_FILE}")
endif()
foreach(RETRY_ATTEMPT RANGE 2)
math(EXPR RETRY_DELAY "10 * ${RETRY_ATTEMPT}" OUTPUT_FORMAT DECIMAL)
if (RETRY_ATTEMPT GREATER 0)
message("Waiting for ${RETRY_DELAY} seconds before retrying download.")
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${RETRY_DELAY})
endif()
message(${DOWNLOAD_MESSAGE})
file(
DOWNLOAD ${DOWNLOAD_LINK}
${DOWNLOAD_FOLDER}/${DOWNLOAD_FILE}
SHOW_PROGRESS
STATUS DOWNLOAD_STATUS
)
list(GET DOWNLOAD_STATUS 0 STATUS_CODE)
if (${STATUS_CODE} EQUAL 0)
break()
else()
list(GET DOWNLOAD_STATUS 1 ERROR_MESSAGE)
message("Download failed with status code ${STATUS_CODE}: ${ERROR_MESSAGE}.")
endif()
endforeach()
if (NOT ${STATUS_CODE} EQUAL 0)
message(FATAL_ERROR "Dependency download failed (Link: ${DOWNLOAD_LINK}).")
endif()
#extract the zip