[vcpkg] Add support of external downloader aria2

This commit is contained in:
Jacob Zhong 2018-03-07 17:57:16 +08:00 committed by Alexander Karatarakis
parent adccba04db
commit 892f7052f9
5 changed files with 81 additions and 13 deletions

View File

@ -103,19 +103,48 @@ function(vcpkg_download_distfile VAR)
endif() endif()
# Tries to download the file. # Tries to download the file.
foreach(url IN LISTS vcpkg_download_distfile_URLS) list(GET vcpkg_download_distfile_URLS 0 SAMPLE_URL)
message(STATUS "Downloading ${url}...") if(${_VCPKG_DOWNLOAD_TOOL} MATCHES "ARIA2" AND NOT ${SAMPLE_URL} MATCHES "aria2")
file(DOWNLOAD ${url} "${download_file_path_part}" STATUS download_status) vcpkg_find_acquire_program("ARIA2")
list(GET download_status 0 status_code) message(STATUS "Downloading ${vcpkg_download_distfile_FILENAME}...")
if (NOT "${status_code}" STREQUAL "0") execute_process(
message(STATUS "Downloading ${url}... Failed. Status: ${download_status}") COMMAND ${ARIA2} ${vcpkg_download_distfile_URLS}
-o temp/${vcpkg_download_distfile_FILENAME}
-l download-${vcpkg_download_distfile_FILENAME}-detailed.log
OUTPUT_FILE download-${vcpkg_download_distfile_FILENAME}-out.log
ERROR_FILE download-${vcpkg_download_distfile_FILENAME}-err.log
RESULT_VARIABLE error_code
WORKING_DIRECTORY ${DOWNLOADS}
)
if (NOT "${error_code}" STREQUAL "0")
message(STATUS
"Downloading ${vcpkg_download_distfile_FILENAME}... Failed.\n"
" Exit Code: ${error_code}\n"
" See logs for more information:\n"
" ${DOWNLOADS}/download-${vcpkg_download_distfile_FILENAME}-out.log\n"
" ${DOWNLOADS}/download-${vcpkg_download_distfile_FILENAME}-err.log\n"
" ${DOWNLOADS}/download-${vcpkg_download_distfile_FILENAME}-detailed.log\n"
)
set(download_success 0) set(download_success 0)
else() else()
message(STATUS "Downloading ${url}... OK") message(STATUS "Downloading ${vcpkg_download_distfile_FILENAME}... OK")
set(download_success 1) set(download_success 1)
break()
endif() endif()
endforeach(url) else()
foreach(url IN LISTS vcpkg_download_distfile_URLS)
message(STATUS "Downloading ${url}...")
file(DOWNLOAD ${url} "${download_file_path_part}" STATUS download_status)
list(GET download_status 0 status_code)
if (NOT "${status_code}" STREQUAL "0")
message(STATUS "Downloading ${url}... Failed. Status: ${download_status}")
set(download_success 0)
else()
message(STATUS "Downloading ${url}... OK")
set(download_success 1)
break()
endif()
endforeach(url)
endif()
if (NOT download_success) if (NOT download_success)
message(FATAL_ERROR message(FATAL_ERROR

View File

@ -25,6 +25,7 @@
## - NASM ## - NASM
## - NINJA ## - NINJA
## - YASM ## - YASM
## - ARIA2 (Downloader)
## ##
## Note that msys2 has a dedicated helper function: [`vcpkg_acquire_msys`](vcpkg_acquire_msys.md). ## Note that msys2 has a dedicated helper function: [`vcpkg_acquire_msys`](vcpkg_acquire_msys.md).
## ##
@ -178,6 +179,13 @@ function(vcpkg_find_acquire_program VAR)
set(URL "http://ftp.stack.nl/pub/users/dimitri/doxygen-1.8.14.windows.bin.zip") set(URL "http://ftp.stack.nl/pub/users/dimitri/doxygen-1.8.14.windows.bin.zip")
set(ARCHIVE "doxygen-1.8.14.windows.bin.zip") set(ARCHIVE "doxygen-1.8.14.windows.bin.zip")
set(HASH d0d706501e7112045b1f401f22d12a2c8d9b7728edee9ad1975a17dff914c16494ae48a70beab6f6304643779935843f268c7afed3b9da7d403b5cb11cac0c50) set(HASH d0d706501e7112045b1f401f22d12a2c8d9b7728edee9ad1975a17dff914c16494ae48a70beab6f6304643779935843f268c7afed3b9da7d403b5cb11cac0c50)
# Download Tools
elseif(VAR MATCHES "ARIA2")
set(PROGNAME aria2c)
set(PATHS ${DOWNLOADS}/tools/aria2c/aria2-1.33.1-win-32bit-build1)
set(URL "https://github.com/aria2/aria2/releases/download/release-1.33.1/aria2-1.33.1-win-32bit-build1.zip")
set(ARCHIVE "aria2-1.33.1-win-32bit-build1.zip")
set(HASH 2456176ba3d506a07cf0cc4f61f080e1ff8cb4106426d66f354c5bb67a9a8720b5ddb26904275e61b1f623c932355f7dcde4cd17556cc895f11293c23c3a9bf3)
else() else()
message(FATAL "unknown tool ${VAR} -- unable to acquire.") message(FATAL "unknown tool ${VAR} -- unable to acquire.")
endif() endif()

View File

@ -57,12 +57,20 @@ namespace vcpkg::Build
RELEASE, RELEASE,
}; };
enum class DownloadTool
{
BUILT_IN,
ARIA2,
};
const std::string& to_string(DownloadTool tool);
struct BuildPackageOptions struct BuildPackageOptions
{ {
UseHeadVersion use_head_version; UseHeadVersion use_head_version;
AllowDownloads allow_downloads; AllowDownloads allow_downloads;
CleanBuildtrees clean_buildtrees; CleanBuildtrees clean_buildtrees;
CleanPackages clean_packages; CleanPackages clean_packages;
DownloadTool download_tool;
}; };
enum class BuildResult enum class BuildResult

