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

ToolCache: Better explain errors. #1099

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,11 @@ DECLARE_MESSAGE(ConflictingFiles,
(msg::path, msg::spec),
"",
"The following files are already installed in {path} and are in conflict with {spec}")
DECLARE_MESSAGE(ConsideredVersions,
(msg::version),
"",
"The following executables were considered but discarded because of the version "
"requirement of {version}:")
DECLARE_MESSAGE(ConstraintViolation, (), "", "Found a constraint violation:")
DECLARE_MESSAGE(ContinueCodeUnitInStart, (), "", "found continue code unit in start position")
DECLARE_MESSAGE(ControlAndManifestFilesPresent,
Expand Down
2 changes: 2 additions & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@
"_ConfigurationNestedDemands.comment": "An example of {json_field} is identifer.",
"ConflictingFiles": "The following files are already installed in {path} and are in conflict with {spec}",
"_ConflictingFiles.comment": "An example of {path} is /foo/bar. An example of {spec} is zlib:x64-windows.",
"ConsideredVersions": "The following executables were considered but discarded because of the version requirement of {version}:",
"_ConsideredVersions.comment": "An example of {version} is 1.3.8.",
"ConstraintViolation": "Found a constraint violation:",
"ContinueCodeUnitInStart": "found continue code unit in start position",
"ControlAndManifestFilesPresent": "Both a manifest file and a CONTROL file exist in port directory: {path}",
Expand Down
25 changes: 23 additions & 2 deletions src/vcpkg/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,16 +627,23 @@ namespace vcpkg
{
}

template<typename Func>
/**
* @param accept_version Callback that accepts a std::array<int,3> and returns true if the version is accepted
* @param log_candidate Callback that accepts Path, ExpectedL<std::string> maybe_version. Gets called on every
* existing candidate.
*/
template<typename Func, typename Func2>
Optional<PathAndVersion> find_first_with_sufficient_version(MessageSink& status_sink,
const ToolProvider& tool_provider,
const std::vector<Path>& candidates,
Func&& accept_version) const
Func&& accept_version,
const Func2& log_candidate) const
{
for (auto&& candidate : candidates)
{
if (!fs.exists(candidate, IgnoreErrors{})) continue;
auto maybe_version = tool_provider.get_version(*this, status_sink, candidate);
log_candidate(candidate, maybe_version);
const auto version = maybe_version.get();
if (!version) continue;
const auto parsed_version = parse_tool_version_string(*version);
Expand Down Expand Up @@ -772,6 +779,7 @@ namespace vcpkg
tool.add_system_paths(fs, candidate_paths);
}

std::string considered_versions;
if (ignore_version)
{
// If we are forcing the system copy (and therefore ignoring versions), take the first entry that
Expand Down Expand Up @@ -804,6 +812,12 @@ namespace vcpkg
(actual_version[0] == min_version[0] && actual_version[1] > min_version[1]) ||
(actual_version[0] == min_version[0] && actual_version[1] == min_version[1] &&
actual_version[2] >= min_version[2]);
},
[&](const auto& path, const ExpectedL<std::string>& maybe_version) {
considered_versions += fmt::format("{}: {}\n",
path,
maybe_version.has_value() ? *maybe_version.get()
: maybe_version.error().data());
});
if (const auto p = maybe_path.get())
{
Expand Down Expand Up @@ -838,6 +852,13 @@ namespace vcpkg
{
s.append_raw(' ').append(msgUnknownTool);
}
if (!considered_versions.empty())
{
s.append_raw('\n')
.append(msgConsideredVersions, msg::version = fmt::join(min_version, "."))
.append_raw('\n')
.append_raw(considered_versions);
}
Checks::msg_exit_maybe_upgrade(VCPKG_LINE_INFO, s);
}

Expand Down