From 876b323c5ab98cd46fe6211643d7362a3f80bf71 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sat, 23 Mar 2024 17:14:59 +0100 Subject: [PATCH 1/2] Track triplets in depend-info --- src/vcpkg/commands.depend-info.cpp | 84 +++++++++++++++++------------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/src/vcpkg/commands.depend-info.cpp b/src/vcpkg/commands.depend-info.cpp index 445ada2a8f..be3bead4b7 100644 --- a/src/vcpkg/commands.depend-info.cpp +++ b/src/vcpkg/commands.depend-info.cpp @@ -88,59 +88,63 @@ namespace {SwitchFormat, msgCmdDependInfoFormatHelp}, }; - void assign_depth_to_dependencies(const std::string& package, - const int depth, - const int max_depth, - std::map& dependencies_map) + void assign_depth_to_dependencies(const std::vector& packages, + const std::map& dependencies_map) { - auto iter = dependencies_map.find(package); - if (iter == dependencies_map.end()) + for (auto it = packages.rbegin(), last = packages.rend(); it != last; ++it) { - Checks::unreachable(VCPKG_LINE_INFO, fmt::format("Not found in dependency graph: {}", package)); - } - - PackageDependInfo& info = iter->second; - - if (depth > info.depth) - { - info.depth = depth; - if (depth < max_depth) + int new_depth = it->depth + 1; + for (const auto& dependency : it->dependencies) { - for (auto&& dependency : info.dependencies) + auto match = dependencies_map.find(dependency); + if (match == dependencies_map.end()) { - assign_depth_to_dependencies(dependency, depth + 1, max_depth, dependencies_map); + Checks::unreachable(VCPKG_LINE_INFO, fmt::format("Not found in dependency graph: {}", dependency)); + } + + if (match->second.depth < new_depth) + { + match->second.depth = new_depth; } } - } + }; } std::vector extract_depend_info(const std::vector& install_actions, + const Triplet& default_triplet, + const Triplet& host_triplet, const int max_depth) { - std::map package_dependencies; + const bool is_native = default_triplet == host_triplet; + auto decorated_name = [&default_triplet, &host_triplet, is_native](const PackageSpec& spec) -> std::string { + if (!is_native && spec.triplet() == host_triplet) return spec.name() + ":host"; + if (spec.triplet() == default_triplet) return spec.name(); + return spec.name() + ':' + spec.triplet().canonical_name(); + }; + + std::vector out; + out.reserve(install_actions.size()); + + std::map package_dependencies; for (const InstallPlanAction* pia : install_actions) { const InstallPlanAction& install_action = *pia; const std::vector dependencies = - Util::fmap(install_action.package_dependencies, [](const PackageSpec& spec) { return spec.name(); }); + Util::fmap(install_action.package_dependencies, + [&decorated_name](const PackageSpec& spec) { return decorated_name(spec); }); std::unordered_set features{install_action.feature_list.begin(), install_action.feature_list.end()}; features.erase(FeatureNameCore.to_string()); - auto& port_name = install_action.spec.name(); + out.push_back({decorated_name(install_action.spec), 0, std::move(features), std::move(dependencies)}); - PackageDependInfo info{port_name, -1, features, dependencies}; - package_dependencies.emplace(port_name, std::move(info)); + package_dependencies.emplace(out.back().package, out.back()); } - const InstallPlanAction& init = *install_actions.back(); - assign_depth_to_dependencies(init.spec.name(), 0, max_depth, package_dependencies); - - std::vector out = - Util::fmap(package_dependencies, [](auto&& kvpair) -> PackageDependInfo { return kvpair.second; }); - Util::erase_remove_if(out, [](auto&& info) { return info.depth < 0; }); + assign_depth_to_dependencies(out, package_dependencies); + Util::erase_remove_if(out, [max_depth](auto&& info) { return info.depth > max_depth; }); return out; } @@ -417,7 +421,8 @@ namespace vcpkg install_actions.push_back(&action); } - std::vector depend_info = extract_depend_info(install_actions, strategy.max_depth); + std::vector depend_info = + extract_depend_info(install_actions, default_triplet, host_triplet, strategy.max_depth); if (strategy.format == DependInfoFormat::Dot) { @@ -461,11 +466,16 @@ namespace vcpkg msg::write_unlocalized_text(Color::error, fmt::format("({})", first->depth)); } - msg::write_unlocalized_text(Color::success, first->package); + auto end_of_name = first->package.find(':'); + msg::write_unlocalized_text(Color::success, first->package.substr(0, end_of_name)); if (!features.empty()) { msg::write_unlocalized_text(Color::warning, "[" + features + "]"); } + if (end_of_name != std::string::npos) + { + msg::write_unlocalized_text(Color::success, first->package.substr(end_of_name)); + } msg::write_unlocalized_text(Color::none, "\n"); std::set printed; @@ -489,21 +499,21 @@ namespace vcpkg for (auto&& info : depend_info) { - if (info.depth < 0) - { - continue; - } - if (strategy.show_depth) { msg::write_unlocalized_text(Color::error, fmt::format("({})", info.depth)); } - msg::write_unlocalized_text(Color::success, info.package); + auto end_of_name = info.package.find(':'); + msg::write_unlocalized_text(Color::success, info.package.substr(0, end_of_name)); if (!info.features.empty()) { msg::write_unlocalized_text(Color::warning, "[" + Strings::join(", ", info.features) + "]"); } + if (end_of_name != std::string::npos) + { + msg::write_unlocalized_text(Color::success, info.package.substr(end_of_name)); + } msg::write_unlocalized_text(Color::none, ": " + Strings::join(", ", info.dependencies) + "\n"); } From 019787c20b201f32a7d21d7c91c01769b5062473 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Sun, 24 Mar 2024 17:00:03 +0100 Subject: [PATCH 2/2] Enable multi-package depend-info Enables feature control for dependencies. --- src/vcpkg/commands.depend-info.cpp | 46 ++++++++++++++++-------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/vcpkg/commands.depend-info.cpp b/src/vcpkg/commands.depend-info.cpp index be3bead4b7..2219e52d36 100644 --- a/src/vcpkg/commands.depend-info.cpp +++ b/src/vcpkg/commands.depend-info.cpp @@ -243,7 +243,7 @@ namespace vcpkg "https://learn.microsoft.com/vcpkg/commands/depend-info", AutocompletePriority::Public, 1, - 1, + SIZE_MAX, {DEPEND_SWITCHES, DEPEND_SETTINGS}, nullptr, }; @@ -457,30 +457,34 @@ namespace vcpkg if (strategy.format == DependInfoFormat::Tree) { - Util::sort(depend_info, reverse); - auto first = depend_info.begin(); - std::string features = Strings::join(", ", first->features); - - if (strategy.show_depth) + std::set printed; + for (auto&& info : depend_info) { - msg::write_unlocalized_text(Color::error, fmt::format("({})", first->depth)); - } + if (info.depth != 0) continue; - auto end_of_name = first->package.find(':'); - msg::write_unlocalized_text(Color::success, first->package.substr(0, end_of_name)); - if (!features.empty()) - { - msg::write_unlocalized_text(Color::warning, "[" + features + "]"); - } - if (end_of_name != std::string::npos) - { - msg::write_unlocalized_text(Color::success, first->package.substr(end_of_name)); + std::string features = Strings::join(", ", info.features); + + if (strategy.show_depth) + { + msg::write_unlocalized_text(Color::error, "(0)"); // legacy + } + + auto end_of_name = info.package.find(':'); + msg::write_unlocalized_text(Color::success, info.package.substr(0, end_of_name)); + if (!features.empty()) + { + msg::write_unlocalized_text(Color::warning, "[" + features + "]"); + } + if (end_of_name != std::string::npos) + { + msg::write_unlocalized_text(Color::success, info.package.substr(end_of_name)); + } + + msg::write_unlocalized_text(Color::none, "\n"); + std::string prefix_buf; + print_dep_tree(prefix_buf, info.package, depend_info, printed); } - msg::write_unlocalized_text(Color::none, "\n"); - std::set printed; - std::string prefix_buf; - print_dep_tree(prefix_buf, first->package, depend_info, printed); Checks::exit_success(VCPKG_LINE_INFO); }