View File

@ -165,6 +165,19 @@ namespace vcpkg::Build
} }
} }
static const std::string NAME_BUILD_IN_DOWNLOAD = "BUILT_IN";
static const std::string NAME_ARIA2_DOWNLOAD = "ARIA2";
const std::string& to_string(DownloadTool tool)
{
switch (tool)
{
case DownloadTool::BUILT_IN: return NAME_BUILD_IN_DOWNLOAD;
case DownloadTool::ARIA2: return NAME_ARIA2_DOWNLOAD;
default: Checks::unreachable(VCPKG_LINE_INFO);
}
}
Optional<LinkageType> to_linkage_type(const std::string& str) Optional<LinkageType> to_linkage_type(const std::string& str)
{ {
if (str == "dynamic") return LinkageType::DYNAMIC; if (str == "dynamic") return LinkageType::DYNAMIC;
@ -348,8 +361,10 @@ namespace vcpkg::Build
{"TARGET_TRIPLET", spec.triplet().canonical_name()}, {"TARGET_TRIPLET", spec.triplet().canonical_name()},
{"VCPKG_PLATFORM_TOOLSET", toolset.version.c_str()}, {"VCPKG_PLATFORM_TOOLSET", toolset.version.c_str()},
{"VCPKG_USE_HEAD_VERSION", {"VCPKG_USE_HEAD_VERSION",
Util::Enum::to_bool(config.build_package_options.use_head_version) ? "1" : "0"}, Util::Enum::to_bool(config.build_package_options.use_head_version) ? "1" : "0"},
{"_VCPKG_NO_DOWNLOADS", !Util::Enum::to_bool(config.build_package_options.allow_downloads) ? "1" : "0"}, {"_VCPKG_NO_DOWNLOADS",
!Util::Enum::to_bool(config.build_package_options.allow_downloads) ? "1" : "0"},
{"_VCPKG_DOWNLOAD_TOOL", to_string(config.build_package_options.download_tool)},
{"GIT", git_exe_path}, {"GIT", git_exe_path},
{"FEATURES", Strings::join(";", config.feature_list)}, {"FEATURES", Strings::join(";", config.feature_list)},
{"ALL_FEATURES", all_features}, {"ALL_FEATURES", all_features},

View File

@ -412,13 +412,15 @@ namespace vcpkg::Install
static constexpr StringLiteral OPTION_RECURSE = "--recurse"; static constexpr StringLiteral OPTION_RECURSE = "--recurse";
static constexpr StringLiteral OPTION_KEEP_GOING = "--keep-going"; static constexpr StringLiteral OPTION_KEEP_GOING = "--keep-going";
static constexpr StringLiteral OPTION_XUNIT = "--x-xunit"; static constexpr StringLiteral OPTION_XUNIT = "--x-xunit";
static constexpr StringLiteral OPTION_USE_ARIA2 = "--use-aria2";
static constexpr std::array<CommandSwitch, 5> INSTALL_SWITCHES = {{ static constexpr std::array<CommandSwitch, 6> INSTALL_SWITCHES = {{
{OPTION_DRY_RUN, "Do not actually build or install"}, {OPTION_DRY_RUN, "Do not actually build or install"},
{OPTION_USE_HEAD_VERSION, "Install the libraries on the command line using the latest upstream sources"}, {OPTION_USE_HEAD_VERSION, "Install the libraries on the command line using the latest upstream sources"},
{OPTION_NO_DOWNLOADS, "Do not download new sources"}, {OPTION_NO_DOWNLOADS, "Do not download new sources"},
{OPTION_RECURSE, "Allow removal of packages as part of installation"}, {OPTION_RECURSE, "Allow removal of packages as part of installation"},
{OPTION_KEEP_GOING, "Continue installing packages on failure"}, {OPTION_KEEP_GOING, "Continue installing packages on failure"},
{OPTION_USE_ARIA2, "Use aria2 to perform download tasks"},
}}; }};
static constexpr std::array<CommandSetting, 1> INSTALL_SETTINGS = {{ static constexpr std::array<CommandSetting, 1> INSTALL_SETTINGS = {{
{OPTION_XUNIT, "File to output results in XUnit format (Internal use)"}, {OPTION_XUNIT, "File to output results in XUnit format (Internal use)"},
@ -547,16 +549,22 @@ namespace vcpkg::Install
const bool use_head_version = Util::Sets::contains(options.switches, (OPTION_USE_HEAD_VERSION)); const bool use_head_version = Util::Sets::contains(options.switches, (OPTION_USE_HEAD_VERSION));
const bool no_downloads = Util::Sets::contains(options.switches, (OPTION_NO_DOWNLOADS)); const bool no_downloads = Util::Sets::contains(options.switches, (OPTION_NO_DOWNLOADS));
const bool is_recursive = Util::Sets::contains(options.switches, (OPTION_RECURSE)); const bool is_recursive = Util::Sets::contains(options.switches, (OPTION_RECURSE));
const bool use_aria2 = Util::Sets::contains(options.switches, (OPTION_USE_ARIA2));
const KeepGoing keep_going = to_keep_going(Util::Sets::contains(options.switches, OPTION_KEEP_GOING)); const KeepGoing keep_going = to_keep_going(Util::Sets::contains(options.switches, OPTION_KEEP_GOING));
// create the plan // create the plan
StatusParagraphs status_db = database_load_check(paths); StatusParagraphs status_db = database_load_check(paths);
Build::DownloadTool download_tool = Build::DownloadTool::BUILT_IN;
if (use_aria2)
download_tool = Build::DownloadTool::ARIA2;
const Build::BuildPackageOptions install_plan_options = { const Build::BuildPackageOptions install_plan_options = {
Util::Enum::to_enum<Build::UseHeadVersion>(use_head_version), Util::Enum::to_enum<Build::UseHeadVersion>(use_head_version),
Util::Enum::to_enum<Build::AllowDownloads>(!no_downloads), Util::Enum::to_enum<Build::AllowDownloads>(!no_downloads),
Build::CleanBuildtrees::NO, Build::CleanBuildtrees::NO,
Build::CleanPackages::NO}; Build::CleanPackages::NO,
download_tool};
auto all_ports = Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports); auto all_ports = Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports);
std::unordered_map<std::string, SourceControlFile> scf_map; std::unordered_map<std::string, SourceControlFile> scf_map;