#include #include #include #include #include namespace Void::Build::Config { Void::Result::Result 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::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