From f5eb489e79b8e54dccec02cad89542596e39424d Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Fri, 4 Dec 2026 08:09:11 +0300 Subject: [PATCH] refactor(editor): share the compdb entry query with a new CLI command --- docs/agent-workflow/STATE.md | 2 + docs/agent-workflow/TASKS.md | 1 + docs/agent-workflow/VERIFICATION.md | 7 +++ docs/roadmap/21-expansion-roadmap.md | 2 +- include/Void/Build/Editor/CompDb.hpp | 25 ++++++++ src/Daemon/Daemon.cpp | 85 +++++++--------------------- src/Editor/CompDb.cpp | 79 ++++++++++++++++++++++++++ src/Main.cpp | 81 ++++++++++++++++++++++++++ tests/CliContracts.cmake | 3 + 9 files changed, 221 insertions(+), 64 deletions(-) diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index ac8aa07..dc109a3 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -263,6 +263,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 85 (`vbs lock show` & Daemon Mermaid Graphs)**: added `vbs lock show [--project DIR]` printing the pinned lock revision, contexts, and entries (package/version/source/digest/signed state). A swarm worker added a `mermaid` format to the daemon `graph` request (flowchart nodes/links/prerequisites) with test coverage (4/5 substantive tasks; the final build/help tasks were stopped and completed by the orchestrator). +- **Wave 86 (Shared Compdb Entry Query & `vbs compdb-entries`)**: extracted the bounded compile-database projection into `Editor::query_compdb_entries` (`CompdbEntry`/`CompdbQuery`/`CompdbQueryResult`), reused by the daemon `compdb_entries` request and exposed as the `vbs compdb-entries [--project] [--build-dir] [--file] [--limit]` CLI. + ## 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))**: Track C (macOS/Windows ports + dual-profile cross-compilation) and dedicated external editor plugins remain planned; Track D3 signing (SBOM, Ed25519 primitives, trusted-key enforcement/distribution, binary-variant signing/distribution) and Track E3 daemon capabilities are implemented, and Track E4 now uses `Void::Net` for the registry client/server and remote cache plus `Void::Sqlite` for the StateStore when available. diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index 2567521..943c2ac 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -89,4 +89,5 @@ Base HEAD: `fe0d1a6` | Wave 83 (Tokens revoke + deps update) | `revoke_token`/`vbs tokens revoke`; swarm added daemon `deps` `update` flag | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 9/9, Daemon suite passes, full CTest 8/8) | `include/Void/Build/Package/RegistryClient.hpp`, `src/Package/RegistryClient.cpp`, `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/{RegistryTests,DaemonTests}.cpp`, `tests/CliContracts.cmake`, docs | | Wave 84 (Install CLI options + users pagination) | `daemon install --component/--no-cmake-export/--no-native-export`; swarm paginated `/api/v1/users` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 9/9, full CTest 8/8) | `src/Main.cpp`, `registry/service/RegistryService.cpp`, `tests/{RegistryTests,CliContracts}.cmake/cpp`, docs | | Wave 85 (Lock show + mermaid graph) | `vbs lock show`; swarm added daemon `graph --format mermaid` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; CLI contract passes, Daemon suite passes, full CTest 8/8) | `src/Main.cpp`, `src/Daemon/Daemon.cpp`, `tests/{DaemonTests,CliContracts}.cpp/cmake`, docs | +| Wave 86 (Shared compdb query + CLI) | `Editor::query_compdb_entries` reused by the daemon and the new `vbs compdb-entries` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon test and CLI contract pass, full CTest 8/8) | `include/Void/Build/Editor/CompDb.hpp`, `src/Editor/CompDb.cpp`, `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/CliContracts.cmake`, docs | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] 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 cc576ae..6fadee7 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1281,6 +1281,13 @@ dev cpp-gcc -c build/pinned/bin/vbs_v1_tests --suite Daemon --no-color re-run by the orchestrator). Registry suite: **9 / 9 passed** (11.10 s). - `vbs_cli_contract` passes (8.53 s). +## Shared Compdb Query & `vbs compdb-entries` (GCC 16.2, pin `0002e74`) + +- `Editor::query_compdb_entries` now backs both the daemon `compdb_entries` request and the new + `vbs compdb-entries` CLI; `Daemon.compdb_entries_queries_published_database` still passes + (4.56 s) and the CLI contract covers `--help` and the no-database error (13.73 s). +- Full CTest: **8 / 8 passed** in 267.19 s. + ## 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 ce8ba5f..982525d 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, `vbs daemon compdb export` returns the published compilation-database path and entry count, `vbs daemon ide generate` writes the editor presets over the socket, `vbs daemon ide poll` exposes a bounded editor-extension watch protocol (changed paths, sequence, overflow state), `vbs daemon ide wait` adds a bounded long-poll variant, `vbs daemon ide status` reports the active editor selection and compdb state, watch requests can be filtered by path prefix, registry endpoints answer OPTIONS with an Allow header and expose admin stats, the daemon serves structured `doctor` diagnostics, `vbs daemon compdb use` switches the active editor profile under the selection lock, `vbs daemon graph` exports the target dependency graph (DOT/JSON/Mermaid), `vbs lock show` prints lockfile contexts, `vbs daemon test` builds and runs declared test targets, `vbs tokens list|revoke` manages registry token metadata, `vbs daemon clean` removes generated outputs while preserving the shared cache, `vbs daemon target info` reports per-target sources/outputs, `vbs daemon actions` lists bounded lowered actions, `vbs daemon pack` creates a confined deterministic source archive, `vbs daemon install` stages an install prefix (and `uninstall` removes only manifest-owned files), `vbs daemon gen-tests` generates the native test registration unit, `vbs daemon init` scaffolds confined projects, `vbs daemon compdb entries` serves bounded per-file compile arguments to editor extensions, `vbs daemon workspace members` lists workspace members cheaply, `vbs daemon ide configs` reports which editor configuration files exist, `vbs daemon compdb generations` lists editor generation history with the active selection, `vbs daemon info` exposes the daemon environment, `vbs daemon deps` resolves/materializes dependencies over the socket, registry package search, user listings, and audit queries support bounded pagination/filters, releases expose a version-specific detail endpoint, package ownership and mutable metadata are managed through audited APIs, and `RegistryClient::fetch_package_owners` reads owners. Daemon workspace support describes members, builds all members in order (or a selected member) with the shared root lock, and serves member-scoped IDE query/generate/compdb requests via `--member`. 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, `vbs daemon compdb export` returns the published compilation-database path and entry count, `vbs daemon ide generate` writes the editor presets over the socket, `vbs daemon ide poll` exposes a bounded editor-extension watch protocol (changed paths, sequence, overflow state), `vbs daemon ide wait` adds a bounded long-poll variant, `vbs daemon ide status` reports the active editor selection and compdb state, watch requests can be filtered by path prefix, registry endpoints answer OPTIONS with an Allow header and expose admin stats, the daemon serves structured `doctor` diagnostics, `vbs daemon compdb use` switches the active editor profile under the selection lock, `vbs daemon graph` exports the target dependency graph (DOT/JSON/Mermaid), `vbs lock show` prints lockfile contexts, `vbs daemon test` builds and runs declared test targets, `vbs tokens list|revoke` manages registry token metadata, `vbs daemon clean` removes generated outputs while preserving the shared cache, `vbs daemon target info` reports per-target sources/outputs, `vbs daemon actions` lists bounded lowered actions, `vbs daemon pack` creates a confined deterministic source archive, `vbs daemon install` stages an install prefix (and `uninstall` removes only manifest-owned files), `vbs daemon gen-tests` generates the native test registration unit, `vbs daemon init` scaffolds confined projects, `vbs daemon compdb entries` and `vbs compdb-entries` serve bounded per-file compile arguments to editor extensions, `vbs daemon workspace members` lists workspace members cheaply, `vbs daemon ide configs` reports which editor configuration files exist, `vbs daemon compdb generations` lists editor generation history with the active selection, `vbs daemon info` exposes the daemon environment, `vbs daemon deps` resolves/materializes dependencies over the socket, registry package search, user listings, and audit queries support bounded pagination/filters, releases expose a version-specific detail endpoint, package ownership and mutable metadata are managed through audited APIs, and `RegistryClient::fetch_package_owners` reads owners. Daemon workspace support describes members, builds all members in order (or a selected member) with the shared root lock, and serves member-scoped IDE query/generate/compdb requests via `--member`. 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** *(Sqlite and Net client adopted)* | 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. `Void::Sqlite` backs the `StateStore` when SQLite3 is present, `Void::Net` backs the `RegistryClient`, remote-cache, and registry-server HTTP transports (TLS-verifying `HttpClient`/`HttpServer`) when `Net` is enabled (`-p openssl -p boost`), keeping the pure-POSIX fallbacks. | All `vbs_registry_tests` and `vbs_core_tests` pass on both minimal and full toolchains (verified: registry 7/7 on the Net transport; default and SQLite builds 8/8). | --- diff --git a/include/Void/Build/Editor/CompDb.hpp b/include/Void/Build/Editor/CompDb.hpp index 9686ed1..0cc4504 100644 --- a/include/Void/Build/Editor/CompDb.hpp +++ b/include/Void/Build/Editor/CompDb.hpp @@ -94,6 +94,31 @@ parse_ide_kind(std::string_view name); [[nodiscard]] Void::Result::Result generate_ide_configs(const Graph::BuildGraph &graph, const IdeConfigOptions &options); +// One projected compile_commands entry (bounded) for editor/tooling queries. +struct CompdbEntry { + std::string file; + std::string directory; + std::string output; + std::string command; + std::vector arguments; +}; + +struct CompdbQuery { + std::string file_filter; // Only entries whose source path ends with this value. + std::size_t limit{50}; // Maximum returned entries (0 allowed). +}; + +struct CompdbQueryResult { + std::filesystem::path compdb_path; + std::size_t total{0}; + std::vector entries; +}; + +// Reads a JSON compilation database and projects bounded entries. Argument count and length +// are capped so a hostile or huge database cannot exhaust the caller. +[[nodiscard]] Void::Result::Result +query_compdb_entries(const std::filesystem::path &compdb_path, const CompdbQuery &query); + // Emits versioned JSON workspace/target metadata for external IDE plugins (`vbs ide query`). [[nodiscard]] std::string format_ide_query_json(const Graph::BuildGraph &graph, const std::filesystem::path &compdb_path, diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index e8c3fc0..d6ba0a0 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -1626,75 +1626,34 @@ std::string compdb_entries_project(const DaemonOptions &options, std::string_vie "compdb_entries: no compilation database is published; run compdb export first"); } - auto text = Void::FileSystem::read_file(compdb_path); - if (!text) { - return error_response(std::format("compdb_entries: {}", text.error().format())); + Editor::CompdbQuery query; + query.file_filter = file_filter; + query.limit = limit; + auto queried = Editor::query_compdb_entries(compdb_path, query); + if (!queried) { + return error_response(std::format("compdb_entries: {}", queried.error().format())); } - auto parsed = Void::Json::Strict::parse(*text); - if (!parsed) { - return error_response("compdb_entries: compilation database is not valid JSON"); - } - const auto *entries = std::get_if(&parsed->value); - if (entries == nullptr) { - return error_response("compdb_entries: compilation database must be a JSON array"); - } - JsonValue::Array matched; - std::size_t total = 0; - for (const auto &entry : *entries) { - const auto *object = std::get_if(&entry.value); - if (object == nullptr) { - continue; - } - const auto file_it = object->find("file"); - if (file_it == object->end()) { - continue; - } - const auto *file = std::get_if(&file_it->second.value); - if (file == nullptr) { - continue; - } - if (!file_filter.empty() && - !std::string_view{*file}.ends_with(std::string_view{file_filter})) { - continue; - } - ++total; - if (matched.size() >= limit) { - continue; - } + for (const auto &entry : queried->entries) { JsonValue::Object projected; - projected.emplace("file", JsonValue{*file}); - const auto copy_string = [&](std::string_view field_name) { - if (const auto it = object->find(field_name); it != object->end()) { - if (const auto *value = std::get_if(&it->second.value)) { - projected.emplace(std::string{field_name}, JsonValue{*value}); - } - } - }; - copy_string("directory"); - copy_string("output"); - copy_string("command"); - if (const auto it = object->find("arguments"); it != object->end()) { - if (const auto *arguments = std::get_if(&it->second.value)) { - JsonValue::Array bounded; - for (const auto &argument : *arguments) { - const auto *value = std::get_if(&argument.value); - if (value == nullptr) { - continue; - } - if (bounded.size() >= kMaxCompdbArguments) { - projected.emplace("arguments_truncated", JsonValue{true}); - break; - } - bounded.emplace_back(value->size() > kMaxCompdbArgumentBytes - ? value->substr(0, kMaxCompdbArgumentBytes) - : *value); - } - projected.emplace("arguments", JsonValue{std::move(bounded)}); - } + projected.emplace("file", JsonValue{entry.file}); + if (!entry.directory.empty()) { + projected.emplace("directory", JsonValue{entry.directory}); } + if (!entry.output.empty()) { + projected.emplace("output", JsonValue{entry.output}); + } + if (!entry.command.empty()) { + projected.emplace("command", JsonValue{entry.command}); + } + JsonValue::Array arguments; + for (const auto &argument : entry.arguments) { + arguments.emplace_back(argument); + } + projected.emplace("arguments", JsonValue{std::move(arguments)}); matched.emplace_back(std::move(projected)); } + const std::size_t total = queried->total; JsonValue::Object object; object.emplace("ok", JsonValue{true}); diff --git a/src/Editor/CompDb.cpp b/src/Editor/CompDb.cpp index 73638f6..35a7ea8 100644 --- a/src/Editor/CompDb.cpp +++ b/src/Editor/CompDb.cpp @@ -1043,6 +1043,85 @@ generate_ide_configs(const Graph::BuildGraph &graph, const IdeConfigOptions &opt return report; } +Void::Result::Result +query_compdb_entries(const std::filesystem::path &compdb_path, const CompdbQuery &query) { + constexpr std::size_t kMaxArguments = 256; + constexpr std::size_t kMaxArgumentBytes = 1024; + + auto text = Void::FileSystem::read_file(compdb_path); + if (!text) { + return std::unexpected{text.error()}; + } + auto parsed = Void::Json::Strict::parse(*text); + if (!parsed) { + return std::unexpected{Void::System::make_system_error( + Void::System::SystemErrorCode::io_error, + std::format("compilation database '{}' is not valid JSON", compdb_path.string()))}; + } + const auto *entries = std::get_if(&parsed->value); + if (!entries) { + return std::unexpected{Void::System::make_system_error( + Void::System::SystemErrorCode::io_error, + "compilation database must be a JSON array")}; + } + + CompdbQueryResult result; + result.compdb_path = compdb_path; + for (const auto &entry : *entries) { + const auto *object = std::get_if(&entry.value); + if (!object) { + continue; + } + const auto file_it = object->find("file"); + if (file_it == object->end()) { + continue; + } + const auto *file = std::get_if(&file_it->second.value); + if (file == nullptr) { + continue; + } + if (!query.file_filter.empty() && + !std::string_view{*file}.ends_with(query.file_filter)) { + continue; + } + ++result.total; + if (result.entries.size() >= query.limit) { + continue; + } + CompdbEntry projected; + projected.file = *file; + const auto read = [&](std::string_view name, std::string &out) { + if (const auto it = object->find(std::string{name}); it != object->end()) { + if (const auto *value = std::get_if(&it->second.value)) { + out = *value; + } + } + }; + read("directory", projected.directory); + read("output", projected.output); + read("command", projected.command); + if (const auto it = object->find("arguments"); it != object->end()) { + if (const auto *arguments = + std::get_if(&it->second.value)) { + for (const auto &argument : *arguments) { + const auto *value = std::get_if(&argument.value); + if (value == nullptr) { + continue; + } + if (projected.arguments.size() >= kMaxArguments) { + break; + } + projected.arguments.push_back(value->size() > kMaxArgumentBytes + ? value->substr(0, kMaxArgumentBytes) + : *value); + } + } + } + result.entries.push_back(std::move(projected)); + } + return result; +} + std::string format_ide_query_json(const Graph::BuildGraph &graph, const std::filesystem::path &compdb_path, const std::filesystem::path &sdk_include_dir) { diff --git a/src/Main.cpp b/src/Main.cpp index 9699282..4625af2 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1201,6 +1201,71 @@ int execute_tokens_command(std::string_view sub, const TokensCmdOptions &opts) { return 0; } +struct CompdbEntriesCmdOptions { + std::string project_arg; + std::optional build_arg; + std::optional file_arg; + std::string limit_arg{"50"}; +}; + +int execute_compdb_entries_command(const CompdbEntriesCmdOptions &opts) { + int parsed_limit = 0; + if (!Void::Str::to_int(opts.limit_arg, parsed_limit) || parsed_limit < 0 || + parsed_limit > 500) { + std::cerr << "vbs compdb entries: invalid --limit value '" << opts.limit_arg << "'\n"; + return 2; + } + const auto limit = static_cast(parsed_limit); + const std::filesystem::path project_root{opts.project_arg}; + const std::filesystem::path build_root = + opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build"); + + auto selection = Editor::read_selection_state(project_root); + if (!selection) { + std::cerr << "vbs compdb entries: " << selection.error().message() << '\n'; + return 1; + } + std::filesystem::path compdb_path; + if (selection->has_value()) { + compdb_path = (*selection)->selected_compdb_path; + } else { + std::error_code ec; + const auto root_alias = build_root / "compile_commands.json"; + if (std::filesystem::exists(root_alias, ec)) { + compdb_path = root_alias; + } + } + if (compdb_path.empty()) { + std::cerr << "vbs compdb entries: no compilation database is published; " + "run 'vbs compdb export' first\n"; + return 1; + } + + Editor::CompdbQuery query; + query.file_filter = opts.file_arg.value_or(std::string{}); + query.limit = limit; + auto queried = Editor::query_compdb_entries(compdb_path, query); + if (!queried) { + std::cerr << "vbs compdb entries: " << queried.error().message() << '\n'; + return 1; + } + std::cout << "# " << queried->compdb_path.string() << " (" << queried->total + << " matching, showing " << queried->entries.size() << ")\n"; + for (const auto &entry : queried->entries) { + std::cout << entry.file << '\n'; + if (!entry.arguments.empty()) { + std::cout << " "; + for (const auto &argument : entry.arguments) { + std::cout << argument << ' '; + } + std::cout << '\n'; + } else if (!entry.command.empty()) { + std::cout << " " << entry.command << '\n'; + } + } + return 0; +} + struct VerifyCmdOptions { std::optional name_arg; std::optional version_arg; @@ -2518,6 +2583,7 @@ int main(int argc, char **argv) { TokensCmdOptions tokens_opts; LockCmdOptions lock_opts; VerifyCmdOptions verify_opts; + CompdbEntriesCmdOptions compdb_entries_opts; publish_opts.project_arg = cwd; BridgeCmdOptions bridge_opts; GcCmdOptions gc_opts; @@ -2681,6 +2747,18 @@ int main(int argc, char **argv) { publish_binary_opts.token_env, "VBS_REGISTRY_TOKEN"); add_log_flags(publish_binary_cmd, false); // `-v` is `--version` on publish-binary. + auto &compdb_entries_root_cmd = + root.subcommand("compdb-entries", "Query bounded entries from the published compile database"); + compdb_entries_root_cmd + .option_default("--project", "-C", "Project directory", compdb_entries_opts.project_arg, + cwd) + .option("--build-dir", "-B", "Build directory", compdb_entries_opts.build_arg) + .option("--file", "", "Only entries whose source path ends with this value", + compdb_entries_opts.file_arg) + .option_default("--limit", "", "Maximum entries (0-500)", compdb_entries_opts.limit_arg, + "50"); + add_log_flags(compdb_entries_root_cmd); + auto &verify_cmd = root.subcommand("verify", "Verify a detached Ed25519 signature over a package artifact"); verify_cmd @@ -3143,6 +3221,9 @@ int main(int argc, char **argv) { if (cmd == "verify") { return execute_verify_command(verify_opts); } + if (cmd == "compdb-entries") { + return execute_compdb_entries_command(compdb_entries_opts); + } if (cmd == "bridge") { return execute_bridge_command(bridge_opts); } diff --git a/tests/CliContracts.cmake b/tests/CliContracts.cmake index 448dfc5..568f6be 100644 --- a/tests/CliContracts.cmake +++ b/tests/CliContracts.cmake @@ -53,6 +53,9 @@ check_process(0 "Usage: vbs releases list " "" releases list --help) check_process(0 "Usage: vbs tokens list " "" tokens list --help) check_process(0 "Usage: vbs lock show " "" lock show --help) check_process(0 "Usage: vbs verify " "" verify --help) +check_process(0 "Usage: vbs compdb-entries " "" compdb-entries --help) +check_process(1 "" "no compilation database is published" compdb-entries --project + "${CMAKE_CURRENT_BINARY_DIR}/no-lock-project") check_process(2 "" "--name, --version, --file, --signature, and --public-key are required" verify) check_process(1 "" "" verify --name demo --version 1.0.0 --file CMakeLists.txt --signature 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000