diff options
| author | Wimok Nupphiboon <wimok.mok@gmail.com> | 2018-04-04 20:09:49 +0700 |
|---|---|---|
| committer | Wimok Nupphiboon <wimok.mok@gmail.com> | 2018-04-04 20:09:49 +0700 |
| commit | 30b56c86148babd61eb6c7c2807421bdcd8d3c13 (patch) | |
| tree | 8609cff09bc6c367cc4646d5f8aaf08f49da26f4 /toolsrc/src | |
| parent | c681f4ee840c81a508fc0e8352c9aedf66fb5eaf (diff) | |
| parent | 599aea98c9a2ef587fd9deacdfcf64dfa2e3c4db (diff) | |
| download | vcpkg-30b56c86148babd61eb6c7c2807421bdcd8d3c13.tar.gz vcpkg-30b56c86148babd61eb6c7c2807421bdcd8d3c13.zip | |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/vcpkg/build.cpp | 25 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/commands.edit.cpp | 17 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/install.cpp | 11 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/vcpkgpaths.cpp | 115 |
4 files changed, 138 insertions, 30 deletions
diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index 953e77460..79a55bd36 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<LinkageType> to_linkage_type(const std::string& str) { if (str == "dynamic") return LinkageType::DYNAMIC; @@ -322,6 +335,12 @@ namespace vcpkg::Build auto& fs = paths.get_filesystem(); const Triplet& triplet = spec.triplet(); +#if !defined(_WIN32) + // TODO: remove when vcpkg.exe is in charge for acquiring tools. Change introduced in vcpkg v0.0.107. + // bootstrap should have already downloaded ninja, but making sure it is present in case it was deleted. + vcpkg::Util::unused(paths.get_ninja_exe()); +#endif + const fs::path& cmake_exe_path = paths.get_cmake_exe(); const fs::path& git_exe_path = paths.get_git_exe(); @@ -342,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/commands.edit.cpp b/toolsrc/src/vcpkg/commands.edit.cpp index ac34a6720..6c696018e 100644 --- a/toolsrc/src/vcpkg/commands.edit.cpp +++ b/toolsrc/src/vcpkg/commands.edit.cpp @@ -34,6 +34,8 @@ namespace vcpkg::Commands::Edit static constexpr StringLiteral OPTION_BUILDTREES = "--buildtrees"; + static constexpr StringLiteral OPTION_ALL = "--all"; + static std::vector<std::string> valid_arguments(const VcpkgPaths& paths) { auto sources_and_errors = Paragraphs::try_load_all_ports(paths.get_filesystem(), paths.ports); @@ -42,9 +44,9 @@ namespace vcpkg::Commands::Edit [](auto&& pgh) -> std::string { return pgh->core_paragraph->name; }); } - static constexpr std::array<CommandSwitch, 1> EDIT_SWITCHES = {{ - {OPTION_BUILDTREES, "Open editor into the port-specific buildtree subfolder"}, - }}; + static constexpr std::array<CommandSwitch, 2> EDIT_SWITCHES = { + {{OPTION_BUILDTREES, "Open editor into the port-specific buildtree subfolder"}, + {OPTION_ALL, "Open editor into the port as well as the port-specific buildtree subfolder"}}}; const CommandStructure COMMAND_STRUCTURE = { Help::create_example_string("edit zlib"), @@ -113,6 +115,15 @@ namespace vcpkg::Commands::Edit Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute(cmd_line)); } + if (Util::Sets::contains(options.switches, OPTION_ALL)) + { + const auto buildtrees_current_dir = paths.buildtrees / port_name; + + const auto cmd_line = Strings::format( + R"("%s" "%s" "%s" -n)", env_editor.u8string(), portpath.u8string(), buildtrees_current_dir.u8string()); + Checks::exit_with_code(VCPKG_LINE_INFO, System::cmd_execute(cmd_line)); + } + const auto cmd_line = Strings::format( R"("%s" "%s" "%s" -n)", env_editor.u8string(), diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp index 1fbf6d97e..fc336d6c7 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 = "--x-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_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<CommandSetting, 1> INSTALL_SETTINGS = {{ {OPTION_XUNIT, "File to output results in XUnit format (Internal use)"}, @@ -547,16 +549,21 @@ 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<Build::UseHeadVersion>(use_head_version), Util::Enum::to_enum<Build::AllowDownloads>(!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<std::string, SourceControlFile> scf_map; diff --git a/toolsrc/src/vcpkg/vcpkgpaths.cpp b/toolsrc/src/vcpkg/vcpkgpaths.cpp index a17ffeb05..bda2c4174 100644 --- a/toolsrc/src/vcpkg/vcpkgpaths.cpp +++ b/toolsrc/src/vcpkg/vcpkgpaths.cpp @@ -18,9 +18,10 @@ namespace vcpkg struct ToolData { std::array<int, 3> required_version; - fs::path downloaded_exe_path; + fs::path exe_path; std::string url; fs::path downloaded_path; + fs::path tool_dir_path; }; static Optional<std::array<int, 3>> parse_version_string(const std::string& version_as_string) @@ -44,11 +45,11 @@ namespace vcpkg static ToolData parse_tool_data_from_xml(const VcpkgPaths& paths, const std::string& tool) { #if defined(_WIN32) - static constexpr StringLiteral OS_STRING = ""; + static constexpr StringLiteral OS_STRING = "windows"; #elif defined(__APPLE__) - static constexpr StringLiteral OS_STRING = R"(os="osx")"; + static constexpr StringLiteral OS_STRING = "osx"; #else // assume linux - static constexpr StringLiteral OS_STRING = R"(os="linux")"; + static constexpr StringLiteral OS_STRING = "linux"; #endif static const fs::path XML_PATH = paths.scripts / "vcpkgTools.xml"; @@ -79,11 +80,16 @@ namespace vcpkg Strings::format(R"###(<archiveRelativePath>([\s\S]*?)</archiveRelativePath>)###")}; static const std::regex URL_REGEX{Strings::format(R"###(<url>([\s\S]*?)</url>)###")}; - const std::regex tool_regex{ - Strings::format(R"###(<tool[\s]+name="%s"[\s]*%s>([\s\S]*?)</tool>)###", tool, OS_STRING)}; + std::regex tool_regex{ + Strings::format(R"###(<tool[\s]+name="%s"[\s]+os="%s">([\s\S]*?)<\/tool>)###", tool, OS_STRING)}; std::smatch match_tool; - const bool has_match_tool = std::regex_search(XML.cbegin(), XML.cend(), match_tool, tool_regex); + bool has_match_tool = std::regex_search(XML.cbegin(), XML.cend(), match_tool, tool_regex); + if (!has_match_tool && OS_STRING == "windows") // Legacy support. Change introduced in vcpkg v0.0.107. + { + tool_regex = Strings::format(R"###(<tool[\s]+name="%s">([\s\S]*?)<\/tool>)###", tool); + has_match_tool = std::regex_search(XML.cbegin(), XML.cend(), match_tool, tool_regex); + } Checks::check_exit(VCPKG_LINE_INFO, has_match_tool, "Could not find entry for tool [%s] in %s", @@ -109,11 +115,20 @@ namespace vcpkg tool, required_version_as_string); +// Legacy support. Change introduced in vcpkg v0.0.107. +#if !defined(_WIN32) + const std::string tool_dir_name = Strings::format("%s-%s", tool, required_version_as_string); + const fs::path tool_dir_path = paths.downloads / "tools" / tool_dir_name; + const fs::path exe_path = tool_dir_path / exe_relative_path; +#else + const fs::path tool_dir_path; const fs::path exe_path = paths.downloads / exe_relative_path; +#endif return ToolData{*required_version.get(), exe_path, url, - paths.downloads / archive_relative_path.value_or(exe_relative_path)}; + paths.downloads / archive_relative_path.value_or(exe_relative_path), + tool_dir_path}; } static bool exists_and_has_equal_or_greater_version(const std::string& version_cmd, @@ -172,6 +187,36 @@ namespace vcpkg return data_lines; } + static void extract_archive(const VcpkgPaths& paths, const fs::path& archive, const fs::path& to_path) + { + Files::Filesystem& fs = paths.get_filesystem(); + const fs::path to_path_partial = to_path.u8string() + ".partial"; + + std::error_code ec; + fs.remove_all(to_path_partial, ec); + fs.create_directories(to_path_partial, ec); + + const auto ext = archive.extension(); + if (ext == ".gz" && ext.extension() != ".tar") + { + const auto code = System::cmd_execute( + Strings::format(R"(cd '%s' && tar xzf '%s')", to_path_partial.u8string(), archive.u8string())); + Checks::check_exit(VCPKG_LINE_INFO, code == 0, "tar failed while extracting %s", archive.u8string()); + } + else if (ext == ".zip") + { + const auto code = System::cmd_execute( + Strings::format(R"(cd '%s' && unzip -qqo '%s')", to_path_partial.u8string(), archive.u8string())); + Checks::check_exit(VCPKG_LINE_INFO, code == 0, "unzip failed while extracting %s", archive.u8string()); + } + else + { + Checks::exit_with_message(VCPKG_LINE_INFO, "Unexpected archive extension: %s", ext.u8string()); + } + + fs.rename(to_path_partial, to_path); + } + static fs::path fetch_tool(const VcpkgPaths& paths, const std::string& tool_name, const ToolData& tool_data) { const auto& fs = paths.get_filesystem(); @@ -195,7 +240,7 @@ namespace vcpkg Checks::check_exit(VCPKG_LINE_INFO, tool_path.size() == 1, "Expected tool path, but got %s", output); const fs::path actual_downloaded_path = Strings::trim(std::string{tool_path.at(0)}); - const fs::path& expected_downloaded_path = tool_data.downloaded_exe_path; + const fs::path& expected_downloaded_path = tool_data.exe_path; std::error_code ec; const auto eq = fs::stdfs::equivalent(expected_downloaded_path, actual_downloaded_path, ec); Checks::check_exit(VCPKG_LINE_INFO, @@ -207,20 +252,21 @@ namespace vcpkg #else if (!fs.exists(tool_data.downloaded_path)) { - auto code = System::cmd_execute( - Strings::format(R"(curl '%s' --create-dirs --output '%s')", tool_data.url, tool_data.downloaded_path)); + auto code = System::cmd_execute(Strings::format( + R"(curl -L '%s' --create-dirs --output '%s')", tool_data.url, tool_data.downloaded_path)); Checks::check_exit(VCPKG_LINE_INFO, code == 0, "curl failed while downloading %s", tool_data.url); } - auto code = System::cmd_execute( - Strings::format(R"(cd '%s' && tar xzf '%s')", paths.downloads, tool_data.downloaded_path)); - Checks::check_exit(VCPKG_LINE_INFO, code == 0, "tar failed while extracting %s", tool_data.downloaded_path); + + System::println("Extracting %s...", tool_name); + extract_archive(paths, tool_data.downloaded_path, tool_data.tool_dir_path); + System::println("Extracting %s... done.", tool_name); Checks::check_exit(VCPKG_LINE_INFO, - fs.exists(tool_data.downloaded_exe_path), + fs.exists(tool_data.exe_path), "Expected %s to exist after extracting", - tool_data.downloaded_exe_path); + tool_data.exe_path); - return tool_data.downloaded_exe_path; + return tool_data.exe_path; #endif } @@ -229,7 +275,7 @@ namespace vcpkg std::vector<fs::path> candidate_paths; #if defined(_WIN32) || defined(__APPLE__) || defined(__linux__) static const ToolData TOOL_DATA = parse_tool_data_from_xml(paths, "cmake"); - candidate_paths.push_back(TOOL_DATA.downloaded_exe_path); + candidate_paths.push_back(TOOL_DATA.exe_path); #else static const ToolData TOOL_DATA = ToolData{{3, 5, 1}, ""}; #endif @@ -257,22 +303,40 @@ namespace vcpkg { #if defined(_WIN32) static const ToolData TOOL_DATA = parse_tool_data_from_xml(paths, "7zip"); - if (!paths.get_filesystem().exists(TOOL_DATA.downloaded_exe_path)) + if (!paths.get_filesystem().exists(TOOL_DATA.exe_path)) { return fetch_tool(paths, "7zip", TOOL_DATA); } - return TOOL_DATA.downloaded_exe_path; + return TOOL_DATA.exe_path; #else Checks::exit_with_message(VCPKG_LINE_INFO, "Cannot download 7zip for non-Windows platforms."); #endif } + static fs::path get_ninja_path(const VcpkgPaths& paths) + { + static const ToolData TOOL_DATA = parse_tool_data_from_xml(paths, "ninja"); + + std::vector<fs::path> candidate_paths; + candidate_paths.push_back(TOOL_DATA.exe_path); + const std::vector<fs::path> from_path = Files::find_from_PATH("ninja"); + candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend()); + + auto path = find_if_has_equal_or_greater_version(candidate_paths, "--version", TOOL_DATA.required_version); + if (const auto p = path.get()) + { + return *p; + } + + return fetch_tool(paths, "ninja", TOOL_DATA); + } + static fs::path get_nuget_path(const VcpkgPaths& paths) { static const ToolData TOOL_DATA = parse_tool_data_from_xml(paths, "nuget"); std::vector<fs::path> candidate_paths; - candidate_paths.push_back(TOOL_DATA.downloaded_exe_path); + candidate_paths.push_back(TOOL_DATA.exe_path); const std::vector<fs::path> from_path = Files::find_from_PATH("nuget"); candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend()); @@ -296,7 +360,7 @@ namespace vcpkg std::vector<fs::path> candidate_paths; #if defined(_WIN32) - candidate_paths.push_back(TOOL_DATA.downloaded_exe_path); + candidate_paths.push_back(TOOL_DATA.exe_path); #endif const std::vector<fs::path> from_path = Files::find_from_PATH("git"); candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend()); @@ -323,7 +387,7 @@ namespace vcpkg static const std::string VERSION_CHECK_ARGUMENTS = "--framework-version"; std::vector<fs::path> candidate_paths; - candidate_paths.push_back(TOOL_DATA.downloaded_exe_path); + candidate_paths.push_back(TOOL_DATA.exe_path); // TODO: Uncomment later // const std::vector<fs::path> from_path = Files::find_from_PATH("installerbase"); // candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend()); @@ -433,6 +497,11 @@ namespace vcpkg return this->git_exe.get_lazy([this]() { return get_git_path(*this); }); } + const fs::path& VcpkgPaths::get_ninja_exe() const + { + return this->ninja_exe.get_lazy([this]() { return get_ninja_path(*this); }); + } + const fs::path& VcpkgPaths::get_nuget_exe() const { return this->nuget_exe.get_lazy([this]() { return get_nuget_path(*this); }); |
