feat(daemon): stage installs on request
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 12s

This commit is contained in:
faumaray committed 2026-12-04 03:09:41 +03:00
1 parent 3f181dc241
commit 2c602fc3e7
8 files changed
+205 -3

No files matched your search

+120 -1
View File
@@ -7,6 +7,7 @@
#include <Void/Build/Editor/CompDb.hpp>
#include <Void/Build/Execution/Scheduler.hpp>
#include <Void/Build/Graph/Graph.hpp>
#include <Void/Build/Install/Installer.hpp>
#include <Void/Build/Package/Lockfile.hpp>
#include <Void/Build/Package/Resolver.hpp>
#include <Void/Build/Package/Toml.hpp>
@@ -907,6 +908,65 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state
return serialize_response(JsonValue{std::move(object)});
}
struct InstallRequest {
std::filesystem::path prefix;
std::string package_name;
std::string package_version{"0.1.0"};
std::optional<std::string> component;
bool export_cmake{true};
bool export_native{true};
};
// Builds the project graph and stages a relocatable install into the requested prefix.
std::string install_project_op(const DaemonOptions &options, State::StateStore &state,
std::string_view profile_name,
std::optional<CompilerFamily> compiler_override,
std::string_view member, const InstallRequest &request) {
auto effective_result = resolve_member_options(options, member);
if (!effective_result) {
return error_response(std::format("install: {}", effective_result.error()));
}
const DaemonOptions &effective = *effective_result;
auto evaluated = evaluate_project_graph(effective, profile_name, compiler_override, "install");
if (!evaluated) {
return error_response(evaluated.error());
}
auto graph = lower_graph(effective, *evaluated, {}, "install");
if (!graph) {
return error_response(graph.error());
}
Execution::ExecutionOptions exec_options;
auto executed = Execution::execute_graph(*graph, state, exec_options);
if (!executed) {
return error_response(std::format("install: {}", executed.error().format()));
}
if (!executed->succeeded) {
return error_response("install: build failed before staging");
}
Install::InstallOptions install_options;
install_options.prefix = request.prefix;
install_options.package_name = request.package_name;
install_options.package_version = request.package_version;
install_options.component = request.component;
install_options.export_cmake_config = request.export_cmake;
install_options.export_native_metadata = request.export_native;
auto installed = Install::install_project(evaluated->description, *graph, install_options);
if (!installed) {
return error_response(std::format("install: {}", installed.error().format()));
}
JsonValue::Object object;
object.emplace("ok", JsonValue{true});
object.emplace("op", JsonValue{std::string{"install"}});
object.emplace("prefix", JsonValue{installed->prefix.string()});
object.emplace("manifest", JsonValue{installed->manifest_path.string()});
object.emplace("files",
JsonValue{static_cast<std::int64_t>(installed->installed_files.size())});
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) {
@@ -1959,7 +2019,7 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
}
if (*name == "describe" || *name == "build" || *name == "test" || *name == "ide_query" ||
*name == "ide_generate" || *name == "compdb_export" || *name == "graph" ||
*name == "deps" || *name == "target_info" || *name == "actions") {
*name == "deps" || *name == "target_info" || *name == "actions" || *name == "install") {
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);
@@ -2006,6 +2066,65 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "deps") {
return {deps_project(options, profile_name, compiler_override, member), false};
}
if (*name == "install") {
InstallRequest install_request;
const auto prefix_entry = object->find("prefix");
if (prefix_entry == object->end()) {
return {error_response("install requires \"prefix\""), false};
}
const auto *prefix_value = std::get_if<std::string>(&prefix_entry->second.value);
if (prefix_value == nullptr || prefix_value->empty() || prefix_value->size() > 4096) {
return {error_response("\"prefix\" must be a bounded non-empty string"), false};
}
install_request.prefix = *prefix_value;
if (const auto entry = object->find("package_name"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
if (value == nullptr || value->empty()) {
return {error_response("\"package_name\" must be a non-empty string"), false};
}
install_request.package_name = *value;
} else {
install_request.package_name =
member.empty() ? options.project_root.filename().string() : member;
if (install_request.package_name.empty()) {
install_request.package_name = "package";
}
}
if (const auto entry = object->find("package_version"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
if (value == nullptr || value->empty()) {
return {error_response("\"package_version\" must be a non-empty string"),
false};
}
install_request.package_version = *value;
}
if (const auto entry = object->find("component"); entry != object->end()) {
const auto *value = std::get_if<std::string>(&entry->second.value);
if (value == nullptr || value->empty()) {
return {error_response("\"component\" must be a non-empty string"), false};
}
install_request.component = *value;
}
const auto read_bool = [&](std::string_view key, bool &out) {
const auto entry = object->find(std::string{key});
if (entry == object->end()) {
return true;
}
const auto *value = std::get_if<bool>(&entry->second.value);
if (value == nullptr) {
return false;
}
out = *value;
return true;
};
if (!read_bool("export_cmake", install_request.export_cmake) ||
!read_bool("export_native", install_request.export_native)) {
return {error_response("export flags must be booleans"), false};
}
return {install_project_op(options, state_store, profile_name, compiler_override,
member, install_request),
false};
}
if (*name == "actions") {
std::string target_filter;
if (const auto entry = object->find("target"); entry != object->end()) {
+16
View File
@@ -1508,6 +1508,8 @@ struct DaemonCmdOptions {
std::string graph_format_arg{"dot"};
std::optional<std::string> target_arg;
std::optional<std::string> pack_output_arg;
std::optional<std::string> prefix_arg;
std::string package_version_arg{"0.1.0"};
std::optional<std::string> file_filter_arg;
std::string limit_arg{"50"};
std::string timeout_ms_arg{"2000"};
@@ -1614,6 +1616,14 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
request_json = opts.pack_output_arg ? std::format(R"({{"op":"pack","output":{}}})",
Util::json_quote(*opts.pack_output_arg))
: R"({"op":"pack"})";
} else if (sub == "install") {
if (!opts.prefix_arg || opts.prefix_arg->empty()) {
std::cerr << "vbs daemon install: --prefix is required\n";
return 2;
}
request_json = std::format(R"({{"op":"install","prefix":{},"package_version":{}}})",
Util::json_quote(*opts.prefix_arg),
Util::json_quote(opts.package_version_arg));
} else if (sub == "editor_status") {
request_json = R"({"op":"editor_status"})";
} else if (sub == "workspace_members") {
@@ -2766,6 +2776,12 @@ int main(int argc, char **argv) {
configure_daemon_common(daemon_pack_cmd);
daemon_pack_cmd.option("--output", "-o", "Archive path relative to the build root",
daemon_opts.pack_output_arg);
auto &daemon_install_cmd =
daemon_cmd.subcommand("install", "Build and stage an install prefix via the daemon");
configure_daemon_common(daemon_install_cmd);
daemon_install_cmd.option("--prefix", "", "Install prefix (required)", daemon_opts.prefix_arg)
.option_default("--package-version", "", "Exported package version",
daemon_opts.package_version_arg, "0.1.0");
auto &daemon_target_cmd =
daemon_cmd.subcommand("target", "Target metadata served by the daemon");
auto &daemon_target_info_cmd = daemon_target_cmd.subcommand(