From add26b7b5f3bc76b709aaf66eb5d35a6c74aa0e4 Mon Sep 17 00:00:00 2001 From: Ninetainedo Date: Sat, 24 Sep 2016 15:23:18 +0200 Subject: Updated vcpkg_download_distfile.cmake to handle MIRRORS. Also updated the HASH errors to match the CMake formatting (easier to read) --- scripts/cmake/vcpkg_download_distfile.cmake | 61 +++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 12 deletions(-) (limited to 'scripts') diff --git a/scripts/cmake/vcpkg_download_distfile.cmake b/scripts/cmake/vcpkg_download_distfile.cmake index 3145c8851..a394642a2 100644 --- a/scripts/cmake/vcpkg_download_distfile.cmake +++ b/scripts/cmake/vcpkg_download_distfile.cmake @@ -1,20 +1,57 @@ -# Usage: vcpkg_download_distfile( URL FILENAME SHA512 <5981de...>) +# Usage: vcpkg_download_distfile( URL FILENAME SHA512 <5981de...> MIRRORS ) 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() -- cgit v1.2.3 From 930d0a7dedbcd3996a490eea5e061a00aca552d4 Mon Sep 17 00:00:00 2001 From: Ninetainedo Date: Sun, 25 Sep 2016 00:23:04 +0200 Subject: URL and MIRRORS are now URLS Updated all portfiles accordingly. --- scripts/cmake/vcpkg_download_distfile.cmake | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/cmake/vcpkg_download_distfile.cmake b/scripts/cmake/vcpkg_download_distfile.cmake index a394642a2..602790190 100644 --- a/scripts/cmake/vcpkg_download_distfile.cmake +++ b/scripts/cmake/vcpkg_download_distfile.cmake @@ -1,7 +1,7 @@ -# Usage: vcpkg_download_distfile( URL FILENAME SHA512 <5981de...> MIRRORS ) +# Usage: vcpkg_download_distfile( URLS FILENAME SHA512 <5981de...>) function(vcpkg_download_distfile VAR) - set(oneValueArgs URL FILENAME SHA512) - set(multipleValuesArgs MIRRORS) + 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}) @@ -18,8 +18,7 @@ function(vcpkg_download_distfile VAR) endif() else() # Tries to download the file. - list(INSERT vcpkg_download_distfile_MIRRORS 0 ${vcpkg_download_distfile_URL}) - foreach(url IN LISTS vcpkg_download_distfile_MIRRORS) + 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) -- cgit v1.2.3 From 62d9473412bff2203f1e0aaa63c9e5dc67b364b2 Mon Sep 17 00:00:00 2001 From: Ninetainedo Date: Sun, 25 Sep 2016 00:24:38 +0200 Subject: Added spaces between brackets for double clicking --- scripts/cmake/vcpkg_download_distfile.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/cmake/vcpkg_download_distfile.cmake b/scripts/cmake/vcpkg_download_distfile.cmake index 602790190..0429bf853 100644 --- a/scripts/cmake/vcpkg_download_distfile.cmake +++ b/scripts/cmake/vcpkg_download_distfile.cmake @@ -11,9 +11,9 @@ function(vcpkg_download_distfile VAR) 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" + " 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() @@ -44,9 +44,9 @@ function(vcpkg_download_distfile VAR) 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" + " 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") -- cgit v1.2.3 From 51da39c1ed3debfe1a4fb45eaa65b181555da841 Mon Sep 17 00:00:00 2001 From: Ninetainedo Date: Sun, 25 Sep 2016 00:25:40 +0200 Subject: Display status on download error --- scripts/cmake/vcpkg_download_distfile.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/cmake/vcpkg_download_distfile.cmake b/scripts/cmake/vcpkg_download_distfile.cmake index 0429bf853..4d6019160 100644 --- a/scripts/cmake/vcpkg_download_distfile.cmake +++ b/scripts/cmake/vcpkg_download_distfile.cmake @@ -23,7 +23,7 @@ function(vcpkg_download_distfile VAR) 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") + message(STATUS "Downloading ${url}... Failed. Status: ${download_status}") file(REMOVE ${downloaded_file_path}) set(download_success 0) else() -- cgit v1.2.3 From c55c9df2285f0c66f054cb4591248501ba3e70fd Mon Sep 17 00:00:00 2001 From: Ninetainedo Date: Sun, 25 Sep 2016 00:26:05 +0200 Subject: Link to "issues" instead of "new issue" --- scripts/cmake/vcpkg_download_distfile.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/cmake/vcpkg_download_distfile.cmake b/scripts/cmake/vcpkg_download_distfile.cmake index 4d6019160..a2f13cd42 100644 --- a/scripts/cmake/vcpkg_download_distfile.cmake +++ b/scripts/cmake/vcpkg_download_distfile.cmake @@ -37,7 +37,7 @@ function(vcpkg_download_distfile VAR) message(FATAL_ERROR "\n" " Failed to download file.\n" - " Add mirrors or submit an issue at https://github.com/Microsoft/vcpkg/issues/new\n") + " Add mirrors or submit an issue at https://github.com/Microsoft/vcpkg/issues\n") else() message(STATUS "Testing integrity of downloaded file...") file(SHA512 ${downloaded_file_path} FILE_HASH) -- cgit v1.2.3 From 586c96e1b13c1bd4f7b5db483568cc5743a7a519 Mon Sep 17 00:00:00 2001 From: Ninetainedo Date: Sun, 25 Sep 2016 00:36:50 +0200 Subject: Used a function to check file integrity --- scripts/cmake/vcpkg_download_distfile.cmake | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'scripts') diff --git a/scripts/cmake/vcpkg_download_distfile.cmake b/scripts/cmake/vcpkg_download_distfile.cmake index a2f13cd42..44b562573 100644 --- a/scripts/cmake/vcpkg_download_distfile.cmake +++ b/scripts/cmake/vcpkg_download_distfile.cmake @@ -3,10 +3,10 @@ function(vcpkg_download_distfile VAR) 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 ${downloaded_file_path}) - message(STATUS "Using cached ${downloaded_file_path}") + + 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 @@ -14,8 +14,14 @@ function(vcpkg_download_distfile VAR) " 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") + "${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() # Tries to download the file. foreach(url IN LISTS vcpkg_download_distfile_URLS) @@ -39,17 +45,7 @@ function(vcpkg_download_distfile VAR) " Failed to download file.\n" " Add mirrors or submit an issue at https://github.com/Microsoft/vcpkg/issues\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") + test_hash("downloaded file" "The file may be corrupted.") endif() endif() set(${VAR} ${downloaded_file_path} PARENT_SCOPE) -- cgit v1.2.3 From 2491a16b0dd4bb88d48cd582e12e953c50a24b10 Mon Sep 17 00:00:00 2001 From: Ninetainedo Date: Sun, 25 Sep 2016 14:46:43 +0200 Subject: Updated portfile.in.cmake to use URLS --- scripts/templates/portfile.in.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') 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@ ) -- cgit v1.2.3