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

Improve depend-info --dot output #1369

Merged
merged 6 commits into from
Mar 25, 2024
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
10 changes: 7 additions & 3 deletions src/vcpkg-test/dependinfo-graphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using namespace vcpkg;
namespace
{
const auto DOT_TEMPLATE =
"digraph G{{ rankdir=LR; edge [minlen=3]; overlap=false;{}empty [label=\"{} singletons...\"]; }}";
"digraph G{{ rankdir=LR; node [fontname=Sans]; edge [minlen=3]; overlap=false;\n{}\"{} singletons...\";\n}}";

const auto DGML_TEMPLATE =
"<?xml version=\"1.0\" encoding=\"utf-8\"?><DirectedGraph "
Expand All @@ -32,13 +32,17 @@ TEST_CASE ("depend-info DOT graph output", "[depend-info]")

SECTION ("single node")
{
CHECK(create_dot_as_string(single_node_dependencies()) == fmt::format(DOT_TEMPLATE, "a;a -> a;", 0));
CHECK(create_dot_as_string(single_node_dependencies()) ==
fmt::format(DOT_TEMPLATE, "\"a\";\n\"a\" -> \"a\";\n", 0));
}

SECTION ("4 nodes")
{
CHECK(create_dot_as_string(four_nodes_dependencies()) ==
fmt::format(DOT_TEMPLATE, "a;a -> b;a -> c;a -> d;b;b -> c;c;c -> d;", 1));
fmt::format(DOT_TEMPLATE,
"\"a\";\n\"a\" -> \"b\";\n\"a\" -> \"c\";\n\"a\" -> \"d\";\n\"b\";\n\"b\" -> "
"\"c\";\n\"c\";\n\"c\" -> \"d\";\n\"d\";\n",
1));
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/vcpkg/commands.depend-info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,26 +165,24 @@ namespace vcpkg
{
int empty_node_count = 0;

std::string s = "digraph G{ rankdir=LR; edge [minlen=3]; overlap=false;";
std::string s = "digraph G{ rankdir=LR; node [fontname=Sans]; edge [minlen=3]; overlap=false;\n";

for (const auto& package : depend_info)
{
fmt::format_to(std::back_inserter(s), "\"{}\";\n", package.package);
if (package.dependencies.empty())
{
empty_node_count++;
continue;
}

const std::string name = Strings::replace_all(std::string{package.package}, "-", "_");
fmt::format_to(std::back_inserter(s), "{};", name);
for (const auto& d : package.dependencies)
{
const std::string dependency_name = Strings::replace_all(std::string{d}, "-", "_");
fmt::format_to(std::back_inserter(s), "{} -> {};", name, dependency_name);
fmt::format_to(std::back_inserter(s), "\"{}\" -> \"{}\";\n", package.package, d);
}
}

fmt::format_to(std::back_inserter(s), "empty [label=\"{} singletons...\"]; }}", empty_node_count);
fmt::format_to(std::back_inserter(s), "\"{} singletons...\";\n}}", empty_node_count);
return s;
}

Expand Down
Loading