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

Add heuristic message. #504

Merged
merged 3 commits into from
Apr 14, 2022
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
8 changes: 4 additions & 4 deletions include/vcpkg/base/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ namespace vcpkg::Util
}
}

template<class Range, class Comp = std::less<typename Range::value_type>>
template<class Range, class Comp = std::less<>>
void sort(Range& cont, Comp comp = Comp())
{
using std::begin;
Expand All @@ -266,12 +266,12 @@ namespace vcpkg::Util
return std::any_of(rng.begin(), rng.end(), std::move(pred));
}

template<class Range>
Range&& sort_unique_erase(Range&& cont)
template<class Range, class Comp = std::less<>>
Range&& sort_unique_erase(Range&& cont, Comp comp = Comp())
{
using std::begin;
using std::end;
std::sort(begin(cont), end(cont));
std::sort(begin(cont), end(cont), comp);
cont.erase(std::unique(begin(cont), end(cont)), end(cont));

return std::forward<Range>(cont);
Expand Down
1 change: 1 addition & 0 deletions locales/messages.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"BuildingPackageFailed": "building {spec} failed with: {build_result}",
"BuildingPackageFailedDueToMissingDeps": "due to the following missing dependencies:",
"CMakeTargetsUsage": "{package_name} provides CMake targets:",
"CMakeTargetsUsageHueristicMessage": "# this is heuristically generated, and may not be correct",
"ChecksFailedCheck": "vcpkg has crashed; no additional details are available.",
"ChecksUnreachableCode": "unreachable code was reached",
"ChecksUpdateVcpkg": "updating vcpkg by rerunning bootstrap-vcpkg may resolve this failure.",
Expand Down
2 changes: 2 additions & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
"_BuildingPackageFailedDueToMissingDeps.comment": "Printed after BuildingPackageFailed, and followed by a list of dependencies that were missing.\n",
"CMakeTargetsUsage": "{package_name} provides CMake targets:",
"_CMakeTargetsUsage.comment": "'targets' are a CMake and Makefile concept\nexample of {package_name} is 'zlib'.\n",
"CMakeTargetsUsageHueristicMessage": "# this is heuristically generated, and may not be correct",
"_CMakeTargetsUsageHueristicMessage.comment": "Displayed after CMakeTargetsUsage; the # must be kept at the beginning so that the message remains a comment.\n",
"ChecksFailedCheck": "vcpkg has crashed; no additional details are available.",
"ChecksUnreachableCode": "unreachable code was reached",
"ChecksUpdateVcpkg": "updating vcpkg by rerunning bootstrap-vcpkg may resolve this failure.",
Expand Down
40 changes: 20 additions & 20 deletions src/vcpkg/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ namespace
(msg::package_name),
"'header' refers to C/C++ .h files",
"{package_name} is header-only and can be used from CMake via:");
DECLARE_AND_REGISTER_MESSAGE(
CMakeTargetsUsageHueristicMessage,
(),
"Displayed after CMakeTargetsUsage; the # must be kept at the beginning so that the message remains a comment.",
"# this is heuristically generated, and may not be correct");
DECLARE_AND_REGISTER_MESSAGE(CMakeTargetsUsage,
(msg::package_name),
"'targets' are a CMake and Makefile concept",
Expand Down Expand Up @@ -814,43 +819,38 @@ namespace vcpkg::Install
}
else
{
auto msg = msg::format(msgCMakeTargetsUsage, msg::package_name = bpgh.spec.name()).extract_data();
auto msg = msg::format(msgCMakeTargetsUsage, msg::package_name = bpgh.spec.name()).appendnl();
msg.append_indent().append(msgCMakeTargetsUsageHueristicMessage).appendnl();

for (auto&& library_target_pair : library_targets)
{
auto config_it = config_files.find(library_target_pair.first);
if (config_it != config_files.end())
Strings::append(msg, " find_package(", config_it->second, " CONFIG REQUIRED)\n");
else
Strings::append(msg, " find_package(", library_target_pair.first, " CONFIG REQUIRED)\n");
msg.append_indent();
msg.append_fmt_raw("find_package({} CONFIG REQUIRED)",
config_it == config_files.end() ? library_target_pair.first : config_it->second);
msg.appendnl();

auto& targets = library_target_pair.second;
Util::sort(targets, [](const std::string& l, const std::string& r) {
Util::sort_unique_erase(targets, [](const std::string& l, const std::string& r) {
if (l.size() < r.size()) return true;
if (l.size() > r.size()) return false;
return l < r;
});
targets.erase(std::unique(targets.begin(), targets.end()), targets.end());

if (targets.size() > 4)
{
auto omitted = targets.size() - 4;
library_target_pair.second.erase(targets.begin() + 4, targets.end());
msg.append(LocalizedString()
.append_indent()
.append_raw("# ")
.append(msgCmakeTargetsExcluded, msg::count = omitted)
.extract_data());
msg.append_indent().append_raw("# ").append(msgCmakeTargetsExcluded, msg::count = omitted);
}
msg.append(LocalizedString()
.append_indent()
.append_raw(fmt::format("target_link_libraries(main PRIVATE {})",
Strings::join(" ", targets)))
.appendnl()
.appendnl()
.extract_data());

msg.append_indent()
.append_fmt_raw("target_link_libraries(main PRIVATE {})", Strings::join(" ", targets))
.appendnl()
.appendnl();
}
ret.message = std::move(msg);

ret.message = msg.extract_data();
}
ret.cmake_targets_map = std::move(library_targets);
}
Expand Down