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()) {
+14
View File
@@ -1470,6 +1470,7 @@ struct DaemonCmdOptions {
std::string jobs_arg{"0"};
std::string editor_arg{"all"};
std::optional<std::string> member_arg;
std::string graph_format_arg{"dot"};
std::string timeout_ms_arg{"2000"};
bool force{false};
std::string max_bytes_arg{"0"};
@@ -1551,6 +1552,10 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
}
request_json =
std::format(R"({{"op":"describe","profile":{}}})", Util::json_quote(opts.profile_arg));
} else if (sub == "graph") {
request_json = std::format(R"({{"op":"graph","profile":{},"format":{}}})",
Util::json_quote(opts.profile_arg),
Util::json_quote(opts.graph_format_arg));
} else if (sub == "editor_status") {
request_json = R"({"op":"editor_status"})";
} else if (sub == "watch_poll") {
@@ -2627,6 +2632,15 @@ int main(int argc, char **argv) {
.option_default("--profile", "-p", "Profile to export", daemon_opts.profile_arg, "debug")
.option("--member", "", "Workspace member (required for workspace roots)",
daemon_opts.member_arg);
auto &daemon_graph_cmd =
daemon_cmd.subcommand("graph", "Export the target dependency graph via the daemon");
configure_daemon_common(daemon_graph_cmd);
daemon_graph_cmd
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
.option_default("--format", "-f", "Output format (dot|json)", daemon_opts.graph_format_arg,
"dot")
.option("--member", "", "Workspace member (required for workspace roots)",
daemon_opts.member_arg);
auto &daemon_ide_cmd = daemon_cmd.subcommand("ide", "Editor/IDE metadata served by the daemon");
configure_daemon_common(daemon_ide_cmd);
auto &daemon_ide_query_cmd =