Skip to content

Commit

Permalink
Improve depend-info --dot output (#1369)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg0yt authored Mar 25, 2024
1 parent 086859d commit 8970d1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
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

0 comments on commit 8970d1d

Please sign in to comment.