file(DOWNLOAD): Change EXPECTED_HASH to take ALGO=value

Make the EXPECTED_HASH option take only a single value instead of two to
avoid handling sub-keyword arguments.  This is also consistent with
URL_HASH in ExternalProject.
This commit is contained in:
Brad King 2012-09-19 11:28:00 -04:00
parent d407dcdbc8
commit 95a0011604
4 changed files with 35 additions and 34 deletions

View File

@ -411,7 +411,7 @@ function(_ep_write_downloadfile_script script_filename remote local timeout hash
endif() endif()
if("${hash}" MATCHES "${_ep_hash_regex}") if("${hash}" MATCHES "${_ep_hash_regex}")
set(hash_args EXPECTED_HASH ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}) set(hash_args EXPECTED_HASH ${CMAKE_MATCH_1}=${CMAKE_MATCH_2})
else() else()
set(hash_args "# no EXPECTED_HASH") set(hash_args "# no EXPECTED_HASH")
endif() endif()

View File

@ -2767,30 +2767,31 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
else if(*i == "EXPECTED_HASH") else if(*i == "EXPECTED_HASH")
{ {
++i; ++i;
if(i != args.end()) if(i == args.end())
{ {
hash = cmsys::auto_ptr<cmCryptoHash>(cmCryptoHash::New(i->c_str())); this->SetError("DOWNLOAD missing ALGO=value for EXPECTED_HASH.");
if(!hash.get()) return false;
}
std::string::size_type pos = i->find("=");
if(pos == std::string::npos)
{ {
std::string err = "DOWNLOAD bad SHA type: "; std::string err =
"DOWNLOAD EXPECTED_HASH expects ALGO=value but got: ";
err += *i; err += *i;
this->SetError(err.c_str()); this->SetError(err.c_str());
return false; return false;
} }
hashMatchMSG = *i; std::string algo = i->substr(0, pos);
hashMatchMSG += " hash"; expectedHash = cmSystemTools::LowerCase(i->substr(pos+1));
hash = cmsys::auto_ptr<cmCryptoHash>(cmCryptoHash::New(algo.c_str()));
++i; if(!hash.get())
}
if(i != args.end())
{ {
expectedHash = cmSystemTools::LowerCase(*i); std::string err = "DOWNLOAD EXPECTED_HASH given unknown ALGO: ";
} err += algo;
else this->SetError(err.c_str());
{
this->SetError("DOWNLOAD missing time for EXPECTED_HASH.");
return false; return false;
} }
hashMatchMSG = algo + " hash";
} }
++i; ++i;
} }

View File

@ -83,8 +83,7 @@ public:
" file(TO_NATIVE_PATH path result)\n" " file(TO_NATIVE_PATH path result)\n"
" file(DOWNLOAD url file [INACTIVITY_TIMEOUT timeout]\n" " file(DOWNLOAD url file [INACTIVITY_TIMEOUT timeout]\n"
" [TIMEOUT timeout] [STATUS status] [LOG log] [SHOW_PROGRESS]\n" " [TIMEOUT timeout] [STATUS status] [LOG log] [SHOW_PROGRESS]\n"
" [EXPECTED_HASH MD5|SHA1|SHA224|SHA256|SHA384|SHA512 hash]\n" " [EXPECTED_HASH ALGO=value] [EXPECTED_MD5 sum]\n"
" [EXPECTED_MD5 sum]\n"
" [TLS_VERIFY on|off] [TLS_CAINFO file])\n" " [TLS_VERIFY on|off] [TLS_CAINFO file])\n"
" file(UPLOAD filename url [INACTIVITY_TIMEOUT timeout]\n" " file(UPLOAD filename url [INACTIVITY_TIMEOUT timeout]\n"
" [TIMEOUT timeout] [STATUS status] [LOG log] [SHOW_PROGRESS])\n" " [TIMEOUT timeout] [STATUS status] [LOG log] [SHOW_PROGRESS])\n"
@ -170,10 +169,11 @@ public:
"timeout after time seconds, time should be specified as an integer. " "timeout after time seconds, time should be specified as an integer. "
"The INACTIVITY_TIMEOUT specifies an integer number of seconds of " "The INACTIVITY_TIMEOUT specifies an integer number of seconds of "
"inactivity after which the operation should terminate. " "inactivity after which the operation should terminate. "
"If EXPECTED_HASH is specified, the operation will verify that the " "If EXPECTED_HASH ALGO=value is specified, the operation will verify "
"downloaded file's actual hash matches the expected value. If it " "that the downloaded file's actual hash matches the expected value, "
"does not match, the operation fails with an error. " "where ALGO is one of MD5, SHA1, SHA224, SHA256, SHA384, or SHA512. "
"(EXPECTED_MD5 is short-hand for EXPECTED_HASH MD5.) " "If it does not match, the operation fails with an error. "
"(\"EXPECTED_MD5 sum\" is short-hand for \"EXPECTED_HASH MD5=sum\".) "
"If SHOW_PROGRESS is specified, progress information will be printed " "If SHOW_PROGRESS is specified, progress information will be printed "
"as status messages until the operation is complete. " "as status messages until the operation is complete. "
"For https URLs CMake must be built with OpenSSL. " "For https URLs CMake must be built with OpenSSL. "

