feat(daemon): clean generated build outputs on request
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 8s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 21s

This commit is contained in:
faumaray committed 2026-12-04 02:10:53 +03:00
1 parent 7fdda96553
commit cf06b427b7
13 files changed
+198 -25

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
#include <Void/Build/Config/BuildTree.hpp>
#include <Void/System/Types.hpp>
#include <filesystem>
#include <format>
#include <system_error>
namespace Void::Build::Config {
Void::Result::Result<CleanReport, Void::Result::Error>
clean_build_tree(const std::filesystem::path &build_root, bool all) {
CleanReport report;
std::error_code ec;
report.build_root_exists = std::filesystem::exists(build_root, ec);
if (!report.build_root_exists) {
return report;
}
if (all) {
std::filesystem::remove_all(build_root, ec);
if (ec) {
return std::unexpected{Void::System::make_system_error(
Void::System::map_errno_to_system_code(ec.value()),
std::format("cannot remove build root '{}': {}", build_root.string(), ec.message()),
ec.value())};
}
report.removed_entire_root = true;
report.removed_paths = 1;
return report;
}
const auto profiles_dir = build_root / "profiles";
if (std::filesystem::exists(profiles_dir, ec)) {
report.removed_paths +=
static_cast<std::size_t>(std::filesystem::remove_all(profiles_dir, ec));
if (ec) {
return std::unexpected{Void::System::make_system_error(
Void::System::map_errno_to_system_code(ec.value()),
std::format("cannot remove profile outputs '{}': {}", profiles_dir.string(),
ec.message()),
ec.value())};
}
}
const auto compdb = build_root / "compile_commands.json";
if (std::filesystem::exists(compdb, ec) || std::filesystem::is_symlink(compdb, ec)) {
std::filesystem::remove(compdb, ec);
if (ec) {
return std::unexpected{Void::System::make_system_error(
Void::System::map_errno_to_system_code(ec.value()),
std::format("cannot remove '{}': {}", compdb.string(), ec.message()), ec.value())};
}
++report.removed_paths;
}
return report;
}
} // namespace Void::Build::Config
+24
View File
@@ -2,6 +2,7 @@
#include <Void/Build.hpp>
#include <Void/Build/BootstrapConfig.hpp>
#include <Void/Build/Config/BuildTree.hpp>
#include <Void/Build/Config/Frontend.hpp>
#include <Void/Build/Editor/CompDb.hpp>
#include <Void/Build/Execution/Scheduler.hpp>
@@ -1695,6 +1696,29 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "ide_configs") {
return {ide_configs_project(options), false};
}
if (*name == "clean") {
bool all = false;
if (const auto entry = object->find("all"); entry != object->end()) {
const auto *value = std::get_if<bool>(&entry->second.value);
if (value == nullptr) {
return {error_response("\"all\" must be a boolean"), false};
}
all = *value;
}
auto cleaned = Config::clean_build_tree(options.build_root, all);
if (!cleaned) {
return {error_response(std::format("clean: {}", cleaned.error().format())), false};
}
JsonValue::Object cleaned_object;
cleaned_object.emplace("ok", JsonValue{true});
cleaned_object.emplace("op", JsonValue{std::string{"clean"}});
cleaned_object.emplace("build_root", JsonValue{options.build_root.string()});
cleaned_object.emplace("existed", JsonValue{cleaned->build_root_exists});
cleaned_object.emplace("removed_all", JsonValue{cleaned->removed_entire_root});
cleaned_object.emplace("removed_paths",
JsonValue{static_cast<std::int64_t>(cleaned->removed_paths)});
return {serialize_response(JsonValue{std::move(cleaned_object)}), false};
}
if (*name == "compdb_generations") {
const auto entry = object->find("profile");
if (entry == object->end()) {
+16 -23
View File
@@ -1,6 +1,7 @@
#include <Void/Build.hpp>
#include <Void/Build/BootstrapConfig.hpp>
#include <Void/Build/Bridge/CMakeBridge.hpp>
#include <Void/Build/Config/BuildTree.hpp>
#include <Void/Build/Config/Frontend.hpp>
#include <Void/Build/Daemon/Daemon.hpp>
#include <Void/Build/Editor/CompDb.hpp>
@@ -1566,6 +1567,8 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
Util::json_quote(opts.graph_format_arg));
} else if (sub == "info") {
request_json = R"({"op":"info"})";
} else if (sub == "clean") {
request_json = opts.force ? R"({"op":"clean","all":true})" : R"({"op":"clean"})";
} else if (sub == "editor_status") {
request_json = R"({"op":"editor_status"})";
} else if (sub == "workspace_members") {
@@ -1935,35 +1938,20 @@ struct CleanCmdOptions {
int execute_clean_command(const CleanCmdOptions &opts) {
const std::filesystem::path build_root{opts.build_arg};
std::error_code ec;
if (!std::filesystem::exists(build_root, ec)) {
auto cleaned = Config::clean_build_tree(build_root, opts.clean_all);
if (!cleaned) {
std::cerr << "vbs clean: " << cleaned.error().message() << '\n';
return 1;
}
if (!cleaned->build_root_exists) {
std::cout << "clean: nothing to remove in " << build_root.string() << '\n';
return 0;
}
if (opts.clean_all) {
Void::Log::info("Clean", "Removing entire build directory '{}'...", build_root.string());
std::filesystem::remove_all(build_root, ec);
if (ec) {
std::cerr << "vbs clean: failed removing '" << build_root.string()
<< "': " << ec.message() << '\n';
return 1;
}
if (cleaned->removed_entire_root) {
std::cout << "cleaned " << build_root.string() << " (all)\n";
return 0;
}
const auto profiles_dir = build_root / "profiles";
std::size_t removed = 0;
if (std::filesystem::exists(profiles_dir, ec)) {
Void::Log::info("Clean", "Removing profile outputs under '{}' (preserving .vbs/cache)...",
profiles_dir.string());
removed += static_cast<std::size_t>(std::filesystem::remove_all(profiles_dir, ec));
}
const auto compdb = build_root / "compile_commands.json";
if (std::filesystem::exists(compdb, ec) || std::filesystem::is_symlink(compdb, ec)) {
std::filesystem::remove(compdb, ec);
++removed;
}
std::cout << "cleaned " << removed << " path(s) in " << build_root.string()
std::cout << "cleaned " << cleaned->removed_paths << " path(s) in " << build_root.string()
<< " (preserved .vbs cache/state)\n";
return 0;
}
@@ -2704,6 +2692,11 @@ int main(int argc, char **argv) {
auto &daemon_info_cmd =
daemon_cmd.subcommand("info", "Show daemon paths, version, and host facts");
configure_daemon_common(daemon_info_cmd);
auto &daemon_clean_cmd = daemon_cmd.subcommand(
"clean", "Remove generated profile outputs (preserving the shared cache)");
configure_daemon_common(daemon_clean_cmd);
daemon_clean_cmd.flag("--all", "", "Also remove the entire build root (cache and state)",
daemon_opts.force);
auto &daemon_deps_cmd =
daemon_cmd.subcommand("deps", "Resolve and materialize dependencies via the daemon");
configure_daemon_common(daemon_deps_cmd);