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