mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-01-14 06:08:03 +08:00
Updated vcpkg_download_distfile.cmake to handle MIRRORS. Also updated the HASH errors to match the CMake formatting (easier to read)
This commit is contained in:
parent
a8b0651e50
commit
add26b7b5f
@ -1,6 +1,7 @@
|
||||
include(vcpkg_common_functions)
|
||||
vcpkg_download_distfile(ARCHIVE
|
||||
URL "https://github.com/Ninetainedo/Sery/archive/v1.0.zip"
|
||||
URL "https://githsdsdub.com/Ninetainedo/Sery/archive/v1.0.zip"
|
||||
MIRRORS "2http://githdfdub.com/Ninetainedo/Sery/archive/v1.0.zip" "https://github.com/Ninetainedo/Sery/archive/v1.0.zip"
|
||||
FILENAME "sery-1.0.0.zip"
|
||||
SHA512 15ef97bf094e8931049d8dd667a778e23847555f0f8d5b949b250e26edcc2541744fac5c34d935880d070546777fa787b1baf018d8ca2240fcd18a820aded04f
|
||||
)
|
||||
|
@ -1,20 +1,57 @@
|
||||
# Usage: vcpkg_download_distfile(<VAR> URL <http://...> FILENAME <output.zip> SHA512 <5981de...>)
|
||||
# Usage: vcpkg_download_distfile(<VAR> URL <http://...> FILENAME <output.zip> SHA512 <5981de...> MIRRORS <http://mirror1> <http://mirror2>)
|
||||
function(vcpkg_download_distfile VAR)
|
||||
set(oneValueArgs URL FILENAME SHA512)
|
||||
cmake_parse_arguments(vcpkg_download_distfile "" "${oneValueArgs}" "" ${ARGN})
|
||||
set(multipleValuesArgs MIRRORS)
|
||||
cmake_parse_arguments(vcpkg_download_distfile "" "${oneValueArgs}" "${multipleValuesArgs}" ${ARGN})
|
||||
|
||||
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}")
|
||||
set(downloaded_file_path ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME})
|
||||
if(EXISTS ${downloaded_file_path})
|
||||
message(STATUS "Using cached ${downloaded_file_path}")
|
||||
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"
|
||||
"Please delete the file and try again if this file should be downloaded again.\n")
|
||||
endif()
|
||||
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.
|
||||
list(INSERT vcpkg_download_distfile_MIRRORS 0 ${vcpkg_download_distfile_URL})
|
||||
foreach(url IN LISTS vcpkg_download_distfile_MIRRORS)
|
||||
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")
|
||||
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/new\n")
|
||||
else()
|
||||
message(STATUS "Testing integrity of downloaded file...")
|
||||
file(SHA512 ${downloaded_file_path} FILE_HASH)
|
||||
if(NOT "${FILE_HASH}" STREQUAL "${vcpkg_download_distfile_SHA512}")
|
||||
message(FATAL_ERROR
|
||||
"\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"
|
||||
"The file may be corrupted.\n")
|
||||
endif()
|
||||
message(STATUS "Testing integrity of downloaded file... OK")
|
||||
endif()
|
||||
endif()
|
||||
set(${VAR} ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME} PARENT_SCOPE)
|
||||
set(${VAR} ${downloaded_file_path} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
Loading…
x
Reference in New Issue
Block a user