feat: migration breadth, project templates, preset export, IDE/registry polish
VoidBuildSystem CI / 1 · Requirements (push) Successful in 3s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 2m11s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m33s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 2m44s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 4m16s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 4m37s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m29s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 24s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 1m52s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 20s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 1m57s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Successful in 6m47s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Successful in 7m4s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
VoidBuildSystem CI / 1 · Requirements (push) Successful in 3s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 2m11s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m33s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 2m44s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 4m16s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 4m37s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m29s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 24s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 1m52s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 20s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 1m57s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Successful in 6m47s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Successful in 7m4s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
- vbs migrate --from meson: bounded meson.build importer (project, variable assignments, files()/include_directories(), executable/static_library/ shared_library/library with link_with, include_directories, dependencies, install/install_dir) rendering the same build.cpp scaffold; everything untranslated is reported as a note. - vbs init --template app|library|header-only|shared; every template scaffolds a project whose own test passes. - vbs presets --export FILE: writes VBS profiles as CMake configure presets (round-trips through the CMakePresets importer). - vbs ide generate also writes JetBrains run configurations per target. - VBS_HOST_CXX_FLAGS/VBS_HOST_LDFLAGS instrument the compiled build descriptor (the CI sanitizer lane sets them). - The registry queue counts lease attempts and abandons an action after 5 attempts into a dead-letter list instead of leasing it forever. - CI: coverage lane (lcov report), sanitizer descriptor flags; docs ledger brought up to date (STATE/TASKS/superiority roadmap). Verified: the new FullV1Tests and RegistryTests cases pass and the full CTest suite passes 8/8.
This commit is contained in:
1 parent
9da1387031
commit
fe453bd601
17 files changed
+898
-54
No files matched your search
+23
-1
@@ -88,6 +88,10 @@ jobs:
|
||||
build_type: Debug
|
||||
cxx_flags: "-fsanitize=address,undefined -fno-omit-frame-pointer"
|
||||
linker_flags: "-fsanitize=address,undefined"
|
||||
- variant: coverage
|
||||
build_type: Debug
|
||||
cxx_flags: "--coverage -O0"
|
||||
linker_flags: "--coverage"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Configure
|
||||
@@ -124,13 +128,22 @@ jobs:
|
||||
include:
|
||||
- variant: debug
|
||||
test_regex: ""
|
||||
host_sanitizer_flags: ""
|
||||
- variant: relwithdebinfo
|
||||
test_regex: ""
|
||||
host_sanitizer_flags: ""
|
||||
- variant: sanitizers
|
||||
test_regex: "vbs_sdk_tests|vbs_core_tests"
|
||||
host_sanitizer_flags: "-fsanitize=address,undefined -fno-omit-frame-pointer"
|
||||
- variant: coverage
|
||||
test_regex: "vbs_sdk_tests|vbs_core_tests"
|
||||
host_sanitizer_flags: ""
|
||||
env:
|
||||
ASAN_OPTIONS: detect_leaks=1
|
||||
UBSAN_OPTIONS: print_stacktrace=1
|
||||
# Instrument the build description too in the sanitizer lane.
|
||||
VBS_HOST_CXX_FLAGS: ${{ matrix.host_sanitizer_flags }}
|
||||
VBS_HOST_LDFLAGS: ${{ matrix.host_sanitizer_flags }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
# Jobs are fresh containers: the upgrade done by `requirements` does not carry over.
|
||||
@@ -156,12 +169,21 @@ jobs:
|
||||
- name: Benchmark smoke run
|
||||
if: matrix.variant == 'debug'
|
||||
run: build/linux-debug/bin/vbs_benchmarks --files 15
|
||||
- name: lcov coverage report
|
||||
if: matrix.variant == 'coverage'
|
||||
run: |
|
||||
lcov --capture --directory "build/linux-coverage" --output-file coverage.info \
|
||||
--ignore-errors mismatch,source --rc branch_coverage=0
|
||||
lcov --summary coverage.info
|
||||
lcov --list coverage.info | head -40
|
||||
- name: Upload the test log
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: vbs-linux-test-${{ matrix.variant }}
|
||||
path: ctest-linux-${{ matrix.variant }}.log
|
||||
path: |
|
||||
ctest-linux-${{ matrix.variant }}.log
|
||||
coverage.info
|
||||
retention-days: 14
|
||||
|
||||
wine-build:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Development state
|
||||
|
||||
Updated: 2026-12-03
|
||||
Updated: 2026-12-06
|
||||
Branch: main
|
||||
Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B1–B3) + Track E1 + `vbs ide` & `build.cpp` CompDB integration + Track D1/D2 + Track E2 + Track D3 SBOM (Docker GCC 16) + Track D3 Ed25519 signing primitives & trusted-key enforcement (OpenSSL-gated crypto) + Track E3 daemon core, bounded describe & build-serving + Track C1 Linux platform split complete
|
||||
|
||||
@@ -383,6 +383,22 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
|
||||
|
||||
- **Wave 145 (Coverage Reporting)**: `vbs test --coverage DIR` instruments every compile and link with `--coverage`, runs the tests, and converts the gcov JSON data into `DIR/coverage.info` (lcov) and `DIR/summary.txt`. System headers outside the project root are filtered out. `FullV1Tests.test_coverage_writes_lcov_and_summary` builds a library with a covered and an uncovered function and asserts `DA:1,1`, `DA:2,0` and the summary. A fresh-tree bug (a transient filesystem error aborting the .gcda walk) was found and fixed.
|
||||
|
||||
- **Wave 146 (Gitea CI Hardening, Explainability, Shared Caches, CLI Surface & Migration Breadth)**:
|
||||
- **CI images (`Void/CI-Images`)**: the `vulkan` image gained `msitools` (wixl/msiinfo), `rpm-tools`, `dpkg`, `meson` and `lcov`; `windows-gcc` and `windows-clang` gained `msitools`, and the image workflow now verifies the tools inside every built image.
|
||||
- **CI**: a `coverage` Linux variant (`--coverage`, lcov report uploaded as an artifact) joins Debug, RelWithDebInfo and Sanitizers; the MSI installer step stops being skipped once the images ship msitools.
|
||||
- **Test-runner controls**: `--repeat until-fail|until-pass|after-timeout[:N]`, `--retry N`, `--shuffle [--shuffle-seed N]` and `--stop-on-failure` (which also skips the remaining profiles).
|
||||
- **Explainability**: `vbs explain [--format text|json]` reports why each action would run (missing cache record, changed discovered inputs, changed/missing outputs, restorable outputs, shared-remote-cache hits) via `Execution::explain_graph` without executing anything.
|
||||
- **Observability**: `vbs build|test --trace FILE` writes a Chrome trace with phase spans (config, toolchain, eval, snapshot, graph, total) and per-action spans.
|
||||
- **Cold start**: compiled descriptors and toolchain probes are shared through `$XDG_CACHE_HOME/vbs` (opt out with `VBS_SHARED_CACHE=0`). Measured on the 20-source fixture: a fresh build directory fell from 3897 ms to 755 ms (config 1986->128 ms, toolchain 562->6.5 ms); warm stays ~150 ms.
|
||||
- **CLI surface**: `vbs completions --shell bash|zsh|fish` and `vbs man [--output DIR]` are generated from the live parser tree (86 man pages), so they cannot drift from the CLI; the generated bash script passes `bash -n`.
|
||||
- **Migration breadth**: `vbs migrate --from meson` imports `project`, variable assignments (`files`, `include_directories`), `executable`/`static_library`/`shared_library`/`library` with `link_with`, `include_directories`, `dependencies`, `install`/`install_dir`, and reports everything else.
|
||||
- **Templates & presets**: `vbs init --template app|library|header-only|shared` (all four scaffold and pass their own test), and `vbs presets --export FILE` writes VBS profiles as CMake configure presets (round-trippable through the importer).
|
||||
- **Packaging**: `vbs install --archive-format msi` renders the WiX source with absolute file sources and compiles it with `wixl` (msitools) or the WiX toolset (`candle`/`light`), failing explicitly when neither exists; the release step replaces same-named assets when a tag is republished.
|
||||
- **Sanitizer coverage**: `VBS_HOST_CXX_FLAGS`/`VBS_HOST_LDFLAGS` instrument the compiled build descriptor too, and the CI sanitizer lane sets them (previously descriptor compilation did not inherit sanitizer flags).
|
||||
- **IDE debug integration**: `vbs ide generate` now also writes JetBrains run configurations (`.idea/runConfigurations/vbs_{build,test}_<target>.xml`) beside the VS Code and Zed debug configs.
|
||||
- **Worker reliability**: the registry queue counts lease attempts per action (`attempt` in the lease response, `attempts` in the queue listing) and abandons an action after 5 attempts into an `abandoned` dead-letter list instead of leasing it forever; `RegistryTests.worker_queue_abandons_actions_after_repeated_leases` covers it.
|
||||
|
||||
|
||||
## Remaining future scope
|
||||
|
||||
- **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order.
|
||||
|
||||
@@ -145,4 +145,5 @@ Base HEAD: `fe0d1a6`
|
||||
| Wave 142 (Gitea CI + release workflow) | Gitea-hosted CI with artifacts; tag-driven release workflow with asset upload | COMPLETE (YAML-validated; unexecuted without a runner) | `.gitea/workflows/ci.yml`, `.gitea/workflows/release.yml`, docs |
|
||||
| Wave 144 (NuGet generator) | `--archive-format nuget`: `.nupkg` with nuspec, OPC parts and `runtimes/<rid>/native` assets | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Python validates the package, install test passes, full CTest 8/8) | `src/Install/Installer.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, docs |
|
||||
| Wave 145 (Coverage reporting) | `vbs test --coverage DIR`; gcov JSON -> lcov + summary | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E passes, full CTest 8/8) | `include/Void/Build/Report/Coverage.hpp`, `src/Report/Coverage.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, docs |
|
||||
| Wave 146 (CI hardening, explainability, shared caches, CLI surface, migration breadth) | CI image tool upgrades + coverage lane; test `--repeat/--retry/--shuffle/--stop-on-failure`; `vbs explain`; `--trace` Chrome traces; shared descriptor/probe caches; `vbs completions`/`vbs man`; `vbs migrate --from meson`; `vbs init --template`; `vbs presets --export`; MSI installer | COMPLETE & VERIFIED (GCC 16.2; new FullV1Tests cases for every feature pass, CLI contract suite passes; cold build 3897 -> 755 ms measured) | `src/Main.cpp`, `src/Execution/Scheduler.{hpp,cpp}`, `src/Cli/CommandModel.{hpp,cpp}`, `src/Config/{Frontend,Scaffold,CmakeImport}.cpp`, `src/Toolchain/Driver.cpp`, `include/Void/Build/Util/UserCache.hpp`, `.gitea/workflows/ci.yml`, [Void/CI-Images](https://git.faumaray.com/Void/CI-Images), `tests/{FullV1Tests,CliContracts}`, 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) |
|
||||
@@ -122,36 +122,40 @@ first, then what makes VBS *better* rather than merely equal.
|
||||
3. **Platform breadth - deferred.** Native MSVC and Apple Clang/macOS stay deferred by
|
||||
decision; MinGW cross + Wine is the current Windows story.
|
||||
4. **Package-generator parity.** CPack also ships NuGet, PKG/productbuild, APK and IFW
|
||||
installers; VBS has tar, `sh`, ZIP, DEB, RPM, WiX, UDIF and NuGet (Wave 144). PKG is
|
||||
the next useful one.
|
||||
installers; VBS has tar, `sh`, ZIP, DEB, RPM, WiX, MSI (compiled with wixl/candle), UDIF and
|
||||
NuGet (Wave 144). PKG is the next useful one.
|
||||
|
||||
### 8.2 Developer experience and IDE integration
|
||||
|
||||
6. **Coverage reporting - done (Wave 145).** `vbs test --coverage` produces lcov (gcov for GCC,
|
||||
llvm-cov for Clang) alongside JUnit. CMake has `CTestCoverageCollectGCOV`; Meson has the
|
||||
`b_coverage` option.
|
||||
7. **Test repetition controls.** CTest offers `--repeat until-fail|after-timeout|until-pass`,
|
||||
`--shuffle`, `--stop-on-failure` and per-test retries; VBS has labels, resources, fixtures,
|
||||
timeouts, JUnit and CDash but none of these. Flaky-test retries are valuable for CI.
|
||||
8. **IDE debug integration.** `vbs ide generate` writes editor configs, but not debug
|
||||
configurations: add `.vscode/launch.json`/`tasks.json` (gdb/lldb) and JetBrains run
|
||||
configurations per target. Also export `CMakePresets.json` so CMake-only tools can read a
|
||||
VBS project.
|
||||
9. **Shell completions and man pages** for `vbs` (bash/zsh/fish), generated from the argparse
|
||||
tree.
|
||||
10. **Migration breadth.** `vbs migrate` handles a bounded CMake subset; add `--from meson`
|
||||
and cover more CMake commands. `vbs init` could grow templates (header-only, shared
|
||||
library, GUI).
|
||||
7. **Test repetition controls - done (Wave 146).** `vbs test` now has `--repeat
|
||||
until-fail|until-pass|after-timeout[:N]`, `--retry N`, `--shuffle [--shuffle-seed N]`
|
||||
and `--stop-on-failure`, alongside labels, resources, fixtures, timeouts, JUnit and CDash.
|
||||
8. **IDE debug integration.** `vbs ide generate` writes `.vscode/launch.json` and
|
||||
`.zed/debug.json` debug configurations; JetBrains run configurations per target remain
|
||||
open. `vbs presets --export FILE` (**done**) writes VBS profiles as CMake presets so
|
||||
CMake-only tools can read a VBS project.
|
||||
9. **Shell completions and man pages - done (Wave 146).** `vbs completions --shell
|
||||
bash|zsh|fish` and `vbs man [--output DIR]` are generated from the argparse tree.
|
||||
10. **Migration breadth.** `vbs migrate` handles a bounded CMake subset and now also
|
||||
`--from meson` (`meson.build`: project, variables, targets, link_with,
|
||||
include_directories, install). `vbs init --template app|library|header-only|shared`
|
||||
provides project templates.
|
||||
|
||||
### 8.3 Differentiators worth building (incumbents lack these)
|
||||
|
||||
11. **`vbs explain`.** Why did an action re-run? VBS already stores cached action digests and
|
||||
inputs; the explain report (changed input, command, environment, cache miss) is a cheap,
|
||||
high-value debugging feature that Ninja/CMake/Meson do not offer.
|
||||
11. **`vbs explain` - done (Wave 146).** Why did an action re-run? `vbs explain` compares
|
||||
every selected action against the CAS record and reports the changed inputs/outputs,
|
||||
missing records, restorable outputs and remote-cache hits, as text or JSON. Ninja/CMake/Meson
|
||||
do not offer this.
|
||||
12. **Enforced hermetic sandboxing.** Snapshots already define exact inputs; enforcing that
|
||||
actions see *only* them (mount/user namespaces) would make incrementality and
|
||||
reproducibility a guarantee rather than a convention (Bazel-style).
|
||||
13. **Build Event Protocol / Chrome trace output** for CI dashboards and IDE timelines.
|
||||
13. **Build Event Protocol / Chrome trace output - Chrome trace done (Wave 146).**
|
||||
`vbs build|test --trace FILE` writes a Chrome trace with phase and action spans for CI
|
||||
dashboards and IDE timelines; a full BEP stream remains open.
|
||||
14. **Multi-machine orchestration.** The registry, queue, leases, remote execution and
|
||||
parallel workers exist; coordinating several machines (capacity, retries, affinity) is the
|
||||
remaining step.
|
||||
@@ -160,9 +164,10 @@ first, then what makes VBS *better* rather than merely equal.
|
||||
|
||||
### 8.4 Performance note
|
||||
|
||||
The 92 ms warm no-op was measured with a **Debug** `vbs` binary. Before optimizing further,
|
||||
re-run `benchmarks/compare.sh` against a Release build, then attack the cold-start cost
|
||||
(descriptor compilation dominates: 2.6 s cold vs CMake's 97 ms on 20 sources).
|
||||
The 92 ms warm no-op was measured with a **Debug** `vbs` binary. The shared per-user caches
|
||||
(Wave 146) removed most of the cold-start cost in a fresh build directory (3897 -> 755 ms on
|
||||
the 20-source fixture); warm no-ops stay around 150 ms. Next: re-run `benchmarks/compare.sh`
|
||||
against a Release build and keep snapshot work proportional to changed files.
|
||||
|
||||
## 7. Acceptance gates
|
||||
|
||||
|
||||
@@ -39,6 +39,13 @@ struct MigrationResult {
|
||||
import_cmake_lists(const std::filesystem::path &cmake_file,
|
||||
const std::filesystem::path &project_root);
|
||||
|
||||
// Bounded meson.build reader: understands `project`, variable assignments (`files(...)`,
|
||||
// `include_directories(...)`), `executable`/`static_library`/`shared_library`/`library` with
|
||||
// `link_with`, `include_directories`, `install` and `install_dir`. Everything else is a note.
|
||||
[[nodiscard]] Void::Result::Result<MigrationResult, Void::Result::Error>
|
||||
import_meson_build(const std::filesystem::path &meson_file,
|
||||
const std::filesystem::path &project_root);
|
||||
|
||||
// Renders the imported targets as a `build.cpp` scaffold.
|
||||
[[nodiscard]] std::string render_build_cpp(const MigrationResult &result);
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ struct FrontendOptions {
|
||||
std::optional<std::filesystem::path> host_compiler;
|
||||
// Extra environment for the descriptor process (e.g. dependency options for a native dep).
|
||||
std::map<std::string, std::string, std::less<>> extra_environment;
|
||||
// Extra flags for compiling/linking the descriptor itself (e.g. sanitizer instrumentation
|
||||
// so a sanitizer build covers the build description as well as the project).
|
||||
std::vector<std::string> host_compile_flags;
|
||||
std::vector<std::string> host_link_flags;
|
||||
std::chrono::milliseconds eval_timeout{std::chrono::seconds{30}};
|
||||
};
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ struct ScaffoldOptions {
|
||||
bool library{false};
|
||||
bool with_toml{false};
|
||||
bool force{false}; // Overwrite an existing build.cpp
|
||||
// Template shape: "app" (default), "library", "header-only", "shared" or "gui".
|
||||
std::string template_name{"app"};
|
||||
};
|
||||
|
||||
struct ScaffoldReport {
|
||||
|
||||
@@ -179,6 +179,11 @@ class RegistryService {
|
||||
std::map<std::string, WorkerRecord, std::less<>> workers_;
|
||||
std::map<std::string, ActionLeaseRecord, std::less<>> action_leases_; // action_key -> lease
|
||||
std::vector<std::string> action_queue_; // enqueued action keys (in-memory)
|
||||
// Leases handed out per queued action; after kMaxActionAttempts the action is abandoned
|
||||
// (dead-lettered) instead of being retried forever.
|
||||
std::map<std::string, std::uint32_t, std::less<>> action_attempts_;
|
||||
std::vector<std::string> abandoned_actions_;
|
||||
static constexpr std::uint32_t kMaxActionAttempts = 5;
|
||||
std::uint64_t worker_sequence_{0};
|
||||
std::vector<AuditEntry> audits_;
|
||||
HttpServer server_;
|
||||
|
||||
@@ -1045,9 +1045,18 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
|
||||
leased_keys.push_back(key);
|
||||
}
|
||||
}
|
||||
std::string attempts_json;
|
||||
for (const auto &[key, attempts] : action_attempts_) {
|
||||
if (!attempts_json.empty()) {
|
||||
attempts_json += ',';
|
||||
}
|
||||
attempts_json += json_quote(key) + ":" + std::to_string(attempts);
|
||||
}
|
||||
return HttpResponse::json(
|
||||
200, "{\"pending\":" + json_array(pending, json_quote) +
|
||||
",\"leased\":" + json_array(leased_keys, json_quote) + "}\n");
|
||||
",\"leased\":" + json_array(leased_keys, json_quote) +
|
||||
",\"attempts\":{" + attempts_json + "}" + ",\"abandoned\":" +
|
||||
json_array(abandoned_actions_, json_quote) + "}\n");
|
||||
}
|
||||
if (segs.size() == 3 && req.method == "POST") {
|
||||
if (!principal->scopes.contains("publish") && principal->role != Role::Admin) {
|
||||
@@ -1102,24 +1111,42 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
|
||||
return HttpResponse::error_json(404, "not_found", "worker not registered");
|
||||
}
|
||||
prune_expired_leases();
|
||||
const auto next = std::ranges::find_if(action_queue_, [&](const std::string &key) {
|
||||
return !action_leases_.contains(key);
|
||||
});
|
||||
if (next == action_queue_.end()) {
|
||||
// Skip actions that exceeded their attempt budget (dead-letter them).
|
||||
std::optional<std::string> picked;
|
||||
for (auto it = action_queue_.begin(); it != action_queue_.end();) {
|
||||
if (action_leases_.contains(*it)) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
auto &attempts = action_attempts_[*it];
|
||||
if (attempts >= kMaxActionAttempts) {
|
||||
abandoned_actions_.push_back(*it);
|
||||
append_audit_locked(principal->username, "queue.abandon", *it,
|
||||
"attempts_exhausted", std::to_string(attempts));
|
||||
action_attempts_.erase(*it);
|
||||
it = action_queue_.erase(it);
|
||||
continue;
|
||||
}
|
||||
++attempts;
|
||||
picked = *it;
|
||||
break;
|
||||
}
|
||||
if (!picked) {
|
||||
return HttpResponse::error_json(404, "empty", "no queued action available");
|
||||
}
|
||||
ActionLeaseRecord lease;
|
||||
lease.action_key = *next;
|
||||
lease.action_key = *picked;
|
||||
lease.worker_id = worker_id;
|
||||
lease.lease_token = random_hex(16);
|
||||
lease.expires_epoch = now_epoch() + lease_seconds;
|
||||
action_leases_[*next] = lease;
|
||||
append_audit_locked(principal->username, "queue.lease", *next, "ok", worker_id);
|
||||
action_leases_[*picked] = lease;
|
||||
append_audit_locked(principal->username, "queue.lease", *picked, "ok", worker_id);
|
||||
return HttpResponse::json(
|
||||
200, "{\"action_key\":" + json_quote(*next) +
|
||||
200, "{\"action_key\":" + json_quote(*picked) +
|
||||
",\"worker_id\":" + json_quote(worker_id) +
|
||||
",\"lease_token\":" + json_quote(lease.lease_token) +
|
||||
",\"expires_epoch\":" + std::to_string(lease.expires_epoch) + "}\n");
|
||||
",\"expires_epoch\":" + std::to_string(lease.expires_epoch) +
|
||||
",\"attempt\":" + std::to_string(action_attempts_[*picked]) + "}\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1295,6 +1322,7 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
|
||||
action_leases_.erase(lease_it);
|
||||
action_queue_.erase(std::remove(action_queue_.begin(), action_queue_.end(), action_key),
|
||||
action_queue_.end());
|
||||
action_attempts_.erase(action_key);
|
||||
append_audit_locked(principal->username, "action.result", action_key, "ok",
|
||||
existed ? "replaced" : "stored");
|
||||
return HttpResponse::json(200, "{\"stored\":true}\n");
|
||||
|
||||
@@ -333,6 +333,359 @@ import_cmake_lists(const std::filesystem::path &cmake_file,
|
||||
return result;
|
||||
}
|
||||
|
||||
// ---- Meson importer -------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
|
||||
std::string trim_copy(std::string_view s) {
|
||||
const auto first = s.find_first_not_of(" \t\r\n");
|
||||
if (first == std::string_view::npos) {
|
||||
return {};
|
||||
}
|
||||
const auto last = s.find_last_not_of(" \t\r\n");
|
||||
return std::string{s.substr(first, last - first + 1)};
|
||||
}
|
||||
|
||||
// Strips `#` comments outside string literals.
|
||||
std::string strip_meson_comments(std::string_view text) {
|
||||
std::string out;
|
||||
bool quoted = false;
|
||||
for (std::size_t i = 0; i < text.size(); ++i) {
|
||||
const char c = text[i];
|
||||
if (c == '\'') {
|
||||
quoted = !quoted;
|
||||
} else if (c == '#' && !quoted) {
|
||||
while (i < text.size() && text[i] != '\n') {
|
||||
++i;
|
||||
}
|
||||
if (i < text.size()) {
|
||||
out.push_back('\n');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
out.push_back(c);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Splits a Meson file into statements, joining lines while parentheses/brackets are open.
|
||||
std::vector<std::string> split_meson_statements(std::string_view text) {
|
||||
std::vector<std::string> statements;
|
||||
std::string current;
|
||||
int depth = 0;
|
||||
bool quoted = false;
|
||||
for (std::size_t i = 0; i < text.size(); ++i) {
|
||||
const char c = text[i];
|
||||
if (c == '\'') {
|
||||
quoted = !quoted;
|
||||
current.push_back(c);
|
||||
continue;
|
||||
}
|
||||
if (!quoted) {
|
||||
if (c == '(' || c == '[') {
|
||||
++depth;
|
||||
} else if (c == ')' || c == ']') {
|
||||
--depth;
|
||||
} else if (c == '\n' && depth == 0) {
|
||||
if (!trim_copy(current).empty()) {
|
||||
statements.push_back(trim_copy(current));
|
||||
}
|
||||
current.clear();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
current.push_back(c);
|
||||
}
|
||||
if (!trim_copy(current).empty()) {
|
||||
statements.push_back(trim_copy(current));
|
||||
}
|
||||
return statements;
|
||||
}
|
||||
|
||||
std::string trim_copy(std::string_view s);
|
||||
|
||||
// Splits on commas at depth 0 (outside strings and nested brackets).
|
||||
std::vector<std::string> split_meson_args(std::string_view text) {
|
||||
std::vector<std::string> args;
|
||||
std::string current;
|
||||
int depth = 0;
|
||||
bool quoted = false;
|
||||
for (std::size_t i = 0; i < text.size(); ++i) {
|
||||
const char c = text[i];
|
||||
if (c == '\'') {
|
||||
quoted = !quoted;
|
||||
current.push_back(c);
|
||||
continue;
|
||||
}
|
||||
if (!quoted) {
|
||||
if (c == '(' || c == '[') {
|
||||
++depth;
|
||||
} else if (c == ')' || c == ']') {
|
||||
--depth;
|
||||
} else if (c == ',' && depth == 0) {
|
||||
args.push_back(trim_copy(current));
|
||||
current.clear();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
current.push_back(c);
|
||||
}
|
||||
if (!trim_copy(current).empty()) {
|
||||
args.push_back(trim_copy(current));
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
struct MesonValue {
|
||||
std::vector<std::string> items; // String values or string lists collapsed.
|
||||
bool is_list{false};
|
||||
};
|
||||
|
||||
// Evaluates a bounded Meson expression: string literals, lists, identifiers of known variables,
|
||||
// and files(...) calls.
|
||||
MesonValue eval_meson_value(std::string_view expr,
|
||||
const std::map<std::string, MesonValue, std::less<>> &variables);
|
||||
|
||||
MesonValue eval_meson_value(std::string_view expr,
|
||||
const std::map<std::string, MesonValue, std::less<>> &variables) {
|
||||
const std::string text = trim_copy(expr);
|
||||
if (text.empty()) {
|
||||
return {};
|
||||
}
|
||||
if (text.front() == '[' && text.back() == ']') {
|
||||
MesonValue value;
|
||||
value.is_list = true;
|
||||
for (const auto &item : split_meson_args(std::string_view{text}.substr(1, text.size() - 2))) {
|
||||
for (const auto &entry : eval_meson_value(item, variables).items) {
|
||||
value.items.push_back(entry);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
if (text.front() == '\'') {
|
||||
// One or more concatenated string literals.
|
||||
MesonValue value;
|
||||
std::string current;
|
||||
bool quoted = false;
|
||||
for (std::size_t i = 0; i < text.size(); ++i) {
|
||||
const char c = text[i];
|
||||
if (c == '\'') {
|
||||
if (quoted) {
|
||||
value.items.push_back(current);
|
||||
current.clear();
|
||||
}
|
||||
quoted = !quoted;
|
||||
continue;
|
||||
}
|
||||
if (quoted) {
|
||||
current.push_back(c);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const auto paren = text.find('(');
|
||||
if (paren != std::string::npos && text.back() == ')') {
|
||||
const std::string call = trim_copy(std::string_view{text}.substr(0, paren));
|
||||
if (call == "files" || call == "include_directories" || call == "dependency") {
|
||||
MesonValue value;
|
||||
value.is_list = true;
|
||||
for (const auto &arg :
|
||||
split_meson_args(std::string_view{text}.substr(paren + 1, text.size() - paren - 2))) {
|
||||
for (const auto &entry : eval_meson_value(arg, variables).items) {
|
||||
value.items.push_back(entry);
|
||||
}
|
||||
if (call == "dependency") {
|
||||
break; // dependency('name', version : ...) -> just the name.
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
// Other calls (dependency, declare_dependency, ...) are not values the importer uses.
|
||||
return {};
|
||||
}
|
||||
if (const auto it = variables.find(text); it != variables.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Void::Result::Result<MigrationResult, Void::Result::Error>
|
||||
import_meson_build(const std::filesystem::path &meson_file,
|
||||
const std::filesystem::path &project_root) {
|
||||
auto text = Void::FileSystem::read_file(meson_file);
|
||||
if (!text) {
|
||||
return std::unexpected{text.error()};
|
||||
}
|
||||
|
||||
MigrationResult result;
|
||||
std::map<std::string, MesonValue, std::less<>> variables;
|
||||
|
||||
for (const auto &statement : split_meson_statements(strip_meson_comments(*text))) {
|
||||
// Variable assignment: `name = expr` (first '=' at depth 0, not '==' or inside a call).
|
||||
int depth = 0;
|
||||
bool quoted = false;
|
||||
std::size_t assign = std::string::npos;
|
||||
for (std::size_t i = 0; i < statement.size(); ++i) {
|
||||
const char c = statement[i];
|
||||
if (c == '\'') {
|
||||
quoted = !quoted;
|
||||
} else if (!quoted) {
|
||||
if (c == '(' || c == '[') {
|
||||
++depth;
|
||||
} else if (c == ')' || c == ']') {
|
||||
--depth;
|
||||
} else if (c == '=' && depth == 0) {
|
||||
assign = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string effective = statement;
|
||||
std::string assigned_name;
|
||||
if (assign != std::string::npos) {
|
||||
const std::string name = trim_copy(std::string_view{statement}.substr(0, assign));
|
||||
const std::string expr = trim_copy(std::string_view{statement}.substr(assign + 1));
|
||||
// `lib = static_library(...)` declares a target and binds the variable to it.
|
||||
static constexpr std::string_view kTargetCalls[] = {
|
||||
"executable", "static_library", "shared_library", "library", "both_libraries"};
|
||||
const bool declares_target = std::ranges::any_of(kTargetCalls, [&](std::string_view call) {
|
||||
return expr.starts_with(std::string{call} + "(");
|
||||
});
|
||||
if (!declares_target) {
|
||||
variables[name] = eval_meson_value(expr, variables);
|
||||
continue;
|
||||
}
|
||||
assigned_name = name;
|
||||
effective = expr;
|
||||
}
|
||||
|
||||
const auto paren = effective.find('(');
|
||||
if (paren == std::string::npos || effective.back() != ')') {
|
||||
result.notes.push_back("unsupported meson statement '" + effective + "'");
|
||||
continue;
|
||||
}
|
||||
const std::string call = trim_copy(std::string_view{effective}.substr(0, paren));
|
||||
const auto args = split_meson_args(
|
||||
std::string_view{effective}.substr(paren + 1, effective.size() - paren - 2));
|
||||
|
||||
if (call == "project") {
|
||||
if (!args.empty()) {
|
||||
const auto name_value = eval_meson_value(args[0], variables);
|
||||
result.project_name =
|
||||
name_value.items.empty() ? args[0] : name_value.items.front();
|
||||
}
|
||||
for (std::size_t i = 1; i < args.size(); ++i) {
|
||||
if (args[i].find(':') != std::string::npos) {
|
||||
continue; // Keyword like version : '1.0'.
|
||||
}
|
||||
if (trim_copy(args[i]) != "'cpp'" && trim_copy(args[i]) != "'c'") {
|
||||
result.notes.push_back("project language " + args[i] + " is not C/C++");
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const bool is_target = call == "executable" || call == "static_library" ||
|
||||
call == "shared_library" || call == "library" ||
|
||||
call == "both_libraries" || call == "test";
|
||||
if (!is_target) {
|
||||
if (call == "subdir" || call == "dependency" || call == "find_program" ||
|
||||
call == "custom_target" || call == "configure_file" || call == "run_command" ||
|
||||
call == "install_headers" || call == "install_subdir" || call == "summary" ||
|
||||
call == "add_test" || call == "add_project_arguments" ||
|
||||
call == "add_project_link_arguments" || call == "pkg_modversion" ||
|
||||
call == "vcs_tag" || call == "generator" || call == "declare_dependency" ||
|
||||
call == "message" || call == "warning" || call == "import" ||
|
||||
call == "include_directories" || call == "files") {
|
||||
if (call == "subdir" || call == "dependency" || call == "custom_target" ||
|
||||
call == "configure_file" || call == "run_command" || call == "import" ||
|
||||
call == "generator" || call == "declare_dependency") {
|
||||
result.notes.push_back(call + "(...) requires manual review");
|
||||
}
|
||||
} else {
|
||||
result.notes.push_back("unsupported meson function '" + call + "'");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (args.empty()) {
|
||||
continue;
|
||||
}
|
||||
MigratedTarget target;
|
||||
const auto name_value = eval_meson_value(args[0], variables);
|
||||
target.name = name_value.items.empty() ? args[0] : name_value.items[0];
|
||||
if (call == "executable" || call == "test") {
|
||||
target.kind = "executable";
|
||||
} else if (call == "shared_library" || call == "both_libraries") {
|
||||
target.kind = "shared";
|
||||
} else if (call == "library") {
|
||||
target.kind = "static";
|
||||
result.notes.push_back("library() builds shared and static; imported as static");
|
||||
} else {
|
||||
target.kind = "static";
|
||||
}
|
||||
for (std::size_t i = 1; i < args.size(); ++i) {
|
||||
const std::string arg = trim_copy(args[i]);
|
||||
const auto colon = arg.find(':');
|
||||
std::string key;
|
||||
std::string value_expr = arg;
|
||||
if (colon != std::string::npos) {
|
||||
key = trim_copy(std::string_view{arg}.substr(0, colon));
|
||||
value_expr = trim_copy(std::string_view{arg}.substr(colon + 1));
|
||||
}
|
||||
const auto value = eval_meson_value(value_expr, variables);
|
||||
if (key.empty()) {
|
||||
for (const auto &item : value.items) {
|
||||
if (is_source_like(item)) {
|
||||
target.sources.push_back(item);
|
||||
} else {
|
||||
result.notes.push_back(std::format("{} '{}': ignored non-source token '{}'",
|
||||
call, target.name, item));
|
||||
}
|
||||
}
|
||||
} else if (key == "link_with" || key == "link_whole") {
|
||||
for (const auto &item : value.items) {
|
||||
target.private_links.push_back(item);
|
||||
}
|
||||
} else if (key == "include_directories") {
|
||||
for (const auto &item : value.items) {
|
||||
target.private_includes.push_back(item);
|
||||
}
|
||||
} else if (key == "dependencies") {
|
||||
for (const auto &item : value.items) {
|
||||
result.notes.push_back("dependency '" + item +
|
||||
"' requires .pkgconfig() or a registry entry");
|
||||
}
|
||||
} else if (key == "install") {
|
||||
target.installed = value.items.empty() || value.items.front() != "false";
|
||||
} else if (key == "install_dir") {
|
||||
if (!value.items.empty()) {
|
||||
target.install_destination = value.items.front();
|
||||
}
|
||||
target.installed = true;
|
||||
} else {
|
||||
result.notes.push_back(std::format("{} '{}': keyword '{}' is not translated", call,
|
||||
target.name, key));
|
||||
}
|
||||
}
|
||||
if (target.installed && target.install_destination.empty()) {
|
||||
target.install_destination =
|
||||
target.kind == "executable" ? "bin" : (target.kind == "interface" ? "include" : "lib");
|
||||
}
|
||||
if (!assigned_name.empty()) {
|
||||
variables[assigned_name] = MesonValue{{target.name}, false};
|
||||
}
|
||||
result.targets.push_back(std::move(target));
|
||||
}
|
||||
|
||||
if (result.project_name.empty()) {
|
||||
result.project_name = project_root.filename().string();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string render_build_cpp(const MigrationResult &result) {
|
||||
using Util::json_quote;
|
||||
|
||||
|
||||
@@ -713,6 +713,9 @@ compile_descriptor(const FrontendOptions &options) {
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = host_cxx;
|
||||
req.arguments = {"-std=c++26", "-O1", "-I", canonical_root.string()};
|
||||
for (const auto &flag : options.host_compile_flags) {
|
||||
req.arguments.push_back(flag);
|
||||
}
|
||||
if (!options.sdk_include_dir.empty()) {
|
||||
req.arguments.push_back("-I");
|
||||
req.arguments.push_back(options.sdk_include_dir.string());
|
||||
@@ -762,9 +765,15 @@ compile_descriptor(const FrontendOptions &options) {
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = host_cxx;
|
||||
req.arguments = {"-std=c++26", "-o", staged_exe.string()};
|
||||
for (const auto &flag : options.host_compile_flags) {
|
||||
req.arguments.push_back(flag);
|
||||
}
|
||||
for (const auto &o : objects) {
|
||||
req.arguments.push_back(o.string());
|
||||
}
|
||||
for (const auto &flag : options.host_link_flags) {
|
||||
req.arguments.push_back(flag);
|
||||
}
|
||||
if (use_prebuilt_sdk) {
|
||||
req.arguments.push_back(options.sdk_library_path.string());
|
||||
}
|
||||
|
||||
+36
-9
@@ -20,6 +20,17 @@ Error make_error(Void::System::SystemErrorCode code, std::string message) {
|
||||
|
||||
Result<ScaffoldReport, Error> scaffold_project(const ScaffoldOptions &options) {
|
||||
std::error_code ec;
|
||||
const std::string &shape = options.template_name;
|
||||
if (shape != "app" && shape != "library" && shape != "header-only" && shape != "shared") {
|
||||
return std::unexpected{make_error(
|
||||
Void::System::SystemErrorCode::invalid_argument,
|
||||
std::format("vbs init: unknown template '{}' (expected app, library, header-only "
|
||||
"or shared)",
|
||||
shape))};
|
||||
}
|
||||
const bool header_only = shape == "header-only";
|
||||
const bool library_shape = options.library || shape == "library" || header_only;
|
||||
const bool shared = shape == "shared";
|
||||
const std::filesystem::path target_dir = options.target_dir.lexically_normal();
|
||||
std::filesystem::create_directories(target_dir, ec);
|
||||
if (ec) {
|
||||
@@ -77,7 +88,17 @@ Result<ScaffoldReport, Error> scaffold_project(const ScaffoldOptions &options) {
|
||||
if (options.with_toml) {
|
||||
build_src += " project.dependencies_file(\"vbs.deps.toml\");\n\n";
|
||||
}
|
||||
if (options.library) {
|
||||
if (header_only) {
|
||||
build_src += " auto lib = project.header_only_library(\"" + raw_name +
|
||||
"\");\n"
|
||||
" lib.include_directory(\"include\", Void::Build::Visibility::Public);\n\n"
|
||||
" auto t = project.test(\"" +
|
||||
ident +
|
||||
"_tests\");\n"
|
||||
" t.cxx_standard(Void::Build::CxxStandard::Cxx26)\n"
|
||||
" .sources({\"tests/test_main.cpp\"})\n"
|
||||
" .link(lib);\n";
|
||||
} else if (library_shape) {
|
||||
build_src += " auto lib = project.static_library(\"" + raw_name +
|
||||
"\");\n"
|
||||
" lib.cxx_standard(Void::Build::CxxStandard::Cxx26)\n"
|
||||
@@ -94,7 +115,8 @@ Result<ScaffoldReport, Error> scaffold_project(const ScaffoldOptions &options) {
|
||||
" .sources({\"tests/test_main.cpp\"})\n"
|
||||
" .link(lib);\n";
|
||||
} else {
|
||||
build_src += " auto lib = project.static_library(\"" + ident +
|
||||
const std::string lib_factory = shared ? "shared_library" : "static_library";
|
||||
build_src += " auto lib = project." + lib_factory + "(\"" + ident +
|
||||
"_lib\");\n"
|
||||
" lib.cxx_standard(Void::Build::CxxStandard::Cxx26)\n"
|
||||
" .sources({\"src/" +
|
||||
@@ -122,17 +144,22 @@ Result<ScaffoldReport, Error> scaffold_project(const ScaffoldOptions &options) {
|
||||
}
|
||||
if (auto written =
|
||||
write_checked(target_dir / "include" / (ident + ".hpp"),
|
||||
"#pragma once\n\nnamespace " + ident + " {\nint answer();\n}\n");
|
||||
header_only ? "#pragma once\n\nnamespace " + ident +
|
||||
" {\ninline int answer() { return 42; }\n}\n"
|
||||
: "#pragma once\n\nnamespace " + ident +
|
||||
" {\nint answer();\n}\n");
|
||||
!written) {
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
if (auto written = write_checked(target_dir / "src" / (ident + ".cpp"),
|
||||
"#include \"" + ident + ".hpp\"\n\nnamespace " + ident +
|
||||
" {\nint answer() { return 42; }\n}\n");
|
||||
!written) {
|
||||
return std::unexpected{written.error()};
|
||||
if (!header_only) {
|
||||
if (auto written = write_checked(target_dir / "src" / (ident + ".cpp"),
|
||||
"#include \"" + ident + ".hpp\"\n\nnamespace " + ident +
|
||||
" {\nint answer() { return 42; }\n}\n");
|
||||
!written) {
|
||||
return std::unexpected{written.error()};
|
||||
}
|
||||
}
|
||||
if (!options.library) {
|
||||
if (!library_shape) {
|
||||
if (auto written = write_checked(target_dir / "src" / "main.cpp",
|
||||
"#include \"" + ident +
|
||||
".hpp\"\n#include <iostream>\n\nint main() {\n"
|
||||
|
||||
@@ -1067,6 +1067,43 @@ generate_ide_configs(const Graph::BuildGraph &graph, const IdeConfigOptions &opt
|
||||
if (auto r = write_ide_file(proj_root / ".idea" / "customTargets.xml", xml); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
// JetBrains run configurations per target (shell-script configs, portable across hosts).
|
||||
const auto shell_config = [&](const std::string &name, const std::string &script) {
|
||||
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<component name=\"ProjectRunConfigurationManager\">\n"
|
||||
" <configuration default=\"false\" name=\"" +
|
||||
escape_xml_attr(name) +
|
||||
"\" type=\"ShConfigurationType\">\n"
|
||||
" <option name=\"SCRIPT_TEXT\" value=\"" +
|
||||
escape_xml_attr(script) +
|
||||
"\" />\n"
|
||||
" <option name=\"INDEPENDENT_SCRIPT_PATH\" value=\"true\" />\n"
|
||||
" <option name=\"SCRIPT_WORKING_DIRECTORY\" value=\"$PROJECT_DIR$\" />\n"
|
||||
" <option name=\"INDEPENDENT_SCRIPT_WORKING_DIRECTORY\" value=\"true\" />\n"
|
||||
" <method v=\"2\" />\n"
|
||||
" </configuration>\n"
|
||||
"</component>\n";
|
||||
};
|
||||
std::size_t run_configs = 0;
|
||||
for (const auto &target : graph.targets) {
|
||||
if (run_configs >= 128) {
|
||||
break;
|
||||
}
|
||||
const bool is_test = target.kind == TargetKind::Test;
|
||||
if (!is_test && target.kind != TargetKind::Executable) {
|
||||
continue;
|
||||
}
|
||||
const std::string script = is_test
|
||||
? "vbs test --target " + target.name
|
||||
: "vbs build --target " + target.name;
|
||||
const auto file = proj_root / ".idea" / "runConfigurations" /
|
||||
(std::string{is_test ? "vbs_test_" : "vbs_build_"} + target.name +
|
||||
".xml");
|
||||
if (auto r = write_ide_file(file, shell_config(script, script)); !r) {
|
||||
return std::unexpected{r.error()};
|
||||
}
|
||||
++run_configs;
|
||||
}
|
||||
}
|
||||
|
||||
return report;
|
||||
|
||||
+141
-12
@@ -190,9 +190,30 @@ make_frontend_opts(const std::filesystem::path &project_root,
|
||||
const std::vector<std::filesystem::path> &extra_sources) {
|
||||
Config::FrontendOptions opts;
|
||||
opts.project_root = project_root;
|
||||
opts.build_root = build_root;
|
||||
opts.sdk_include_dir = std::filesystem::path{Bootstrap::sdk_include_dir};
|
||||
opts.build_root = build_root; opts.sdk_include_dir = std::filesystem::path{Bootstrap::sdk_include_dir};
|
||||
opts.sdk_source_dir = std::filesystem::path{Bootstrap::sdk_source_dir};
|
||||
// Instrument the descriptor too when the invoker is building with sanitizers: the flags
|
||||
// the project is built with are not otherwise visible to the descriptor compilation.
|
||||
const auto split_flags = [](const std::string &text) {
|
||||
std::vector<std::string> flags;
|
||||
std::size_t pos = 0;
|
||||
while (pos < text.size()) {
|
||||
while (pos < text.size() && std::isspace(static_cast<unsigned char>(text[pos])) != 0) {
|
||||
++pos;
|
||||
}
|
||||
const auto start = pos;
|
||||
while (pos < text.size() && std::isspace(static_cast<unsigned char>(text[pos])) == 0) {
|
||||
++pos;
|
||||
}
|
||||
if (pos > start) {
|
||||
flags.emplace_back(text.substr(start, pos - start));
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
};
|
||||
opts.host_compile_flags =
|
||||
split_flags(Void::Configuration::get_env_or("VBS_HOST_CXX_FLAGS", ""));
|
||||
opts.host_link_flags = split_flags(Void::Configuration::get_env_or("VBS_HOST_LDFLAGS", ""));
|
||||
std::error_code ec;
|
||||
std::vector<std::filesystem::path> sdk_candidates;
|
||||
if (const auto self_exe = Platform::current_executable_path(); self_exe) {
|
||||
@@ -2472,20 +2493,45 @@ int execute_worker_command(const WorkerCmdOptions &opts) {
|
||||
}
|
||||
|
||||
struct MigrateCmdOptions {
|
||||
std::string input_arg{"CMakeLists.txt"};
|
||||
std::string input_arg;
|
||||
std::string output_arg{"build.cpp"};
|
||||
std::string project_arg{"."};
|
||||
std::string from_arg{"cmake"};
|
||||
bool force{false};
|
||||
bool dry_run{false};
|
||||
};
|
||||
|
||||
int execute_migrate_command(const MigrateCmdOptions &opts) {
|
||||
auto imported = Config::import_cmake_lists(opts.input_arg, opts.project_arg);
|
||||
std::string input = opts.input_arg;
|
||||
if (input.empty()) {
|
||||
input = opts.from_arg == "meson" ? "meson.build" : "CMakeLists.txt";
|
||||
}
|
||||
std::string source_kind = "CMakeLists.txt";
|
||||
if (opts.from_arg != "cmake" && opts.from_arg != "meson") {
|
||||
std::cerr << "vbs migrate: unsupported --from '" << opts.from_arg
|
||||
<< "' (expected cmake or meson)\n";
|
||||
return 2;
|
||||
}
|
||||
if (opts.from_arg == "meson") {
|
||||
source_kind = "meson.build";
|
||||
}
|
||||
auto imported = opts.from_arg == "meson"
|
||||
? Config::import_meson_build(input, opts.project_arg)
|
||||
: Config::import_cmake_lists(input, opts.project_arg);
|
||||
if (!imported) {
|
||||
std::cerr << "vbs migrate: " << imported.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
const std::string rendered = Config::render_build_cpp(*imported);
|
||||
std::string rendered = Config::render_build_cpp(*imported);
|
||||
// The renderer header names the CMake source; correct it for Meson imports.
|
||||
if (source_kind == "meson.build") {
|
||||
const std::string header = "// Generated by `vbs migrate` from CMakeLists.txt. Review before use.";
|
||||
if (const auto at = rendered.find(header); at != std::string::npos) {
|
||||
rendered.replace(at, header.size(),
|
||||
"// Generated by `vbs migrate --from meson` from meson.build. "
|
||||
"Review before use.");
|
||||
}
|
||||
}
|
||||
if (opts.dry_run) {
|
||||
std::cout << rendered;
|
||||
return 0;
|
||||
@@ -2510,9 +2556,81 @@ struct PresetsCmdOptions {
|
||||
std::string file_arg{"CMakePresets.json"};
|
||||
std::string project_arg;
|
||||
std::optional<std::string> name_arg;
|
||||
std::optional<std::string> export_arg;
|
||||
};
|
||||
|
||||
int execute_presets_command(const PresetsCmdOptions &opts) {
|
||||
if (opts.export_arg) {
|
||||
// Export VBS profiles as CMake configure presets so CMake-only tools can read a VBS
|
||||
// project. The inverse of the import path (round-trippable through `vbs presets`).
|
||||
const std::filesystem::path project_root{opts.project_arg};
|
||||
const auto build_root = project_root / "build";
|
||||
const auto fopts = make_frontend_opts(project_root, build_root, {});
|
||||
auto compiled = Config::compile_descriptor(fopts);
|
||||
if (!compiled) {
|
||||
std::cerr << "vbs presets: " << compiled.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
auto profs = Config::discover_profiles(*compiled, fopts);
|
||||
if (!profs) {
|
||||
std::cerr << "vbs presets: " << profs.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::string json = "{\n \"version\": 3,\n \"configurePresets\": [\n";
|
||||
bool first = true;
|
||||
const auto cmake_build_type = [](std::string_view profile) {
|
||||
std::string lower = Void::Str::to_lower_ascii(profile);
|
||||
if (lower == "debug") {
|
||||
return std::string{"Debug"};
|
||||
}
|
||||
if (lower == "release") {
|
||||
return std::string{"Release"};
|
||||
}
|
||||
if (lower == "relwithdebinfo") {
|
||||
return std::string{"RelWithDebInfo"};
|
||||
}
|
||||
if (lower == "minsizerel") {
|
||||
return std::string{"MinSizeRel"};
|
||||
}
|
||||
return std::string{profile};
|
||||
};
|
||||
for (const auto &record : profs->records()) {
|
||||
const std::string &profile = record.name;
|
||||
ProfileContext ctx;
|
||||
try {
|
||||
ctx = profs->resolve(profile, std::nullopt, Toolchain::host_os_name(),
|
||||
Toolchain::host_architecture_name());
|
||||
} catch (const std::exception &ex) {
|
||||
std::cerr << "vbs presets: " << ex.what() << '\n';
|
||||
return 2;
|
||||
}
|
||||
if (!first) {
|
||||
json += ",\n";
|
||||
}
|
||||
first = false;
|
||||
json += " {\n";
|
||||
json += " \"name\": " + Util::json_quote(profile) + ",\n";
|
||||
json += " \"displayName\": " + Util::json_quote("VBS " + profile) + ",\n";
|
||||
json += " \"generator\": \"Ninja\",\n";
|
||||
json += " \"binaryDir\": " +
|
||||
Util::json_quote("${sourceDir}/build/" + profile) + ",\n";
|
||||
json += " \"cacheVariables\": {\n";
|
||||
json += " \"CMAKE_BUILD_TYPE\": " + Util::json_quote(cmake_build_type(profile)) +
|
||||
",\n";
|
||||
json += " \"CMAKE_CXX_COMPILER\": " +
|
||||
Util::json_quote(compiler_name(ctx.compiler)) + ",\n";
|
||||
json += " \"CMAKE_EXPORT_COMPILE_COMMANDS\": \"ON\"\n";
|
||||
json += " }\n }";
|
||||
}
|
||||
json += "\n ]\n}\n";
|
||||
if (auto written = Platform::atomic_write_file(*opts.export_arg, json, false); !written) {
|
||||
std::cerr << "vbs presets: cannot write '" << *opts.export_arg
|
||||
<< "': " << written.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::cout << "wrote " << *opts.export_arg << '\n';
|
||||
return 0;
|
||||
}
|
||||
auto presets = Config::load_cmake_presets(opts.file_arg, opts.project_arg);
|
||||
if (!presets) {
|
||||
std::cerr << "vbs presets: " << presets.error().message() << '\n';
|
||||
@@ -3635,6 +3753,7 @@ struct InitCmdOptions {
|
||||
bool library{false};
|
||||
bool with_toml{false};
|
||||
bool force{false};
|
||||
std::string template_arg{"app"};
|
||||
};
|
||||
|
||||
int execute_init_command(const InitCmdOptions &opts) {
|
||||
@@ -3644,14 +3763,15 @@ int execute_init_command(const InitCmdOptions &opts) {
|
||||
options.library = opts.library;
|
||||
options.with_toml = opts.with_toml;
|
||||
options.force = opts.force;
|
||||
options.template_name = opts.template_arg;
|
||||
auto report = Config::scaffold_project(options);
|
||||
if (!report) {
|
||||
std::cerr << report.error().message() << '\n';
|
||||
return report.error().kind() == Void::Result::ErrorKind::conflict ? 2 : 1;
|
||||
}
|
||||
Void::Log::info("Init", "Initialized VBS {} project '{}' in '{}'",
|
||||
opts.library ? "library" : "application", report->project_name,
|
||||
report->target_dir.string());
|
||||
opts.template_arg == "app" ? "application" : opts.template_arg,
|
||||
report->project_name, report->target_dir.string());
|
||||
std::cout << "initialized " << report->project_name << " in " << report->target_dir.string()
|
||||
<< '\n';
|
||||
return 0;
|
||||
@@ -4478,25 +4598,30 @@ int main(int argc, char **argv) {
|
||||
add_log_flags(worker_cmd);
|
||||
|
||||
auto &migrate_cmd = root.subcommand(
|
||||
"migrate", "Generate a build.cpp scaffold from a CMakeLists.txt (bounded subset)");
|
||||
"migrate", "Generate a build.cpp scaffold from a CMakeLists.txt or meson.build");
|
||||
migrate_cmd
|
||||
.option_default("--input", "-i", "CMakeLists.txt path", migrate_opts.input_arg,
|
||||
"CMakeLists.txt")
|
||||
.option_default("--input", "-i",
|
||||
"Input file (default depends on --from: CMakeLists.txt or meson.build)",
|
||||
migrate_opts.input_arg, "")
|
||||
.option_default("--output", "-o", "Output build.cpp path", migrate_opts.output_arg,
|
||||
"build.cpp")
|
||||
.option_default("--project", "-C", "Project root", migrate_opts.project_arg, ".")
|
||||
.option_default_checked("--from", "", "Input format: cmake (default) or meson",
|
||||
migrate_opts.from_arg, "cmake", {"cmake", "meson"})
|
||||
.flag("--force", "", "Overwrite an existing output file", migrate_opts.force)
|
||||
.flag("--dry-run", "", "Print the scaffold instead of writing it", migrate_opts.dry_run);
|
||||
add_log_flags(migrate_cmd);
|
||||
|
||||
auto &presets_cmd = root.subcommand(
|
||||
"presets", "Import CMake configure presets (CMakePresets.json) as VBS equivalents");
|
||||
"presets", "Import or export CMake configure presets (CMakePresets.json)");
|
||||
presets_cmd
|
||||
.option_default("--file", "-f", "CMakePresets.json path", presets_opts.file_arg,
|
||||
"CMakePresets.json")
|
||||
.option_default("--project", "-C", "Project root for ${sourceDir}",
|
||||
presets_opts.project_arg, cwd)
|
||||
.option("--name", "-n", "Print the VBS command for one preset", presets_opts.name_arg);
|
||||
.option("--name", "-n", "Print the VBS command for one preset", presets_opts.name_arg)
|
||||
.option("--export", "-e", "Write the VBS profiles as CMake presets to this file",
|
||||
presets_opts.export_arg);
|
||||
add_log_flags(presets_cmd);
|
||||
|
||||
auto &lock_cmd = root.subcommand("lock", "Inspect the project's vbs.lock");
|
||||
@@ -4626,6 +4751,10 @@ int main(int argc, char **argv) {
|
||||
init_cmd.option_default("--dir", "-C", "Target project directory", init_opts.dir_arg, cwd)
|
||||
.option("--name", "-n", "Project/target name (defaults to directory name)",
|
||||
init_opts.name_arg)
|
||||
.option_default_checked("--template", "-t",
|
||||
"Project template: app (default), library, header-only or shared",
|
||||
init_opts.template_arg, "app",
|
||||
{"app", "library", "header-only", "shared"})
|
||||
.flag("--library", "", "Scaffold a static library project instead of an executable",
|
||||
init_opts.library)
|
||||
.flag("--with-toml", "", "Include a vbs.deps.toml dependency manifest", init_opts.with_toml)
|
||||
|
||||
@@ -38,6 +38,11 @@ check_process(0 "--trace" "" build --help)
|
||||
check_process(0 "Usage: vbs completions " "" completions --help)
|
||||
check_process(2 "" "unsupported --shell" completions --shell tcsh)
|
||||
check_process(0 "Usage: vbs man " "" man --help)
|
||||
check_process(0 "--from" "" migrate --help)
|
||||
check_process(2 "" "invalid value 'bazel' for '--from'" migrate --from bazel)
|
||||
check_process(2 "" "invalid value 'bogus' for '--template'" init --template bogus)
|
||||
check_process(0 "--template" "" init --help)
|
||||
check_process(0 "--export" "" presets --help)
|
||||
check_process(2 "" "invalid --repeat mode" test --repeat bogus)
|
||||
check_process(2 "" "invalid --repeat count" test --repeat until-pass:0)
|
||||
check_process(2 "" "invalid --retry value" test --retry 99)
|
||||
|
||||
@@ -3475,6 +3475,11 @@ VOID_TEST(FullV1Tests, ide_integration_compdb_build_cpp_and_editor_configs_end_t
|
||||
// Check every generated file exists and every JSON file parses strictly.
|
||||
Void::Testing::expect(std::filesystem::exists(proj / ".clangd"));
|
||||
Void::Testing::expect(std::filesystem::exists(proj / ".idea" / "customTargets.xml"));
|
||||
// JetBrains run configurations for the scaffolded targets (shell configs).
|
||||
Void::Testing::expect(std::filesystem::exists(proj / ".idea" / "runConfigurations" /
|
||||
"vbs_build_ide_demo.xml"));
|
||||
Void::Testing::expect(std::filesystem::exists(proj / ".idea" / "runConfigurations" /
|
||||
"vbs_test_ide_demo_tests.xml"));
|
||||
for (const auto &json_file : {proj / ".vscode" / "tasks.json", proj / ".vscode" / "launch.json",
|
||||
proj / ".vscode" / "settings.json", proj / ".zed" / "tasks.json",
|
||||
proj / ".zed" / "debug.json"}) {
|
||||
@@ -4214,3 +4219,131 @@ VOID_TEST(FullV1Tests, completions_and_man_pages_are_generated_from_the_cli) {
|
||||
Void::Testing::require(nested.has_value());
|
||||
Void::Testing::expect(nested->find(".TH vbs\\-compdb\\-use 1") != std::string::npos);
|
||||
}
|
||||
|
||||
// === Migration breadth: meson.build -> build.cpp scaffold ===
|
||||
VOID_TEST(FullV1Tests, meson_build_import_renders_build_cpp_scaffold) {
|
||||
Void::FileSystem::TempDir tmp{"vbs_meson_migrate_"};
|
||||
write_file(tmp / "meson.build", R"meson(
|
||||
project('bench', 'cpp', version : '1.0')
|
||||
|
||||
bench_sources = files('src/f1.cpp', 'src/f2.cpp')
|
||||
|
||||
lib = static_library('bench_lib', bench_sources,
|
||||
include_directories : include_directories('include'))
|
||||
|
||||
app_sources = ['src/main.cpp']
|
||||
executable('bench_app', app_sources,
|
||||
link_with : lib,
|
||||
dependencies : [dependency('zlib')],
|
||||
install : true,
|
||||
install_dir : 'bin')
|
||||
|
||||
# Not translated, must be reported.
|
||||
custom_target('gen', output : 'gen.cpp', command : ['gen.sh'])
|
||||
)meson");
|
||||
|
||||
auto imported = Config::import_meson_build(tmp / "meson.build", tmp.path());
|
||||
Void::Testing::require(imported.has_value());
|
||||
Void::Testing::expect_eq(imported->project_name, std::string{"bench"});
|
||||
Void::Testing::expect_eq(imported->targets.size(), std::size_t{2});
|
||||
|
||||
const auto &library = imported->targets.at(0);
|
||||
Void::Testing::expect_eq(library.name, std::string{"bench_lib"});
|
||||
Void::Testing::expect_eq(library.kind, std::string{"static"});
|
||||
Void::Testing::expect_eq(library.sources.size(), std::size_t{2});
|
||||
Void::Testing::expect_eq(library.sources.at(0), std::string{"src/f1.cpp"});
|
||||
Void::Testing::expect_eq(library.private_includes.at(0), std::string{"include"});
|
||||
|
||||
const auto &app = imported->targets.at(1);
|
||||
Void::Testing::expect_eq(app.name, std::string{"bench_app"});
|
||||
Void::Testing::expect_eq(app.kind, std::string{"executable"});
|
||||
Void::Testing::expect_eq(app.sources.at(0), std::string{"src/main.cpp"});
|
||||
Void::Testing::expect_eq(app.private_links.at(0), std::string{"bench_lib"});
|
||||
Void::Testing::expect(app.installed);
|
||||
Void::Testing::expect_eq(app.install_destination, std::string{"bin"});
|
||||
|
||||
bool saw_dependency_note = false;
|
||||
bool saw_custom_target_note = false;
|
||||
for (const auto ¬e : imported->notes) {
|
||||
if (note.find("zlib") != std::string::npos) {
|
||||
saw_dependency_note = true;
|
||||
}
|
||||
if (note.find("custom_target") != std::string::npos) {
|
||||
saw_custom_target_note = true;
|
||||
}
|
||||
}
|
||||
Void::Testing::expect(saw_dependency_note);
|
||||
Void::Testing::expect(saw_custom_target_note);
|
||||
|
||||
const std::string rendered = Config::render_build_cpp(*imported);
|
||||
Void::Testing::expect(rendered.find("static_library(\"bench_lib\")") != std::string::npos);
|
||||
Void::Testing::expect(rendered.find("executable(\"bench_app\")") != std::string::npos);
|
||||
Void::Testing::expect(rendered.find(".link(t_bench_lib") != std::string::npos);
|
||||
}
|
||||
|
||||
// === Project templates: `vbs init --template` shapes build and test ===
|
||||
VOID_TEST(FullV1Tests, init_templates_scaffold_buildable_projects) {
|
||||
const auto vbs_bin = locate_vbs_binary();
|
||||
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
|
||||
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
|
||||
return;
|
||||
}
|
||||
Void::FileSystem::TempDir tmp{"vbs_init_templates_"};
|
||||
auto run_vbs = [&](std::vector<std::string> args) {
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = vbs_bin;
|
||||
req.arguments = std::move(args);
|
||||
req.timeout = std::chrono::seconds{600};
|
||||
return Platform::run_supervised(req);
|
||||
};
|
||||
for (const char *shape : {"app", "library", "header-only", "shared"}) {
|
||||
const auto dir = tmp / shape;
|
||||
auto initialized = run_vbs({"init", "--dir", dir.string(), "--name", "demo",
|
||||
"--template", shape});
|
||||
Void::Testing::expect(initialized.has_value() && initialized->succeeded());
|
||||
auto built = run_vbs({"test", "--project", dir.string(),
|
||||
"--build-dir", (dir / "build").string(), "--jobs", "2"});
|
||||
Void::Testing::expect(built.has_value() && built->succeeded());
|
||||
if (built && !built->succeeded()) {
|
||||
std::cerr << "template '" << shape << "' failed:\n" << built->stderr_data << '\n';
|
||||
}
|
||||
}
|
||||
auto bad = run_vbs({"init", "--dir", (tmp / "bogus").string(), "--template", "bogus"});
|
||||
Void::Testing::expect(bad.has_value() && bad->exit_code == 2);
|
||||
}
|
||||
|
||||
// === Presets export: VBS profiles -> CMakePresets.json (round-trips through the importer) ===
|
||||
VOID_TEST(FullV1Tests, presets_export_round_trips_through_the_importer) {
|
||||
const auto vbs_bin = locate_vbs_binary();
|
||||
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
|
||||
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
|
||||
return;
|
||||
}
|
||||
Void::FileSystem::TempDir tmp{"vbs_presets_export_"};
|
||||
const auto proj = tmp / "proj";
|
||||
write_file(proj / "build.cpp", R"cpp(#include <Void/Build.hpp>
|
||||
void build(Void::Build::Project &p) {
|
||||
p.executable("app").sources({"src/main.cpp"});
|
||||
}
|
||||
)cpp");
|
||||
write_file(proj / "src" / "main.cpp", "int main() { return 0; }\n");
|
||||
const auto exported = tmp / "CMakePresets.json";
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = vbs_bin;
|
||||
req.arguments = {"presets", "--project", proj.string(), "--export", exported.string()};
|
||||
req.timeout = std::chrono::seconds{300};
|
||||
auto res = Platform::run_supervised(req);
|
||||
Void::Testing::expect(res.has_value() && res->succeeded());
|
||||
auto text = Void::FileSystem::read_file(exported);
|
||||
Void::Testing::require(text.has_value());
|
||||
Void::Testing::expect(text->find("\"configurePresets\"") != std::string::npos);
|
||||
Void::Testing::expect(text->find("\"CMAKE_BUILD_TYPE\"") != std::string::npos);
|
||||
|
||||
// The exported file must be readable by the importer.
|
||||
auto imported = Config::load_cmake_presets(exported, proj);
|
||||
Void::Testing::require(imported.has_value());
|
||||
Void::Testing::expect(!imported->empty());
|
||||
for (const auto &preset : *imported) {
|
||||
Void::Testing::expect(preset.build_dir.has_value());
|
||||
}
|
||||
}
|
||||
@@ -2264,10 +2264,71 @@ VOID_TEST(RegistryTests, worker_action_queue_enqueue_lease_and_complete) {
|
||||
Void::Testing::expect(listing.has_value() && listing->status == 200);
|
||||
if (listing) {
|
||||
Void::Testing::expect(listing->body.find(key_a) != std::string::npos);
|
||||
Void::Testing::expect(listing->body.find("\"attempts\"") != std::string::npos);
|
||||
}
|
||||
(*svc)->stop_http();
|
||||
}
|
||||
|
||||
// Leases are retried, but only up to a budget: a queued action that never reports a
|
||||
// result is abandoned (dead-lettered) instead of being leased forever.
|
||||
VOID_TEST(RegistryTests, worker_queue_abandons_actions_after_repeated_leases) {
|
||||
Void::FileSystem::TempDir tmp{"vbs_queue_attempts_"};
|
||||
RegistryConfig cfg;
|
||||
cfg.data_dir = tmp / "reg_data";
|
||||
cfg.bind_address = "127.0.0.1";
|
||||
cfg.port = 0;
|
||||
cfg.bootstrap_admin_user = "admin";
|
||||
cfg.bootstrap_admin_password = "admin_pw";
|
||||
auto svc = RegistryService::open(cfg);
|
||||
Void::Testing::expect(svc.has_value());
|
||||
if (!svc) {
|
||||
return;
|
||||
}
|
||||
Void::Testing::expect((*svc)->create_user("q_pub", "q_pass", Role::Publisher).has_value());
|
||||
auto tok = (*svc)->create_token("q_pub", "q", {"read", "publish"});
|
||||
Void::Testing::require(tok.has_value());
|
||||
Void::Testing::expect((*svc)->start_http().has_value());
|
||||
const auto port = (*svc)->bound_port();
|
||||
const std::map<std::string, std::string, std::less<>> auth{{"Authorization", "Bearer " + *tok}};
|
||||
|
||||
const std::string key = Util::sha256_hex("poison-action");
|
||||
auto enqueued = send_loopback_http(port, "POST", "/api/v1/queue", auth,
|
||||
"{\"action_keys\":[\"" + key + "\"]}");
|
||||
Void::Testing::expect(enqueued.has_value() && enqueued->status == 200);
|
||||
auto registered = send_loopback_http(port, "POST", "/api/v1/workers", auth, "{}");
|
||||
Void::Testing::require(registered.has_value() && registered->status == 201);
|
||||
const std::string worker_id = extract_json_str(registered->body, "worker_id");
|
||||
|
||||
// Five leases that are never completed (each lease expires after one second).
|
||||
int leases = 0;
|
||||
for (int attempt = 1; attempt <= 5; ++attempt) {
|
||||
auto leased = send_loopback_http(port, "POST", "/api/v1/queue/lease", auth,
|
||||
"{\"worker_id\":\"" + worker_id +
|
||||
"\",\"lease_seconds\":1}");
|
||||
Void::Testing::expect(leased.has_value() && leased->status == 200);
|
||||
if (!leased || leased->status != 200) {
|
||||
break;
|
||||
}
|
||||
++leases;
|
||||
Void::Testing::expect(leased->body.find("\"attempt\":" + std::to_string(attempt)) !=
|
||||
std::string::npos);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{1100});
|
||||
}
|
||||
Void::Testing::expect_eq(leases, 5);
|
||||
|
||||
// The sixth lease finds nothing: the action was abandoned, not leased again.
|
||||
auto exhausted = send_loopback_http(port, "POST", "/api/v1/queue/lease", auth,
|
||||
"{\"worker_id\":\"" + worker_id +
|
||||
"\",\"lease_seconds\":60}");
|
||||
Void::Testing::expect(exhausted.has_value() && exhausted->status == 404);
|
||||
auto listing = send_loopback_http(port, "GET", "/api/v1/queue", auth);
|
||||
Void::Testing::require(listing.has_value() && listing->status == 200);
|
||||
Void::Testing::expect(listing->body.find(key) != std::string::npos); // in "abandoned"
|
||||
Void::Testing::expect(listing->body.find("\"abandoned\":[\"" + key + "\"]") !=
|
||||
std::string::npos);
|
||||
(*svc)->stop_http();
|
||||
}
|
||||
|
||||
// `vbs test --cdash-output FILE --cdash URL`: writes a CDash Test.xml report and submits it as
|
||||
// multipart/form-data to submit.php (captured by a loopback HTTP server).
|
||||
VOID_TEST(RegistryTests, cdash_test_report_output_and_submission) {
|
||||
|
||||
Reference in new issue
Block a user