feat(daemon): clean generated build outputs on request
This commit is contained in:
1 parent
7fdda96553
commit
cf06b427b7
13 files changed
+198
-25
No files matched your search
+16
-23
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user