feat(daemon): pack the project into a confined source archive
This commit is contained in:
1 parent
3a3376c331
commit
69d1a8d274
8 files changed
+101
-2
No files matched your search
@@ -10,6 +10,7 @@
|
||||
#include <Void/Build/Package/Lockfile.hpp>
|
||||
#include <Void/Build/Package/Resolver.hpp>
|
||||
#include <Void/Build/Package/Toml.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/Provenance/TrustedKeys.hpp>
|
||||
#include <Void/Build/Provider/Provider.hpp>
|
||||
@@ -1744,6 +1745,34 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
if (*name == "ide_configs") {
|
||||
return {ide_configs_project(options), false};
|
||||
}
|
||||
if (*name == "pack") {
|
||||
std::string output_name{"package.tar"};
|
||||
if (const auto entry = object->find("output"); entry != object->end()) {
|
||||
const auto *value = std::get_if<std::string>(&entry->second.value);
|
||||
if (value == nullptr || value->empty() || value->size() > 1024) {
|
||||
return {error_response("output must be a bounded non-empty string"), false};
|
||||
}
|
||||
output_name = *value;
|
||||
}
|
||||
// Writes stay confined to the build root; absolute or escaping paths are rejected.
|
||||
std::error_code ec;
|
||||
const auto build_root = std::filesystem::weakly_canonical(options.build_root, ec);
|
||||
const auto candidate = (build_root / output_name).lexically_normal();
|
||||
if (ec || !Void::Build::Platform::path_is_within(build_root, candidate) ||
|
||||
candidate == build_root) {
|
||||
return {error_response("output must stay inside the build root"), false};
|
||||
}
|
||||
auto sha = Package::create_source_package(options.project_root, candidate, 0);
|
||||
if (!sha) {
|
||||
return {error_response(std::format("pack: {}", sha.error().format())), false};
|
||||
}
|
||||
JsonValue::Object packed;
|
||||
packed.emplace("ok", JsonValue{true});
|
||||
packed.emplace("op", JsonValue{std::string{"pack"}});
|
||||
packed.emplace("archive", JsonValue{candidate.string()});
|
||||
packed.emplace("sha256", JsonValue{*sha});
|
||||
return {serialize_response(JsonValue{std::move(packed)}), false};
|
||||
}
|
||||
if (*name == "clean") {
|
||||
bool all = false;
|
||||
if (const auto entry = object->find("all"); entry != object->end()) {
|
||||
|
||||
@@ -1479,6 +1479,7 @@ struct DaemonCmdOptions {
|
||||
std::optional<std::string> member_arg;
|
||||
std::string graph_format_arg{"dot"};
|
||||
std::optional<std::string> target_arg;
|
||||
std::optional<std::string> pack_output_arg;
|
||||
std::optional<std::string> file_filter_arg;
|
||||
std::string limit_arg{"50"};
|
||||
std::string timeout_ms_arg{"2000"};
|
||||
@@ -1578,6 +1579,10 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
request_json = R"({"op":"info"})";
|
||||
} else if (sub == "clean") {
|
||||
request_json = opts.force ? R"({"op":"clean","all":true})" : R"({"op":"clean"})";
|
||||
} else if (sub == "pack") {
|
||||
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 == "editor_status") {
|
||||
request_json = R"({"op":"editor_status"})";
|
||||
} else if (sub == "workspace_members") {
|
||||
@@ -2713,6 +2718,11 @@ int main(int argc, char **argv) {
|
||||
.option_default("--profile", "-p", "Profile to resolve", daemon_opts.profile_arg, "debug")
|
||||
.option("--member", "", "Workspace member (required for workspace roots)",
|
||||
daemon_opts.member_arg);
|
||||
auto &daemon_pack_cmd =
|
||||
daemon_cmd.subcommand("pack", "Create a deterministic source archive in the build root");
|
||||
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_target_cmd =
|
||||
daemon_cmd.subcommand("target", "Target metadata served by the daemon");
|
||||
auto &daemon_target_info_cmd = daemon_target_cmd.subcommand(
|
||||
|
||||
Reference in new issue
Block a user