Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 12 commits into from
Nov 26, 2021
77 changes: 47 additions & 30 deletions scripts/cmake/vcpkg_download_distfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -106,49 +106,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()

Expand Down Expand Up @@ -240,13 +254,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()
Expand Down
2 changes: 1 addition & 1 deletion scripts/ports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down