diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/cmake/vcpkg_download_distfile.cmake | 58 | ||||
| -rw-r--r-- | scripts/templates/portfile.in.cmake | 2 |
2 files changed, 46 insertions, 14 deletions
diff --git a/scripts/cmake/vcpkg_download_distfile.cmake b/scripts/cmake/vcpkg_download_distfile.cmake index 3145c8851..44b562573 100644 --- a/scripts/cmake/vcpkg_download_distfile.cmake +++ b/scripts/cmake/vcpkg_download_distfile.cmake @@ -1,20 +1,52 @@ -# Usage: vcpkg_download_distfile(<VAR> URL <http://...> FILENAME <output.zip> SHA512 <5981de...>) +# Usage: vcpkg_download_distfile(<VAR> URLS <http://mainUrl> <http://mirror1> <http://mirror2> FILENAME <output.zip> SHA512 <5981de...>) function(vcpkg_download_distfile VAR) - set(oneValueArgs URL FILENAME SHA512) - cmake_parse_arguments(vcpkg_download_distfile "" "${oneValueArgs}" "" ${ARGN}) + set(oneValueArgs FILENAME SHA512) + set(multipleValuesArgs URLS) + cmake_parse_arguments(vcpkg_download_distfile "" "${oneValueArgs}" "${multipleValuesArgs}" ${ARGN}) + set(downloaded_file_path ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME}) - if(EXISTS ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME}) - message(STATUS "Using cached ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME}") - file(SHA512 ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME} FILE_HASH) - if(NOT FILE_HASH STREQUAL "${vcpkg_download_distfile_SHA512}") + function(test_hash FILE_KIND CUSTOM_ERROR_ADVICE) + message(STATUS "Testing integrity of ${FILE_KIND}...") + file(SHA512 ${downloaded_file_path} FILE_HASH) + if(NOT "${FILE_HASH}" STREQUAL "${vcpkg_download_distfile_SHA512}") message(FATAL_ERROR - "File does not have expected hash: ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME}\n" - " '${FILE_HASH}' <> '${vcpkg_download_distfile_SHA512}'\n" - "Please delete the file and try again if this file should be downloaded again.") + "\nFile does not have expected hash:\n" + " File path: [ ${downloaded_file_path} ]\n" + " Expected hash: [ ${vcpkg_download_distfile_SHA512} ]\n" + " Actual hash: [ ${FILE_HASH} ]\n" + "${CUSTOM_ERROR_ADVICE}\n") endif() + message(STATUS "Testing integrity of ${FILE_KIND}... OK") + endfunction() + + if(EXISTS ${downloaded_file_path}) + message(STATUS "Using cached ${downloaded_file_path}") + test_hash("cached file" "Please delete the file and retry if this file should be downloaded again.") else() - message(STATUS "Downloading ${vcpkg_download_distfile_URL}") - file(DOWNLOAD ${vcpkg_download_distfile_URL} ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME} EXPECTED_HASH SHA512=${vcpkg_download_distfile_SHA512}) + # Tries to download the file. + foreach(url IN LISTS vcpkg_download_distfile_URLS) + message(STATUS "Downloading ${url}...") + file(DOWNLOAD ${url} ${downloaded_file_path} STATUS download_status) + list(GET download_status 0 status_code) + if (NOT "${status_code}" STREQUAL "0") + message(STATUS "Downloading ${url}... Failed. Status: ${download_status}") + file(REMOVE ${downloaded_file_path}) + set(download_success 0) + else() + message(STATUS "Downloading ${url}... OK") + set(download_success 1) + break() + endif() + endforeach(url) + + if (NOT ${download_success}) + message(FATAL_ERROR + "\n" + " Failed to download file.\n" + " Add mirrors or submit an issue at https://github.com/Microsoft/vcpkg/issues\n") + else() + test_hash("downloaded file" "The file may be corrupted.") + endif() endif() - set(${VAR} ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME} PARENT_SCOPE) + set(${VAR} ${downloaded_file_path} PARENT_SCOPE) endfunction() diff --git a/scripts/templates/portfile.in.cmake b/scripts/templates/portfile.in.cmake index 99a3ac3e8..f74c89aca 100644 --- a/scripts/templates/portfile.in.cmake +++ b/scripts/templates/portfile.in.cmake @@ -1,6 +1,6 @@ include(vcpkg_common_functions) vcpkg_download_distfile(ARCHIVE - URL "@URL@" + URLS "@URL@" FILENAME "@FILENAME@" SHA512 @SHA512@ ) |
