ExternalProject: Re-implement download verification as a dedicated script
Move the content to a `ExternalProject-verify.cmake.in` file and use `configure_file` to generate the final script.
This commit is contained in:
parent
ebcc70271d
commit
e7d5e4b4bf
|
@ -0,0 +1,48 @@
|
||||||
|
#=============================================================================
|
||||||
|
# Copyright 2008-2013 Kitware, Inc.
|
||||||
|
# Copyright 2016 Ruslan Baratov
|
||||||
|
#
|
||||||
|
# Distributed under the OSI-approved BSD License (the "License");
|
||||||
|
# see accompanying file Copyright.txt for details.
|
||||||
|
#
|
||||||
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||||
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
# See the License for more information.
|
||||||
|
#=============================================================================
|
||||||
|
# (To distribute this file outside of CMake, substitute the full
|
||||||
|
# License text for the above reference.)
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
if("@LOCAL@" STREQUAL "")
|
||||||
|
message(FATAL_ERROR "LOCAL can't be empty")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT EXISTS "@LOCAL@")
|
||||||
|
message(FATAL_ERROR "File not found: @LOCAL@")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if("@ALGO@" STREQUAL "")
|
||||||
|
message(WARNING "File will not be verified since no URL_HASH specified")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if("@EXPECT_VALUE@" STREQUAL "")
|
||||||
|
message(FATAL_ERROR "EXPECT_VALUE can't be empty")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "verifying file...
|
||||||
|
file='@LOCAL@'")
|
||||||
|
|
||||||
|
file("@ALGO@" "@LOCAL@" actual_value)
|
||||||
|
|
||||||
|
if(NOT "${actual_value}" STREQUAL "@EXPECT_VALUE@")
|
||||||
|
message(FATAL_ERROR "error: @ALGO@ hash of
|
||||||
|
@LOCAL@
|
||||||
|
does not match expected value
|
||||||
|
expected: '@EXPECT_VALUE@'
|
||||||
|
actual: '${actual_value}'
|
||||||
|
")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "verifying file... done")
|
|
@ -377,6 +377,7 @@ file::
|
||||||
|
|
||||||
#=============================================================================
|
#=============================================================================
|
||||||
# Copyright 2008-2013 Kitware, Inc.
|
# Copyright 2008-2013 Kitware, Inc.
|
||||||
|
# Copyright 2016 Ruslan Baratov
|
||||||
#
|
#
|
||||||
# Distributed under the OSI-approved BSD License (the "License");
|
# Distributed under the OSI-approved BSD License (the "License");
|
||||||
# see accompanying file Copyright.txt for details.
|
# see accompanying file Copyright.txt for details.
|
||||||
|
@ -418,6 +419,9 @@ endif()
|
||||||
set(_ep_hash_algos "MD5|SHA1|SHA224|SHA256|SHA384|SHA512")
|
set(_ep_hash_algos "MD5|SHA1|SHA224|SHA256|SHA384|SHA512")
|
||||||
set(_ep_hash_regex "^(${_ep_hash_algos})=([0-9A-Fa-f]+)$")
|
set(_ep_hash_regex "^(${_ep_hash_algos})=([0-9A-Fa-f]+)$")
|
||||||
|
|
||||||
|
set(_ExternalProject_SELF "${CMAKE_CURRENT_LIST_FILE}")
|
||||||
|
get_filename_component(_ExternalProject_SELF_DIR "${_ExternalProject_SELF}" PATH)
|
||||||
|
|
||||||
function(_ep_parse_arguments f name ns args)
|
function(_ep_parse_arguments f name ns args)
|
||||||
# Transfer the arguments to this function into target properties for the
|
# Transfer the arguments to this function into target properties for the
|
||||||
# new custom target we just added so that we can set up all the build steps
|
# new custom target we just added so that we can set up all the build steps
|
||||||
|
@ -937,33 +941,22 @@ endfunction()
|
||||||
|
|
||||||
function(_ep_write_verifyfile_script script_filename LOCAL hash)
|
function(_ep_write_verifyfile_script script_filename LOCAL hash)
|
||||||
if("${hash}" MATCHES "${_ep_hash_regex}")
|
if("${hash}" MATCHES "${_ep_hash_regex}")
|
||||||
set(algo "${CMAKE_MATCH_1}")
|
set(ALGO "${CMAKE_MATCH_1}")
|
||||||
string(TOLOWER "${CMAKE_MATCH_2}" expect_value)
|
string(TOLOWER "${CMAKE_MATCH_2}" EXPECT_VALUE)
|
||||||
set(script_content "set(expect_value \"${expect_value}\")
|
else()
|
||||||
set(succeeded 0)
|
set(ALGO "")
|
||||||
file(${algo} \"\${file}\" actual_value)
|
set(EXPECT_VALUE "")
|
||||||
if(\"\${actual_value}\" STREQUAL \"\${expect_value}\")
|
|
||||||
set(succeeded 1)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(\${succeeded})
|
# Used variables:
|
||||||
message(STATUS \"verifying file... done\")
|
# * ALGO
|
||||||
else()
|
# * EXPECT_VALUE
|
||||||
message(FATAL_ERROR \"error: ${algo} hash of
|
# * LOCAL
|
||||||
\${file}
|
configure_file(
|
||||||
does not match expected value
|
"${_ExternalProject_SELF_DIR}/ExternalProject-verify.cmake.in"
|
||||||
expected: \${expect_value}
|
"${script_filename}"
|
||||||
actual: \${actual_value}
|
@ONLY
|
||||||
\")
|
)
|
||||||
endif()")
|
|
||||||
else()
|
|
||||||
set(script_content "message(STATUS \"verifying file... warning: did not verify file - no URL_HASH specified?\")")
|
|
||||||
endif()
|
|
||||||
file(WRITE ${script_filename} "set(file \"${LOCAL}\")
|
|
||||||
message(STATUS \"verifying file...
|
|
||||||
file='\${file}'\")
|
|
||||||
${script_content}
|
|
||||||
")
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue