feat(daemon): export the profile compilation database over the Unix socket
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 16s

This commit is contained in:
faumaray committed 2026-12-03 20:30:19 +03:00
1 parent 8001d98bb7
commit 72f4237af2
9 files changed
+153 -21

No files matched your search

+58 -15
View File
@@ -559,6 +559,56 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
return serialize_response(JsonValue{std::move(object)});
}
// Publishes the profile compilation database, selecting it when no editor selection exists.
Void::Result::Result<Editor::EditorGeneration, std::string>
publish_compdb(const DaemonOptions &options, const Graph::BuildGraph &graph) {
const auto frontend = make_frontend_options(options);
const auto existing_selection =
Editor::read_selection_state(options.project_root).value_or(std::nullopt);
Editor::PublishOptions publish;
publish.project_root = options.project_root;
publish.build_root = options.build_root;
publish.update_selection = !existing_selection.has_value();
publish.sdk_include_dir = frontend.sdk_include_dir;
auto published = Editor::publish_profile_compdb(graph, publish);
if (!published) {
return std::unexpected{published.error().format()};
}
return *published;
}
std::filesystem::path effective_compdb_path(const DaemonOptions &options,
const Editor::EditorGeneration &published) {
std::error_code ec;
const auto root_compdb = options.build_root / "compile_commands.json";
return std::filesystem::exists(root_compdb, ec) ? root_compdb : published.compdb_path;
}
// Publishes the compilation database and reports its path and entry count.
std::string compdb_export_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override) {
auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "compdb");
if (!evaluated) {
return error_response(evaluated.error());
}
auto graph = lower_graph(options, *evaluated, {}, "compdb");
if (!graph) {
return error_response(graph.error());
}
auto published = publish_compdb(options, *graph);
if (!published) {
return error_response(std::format("compdb: {}", published.error()));
}
JsonValue::Object object;
object.emplace("ok", JsonValue{true});
object.emplace("op", JsonValue{std::string{"compdb"}});
object.emplace("profile", JsonValue{evaluated->context.name});
object.emplace("compdb", JsonValue{effective_compdb_path(options, *published).string()});
object.emplace("entries", JsonValue{static_cast<std::int64_t>(published->entry_count)});
return serialize_response(JsonValue{std::move(object)});
}
// Publishes the profile compilation database and returns the IDE query metadata JSON.
std::string ide_query_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override) {
@@ -572,23 +622,12 @@ std::string ide_query_project(const DaemonOptions &options, std::string_view pro
}
const auto frontend = make_frontend_options(options);
const auto existing_selection =
Editor::read_selection_state(options.project_root).value_or(std::nullopt);
Editor::PublishOptions publish;
publish.project_root = options.project_root;
publish.build_root = options.build_root;
publish.update_selection = !existing_selection.has_value();
publish.sdk_include_dir = frontend.sdk_include_dir;
auto published = Editor::publish_profile_compdb(*graph, publish);
auto published = publish_compdb(options, *graph);
if (!published) {
return error_response(std::format("ide_query: {}", published.error().format()));
return error_response(std::format("ide_query: {}", published.error()));
}
std::error_code ec;
const auto root_compdb = options.build_root / "compile_commands.json";
const auto compdb_path =
std::filesystem::exists(root_compdb, ec) ? root_compdb : published->compdb_path;
const auto compdb_path = effective_compdb_path(options, *published);
std::string query =
Editor::format_ide_query_json(*graph, compdb_path, frontend.sdk_include_dir);
// The socket protocol is one JSON object per line: the embedded query must not contain
@@ -756,7 +795,8 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "status") {
return {status_response(), false};
}
if (*name == "describe" || *name == "build" || *name == "ide_query") {
if (*name == "describe" || *name == "build" || *name == "ide_query" ||
*name == "compdb_export") {
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);
@@ -789,6 +829,9 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "ide_query") {
return {ide_query_project(options, profile_name, compiler_override), false};
}
if (*name == "compdb_export") {
return {compdb_export_project(options, profile_name, compiler_override), false};
}
std::vector<std::string> selected_targets;
if (const auto entry = object->find("targets"); entry != object->end()) {