feat(daemon): stage installs on request
This commit is contained in:
1 parent
3f181dc241
commit
2c602fc3e7
8 files changed
+205
-3
No files matched your search
+120
-1
@@ -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()) {
|
||||
|
||||
Reference in new issue
Block a user