-
Notifications
You must be signed in to change notification settings - Fork 288
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
Enable multi-package depend-info
, track triplets
#1370
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<std::string, PackageDependInfo>& dependencies_map) | ||
void assign_depth_to_dependencies(const std::vector<PackageDependInfo>& packages, | ||
const std::map<std::string, PackageDependInfo&>& 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<PackageDependInfo> extract_depend_info(const std::vector<const InstallPlanAction*>& install_actions, | ||
const Triplet& default_triplet, | ||
const Triplet& host_triplet, | ||
const int max_depth) | ||
{ | ||
std::map<std::string, PackageDependInfo> 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<PackageDependInfo> out; | ||
out.reserve(install_actions.size()); | ||
|
||
std::map<std::string, PackageDependInfo&> package_dependencies; | ||
for (const InstallPlanAction* pia : install_actions) | ||
{ | ||
const InstallPlanAction& install_action = *pia; | ||
|
||
const std::vector<std::string> 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<std::string> 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<PackageDependInfo> 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; | ||
} | ||
|
||
|
@@ -237,7 +241,7 @@ namespace vcpkg | |
"https://learn.microsoft.com/vcpkg/commands/depend-info", | ||
AutocompletePriority::Public, | ||
1, | ||
1, | ||
SIZE_MAX, | ||
{DEPEND_SWITCHES, DEPEND_SETTINGS}, | ||
nullptr, | ||
}; | ||
|
@@ -415,7 +419,8 @@ namespace vcpkg | |
install_actions.push_back(&action); | ||
} | ||
|
||
std::vector<PackageDependInfo> depend_info = extract_depend_info(install_actions, strategy.max_depth); | ||
std::vector<PackageDependInfo> depend_info = | ||
extract_depend_info(install_actions, default_triplet, host_triplet, strategy.max_depth); | ||
|
||
if (strategy.format == DependInfoFormat::Dot) | ||
{ | ||
|
@@ -450,25 +455,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<std::string> printed; | ||
for (auto&& info : depend_info) | ||
{ | ||
msg::write_unlocalized_text(Color::error, fmt::format("({})", first->depth)); | ||
} | ||
if (info.depth != 0) continue; | ||
|
||
msg::write_unlocalized_text(Color::success, first->package); | ||
if (!features.empty()) | ||
{ | ||
msg::write_unlocalized_text(Color::warning, "[" + features + "]"); | ||
std::string features = Strings::join(", ", info.features); | ||
|
||
if (strategy.show_depth) | ||
{ | ||
msg::write_unlocalized_text(Color::error, "(0)"); // legacy | ||
} | ||
Comment on lines
+465
to
+468
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Entirely pointless, but kept for compatibility: output depth at top level tree (actually digraph now) nodes. |
||
|
||
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<std::string> printed; | ||
std::string prefix_buf; | ||
print_dep_tree(prefix_buf, first->package, depend_info, printed); | ||
Checks::exit_success(VCPKG_LINE_INFO); | ||
} | ||
|
||
|
@@ -487,21 +501,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"); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using emplace_back here would allow us to get rid of the calls to back below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is good enough.