[vcpkg_download_distfile] Fix the parameter mismatch issues of some internal functions and fix the recursive call (step 3) (#20585)

* [vcpkg_download_distfile] Fix incorrect arguments in z_vcpkg_download_distfile_test_hash

* Add parameter DISABLE_AIRA2 to avoid recursive calls

* Pass SKIP_SHA512

* Update doc

* typo

* Use downloaded aria2, fix download for multiple url

* typo

* Update vcpkg min release version 2021-11-02

Co-authored-by: Billy Robert O'Neal III <bion@microsoft.com>
This commit is contained in:
Jack·Boos·Yu 2021-11-26 15:21:00 +08:00 committed by GitHub
parent f35e0e3291
commit 520b5c4851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 31 deletions

View File

@ -107,49 +107,63 @@ function(z_vcpkg_download_distfile_show_proxy_and_fail error_code)
" Otherwise, please submit an issue at https://github.com/Microsoft/vcpkg/issues\n")
endfunction()
function(z_vcpkg_download_distfile_via_aria filename urls headers sha512 skip_sha512)
vcpkg_find_acquire_program(ARIA2)
message(STATUS "Downloading ${filename}...")
function(z_vcpkg_download_distfile_via_aria)
cmake_parse_arguments(PARSE_ARGV 1 arg
"SKIP_SHA512"
"FILENAME;SHA512"
"URLS;HEADERS"
)
message(STATUS "Downloading ${arg_FILENAME}...")
vcpkg_list(SET headers_param)
foreach(header IN LISTS headers)
foreach(header IN LISTS arg_HEADERS)
vcpkg_list(APPEND headers_param "--header=${header}")
endforeach()
vcpkg_execute_in_download_mode(
COMMAND ${ARIA2} ${urls}
-o temp/${filename}
-l download-${filename}-detailed.log
${headers_param}
OUTPUT_FILE download-${filename}-out.log
ERROR_FILE download-${filename}-err.log
RESULT_VARIABLE error_code
WORKING_DIRECTORY "${DOWNLOADS}"
)
foreach(URL IN LISTS arg_URLS)
debug_message("Download Command: ${ARIA2} ${URL} -o temp/${filename} -l download-${filename}-detailed.log ${headers_param}")
vcpkg_execute_in_download_mode(
COMMAND ${ARIA2} ${URL}
-o temp/${arg_FILENAME}
-l download-${arg_FILENAME}-detailed.log
${headers_param}
OUTPUT_FILE download-${arg_FILENAME}-out.log
ERROR_FILE download-${arg_FILENAME}-err.log
RESULT_VARIABLE error_code
WORKING_DIRECTORY "${DOWNLOADS}"
)
if ("${error_code}" STREQUAL "0")
break()
endif()
endforeach()
if (NOT "${error_code}" STREQUAL "0")
message(STATUS
"Downloading ${filename}... Failed.\n"
"Downloading ${arg_FILENAME}... Failed.\n"
" Exit Code: ${error_code}\n"
" See logs for more information:\n"
" ${DOWNLOADS}/download-${filename}-out.log\n"
" ${DOWNLOADS}/download-${filename}-err.log\n"
" ${DOWNLOADS}/download-${filename}-detailed.log\n"
" ${DOWNLOADS}/download-${arg_FILENAME}-out.log\n"
" ${DOWNLOADS}/download-${arg_FILENAME}-err.log\n"
" ${DOWNLOADS}/download-${arg_FILENAME}-detailed.log\n"
)
z_vcpkg_download_distfile_show_proxy_and_fail()
z_vcpkg_download_distfile_show_proxy_and_fail("${error_code}")
else()
z_vcpkg_download_distfile_test_hash(
"${DOWNLOADS}/temp/${filename}"
"${DOWNLOADS}/temp/${arg_FILENAME}"
"downloaded file"
"The file may have been corrupted in transit."
"${arg_SHA512}"
${arg_SKIP_SHA512}
)
file(REMOVE
${DOWNLOADS}/download-${filename}-out.log
${DOWNLOADS}/download-${filename}-err.log
${DOWNLOADS}/download-${filename}-detailed.log
${DOWNLOADS}/download-${arg_FILENAME}-out.log
${DOWNLOADS}/download-${arg_FILENAME}-err.log
${DOWNLOADS}/download-${arg_FILENAME}-detailed.log
)
get_filename_component(downloaded_file_dir "${downloaded_file_path}" DIRECTORY)
file(MAKE_DIRECTORY "${downloaded_file_dir}")
file(RENAME "${DOWNLOADS}/temp/${filename}" "${downloaded_file_path}")
file(RENAME "${DOWNLOADS}/temp/${arg_FILENAME}" "${downloaded_file_path}")
endif()
endfunction()
@ -241,13 +255,16 @@ If you do not know the SHA512, add it as 'SHA512 0' and re-run this command.")
return()
endif()
if(_VCPKG_DOWNLOAD_TOOL STREQUAL "ARIA2" AND NOT EXISTS "${downloaded_file_path}")
if(NOT arg_DISABLE_ARIA2 AND _VCPKG_DOWNLOAD_TOOL STREQUAL "ARIA2" AND NOT EXISTS "${downloaded_file_path}")
if (arg_SKIP_SHA512)
set(OPTION_SKIP_SHA512 "SKIP_SHA512")
endif()
z_vcpkg_download_distfile_via_aria(
"${arg_FILENAME}"
"${arg_URLS}"
"${arg_HEADERS}"
"${arg_SHA512}"
"${arg_skip_sha512}"
"${OPTION_SKIP_SHA512}"
FILENAME "${arg_FILENAME}"
SHA512 "${arg_SHA512}"
URLS "${arg_URLS}"
HEADERS "${arg_HEADERS}"
)
set("${out_var}" "${downloaded_file_path}" PARENT_SCOPE)
return()

View File

@ -82,7 +82,7 @@ else()
set(Z_VCPKG_BACKCOMPAT_MESSAGE_LEVEL "WARNING")
endif()
vcpkg_minimum_required(VERSION 2021-08-03)
vcpkg_minimum_required(VERSION 2021-11-02)
file(TO_CMAKE_PATH "${BUILDTREES_DIR}" BUILDTREES_DIR)
file(TO_CMAKE_PATH "${PACKAGES_DIR}" PACKAGES_DIR)