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
71 changes: 45 additions & 26 deletions scripts/cmake/vcpkg_download_distfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ vcpkg_download_distfile(
FILENAME <output.zip>
SHA512 <5981de...>
[ALWAYS_REDOWNLOAD]
[DISABLE_AIRA2]
)
```
## Parameters
Expand Down Expand Up @@ -43,6 +44,11 @@ Avoid caching; this is a REST call or otherwise unstable.

Requires `SKIP_SHA512`.

### DISABLE_AIRA2
Avoid using aira2 to download files.

This switch is mainly used for downloading AIRA2.

### HEADERS
A list of headers to append to the download request. This can be used for authentication during a download.

Expand Down Expand Up @@ -75,7 +81,7 @@ function(z_vcpkg_download_distfile_test_hash path kind error_advice sha512 skip_
" File path: [ ${file_path} ]\n"
" Expected hash: [ ${sha512} ]\n"
" Actual hash: [ ${file_hash} ]\n"
"${CUSTOM_ERROR_ADVICE}\n")
"${error_advice}\n")
endif()
endfunction()

Expand Down Expand Up @@ -106,55 +112,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)
function(z_vcpkg_download_distfile_via_aria)
cmake_parse_arguments(PARSE_ARGV 1 arg
"SKIP_SHA512"
"FILENAME;SHA512"
"URLS;HEADERS"
)

vcpkg_find_acquire_program(ARIA2)
message(STATUS "Downloading ${filename}...")
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
COMMAND ${ARIA2} ${arg_URLS}
-o temp/${arg_FILENAME}
-l download-${arg_FILENAME}-detailed.log
${headers_param}
OUTPUT_FILE download-${filename}-out.log
ERROR_FILE download-${filename}-err.log
OUTPUT_FILE download-${arg_FILENAME}-out.log
ERROR_FILE download-${arg_FILENAME}-err.log
RESULT_VARIABLE error_code
WORKING_DIRECTORY "${DOWNLOADS}"
)
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()

function(vcpkg_download_distfile out_var)
cmake_parse_arguments(PARSE_ARGV 1 arg
"SKIP_SHA512;SILENT_EXIT;QUIET;ALWAYS_REDOWNLOAD"
"SKIP_SHA512;SILENT_EXIT;QUIET;ALWAYS_REDOWNLOAD;DISABLE_AIRA2"
"FILENAME;SHA512"
"URLS;HEADERS"
)
Expand Down Expand Up @@ -218,18 +232,23 @@ If you do not know the SHA512, add it as 'SHA512 0' and re-run this command.")
"${downloaded_file_path}"
"cached file"
"Please delete the file and retry if this file should be downloaded again."
"${arg_SHA512}"
${arg_SKIP_SHA512}
)
set("${out_var}" "${downloaded_file_path}" PARENT_SCOPE)
return()
endif()

if(_VCPKG_DOWNLOAD_TOOL STREQUAL "ARIA2" AND NOT EXISTS "${downloaded_file_path}")
if(NOT arg_DISABLE_AIRA2 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
1 change: 1 addition & 0 deletions scripts/cmake/vcpkg_find_acquire_program.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ function(vcpkg_find_acquire_program VAR)
URLS ${URL}
SHA512 ${HASH}
FILENAME ${ARCHIVE}
DISABLE_AIRA2
)

file(MAKE_DIRECTORY ${PROG_PATH_SUBDIR})
Expand Down