From 2019380bfae3cd8609c7f8b57d27a934370a5e8e Mon Sep 17 00:00:00 2001 From: John Szakmeister Date: Fri, 6 Feb 2015 17:30:02 -0500 Subject: build: split hash checking from the download step It turns out that `file(DOWNLOAD ...)` is not very user friendly with it's error message, and only supports MD5 on v2.8.10 of CMake (the default for Ubuntu 12.04). If CMake is built without SSL support, users are left hanging with a message that the hashes don't match. It turns out that `file(SHA1 ...)` exists in v2.8.10, and we can use that to compute the hash ourselves. So this splits the hash checking into a separate step, where we can provide some additional advice if the SHA1 is the hash for an empty file. Additionally, it also allows us to drop the MD5 hashes and maintain only SHA1 hashes for our dependencies. --- third-party/cmake/DownloadAndExtractFile.cmake | 36 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'third-party/cmake/DownloadAndExtractFile.cmake') diff --git a/third-party/cmake/DownloadAndExtractFile.cmake b/third-party/cmake/DownloadAndExtractFile.cmake index b0d28355cb..bdf8742af1 100644 --- a/third-party/cmake/DownloadAndExtractFile.cmake +++ b/third-party/cmake/DownloadAndExtractFile.cmake @@ -10,8 +10,8 @@ if(NOT DEFINED DOWNLOAD_DIR) message(FATAL_ERROR "DOWNLOAD_DIR must be defined.") endif() -if((NOT DEFINED EXPECTED_SHA1) OR (NOT DEFINED EXPECTED_MD5)) - message(FATAL_ERROR "EXPECTED_SHA1 or EXPECTED_MD5 must be defined.") +if(NOT DEFINED EXPECTED_SHA1) + message(FATAL_ERROR "EXPECTED_SHA1 must be defined.") endif() if(NOT DEFINED TARGET) @@ -58,16 +58,6 @@ message(STATUS "downloading... dst='${file}' timeout='${timeout_msg}'") -if((DEFINED EXPECTED_SHA1) AND (${CMAKE_VERSION} VERSION_GREATER 2.8.10)) - if(NOT (EXPECTED_SHA1 STREQUAL "0000000000000000000000000000000000000000")) - set(hash_args EXPECTED_HASH SHA1=${EXPECTED_SHA1}) - endif() -else() - if(NOT (EXPECTED_MD5 STREQUAL "00000000000000000000000000000000")) - set(hash_args EXPECTED_MD5 ${EXPECTED_MD5}) - endif() -endif() - file(DOWNLOAD ${URL} ${file} ${timeout_args} ${hash_args} @@ -85,6 +75,27 @@ if(NOT status_code EQUAL 0) ") endif() +set(NULL_SHA1 "0000000000000000000000000000000000000000") + +# We could avoid computing the SHA1 entirely if a NULL_SHA1 was given, +# but we want to warn users of an empty file. +file(SHA1 ${file} ACTUAL_SHA1) +if(ACTUAL_SHA1 STREQUAL "da39a3ee5e6b4b0d3255bfef95601890afd80709") + # File was empty. It's likely due to lack of SSL support. + message(FATAL_ERROR + "Failed to download ${URL}. The file is empty and likely means CMake " + "was built without SSL support. Please use a version of CMake with " + "proper SSL support. See " + "https://github.com/neovim/neovim/wiki/Building-Neovim#build-prerequisites " + "for more information.") +elseif((NOT EXPECTED_SHA1 STREQUAL NULL_SHA1) AND + (NOT EXPECTED_SHA1 STREQUAL ACTUAL_SHA1)) + # Wasn't a NULL SHA1 and we didn't match, so we fail. + message(FATAL_ERROR + "Failed to download ${URL}. Expected a SHA1 of " + "${EXPECTED_SHA1} but got ${ACTUAL_SHA1} instead.") +endif() + message(STATUS "downloading... done") # Slurped from a generated extract-TARGET.cmake file. @@ -140,4 +151,3 @@ message(STATUS "extracting... [clean up]") file(REMOVE_RECURSE "${ut_dir}") message(STATUS "extracting... done") - -- cgit From aa45a2c6cf8d2c58b3190d5d190cf06dc0ff8641 Mon Sep 17 00:00:00 2001 From: John Szakmeister Date: Mon, 9 Feb 2015 06:26:59 -0500 Subject: build: allow SKIP or skip to be used as the SHA1 This will skip hash checking, just like the all zeros hash. --- third-party/cmake/DownloadAndExtractFile.cmake | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'third-party/cmake/DownloadAndExtractFile.cmake') diff --git a/third-party/cmake/DownloadAndExtractFile.cmake b/third-party/cmake/DownloadAndExtractFile.cmake index bdf8742af1..875d45795d 100644 --- a/third-party/cmake/DownloadAndExtractFile.cmake +++ b/third-party/cmake/DownloadAndExtractFile.cmake @@ -77,6 +77,12 @@ endif() set(NULL_SHA1 "0000000000000000000000000000000000000000") +# Allow users to use "SKIP" or "skip" as the sha1 to skip checking the hash. +# You can still use the all zeros hash too. +if((EXPECTED_SHA1 STREQUAL "SKIP") OR (EXPECTED_SHA1 STREQUAL "skip")) + set(EXPECTED_SHA1 ${NULL_SHA1}) +endif() + # We could avoid computing the SHA1 entirely if a NULL_SHA1 was given, # but we want to warn users of an empty file. file(SHA1 ${file} ACTUAL_SHA1) -- cgit