From 892f7052f943570eb5d8da991ace01725323c695 Mon Sep 17 00:00:00 2001 From: Jacob Zhong Date: Wed, 7 Mar 2018 17:57:16 +0800 Subject: [PATCH] [vcpkg] Add support of external downloader aria2 --- scripts/cmake/vcpkg_download_distfile.cmake | 47 +++++++++++++++---- .../cmake/vcpkg_find_acquire_program.cmake | 8 ++++ toolsrc/include/vcpkg/build.h | 8 ++++ toolsrc/src/vcpkg/build.cpp | 19 +++++++- toolsrc/src/vcpkg/install.cpp | 12 ++++- 5 files changed, 81 insertions(+), 13 deletions(-) diff --git a/scripts/cmake/vcpkg_download_distfile.cmake b/scripts/cmake/vcpkg_download_distfile.cmake index 4b111f3f021..fc61991467f 100644 --- a/scripts/cmake/vcpkg_download_distfile.cmake +++ b/scripts/cmake/vcpkg_download_distfile.cmake @@ -103,19 +103,48 @@ function(vcpkg_download_distfile VAR) endif() # Tries to download the file. - 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}") + list(GET vcpkg_download_distfile_URLS 0 SAMPLE_URL) + if(${_VCPKG_DOWNLOAD_TOOL} MATCHES "ARIA2" AND NOT ${SAMPLE_URL} MATCHES "aria2") + vcpkg_find_acquire_program("ARIA2") + message(STATUS "Downloading ${vcpkg_download_distfile_FILENAME}...") + execute_process( + 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) else() - message(STATUS "Downloading ${url}... OK") + message(STATUS "Downloading ${vcpkg_download_distfile_FILENAME}... OK") set(download_success 1) - break() 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) message(FATAL_ERROR diff --git a/scripts/cmake/vcpkg_find_acquire_program.cmake b/scripts/cmake/vcpkg_find_acquire_program.cmake index 0352b18909f..ef0e1584f68 100644 --- a/scripts/cmake/vcpkg_find_acquire_program.cmake +++ b/scripts/cmake/vcpkg_find_acquire_program.cmake @@ -25,6 +25,7 @@ ## - NASM ## - NINJA ## - YASM +## - ARIA2 (Downloader) ## ## 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(ARCHIVE "doxygen-1.8.14.windows.bin.zip") 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() message(FATAL "unknown tool ${VAR} -- unable to acquire.") endif() diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index 1c22d39d815..a86245ccf1b 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -57,12 +57,20 @@ namespace vcpkg::Build RELEASE, }; + enum class DownloadTool + { + BUILT_IN, + ARIA2, + }; + const std::string& to_string(DownloadTool tool); + struct BuildPackageOptions { UseHeadVersion use_head_version; AllowDownloads allow_downloads; CleanBuildtrees clean_buildtrees; CleanPackages clean_packages; + DownloadTool download_tool; }; enum class BuildResult diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index ab2e46aa721..79a55bd36f2 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -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 to_linkage_type(const std::string& str) { if (str == "dynamic") return LinkageType::DYNAMIC; @@ -348,8 +361,10 @@ namespace vcpkg::Build {"TARGET_TRIPLET", spec.triplet().canonical_name()}, {"VCPKG_PLATFORM_TOOLSET", toolset.version.c_str()}, {"VCPKG_USE_HEAD_VERSION", - 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"}, + 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_DOWNLOAD_TOOL", to_string(config.build_package_options.download_tool)}, {"GIT", git_exe_path}, {"FEATURES", Strings::join(";", config.feature_list)}, {"ALL_FEATURES", all_features}, diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp index 1fbf6d97e05..b998d19abb2 100644 --- a/toolsrc/src/vcpkg/install.cpp +++ b/toolsrc/src/vcpkg/install.cpp @@ -412,13 +412,15 @@ namespace vcpkg::Install static constexpr StringLiteral OPTION_RECURSE = "--recurse"; static constexpr StringLiteral OPTION_KEEP_GOING = "--keep-going"; static constexpr StringLiteral OPTION_XUNIT = "--x-xunit"; + static constexpr StringLiteral OPTION_USE_ARIA2 = "--use-aria2"; - static constexpr std::array INSTALL_SWITCHES = {{ + static constexpr std::array INSTALL_SWITCHES = {{ {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_NO_DOWNLOADS, "Do not download new sources"}, {OPTION_RECURSE, "Allow removal of packages as part of installation"}, {OPTION_KEEP_GOING, "Continue installing packages on failure"}, + {OPTION_USE_ARIA2, "Use aria2 to perform download tasks"}, }}; static constexpr std::array INSTALL_SETTINGS = {{ {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 no_downloads = Util::Sets::contains(options.switches, (OPTION_NO_DOWNLOADS)); 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)); // create the plan 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 = { Util::Enum::to_enum(use_head_version), Util::Enum::to_enum(!no_downloads), Build::CleanBuildtrees::NO, - Build::CleanPackages::NO}; + Build::CleanPackages::NO, + download_tool}; auto all_ports = Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports); std::unordered_map scf_map;