diff --git a/README.md b/README.md index 6b2a669..722e868 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ All CLI help text (`vbs --help`, `vbs --help`, `vbs compdb --help`, `v - `vbs publish --registry URL --name PKG --version X.Y.Z [--project DIR] [--description TEXT] [--token-env VAR] [--private]` - `vbs bridge --request FILE --output FILE` (backend for [cmake/bridge/VbsDeps.cmake](cmake/bridge/VbsDeps.cmake)) - `vbs gc [--build-dir DIR] [--max-bytes N]` -- `vbs daemon run|status|stop|gc|recover|describe|build|ide query [--project DIR] [--build-dir DIR] [--socket PATH]` (Unix-socket daemon holding a warm state store and project watcher; `run` serves in the foreground, the rest are client requests) +- `vbs daemon run|status|stop|gc|recover|describe|build|ide query|compdb export [--project DIR] [--build-dir DIR] [--socket PATH]` (Unix-socket daemon holding a warm state store and project watcher; `run` serves in the foreground, the rest are client requests) - `vbs gen-tests --input FILE --output-dir DIR` - `vbs-registry --data-dir DIR --web-root DIR [--bind ADDR] [--port PORT] ...` diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 910d13e..102cce0 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -112,9 +112,13 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 23 (Track C1 Watcher Backend Split)**: - Moved the Linux `inotify` watcher implementation to `src/Watch/Linux/Watcher.cpp` with an explicit non-Linux compile-time boundary, completing the `src/Watch/Linux/` layout alongside `src/Platform/Linux/`; source lists (CMake, `build.cpp`, self-host recipe) and path references updated. +- **Wave 24 (Track E3 Daemon Compdb Export)**: + - Added the `compdb_export` daemon request (`vbs daemon compdb export [--profile]`): it lowers the project graph, publishes/selects the profile compilation database, and returns `ok`/`op=compdb`/`profile`/`compdb` path/`entries` count. Shared compdb publication helpers are reused by `ide_query`. + - Added `Daemon.compdb_export_publishes_compilation_database` and a CLI help contract; Daemon suite is now 10 cases. + ## Remaining future scope -- **Post-v1 Expansion Roadmap ([21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md) & [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md))**: Live `conan` CLI verification (Track B3), Track C (macOS/Windows ports + dual-profile cross-compilation), Track D3 signing (SBOM, Ed25519 primitives, trusted-key enforcement and distribution, binary-variant signing and distribution materialization, the #52 built-in-backend capability probe, and the VoidLibrary pin bump to `0002e74` done), Track E3 (daemon core, bounded `describe`, build-serving, dependency materialization, and daemon-backed IDE metadata done; dedicated external editor extensions remain), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned scope. +- **Post-v1 Expansion Roadmap ([21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md) & [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md))**: Live `conan` CLI verification (Track B3), Track C (macOS/Windows ports + dual-profile cross-compilation), Track D3 signing (SBOM, Ed25519 primitives, trusted-key enforcement and distribution, binary-variant signing and distribution materialization, the #52 built-in-backend capability probe, and the VoidLibrary pin bump to `0002e74` done), Track E3 (daemon core, bounded `describe`, build-serving, dependency materialization, daemon-backed IDE metadata and compdb export done; dedicated external editor extensions remain), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned scope. ## Environment notes & upstream boundaries diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index ab2f70f..69d2505 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -30,4 +30,5 @@ Base HEAD: `fe0d1a6` | Wave 21 (Track E3 daemon-backed editor metadata) | `ide_query` daemon request + `vbs daemon ide query` CLI: lowers the graph, publishes/selects the profile compdb, returns IDE query JSON (workspace/targets/compdb) over the socket | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 9/9, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | | Wave 22 (Track D3 binary-variant distribution) | `download_binary_artifact` with SHA-256 verification; `materialize_binary_variant` (signed selection, digest-validated cache reuse, download) | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; registry distribution test, full CTest 8/8) | `include/Void/Build/Package/{RegistryClient,Fetch}.hpp`, `src/Package/{RegistryClient,Fetch}.cpp`, `tests/RegistryTests.cpp`, docs | | Wave 23 (Track C1 watcher split) | Move the Linux inotify watcher to `src/Watch/Linux/Watcher.cpp` with an explicit non-Linux boundary; update source lists/docs | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; full CTest 8/8) | `src/Watch/Linux/Watcher.cpp`, `CMakeLists.txt`, `build.cpp`, `recipes/SelfHost/VbsSelfHostRecipe.cpp`, docs | +| Wave 24 (Track E3 daemon compdb export) | `compdb_export` daemon request + `vbs daemon compdb export` CLI: lowers the graph, publishes/selects the profile compdb, returns path/entry count | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 10/10, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions, E4, live `conan`) | Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) | diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index 65062d8..609ca58 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -447,6 +447,21 @@ dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure - After the formatting pass, `vbs_v1_tests --filter watcher_inotify` still **passed** (4.43 s), and `clang-format --dry-run --Werror` is clean on the moved file. +## Track E3 Daemon Compdb Export (GCC 16.2, pin `0002e74`) + +```sh +dev cpp-gcc -c cmake --build build/pinned --parallel 8 +dev cpp-gcc -c build/pinned/bin/vbs_v1_tests --suite Daemon --no-color +dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure +``` + +- Build: exit 0. Daemon suite: **10 / 10 passed** in 17.46 s, including + `compdb_export_publishes_compilation_database`: the daemon lowers the graph, publishes the + profile compilation database, and returns `ok`/`op=compdb`/`profile=debug` with an existing + `compdb` path and `entries >= 1`. +- Full CTest: **8 / 8 passed** in 201.96 s. +- `clang-format --dry-run --Werror` passes on the changed C++ files. + ## Limits and Unrun Checks 1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified). diff --git a/docs/roadmap/21-expansion-roadmap.md b/docs/roadmap/21-expansion-roadmap.md index 7c4dadb..3e4c3ef 100644 --- a/docs/roadmap/21-expansion-roadmap.md +++ b/docs/roadmap/21-expansion-roadmap.md @@ -73,7 +73,7 @@ flowchart LR | --- | --- | --- | | **E1 — Everyday CLI Ergonomics (Implemented in Wave 8)** | `vbs init` project scaffolding, `vbs clean`, `vbs doctor` environment diagnostics, `vbs graph --format dot|json`, and `vbs build --native-foreign`. | End-to-end CLI & integration tests passing in `vbs_cli_contract` and `vbs_v1_tests`. | | **E2 — Multi-Package Workspaces (`workspace.cpp`)** *(verified in Docker GCC 16)* | Shared root `vbs.lock` and `build/.vbs` CAS, `workspace_dependency()` cross-member native linking, and affected-member selection (`vbs build/test --member ` / `--changed-since `). | 3-package workspace fixture (shared library + app + tests) builds/tests with one root lockfile; member selection and `--changed-since` verified in `FullV1Tests.workspace_members_shared_build_and_member_selection`. | -| **E3 — IDE Config/Query & Background Daemon** | `build.cpp`/`build.profiles.cpp`/`build-support/` SDK entries in `compile_commands.json` + `vbs ide generate` (`.clangd`, `.vscode/`, `.zed/`, `.idea/customTargets.xml`) & `vbs ide query` (**Implemented & Verified in Wave 10**); Unix-socket daemon core holding a warm `StateStore` + project `DirectoryWatcher` with `vbs daemon run\|status\|stop\|gc\|recover\|describe` (**Implemented & Verified in Wave 14; bounded `describe` added in the post-v1 daemon follow-up**). `describe` returns a bounded graph summary (`target_names` ≤ 128 entries × 200 bytes, `profile` ≤ 128 bytes, 10 s evaluation timeout); `vbs daemon build` executes the lowered graph in-process against the warm state store with bounded `profile`/`targets`/`jobs`, including daemon-side dependency resolution/materialization and provider import via `Package::resolve_and_materialize_dependencies`; `vbs daemon ide query` publishes/selects the profile compilation database and serves the IDE workspace/target metadata JSON over the socket. Dedicated editor extensions remain planned. | `vbs ide` & `build.cpp` syntax-check verified in `FullV1Tests.cpp`; daemon lifecycle/status/gc/shutdown/describe verified in `DaemonTests.cpp` (6/6 under `dev cpp-gcc`); the live `vbs daemon describe` CLI round-trip is verified in `vbs_cli_contract`. | +| **E3 — IDE Config/Query & Background Daemon** | `build.cpp`/`build.profiles.cpp`/`build-support/` SDK entries in `compile_commands.json` + `vbs ide generate` (`.clangd`, `.vscode/`, `.zed/`, `.idea/customTargets.xml`) & `vbs ide query` (**Implemented & Verified in Wave 10**); Unix-socket daemon core holding a warm `StateStore` + project `DirectoryWatcher` with `vbs daemon run\|status\|stop\|gc\|recover\|describe` (**Implemented & Verified in Wave 14; bounded `describe` added in the post-v1 daemon follow-up**). `describe` returns a bounded graph summary (`target_names` ≤ 128 entries × 200 bytes, `profile` ≤ 128 bytes, 10 s evaluation timeout); `vbs daemon build` executes the lowered graph in-process against the warm state store with bounded `profile`/`targets`/`jobs`, including daemon-side dependency resolution/materialization and provider import via `Package::resolve_and_materialize_dependencies`; `vbs daemon ide query` publishes/selects the profile compilation database and serves the IDE workspace/target metadata JSON over the socket, and `vbs daemon compdb export` returns the published compilation-database path and entry count. Dedicated editor extensions remain planned. | `vbs ide` & `build.cpp` syntax-check verified in `FullV1Tests.cpp`; daemon lifecycle/status/gc/shutdown/describe verified in `DaemonTests.cpp` (6/6 under `dev cpp-gcc`); the live `vbs daemon describe` CLI round-trip is verified in `vbs_cli_contract`. | | **E4 — Transport & Storage Upstream Alignment** | Adopt `Void::Net` (`VL-004`/`VL-005`) and `Void::Sqlite` (`VL-011b`) when lightweight/bundled builds become available in minimal Nix toolchains, reducing VBS transport code further. | All `vbs_registry_tests` and `vbs_core_tests` pass on both minimal and full toolchains. | --- diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 0fef09f..1c50c67 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -559,6 +559,56 @@ std::string build_project(const DaemonOptions &options, State::StateStore &state return serialize_response(JsonValue{std::move(object)}); } +// Publishes the profile compilation database, selecting it when no editor selection exists. +Void::Result::Result +publish_compdb(const DaemonOptions &options, const Graph::BuildGraph &graph) { + const auto frontend = make_frontend_options(options); + const auto existing_selection = + Editor::read_selection_state(options.project_root).value_or(std::nullopt); + Editor::PublishOptions publish; + publish.project_root = options.project_root; + publish.build_root = options.build_root; + publish.update_selection = !existing_selection.has_value(); + publish.sdk_include_dir = frontend.sdk_include_dir; + auto published = Editor::publish_profile_compdb(graph, publish); + if (!published) { + return std::unexpected{published.error().format()}; + } + return *published; +} + +std::filesystem::path effective_compdb_path(const DaemonOptions &options, + const Editor::EditorGeneration &published) { + std::error_code ec; + const auto root_compdb = options.build_root / "compile_commands.json"; + return std::filesystem::exists(root_compdb, ec) ? root_compdb : published.compdb_path; +} + +// Publishes the compilation database and reports its path and entry count. +std::string compdb_export_project(const DaemonOptions &options, std::string_view profile_name, + std::optional compiler_override) { + auto evaluated = evaluate_project_graph(options, profile_name, compiler_override, "compdb"); + if (!evaluated) { + return error_response(evaluated.error()); + } + auto graph = lower_graph(options, *evaluated, {}, "compdb"); + if (!graph) { + return error_response(graph.error()); + } + auto published = publish_compdb(options, *graph); + if (!published) { + return error_response(std::format("compdb: {}", published.error())); + } + + JsonValue::Object object; + object.emplace("ok", JsonValue{true}); + object.emplace("op", JsonValue{std::string{"compdb"}}); + object.emplace("profile", JsonValue{evaluated->context.name}); + object.emplace("compdb", JsonValue{effective_compdb_path(options, *published).string()}); + object.emplace("entries", JsonValue{static_cast(published->entry_count)}); + return serialize_response(JsonValue{std::move(object)}); +} + // Publishes the profile compilation database and returns the IDE query metadata JSON. std::string ide_query_project(const DaemonOptions &options, std::string_view profile_name, std::optional compiler_override) { @@ -572,23 +622,12 @@ std::string ide_query_project(const DaemonOptions &options, std::string_view pro } const auto frontend = make_frontend_options(options); - const auto existing_selection = - Editor::read_selection_state(options.project_root).value_or(std::nullopt); - - Editor::PublishOptions publish; - publish.project_root = options.project_root; - publish.build_root = options.build_root; - publish.update_selection = !existing_selection.has_value(); - publish.sdk_include_dir = frontend.sdk_include_dir; - auto published = Editor::publish_profile_compdb(*graph, publish); + auto published = publish_compdb(options, *graph); if (!published) { - return error_response(std::format("ide_query: {}", published.error().format())); + return error_response(std::format("ide_query: {}", published.error())); } - std::error_code ec; - const auto root_compdb = options.build_root / "compile_commands.json"; - const auto compdb_path = - std::filesystem::exists(root_compdb, ec) ? root_compdb : published->compdb_path; + const auto compdb_path = effective_compdb_path(options, *published); std::string query = Editor::format_ide_query_json(*graph, compdb_path, frontend.sdk_include_dir); // The socket protocol is one JSON object per line: the embedded query must not contain @@ -756,7 +795,8 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view if (*name == "status") { return {status_response(), false}; } - if (*name == "describe" || *name == "build" || *name == "ide_query") { + if (*name == "describe" || *name == "build" || *name == "ide_query" || + *name == "compdb_export") { std::string profile_name{"debug"}; if (const auto entry = object->find("profile"); entry != object->end()) { const auto *value = std::get_if(&entry->second.value); @@ -789,6 +829,9 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view if (*name == "ide_query") { return {ide_query_project(options, profile_name, compiler_override), false}; } + if (*name == "compdb_export") { + return {compdb_export_project(options, profile_name, compiler_override), false}; + } std::vector selected_targets; if (const auto entry = object->find("targets"); entry != object->end()) { diff --git a/src/Main.cpp b/src/Main.cpp index ab0d6c8..0d740d4 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1443,6 +1443,13 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) { } request_json = std::format(R"({{"op":"describe","profile":{}}})", Util::json_quote(opts.profile_arg)); + } else if (sub == "compdb_export") { + if (opts.profile_arg.empty()) { + std::cerr << "vbs daemon compdb export: --profile must not be empty\n"; + return 2; + } + request_json = std::format(R"({{"op":"compdb_export","profile":{}}})", + Util::json_quote(opts.profile_arg)); } else if (sub == "ide_query") { if (opts.profile_arg.empty()) { std::cerr << "vbs daemon ide query: --profile must not be empty\n"; @@ -1474,9 +1481,10 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) { // Describe evaluates the whole project graph (descriptor compile, toolchain probe, lowering), // which can exceed the 2 s default; the daemon bounds evaluation at 10 s. const auto request_timeout = sub == "build" ? std::chrono::milliseconds{std::chrono::hours{1}} - : sub == "describe" ? std::chrono::milliseconds{15000} - : sub == "ide_query" ? std::chrono::milliseconds{30000} - : std::chrono::milliseconds{2000}; + : sub == "describe" ? std::chrono::milliseconds{15000} + : (sub == "ide_query" || sub == "compdb_export") + ? std::chrono::milliseconds{30000} + : std::chrono::milliseconds{2000}; auto response = Daemon::request(socket_path, request_json, request_timeout); if (!response) { std::cerr << "vbs daemon: " << response.error().message() << '\n'; @@ -2419,6 +2427,13 @@ int main(int argc, char **argv) { .option_many("--target", "-t", "Target to build", daemon_opts.targets) .option_default("--jobs", "-j", "Maximum parallel jobs (0 = hardware concurrency)", daemon_opts.jobs_arg, "0"); + auto &daemon_compdb_cmd = + daemon_cmd.subcommand("compdb", "Editor compilation database served by the daemon"); + auto &daemon_compdb_export_cmd = + daemon_compdb_cmd.subcommand("export", "Publish the profile compilation database"); + configure_daemon_common(daemon_compdb_export_cmd); + daemon_compdb_export_cmd.option_default("--profile", "-p", "Profile to export", + daemon_opts.profile_arg, "debug"); auto &daemon_ide_cmd = daemon_cmd.subcommand("ide", "Editor/IDE metadata served by the daemon"); configure_daemon_common(daemon_ide_cmd); auto &daemon_ide_query_cmd = @@ -2522,6 +2537,9 @@ int main(int argc, char **argv) { if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 && parsed.matched_command_path[2] == "query") { daemon_sub = "ide_query"; + } else if (daemon_sub == "compdb" && parsed.matched_command_path.size() > 2 && + parsed.matched_command_path[2] == "export") { + daemon_sub = "compdb_export"; } return execute_daemon_command(daemon_sub, daemon_opts); } diff --git a/tests/CliContracts.cmake b/tests/CliContracts.cmake index 46c62a8..c4d3b1a 100644 --- a/tests/CliContracts.cmake +++ b/tests/CliContracts.cmake @@ -50,6 +50,7 @@ check_process(0 "Usage: vbs daemon run " "" daemon run --help) check_process(0 "Usage: vbs daemon describe .*--profile" "" daemon describe --help) check_process(0 "Usage: vbs daemon build .*--profile.*--target.*--jobs" "" daemon build --help) check_process(0 "Usage: vbs daemon ide query .*--profile" "" daemon ide query --help) +check_process(0 "Usage: vbs daemon compdb export .*--profile" "" daemon compdb export --help) check_process(2 "" "missing subcommand for 'vbs daemon'" daemon) # Daemon-backed describe contract: start `vbs daemon run`, query the bounded graph summary over diff --git a/tests/DaemonTests.cpp b/tests/DaemonTests.cpp index e90b726..a37ac81 100644 --- a/tests/DaemonTests.cpp +++ b/tests/DaemonTests.cpp @@ -491,6 +491,56 @@ void build(Void::Build::Project &project) { Void::Testing::expect(raw->find("\"name\":\"app\"") != std::string::npos); } +VOID_TEST(Daemon, compdb_export_publishes_compilation_database) { + auto temp = Void::FileSystem::TempDir::open("vbs_daemon_"); + Void::Testing::require(temp.has_value()); + const auto options = make_options(temp->path()); + + { + std::ofstream descriptor{options.project_root / "build.cpp"}; + descriptor << R"cpp(#include + +void build(Void::Build::Project &project) { + auto app = project.executable("app"); + app.sources({"main.cpp"}); +} +)cpp"; + Void::Testing::require(descriptor.good()); + } + { + std::ofstream source{options.project_root / "main.cpp"}; + source << "int main() { return 0; }\n"; + Void::Testing::require(source.good()); + } + + auto server = Void::Build::Daemon::DaemonServer::create(options); + Void::Testing::require(server.has_value()); + const auto socket = server->socket_path(); + + Void::Result::Result run_result; + std::jthread worker{[&] { run_result = server->run(); }}; + Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5})); + + auto raw = Void::Build::Daemon::request(socket, R"({"op":"compdb_export"})", + std::chrono::seconds{120}); + auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})"); + Void::Testing::expect(shutdown.has_value()); + worker.join(); + Void::Testing::expect(run_result.has_value()); + + Void::Testing::require(raw.has_value()); + const auto parsed = parse_json(*raw); + Void::Testing::require(parsed.has_value()); + const auto *object = as_object(*parsed); + Void::Testing::require(object != nullptr); + Void::Testing::expect(bool_field(*object, "ok")); + Void::Testing::expect_eq(str_field(*object, "op"), std::string{"compdb"}); + Void::Testing::expect(int_field(*object, "entries") >= 1); + const std::string compdb = str_field(*object, "compdb"); + Void::Testing::expect(!compdb.empty()); + Void::Testing::expect(std::filesystem::exists(compdb)); +} + VOID_TEST(Daemon, describe_empty_project_reports_zero_targets) { auto temp = Void::FileSystem::TempDir::open("vbs_daemon_"); Void::Testing::require(temp.has_value());