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

Refactor tools.cpp to homogenize system tools policies #540

Merged
merged 6 commits into from
May 19, 2022

Conversation

ras0219-msft
Copy link
Contributor

@ras0219-msft ras0219-msft commented May 13, 2022

This PR subsumes #181.

This PR refactors the internal implementation of ToolsCache to achieve several goals:

  1. Makes parsing of vcpkgTools.xml testable
  2. Remove VcpkgPaths from the ToolsCache / ToolsProvider interface by injecting the specific data required
  3. Downgrade VcpkgPaths to ToolsCache in the archives.cpp functions
  4. Localize many existing and all new messages in tools.cpp
  5. Centralize handling of VCPKG_FORCE_SYSTEM_BINARIES & VCPKG_FORCE_DOWNLOADED_BINARIES

Fetch tool without an entry

$ vcpkg fetch foo
error: Could not fetch foo. vcpkg does not have a definition of this tool for this platform.
note: updating vcpkg by rerunning bootstrap-vcpkg may resolve this failure.

Fetch missing tool with special failure instructions

$ vcpkg fetch mono
error: Could not fetch mono. You may be able to install this tool via your system package manager (sudo apt install mono-complete). Ubuntu 18.04 users may need a newer version of mono, available at https://www.mono-project.com/download/stable/.
note: updating vcpkg by rerunning bootstrap-vcpkg may resolve this failure.

Successful fetch

$ vcpkg fetch tar
/usr/bin/tar

CMake from system + VCPKG_FORCE_SYSTEM_BINARIES

$ /usr/bin/cmake --version
cmake version 3.16.3
$ VCPKG_FORCE_SYSTEM_BINARIES=1 vcpkg fetch cmake
/usr/bin/cmake
$ vcpkg fetch cmake
A suitable version of cmake was not found (required v3.22.2). Downloading portable cmake v3.22.2...
Extracting cmake...
/workspaces/vcpkg-tool/vcpkg/downloads/tools/cmake-3.22.2-linux/cmake-3.22.2-linux-x86_64/bin/cmake

/* todo: add more examples of error messages */

@ras0219-msft
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -2,6 +2,7 @@

namespace vcpkg
{
struct DownloadManager;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is the right fwd header for that?

@BillyONeal
Copy link
Member

This PR subsumes #181.

Can you add an e2e test for that? (I think setting that env var and doing vcpkg fetch git should be sufficient?)

Copy link
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great change, thank you!

src/vcpkg/export.ifw.cpp Show resolved Hide resolved
src/vcpkg/tools.cpp Show resolved Hide resolved
src/vcpkg/tools.cpp Outdated Show resolved Hide resolved
src/vcpkg/tools.cpp Outdated Show resolved Hide resolved
src/vcpkg/tools.cpp Outdated Show resolved Hide resolved
[this]() { return this->fs.read_contents(this->xml_config, VCPKG_LINE_INFO); });
}

virtual const Path& get_tool_path(StringView tool) const override { return get_tool_pathversion(tool).p; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make callers just do that now if we aren't going to special case it anymore?

It looks like before the special case was there so that we didn't have to try to get a version when we didn't know how to extract one...

Copy link
Contributor Author

@ras0219-msft ras0219-msft May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this more direct function because 90% of callers just want the path so they can proceed to build a command out of it.

If you would like to see get_tool_version() replaced with get_tool_pathversion().version while keeping get_tool_path(), I can do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make it nonvirtual and in the interface if it's to make callers prettier.

Copy link
Contributor Author

@ras0219-msft ras0219-msft May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be fine by me -- I thought you hated having any code in the interface though? Or is that only for virtual member default implementations?

src/vcpkg/tools.cpp Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants