feat(daemon): export the target dependency graph as DOT or JSON
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 1m6s

This commit is contained in:
faumaray committed 2026-12-03 22:30:41 +03:00
1 parent 66d2fa6a2e
commit ae57ee7666
9 files changed
+175 -4

No files matched your search

+78 -1
View File
@@ -810,6 +810,71 @@ std::string compdb_export_project(const DaemonOptions &options, std::string_view
return serialize_response(JsonValue{std::move(object)});
}
// Renders the evaluated target dependency graph as Graphviz DOT or JSON.
std::string graph_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override, std::string_view member,
std::string_view format) {
if (format != "dot" && format != "json") {
return error_response(
std::format("graph: unsupported format '{}' (expected dot or json)", format));
}
auto effective_result = resolve_member_options(options, member);
if (!effective_result) {
return error_response(std::format("graph: {}", effective_result.error()));
}
auto evaluated =
evaluate_project_graph(*effective_result, profile_name, compiler_override, "graph");
if (!evaluated) {
return error_response(evaluated.error());
}
const auto &description = evaluated->description;
const auto link_name = [](const LinkRecord &link) {
return link.kind == LinkKind::Imported ? (link.dependency + "::" + link.target)
: link.target;
};
std::string rendered;
if (format == "json") {
rendered = "{\"profile\":" + Util::json_quote(description.profile.name) + ",\"targets\":";
rendered += Util::json_array(description.targets, [](const TargetRecord &target) {
return "{\"name\":" + Util::json_quote(target.name) +
",\"kind\":" + Util::json_quote(target_kind_name(target.kind)) + ",\"links\":" +
Util::json_array(target.links,
[](const LinkRecord &link) {
return Util::json_quote(
link.kind == LinkKind::Imported
? (link.dependency + "::" + link.target)
: link.target);
}) +
'}';
});
rendered += '}';
} else {
rendered = "digraph vbs_targets {\n rankdir=LR;\n";
for (const auto &target : description.targets) {
rendered += " " + Util::json_quote(target.name) + " [label=" +
Util::json_quote(target.name + "\\n(" +
std::string{target_kind_name(target.kind)} + ")") +
"];\n";
}
for (const auto &target : description.targets) {
for (const auto &prerequisite : target.prerequisites) {
rendered += " " + Util::json_quote(target.name) + " -> " +
Util::json_quote(prerequisite) + " [style=dashed];\n";
}
for (const auto &link : target.links) {
rendered += " " + Util::json_quote(target.name) + " -> " +
Util::json_quote(link_name(link)) + ";\n";
}
}
rendered += "}\n";
}
return "{\"ok\":true,\"op\":\"graph\",\"format\":" + Util::json_quote(format) +
",\"profile\":" + Util::json_quote(description.profile.name) +
",\"graph\":" + Util::json_quote(rendered) + '}';
}
// Switches the active editor profile to an already-published compilation database.
std::string compdb_use_project(const DaemonOptions &options, std::string_view profile_name) {
auto state =
@@ -1246,7 +1311,7 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
return {serialize_response(JsonValue{std::move(object)}), false};
}
if (*name == "describe" || *name == "build" || *name == "ide_query" ||
*name == "ide_generate" || *name == "compdb_export") {
*name == "ide_generate" || *name == "compdb_export" || *name == "graph") {
std::string profile_name{"debug"};
if (const auto entry = object->find("profile"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
@@ -1290,6 +1355,18 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "compdb_export") {
return {compdb_export_project(options, profile_name, compiler_override, member), false};
}
if (*name == "graph") {
std::string graph_format{"dot"};
if (const auto entry = object->find("format"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
if (value == nullptr) {
return {error_response("\"format\" must be a string"), false};
}
graph_format = *value;
}
return {graph_project(options, profile_name, compiler_override, member, graph_format),
false};
}
if (*name == "ide_generate") {
std::string editor_name{"all"};
if (const auto entry = object->find("editor"); entry != object->end()) {