View File

@ -38,7 +38,7 @@ file(DOWNLOAD
${dir}/file3.png ${dir}/file3.png
TIMEOUT 2 TIMEOUT 2
STATUS status STATUS status
EXPECTED_HASH SHA1 50c614fc28b39c1281d0517bb6d5858b4359c9b7 EXPECTED_HASH SHA1=50c614fc28b39c1281d0517bb6d5858b4359c9b7
) )
message(STATUS "FileDownload:5") message(STATUS "FileDownload:5")
@ -47,7 +47,7 @@ file(DOWNLOAD
${dir}/file3.png ${dir}/file3.png
TIMEOUT 2 TIMEOUT 2
STATUS status STATUS status
EXPECTED_HASH SHA224 73cd5f442b04e8320e4f907f8e1b21d4befff98b5bd77bc32526ea68 EXPECTED_HASH SHA224=73cd5f442b04e8320e4f907f8e1b21d4befff98b5bd77bc32526ea68
) )
message(STATUS "FileDownload:6") message(STATUS "FileDownload:6")
@ -56,7 +56,7 @@ file(DOWNLOAD
${dir}/file3.png ${dir}/file3.png
TIMEOUT 2 TIMEOUT 2
STATUS status STATUS status
EXPECTED_HASH SHA256 2e067f6c09cbc7cd619c8fbcc44eb64cd6b45a95e4cddb3a585eee1f731c4da9 EXPECTED_HASH SHA256=2e067f6c09cbc7cd619c8fbcc44eb64cd6b45a95e4cddb3a585eee1f731c4da9
) )
message(STATUS "FileDownload:7") message(STATUS "FileDownload:7")
@ -65,7 +65,7 @@ file(DOWNLOAD
${dir}/file3.png ${dir}/file3.png
TIMEOUT 2 TIMEOUT 2
STATUS status STATUS status
EXPECTED_HASH SHA384 398bf41902a7251c30e522b307e3e41e3fb617c765b3feaa99b2f7d063894708ad399267ccc25d877437a10e5e890d35 EXPECTED_HASH SHA384=398bf41902a7251c30e522b307e3e41e3fb617c765b3feaa99b2f7d063894708ad399267ccc25d877437a10e5e890d35
) )
message(STATUS "FileDownload:8") message(STATUS "FileDownload:8")
@ -74,7 +74,7 @@ file(DOWNLOAD
${dir}/file3.png ${dir}/file3.png
TIMEOUT 2 TIMEOUT 2
STATUS status STATUS status
EXPECTED_HASH SHA512 c51854d21052713968b849c2b4263cf54be03bc3a7e9847a6c71c6c8d1d13cd805fe1b9fa95f9ba1d0a5631513974f6fae21e34ab5b171d94bad48df5f073e48 EXPECTED_HASH SHA512=c51854d21052713968b849c2b4263cf54be03bc3a7e9847a6c71c6c8d1d13cd805fe1b9fa95f9ba1d0a5631513974f6fae21e34ab5b171d94bad48df5f073e48
) )
message(STATUS "FileDownload:9") message(STATUS "FileDownload:9")
file(DOWNLOAD file(DOWNLOAD
@ -82,7 +82,7 @@ file(DOWNLOAD
${dir}/file3.png ${dir}/file3.png
TIMEOUT 2 TIMEOUT 2
STATUS status STATUS status
EXPECTED_HASH MD5 d16778650db435bda3a8c3435c3ff5d1 EXPECTED_HASH MD5=d16778650db435bda3a8c3435c3ff5d1
) )
message(STATUS "FileDownload:10") message(STATUS "FileDownload:10")