file(DOWNLOAD EXPECTED_HASH): better error message when download failed
requested to merge aurelienrb/cmake-fix-download-failure-msg:better-file-download-failure-msg into master
Better error message in case the requested file could not be downloaded. See #24122 (closed) for details.
Test script
cmake_minimum_required(VERSION 3.19)
project(TestTls)
set(VERBOSE ON)
# bad url on purpose
file(DOWNLOAD
https://example.com/badurl
output.txt
EXPECTED_HASH SHA256=b7e13f0b4259e80c3070b583c2f39e53153085a6918718b1c710caf7037572b0
)
set(OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/output.tar.gz)
file(REMOVE ${OUTPUT_FILE})
file(DOWNLOAD
https://github.com/census-instrumentation/opencensus-proto/archive/v0.3.0.tar.gz
${OUTPUT_FILE}
# bad hash on purpose
EXPECTED_HASH SHA256=b7e13f0b4259e80c3070b583c2f39e53153085a6918718b1c710caf7037572b1
TLS_VERIFY ON
)
Output without this MR
CMake Error at CMakeLists.txt:7 (file):
file DOWNLOAD HASH mismatch
for file: [output.txt]
expected hash: [b7e13f0b4259e80c3070b583c2f39e53153085a6918718b1c710caf7037572b0]
actual hash: [e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855]
status: [22;"HTTP response code said error"]
CMake Error at CMakeLists.txt:15 (file):
file DOWNLOAD HASH mismatch
for file: [C:/dev-cmake/bug-cmake-download/build/output.tar.gz]
expected hash: [b7e13f0b4259e80c3070b583c2f39e53153085a6918718b1c710caf7037572b1]
actual hash: [b7e13f0b4259e80c3070b583c2f39e53153085a6918718b1c710caf7037572b0]
status: [0;"No error"]
Output with this MR
CMake Error at CMakeLists.txt:7 (file):
file DOWNLOAD cannot compute hash on failed download
status: [22;"HTTP response code said error"]
CMake Error at CMakeLists.txt:15 (file):
file DOWNLOAD HASH mismatch
for file: [C:/dev-cmake/bug-cmake-download/build/output.tar.gz]
expected hash: [b7e13f0b4259e80c3070b583c2f39e53153085a6918718b1c710caf7037572b1]
actual hash: [b7e13f0b4259e80c3070b583c2f39e53153085a6918718b1c710caf7037572b0]
Issue: #24122 (closed)
Edited by Aurelien Regat-Barrel