diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2018-07-09 06:29:37 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2018-07-09 06:29:37 -0700 |
| commit | 802f51a142283a117bf5bfa3f456493d8a20017d (patch) | |
| tree | ff5d1dc039293ca57ec75f43c5e1a61de68f52a0 /toolsrc/src | |
| parent | 1258c413f62c96aa86af3fbdaed1ef9f7408a520 (diff) | |
| download | vcpkg-802f51a142283a117bf5bfa3f456493d8a20017d.tar.gz vcpkg-802f51a142283a117bf5bfa3f456493d8a20017d.zip | |
[vcpkg] Split vcpkg::Commands::Fetch into backend and frontend
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/vcpkg.cpp | 2 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/base/archives.cpp | 5 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/build.cpp | 2 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/commands.cpp | 21 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/tools.cpp (renamed from toolsrc/src/vcpkg/commands.fetch.cpp) | 113 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg/vcpkgpaths.cpp | 8 |
6 files changed, 88 insertions, 63 deletions
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index ac2eec876..6f10c503d 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -104,7 +104,7 @@ static void inner(const VcpkgCmdArguments& args) "Error: Invalid vcpkg root directory %s: %s", vcpkg_root_dir.string(), expected_paths.error().message()); - const VcpkgPaths paths = expected_paths.value_or_exit(VCPKG_LINE_INFO); + const VcpkgPaths& paths = expected_paths.value_or_exit(VCPKG_LINE_INFO); #if defined(_WIN32) const int exit_code = _wchdir(paths.root.c_str()); diff --git a/toolsrc/src/vcpkg/base/archives.cpp b/toolsrc/src/vcpkg/base/archives.cpp index e2fca332d..5d0f1c7a1 100644 --- a/toolsrc/src/vcpkg/base/archives.cpp +++ b/toolsrc/src/vcpkg/base/archives.cpp @@ -21,7 +21,7 @@ namespace vcpkg::Archives static bool recursion_limiter_sevenzip_old = false; Checks::check_exit(VCPKG_LINE_INFO, !recursion_limiter_sevenzip_old); recursion_limiter_sevenzip_old = true; - const auto nuget_exe = Commands::Fetch::get_tool_path(paths, Tools::NUGET); + const auto nuget_exe = paths.get_tool_exe(Tools::NUGET); const std::string stem = archive.stem().u8string(); // assuming format of [name].[version in the form d.d.d] @@ -56,7 +56,7 @@ namespace vcpkg::Archives static bool recursion_limiter_sevenzip = false; Checks::check_exit(VCPKG_LINE_INFO, !recursion_limiter_sevenzip); recursion_limiter_sevenzip = true; - const auto seven_zip = Commands::Fetch::get_tool_path(paths, Tools::SEVEN_ZIP); + const auto seven_zip = paths.get_tool_exe(Tools::SEVEN_ZIP); const auto code_and_output = System::cmd_execute_and_capture_output(Strings::format( R"("%s" x "%s" -o"%s" -y)", seven_zip.u8string(), archive.u8string(), to_path_partial.u8string())); Checks::check_exit(VCPKG_LINE_INFO, @@ -103,5 +103,4 @@ namespace vcpkg::Archives to_path.u8string(), ec.message()); } - } diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index 0659b82cf..4e7a58048 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -462,7 +462,7 @@ namespace vcpkg::Build std::vector<AbiEntry> abi_tag_entries; - abi_tag_entries.emplace_back(AbiEntry{"cmake", Commands::Fetch::get_tool_version(paths, Tools::CMAKE)}); + abi_tag_entries.emplace_back(AbiEntry{"cmake", paths.get_tool_version(Tools::CMAKE)}); abi_tag_entries.insert(abi_tag_entries.end(), dependency_abis.begin(), dependency_abis.end()); diff --git a/toolsrc/src/vcpkg/commands.cpp b/toolsrc/src/vcpkg/commands.cpp index 09da57705..76fdf54fc 100644 --- a/toolsrc/src/vcpkg/commands.cpp +++ b/toolsrc/src/vcpkg/commands.cpp @@ -57,3 +57,24 @@ namespace vcpkg::Commands return t; } } + +namespace vcpkg::Commands::Fetch +{ + const CommandStructure COMMAND_STRUCTURE = { + Strings::format("The argument should be tool name\n%s", Help::create_example_string("fetch cmake")), + 1, + 1, + {}, + nullptr, + }; + + void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) + { + Util::unused(args.parse_arguments(COMMAND_STRUCTURE)); + + const std::string tool = args.command_arguments[0]; + const fs::path tool_path = paths.get_tool_exe(tool); + System::println(tool_path.u8string()); + Checks::exit_success(VCPKG_LINE_INFO); + } +} diff --git a/toolsrc/src/vcpkg/commands.fetch.cpp b/toolsrc/src/vcpkg/tools.cpp index 30aec74e5..d47035edf 100644 --- a/toolsrc/src/vcpkg/commands.fetch.cpp +++ b/toolsrc/src/vcpkg/tools.cpp @@ -1,16 +1,16 @@ #include "pch.h" +#include <vcpkg/tools.h> +#include <vcpkg/vcpkgpaths.h> + #include <vcpkg/base/archives.h> -#include <vcpkg/base/checks.h> #include <vcpkg/base/downloads.h> +#include <vcpkg/base/files.h> +#include <vcpkg/base/optional.h> #include <vcpkg/base/stringrange.h> -#include <vcpkg/base/strings.h> -#include <vcpkg/base/system.h> #include <vcpkg/base/util.h> -#include <vcpkg/commands.h> -#include <vcpkg/help.h> -namespace vcpkg::Commands::Fetch +namespace vcpkg { struct ToolData { @@ -307,7 +307,7 @@ namespace vcpkg::Commands::Fetch } /* Sample output: -1.8.2 + 1.8.2 */ return rc.output; } @@ -348,11 +348,11 @@ namespace vcpkg::Commands::Fetch } /* Sample output: -NuGet Version: 4.6.2.5055 -usage: NuGet <command> [args] [options] -Type 'NuGet help <command>' for help on a specific command. + NuGet Version: 4.6.2.5055 + usage: NuGet <command> [args] [options] + Type 'NuGet help <command>' for help on a specific command. -[[[List of available commands follows]]] + [[[List of available commands follows]]] */ return StringRange::find_exactly_one_enclosed(rc.output, "NuGet Version: ", "\n").to_string(); } @@ -393,7 +393,7 @@ Type 'NuGet help <command>' for help on a specific command. } /* Sample output: -git version 2.17.1.windows.2 + git version 2.17.1.windows.2 */ const auto idx = rc.output.find("git version "); Checks::check_exit(VCPKG_LINE_INFO, @@ -446,7 +446,7 @@ git version 2.17.1.windows.2 } /* Sample output: -3.1.81 + 3.1.81 */ return rc.output; } @@ -478,55 +478,54 @@ git version 2.17.1.windows.2 } } - fs::path get_tool_path(const VcpkgPaths& paths, const std::string& tool) + struct ToolCacheImpl final : ToolCache { - // First deal with specially handled tools. - // For these we may look in locations like Program Files, the PATH etc as well as the auto-downloaded location. - if (tool == Tools::SEVEN_ZIP) return get_7za_path(paths); - if (tool == Tools::CMAKE) return CMake::get_path(paths).path; - if (tool == Tools::GIT) return Git::get_path(paths).path; - if (tool == Tools::NINJA) return Ninja::get_path(paths).path; - if (tool == Tools::NUGET) return Nuget::get_path(paths).path; - if (tool == Tools::IFW_INSTALLER_BASE) return IfwInstallerBase::get_path(paths).path; - if (tool == Tools::IFW_BINARYCREATOR) - return IfwInstallerBase::get_path(paths).path.parent_path() / "binarycreator.exe"; - if (tool == Tools::IFW_REPOGEN) return IfwInstallerBase::get_path(paths).path.parent_path() / "repogen.exe"; - - // For other tools, we simply always auto-download them. - const ToolData tool_data = parse_tool_data_from_xml(paths, tool); - if (paths.get_filesystem().exists(tool_data.exe_path)) + vcpkg::Cache<std::string, fs::path> path_only_cache; + vcpkg::Cache<std::string, PathAndVersion> path_version_cache; + + virtual const fs::path& get_tool_path(const VcpkgPaths& paths, const std::string& tool) const override { - return tool_data.exe_path; + return path_only_cache.get_lazy(tool, [&]() { + // First deal with specially handled tools. + // For these we may look in locations like Program Files, the PATH etc as well as the auto-downloaded + // location. + if (tool == Tools::SEVEN_ZIP) return get_7za_path(paths); + if (tool == Tools::CMAKE || tool == Tools::GIT || tool == Tools::NINJA || tool == Tools::NUGET || + tool == Tools::IFW_INSTALLER_BASE) + return get_tool_pathversion(paths, tool).path; + if (tool == Tools::IFW_BINARYCREATOR) + return IfwInstallerBase::get_path(paths).path.parent_path() / "binarycreator.exe"; + if (tool == Tools::IFW_REPOGEN) + return IfwInstallerBase::get_path(paths).path.parent_path() / "repogen.exe"; + + // For other tools, we simply always auto-download them. + const ToolData tool_data = parse_tool_data_from_xml(paths, tool); + if (paths.get_filesystem().exists(tool_data.exe_path)) + { + return tool_data.exe_path; + } + return fetch_tool(paths, tool, tool_data); + }); } - return fetch_tool(paths, tool, tool_data); - } - - std::string get_tool_version(const VcpkgPaths& paths, const std::string& tool) - { - if (tool == Tools::CMAKE) return CMake::get_path(paths).version; - if (tool == Tools::GIT) return Git::get_path(paths).version; - if (tool == Tools::NINJA) return Ninja::get_path(paths).version; - if (tool == Tools::NUGET) return Nuget::get_path(paths).version; - if (tool == Tools::IFW_INSTALLER_BASE) return IfwInstallerBase::get_path(paths).version; - Checks::exit_with_message(VCPKG_LINE_INFO, "Finding version for %s is not implemented yet.", tool); - } + const PathAndVersion& get_tool_pathversion(const VcpkgPaths& paths, const std::string& tool) const + { + return path_version_cache.get_lazy(tool, [&]() { + if (tool == Tools::CMAKE) return CMake::get_path(paths); + if (tool == Tools::GIT) return Git::get_path(paths); + if (tool == Tools::NINJA) return Ninja::get_path(paths); + if (tool == Tools::NUGET) return Nuget::get_path(paths); + if (tool == Tools::IFW_INSTALLER_BASE) return IfwInstallerBase::get_path(paths); + + Checks::exit_with_message(VCPKG_LINE_INFO, "Finding version for %s is not implemented yet.", tool); + }); + } - const CommandStructure COMMAND_STRUCTURE = { - Strings::format("The argument should be tool name\n%s", Help::create_example_string("fetch cmake")), - 1, - 1, - {}, - nullptr, + virtual const std::string& get_tool_version(const VcpkgPaths& paths, const std::string& tool) const override + { + return get_tool_pathversion(paths, tool).version; + } }; - void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) - { - Util::unused(args.parse_arguments(COMMAND_STRUCTURE)); - - const std::string tool = args.command_arguments[0]; - const fs::path tool_path = get_tool_path(paths, tool); - System::println(tool_path.u8string()); - Checks::exit_success(VCPKG_LINE_INFO); - } + std::unique_ptr<ToolCache> get_tool_cache() { return std::make_unique<ToolCacheImpl>(); } } diff --git a/toolsrc/src/vcpkg/vcpkgpaths.cpp b/toolsrc/src/vcpkg/vcpkgpaths.cpp index f98e51764..748fd20e0 100644 --- a/toolsrc/src/vcpkg/vcpkgpaths.cpp +++ b/toolsrc/src/vcpkg/vcpkgpaths.cpp @@ -93,7 +93,13 @@ namespace vcpkg const fs::path& VcpkgPaths::get_tool_exe(const std::string& tool) const { - return this->tool_paths.get_lazy(tool, [&]() { return Commands::Fetch::get_tool_path(*this, tool); }); + if (!m_tool_cache) m_tool_cache = get_tool_cache(); + return m_tool_cache->get_tool_path(*this, tool); + } + const std::string& VcpkgPaths::get_tool_version(const std::string& tool) const + { + if (!m_tool_cache) m_tool_cache = get_tool_cache(); + return m_tool_cache->get_tool_version(*this, tool); } const Toolset& VcpkgPaths::get_toolset(const Build::PreBuildInfo& prebuildinfo) const |
