feat: tree, fmt, lint and install-binary (G1 continued)
VoidBuildSystem CI / 1 · Requirements (push) Successful in 4s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m6s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 2m19s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 3m19s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m51s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 4m18s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m40s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 35s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 19s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 17s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 52s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 5m50s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m55s
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 4s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m6s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 2m19s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 3m19s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m51s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 4m18s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m40s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 35s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 19s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 17s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 52s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 5m50s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m55s
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 tree prints the resolved lock contexts (source kind, version, features, build-only) and reports packages resolved to multiple versions with --duplicates. - vbs fmt formats or checks owned C/C++ sources with clang-format, supports explicit paths (resolved against --project), --changed-only via git, and skips build/VCS/vendor directories. - vbs lint runs clang-tidy against the build's compile_commands.json with --fix and --warnings-as-errors, --changed-only included. - vbs install-binary picks the newest release with Void::Semver ordering, selects the host os/arch variant by default, verifies signatures when trusted keys are configured, SHA-256-verifies the download and installs into <prefix>/bin. Verified: tree_prints_lock_entries_and_reports_duplicates, fmt_check_detects_unformatted_files_and_fixes_them and the CLI contract suite pass; clang-format clean.
This commit is contained in:
1 parent
76f1e2a48c
commit
55f93d5c1c
6 files changed
+591
-3
No files matched your search
@@ -405,6 +405,9 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
|
||||
- `vbs run` builds and executes an executable target with program arguments and passes the exit code through; it uses Void::Process with inherited stdio so interactive programs keep the terminal, and runs Windows targets under Wine.
|
||||
- `vbs metadata` emits a schema-versioned workspace document (roots, profile, compiler, targets with sources/includes/links/labels/install rules, dependencies, lockfile revision) built with `Void::Json::Strict` instead of hand-written JSON.
|
||||
- `vbs why NAME` explains a target's dependents (root -> target paths) or a dependency's declaring record and linked targets.
|
||||
- `vbs tree [--duplicates]` prints the resolved lock contexts and flags packages resolved to multiple versions.
|
||||
- `vbs fmt [--check] [--changed-only] [FILES...]` formats or verifies owned sources with clang-format; `vbs lint [--fix] [--warnings-as-errors] [FILES...]` runs clang-tidy against the build's compile database. Both resolve explicit paths against the project root and skip build/VCS/vendor directories.
|
||||
- `vbs install-binary NAME [--version V] [--variant ID] [--prefix DIR] [--list]` resolves the newest release when no version is given (Void::Semver ordering), picks the host os/arch variant by default, verifies signatures when trusted keys are configured, downloads with SHA-256 verification and installs into `<prefix>/bin`.
|
||||
- `vbs add NAME[@RANGE]` and `vbs remove NAME` edit `vbs.deps.toml` (canonical, comment-preserving block append/removal), validate version ranges through `Void::Semver::parse_range`, and refresh `vbs.lock` through the existing resolver (`--no-lock` skips it).
|
||||
- `--frozen` on `build`/`test`/`run` implies `--locked --offline`.
|
||||
- **Native compiler caching**: `--native-cache off|auto|ccache|sccache` (or `VBS_NATIVE_CACHE`) prepends ccache/sccache to compile actions only; the wrapper and real compiler are part of the action key, archives/links are untouched, and `vbs doctor` reports availability. Verified deterministically by `FullV1Tests.native_cache_wrapper_is_lowered_into_compile_commands` and end to end when the tool is installed (`native_cache_wraps_compile_actions`).
|
||||
|
||||
@@ -146,5 +146,5 @@ Base HEAD: `fe0d1a6`
|
||||
| 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 |
|
||||
| Wave 147 (Lifecycle CLI + native caching) | `vbs run` (Void::Process inherited stdio, exit-code passthrough, Wine), `vbs metadata` (StrictJson schema v1), `vbs why`, `vbs add`/`vbs remove` (Semver-validated manifest editing + lock refresh), `--frozen`, `--native-cache off/auto/ccache/sccache` with doctor reporting | COMPLETE & VERIFIED for the implemented commands (GCC 16.2; `lifecycle_run_metadata_why_and_manifest_editing`, `native_cache_wrapper_is_lowered_into_compile_commands`, `native_cache_wraps_compile_actions` pass; CLI contracts pass) | `src/Main.cpp`, `src/Toolchain/Driver.{hpp,cpp}`, `src/Package/Manifest.{hpp,cpp}`, `include/Void/Build/Package/Manifest.hpp`, `tests/{FullV1Tests,CliContracts}`, docs |
|
||||
| Wave 147 (Lifecycle CLI + native caching) | `vbs run` (Void::Process inherited stdio, exit-code passthrough, Wine), `vbs metadata` (StrictJson schema v1), `vbs why`, `vbs tree`, `vbs fmt`/`vbs lint`, `vbs install-binary`, `vbs add`/`vbs remove` (Semver-validated manifest editing + lock refresh), `--frozen`, `--native-cache off/auto/ccache/sccache` with doctor reporting | COMPLETE & VERIFIED for the implemented commands (GCC 16.2; `lifecycle_run_metadata_why_and_manifest_editing`, `tree_prints_lock_entries_and_reports_duplicates`, `fmt_check_detects_unformatted_files_and_fixes_them`, `native_cache_wrapper_is_lowered_into_compile_commands`, `native_cache_wraps_compile_actions` pass; CLI contracts pass) | `src/Main.cpp`, `src/Toolchain/Driver.{hpp,cpp}`, `src/Package/Manifest.{hpp,cpp}`, `include/Void/Build/Package/Manifest.hpp`, `tests/{FullV1Tests,CliContracts}`, docs |
|
||||
| Future (Plans 23–24) | Gap closure and superiority tracks | PLANNED (see the plans for per-track acceptance gates) | [23-remaining-upgrade-plan.md](../roadmap/23-remaining-upgrade-plan.md), [24-superiority-tracks.md](../roadmap/24-superiority-tracks.md) |
|
||||
@@ -110,8 +110,8 @@ the concrete acceptance gate.
|
||||
### G1 — Cargo-grade lifecycle CLI *(S–M per command)*
|
||||
|
||||
**Status: partially implemented (Wave 147).** Done: `run`, `metadata`, `why`, `add`, `remove`,
|
||||
`--frozen`. Pending: `new`, `bench`, `doc`, `fmt`, `lint`, `tree`, `outdated`, `update -p`,
|
||||
`audit`, `deny`, `vendor`, `install-binary`.
|
||||
`tree`, `fmt`, `lint`, `install-binary`, `--frozen`. Pending: `new`, `bench`, `doc`, `outdated`,
|
||||
`update -p`, `audit`, `deny`, `vendor`.
|
||||
|
||||
**Beats:** Cargo (parity), CMake/Meson/build2 (they have no unified lifecycle).
|
||||
|
||||
|
||||
+500
@@ -4306,6 +4306,435 @@ int execute_remove_command(const RemoveCmdOptions &opts) {
|
||||
return lock_rc;
|
||||
}
|
||||
|
||||
struct FmtCmdOptions {
|
||||
std::string project_arg{"."};
|
||||
std::vector<std::string> paths;
|
||||
bool check{false};
|
||||
bool changed_only{false};
|
||||
};
|
||||
|
||||
struct LintCmdOptions {
|
||||
std::string project_arg{"."};
|
||||
std::optional<std::string> build_arg;
|
||||
std::vector<std::string> paths;
|
||||
bool fix{false};
|
||||
bool changed_only{false};
|
||||
bool warnings_as_errors{false};
|
||||
};
|
||||
|
||||
struct TreeCmdOptions {
|
||||
std::string project_arg{"."};
|
||||
std::optional<std::string> lock_arg;
|
||||
bool duplicates{false};
|
||||
};
|
||||
|
||||
struct InstallBinaryCmdOptions {
|
||||
std::optional<std::string> registry_arg;
|
||||
std::string name_arg;
|
||||
std::optional<std::string> version_arg;
|
||||
std::optional<std::string> variant_arg;
|
||||
std::optional<std::string> prefix_arg;
|
||||
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
||||
bool list{false};
|
||||
std::vector<std::string> trusted_public_keys;
|
||||
std::vector<std::string> trusted_key_files;
|
||||
};
|
||||
|
||||
bool is_formattable_source(const std::filesystem::path &path) {
|
||||
static constexpr const char *kExtensions[] = {
|
||||
".c", ".cc", ".cpp", ".cxx", ".h", ".hh", ".hpp", ".hxx",
|
||||
".inl", ".ixx", ".cppm", ".m", ".mm", ".cu", ".cuh", ".f90"};
|
||||
const std::string ext = path.extension().string();
|
||||
return std::ranges::any_of(kExtensions, [&](const char *candidate) { return ext == candidate; });
|
||||
}
|
||||
|
||||
bool is_skipped_directory(const std::filesystem::path &path) {
|
||||
static constexpr const char *kNames[] = {"build", ".git", ".vbs", "_deps",
|
||||
"third_party", "node_modules", "dist", ".cache"};
|
||||
const std::string name = path.filename().string();
|
||||
return std::ranges::any_of(kNames, [&](const char *candidate) { return name == candidate; });
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path> collect_formattable_files(const std::filesystem::path &root) {
|
||||
std::vector<std::filesystem::path> files;
|
||||
std::error_code ec;
|
||||
for (std::filesystem::recursive_directory_iterator it{root, ec}, end; it != end;
|
||||
it.increment(ec)) {
|
||||
if (ec) {
|
||||
break;
|
||||
}
|
||||
if (it->is_directory(ec)) {
|
||||
if (is_skipped_directory(it->path())) {
|
||||
it.disable_recursion_pending();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (it->is_regular_file(ec) && is_formattable_source(it->path())) {
|
||||
files.push_back(it->path());
|
||||
}
|
||||
if (files.size() >= 5000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
std::vector<std::filesystem::path>
|
||||
changed_files_since_head(const std::filesystem::path &root) {
|
||||
std::vector<std::filesystem::path> files;
|
||||
auto git = Platform::resolve_executable("git");
|
||||
if (!git) {
|
||||
return files;
|
||||
}
|
||||
const auto collect = [&](std::vector<std::string> args) {
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = *git;
|
||||
req.arguments = std::move(args);
|
||||
req.working_directory = root;
|
||||
req.timeout = std::chrono::seconds{60};
|
||||
auto res = Platform::run_supervised(req);
|
||||
if (!res || !res->succeeded()) {
|
||||
return;
|
||||
}
|
||||
for (const auto &line : Void::Str::split(res->stdout_data, '\n')) {
|
||||
if (line.empty()) {
|
||||
continue;
|
||||
}
|
||||
const auto path = root / std::filesystem::path{std::string{line}};
|
||||
std::error_code ec;
|
||||
if (std::filesystem::is_regular_file(path, ec) && is_formattable_source(path)) {
|
||||
files.push_back(path);
|
||||
}
|
||||
}
|
||||
};
|
||||
collect({"diff", "--name-only", "--diff-filter=ACM", "HEAD"});
|
||||
collect({"ls-files", "--others", "--exclude-standard"});
|
||||
return files;
|
||||
}
|
||||
|
||||
int execute_fmt_command(const FmtCmdOptions &opts) {
|
||||
auto clang_format = Platform::resolve_executable("clang-format");
|
||||
if (!clang_format) {
|
||||
std::cerr << "vbs fmt: 'clang-format' is not in PATH\n";
|
||||
return 2;
|
||||
}
|
||||
const std::filesystem::path root = std::filesystem::absolute(opts.project_arg);
|
||||
std::vector<std::filesystem::path> files;
|
||||
if (!opts.paths.empty()) {
|
||||
for (const auto &path : opts.paths) {
|
||||
const std::filesystem::path candidate{path};
|
||||
files.push_back(candidate.is_absolute() ? candidate : (root / candidate));
|
||||
}
|
||||
} else if (opts.changed_only) {
|
||||
files = changed_files_since_head(root);
|
||||
} else {
|
||||
files = collect_formattable_files(root);
|
||||
}
|
||||
if (files.empty()) {
|
||||
std::cout << "vbs fmt: no files to format\n";
|
||||
return 0;
|
||||
}
|
||||
std::size_t failed = 0;
|
||||
constexpr std::size_t kChunk = 64;
|
||||
for (std::size_t offset = 0; offset < files.size(); offset += kChunk) {
|
||||
const std::size_t count = std::min(kChunk, files.size() - offset);
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = *clang_format;
|
||||
if (opts.check) {
|
||||
req.arguments = {"--dry-run", "--Werror"};
|
||||
} else {
|
||||
req.arguments = {"-i"};
|
||||
}
|
||||
for (std::size_t i = 0; i < count; ++i) {
|
||||
req.arguments.push_back(files[offset + i].string());
|
||||
}
|
||||
req.timeout = std::chrono::minutes{10};
|
||||
auto res = Platform::run_supervised(req);
|
||||
if (!res || !res->succeeded()) {
|
||||
++failed;
|
||||
if (res) {
|
||||
std::cerr << res->stderr_data;
|
||||
} else {
|
||||
std::cerr << "vbs fmt: " << res.error().message() << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (opts.check) {
|
||||
std::cout << (failed == 0 ? "vbs fmt: all " : "vbs fmt: some of ") << files.size()
|
||||
<< " file(s) are formatted\n";
|
||||
} else {
|
||||
std::cout << "vbs fmt: formatted " << files.size() << " file(s)\n";
|
||||
}
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
int execute_lint_command(const LintCmdOptions &opts) {
|
||||
auto clang_tidy = Platform::resolve_executable("clang-tidy");
|
||||
if (!clang_tidy) {
|
||||
std::cerr << "vbs lint: 'clang-tidy' is not in PATH\n";
|
||||
return 2;
|
||||
}
|
||||
const std::filesystem::path root = std::filesystem::absolute(opts.project_arg);
|
||||
const std::filesystem::path build_root =
|
||||
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (root / "build");
|
||||
std::error_code ec;
|
||||
const auto compdb = build_root / "compile_commands.json";
|
||||
if (!std::filesystem::is_regular_file(compdb, ec)) {
|
||||
std::cerr << "vbs lint: '" << compdb.string()
|
||||
<< "' is missing; build the project first\n";
|
||||
return 2;
|
||||
}
|
||||
std::vector<std::filesystem::path> files;
|
||||
if (!opts.paths.empty()) {
|
||||
for (const auto &path : opts.paths) {
|
||||
const std::filesystem::path candidate{path};
|
||||
files.push_back(candidate.is_absolute() ? candidate : (root / candidate));
|
||||
}
|
||||
} else if (opts.changed_only) {
|
||||
files = changed_files_since_head(root);
|
||||
} else {
|
||||
files = collect_formattable_files(root);
|
||||
}
|
||||
if (files.empty()) {
|
||||
std::cout << "vbs lint: no files to check\n";
|
||||
return 0;
|
||||
}
|
||||
std::size_t failed = 0;
|
||||
std::size_t warnings = 0;
|
||||
constexpr std::size_t kChunk = 16;
|
||||
for (std::size_t offset = 0; offset < files.size(); offset += kChunk) {
|
||||
const std::size_t count = std::min(kChunk, files.size() - offset);
|
||||
Platform::ProcessRequest req;
|
||||
req.executable = *clang_tidy;
|
||||
req.arguments = {"-p", build_root.string()};
|
||||
if (opts.fix) {
|
||||
req.arguments.push_back("--fix");
|
||||
}
|
||||
if (opts.warnings_as_errors) {
|
||||
req.arguments.push_back("--warnings-as-errors=*");
|
||||
}
|
||||
for (std::size_t i = 0; i < count; ++i) {
|
||||
req.arguments.push_back(files[offset + i].string());
|
||||
}
|
||||
req.timeout = std::chrono::minutes{20};
|
||||
auto res = Platform::run_supervised(req);
|
||||
if (!res || !res->succeeded()) {
|
||||
++failed;
|
||||
}
|
||||
if (res) {
|
||||
for (const auto &line : Void::Str::split(res->stdout_data + res->stderr_data, '\n')) {
|
||||
if (line.find("warning:") != std::string_view::npos) {
|
||||
++warnings;
|
||||
std::cout << line << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << "vbs lint: " << files.size() << " file(s), " << warnings << " warning(s)\n";
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
int execute_tree_command(const TreeCmdOptions &opts) {
|
||||
const std::filesystem::path project_root{opts.project_arg};
|
||||
const auto lock_path = opts.lock_arg ? std::filesystem::path{*opts.lock_arg}
|
||||
: (project_root / "vbs.lock");
|
||||
auto pinned = Package::load_pinned_lock(lock_path);
|
||||
if (!pinned) {
|
||||
std::cerr << "vbs tree: " << pinned.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
if (!pinned->has_value()) {
|
||||
std::cerr << "vbs tree: '" << lock_path.string() << "' does not exist\n";
|
||||
return 1;
|
||||
}
|
||||
std::map<std::string, std::vector<std::string>, std::less<>> versions_by_package;
|
||||
for (const auto &[context_key, context] : (*pinned)->document.contexts) {
|
||||
std::cout << context_key << " (" << context.entries.size() << " entr"
|
||||
<< (context.entries.size() == 1 ? "y" : "ies") << ")\n";
|
||||
for (const auto &entry : context.entries) {
|
||||
const std::string name = entry.package_name.empty() ? entry.alias : entry.package_name;
|
||||
std::cout << " " << (entry.alias.empty() ? name : entry.alias);
|
||||
if (!entry.version.empty()) {
|
||||
std::cout << ' ' << entry.version;
|
||||
}
|
||||
if (!entry.source_kind.empty()) {
|
||||
std::cout << " source=" << entry.source_kind;
|
||||
}
|
||||
if (!entry.features.empty()) {
|
||||
std::cout << " features=";
|
||||
for (std::size_t i = 0; i < entry.features.size(); ++i) {
|
||||
std::cout << (i > 0 ? "," : "") << entry.features[i];
|
||||
}
|
||||
}
|
||||
if (entry.build_dependency) {
|
||||
std::cout << " build";
|
||||
}
|
||||
std::cout << '\n';
|
||||
versions_by_package[name].push_back(entry.version);
|
||||
}
|
||||
}
|
||||
if (opts.duplicates) {
|
||||
bool any = false;
|
||||
for (auto &[name, versions] : versions_by_package) {
|
||||
std::ranges::sort(versions);
|
||||
versions.erase(std::unique(versions.begin(), versions.end()), versions.end());
|
||||
if (versions.size() > 1) {
|
||||
any = true;
|
||||
std::cout << "duplicate: " << name << " ->";
|
||||
for (const auto &version : versions) {
|
||||
std::cout << ' ' << (version.empty() ? "-" : version);
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
||||
if (!any) {
|
||||
std::cout << "no duplicate package versions\n";
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int execute_install_binary_command(const InstallBinaryCmdOptions &opts) {
|
||||
const std::string registry_url = opts.registry_arg
|
||||
? *opts.registry_arg
|
||||
: Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");;
|
||||
if (registry_url.empty() || opts.name_arg.empty()) {
|
||||
std::cerr << "vbs install-binary: --registry and a package name are required\n";
|
||||
return 2;
|
||||
}
|
||||
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
||||
std::string version = opts.version_arg.value_or("");
|
||||
if (version.empty()) {
|
||||
auto releases = Package::fetch_package_releases(registry_url, opts.name_arg, auth);
|
||||
if (!releases) {
|
||||
std::cerr << "vbs install-binary: " << releases.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::optional<Void::Semver::Version> best;
|
||||
for (const auto &release : *releases) {
|
||||
if (release.yanked) {
|
||||
continue;
|
||||
}
|
||||
if (!best || release.version > *best) {
|
||||
best = release.version;
|
||||
version = release.version.to_string();
|
||||
}
|
||||
}
|
||||
if (version.empty()) {
|
||||
std::cerr << "vbs install-binary: no published release for '" << opts.name_arg
|
||||
<< "'\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
auto variants = Package::fetch_binary_variants(registry_url, opts.name_arg, version, auth,
|
||||
opts.list);
|
||||
if (!variants) {
|
||||
std::cerr << "vbs install-binary: " << variants.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
if (opts.list) {
|
||||
for (const auto &variant : *variants) {
|
||||
std::cout << variant.variant_id << ' ' << variant.sha256 << ' '
|
||||
<< ((variant.signature && variant.public_key) ? "signed" : "unsigned");
|
||||
if (variant.yanked) {
|
||||
std::cout << " yanked";
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
const Package::BinaryReleaseInfo *chosen = nullptr;
|
||||
if (opts.variant_arg) {
|
||||
for (const auto &variant : *variants) {
|
||||
if (variant.variant_id == *opts.variant_arg) {
|
||||
chosen = &variant;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (chosen == nullptr) {
|
||||
std::cerr << "vbs install-binary: variant '" << *opts.variant_arg << "' not found\n";
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
const std::string os = Toolchain::host_os_name();
|
||||
const std::string arch = Toolchain::host_architecture_name();
|
||||
for (const auto &variant : *variants) {
|
||||
if (variant.variant_id.find(os) != std::string::npos &&
|
||||
variant.variant_id.find(arch) != std::string::npos) {
|
||||
chosen = &variant;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (chosen == nullptr && variants->size() == 1) {
|
||||
chosen = &variants->front();
|
||||
}
|
||||
if (chosen == nullptr) {
|
||||
std::cerr << "vbs install-binary: no variant matches " << os << '-' << arch
|
||||
<< "; choose one with --variant\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
auto trusted = combine_trusted_keys(opts.trusted_public_keys, opts.trusted_key_files,
|
||||
std::filesystem::current_path());
|
||||
if (!trusted) {
|
||||
std::cerr << "vbs install-binary: " << trusted.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
if (!trusted->empty()) {
|
||||
auto decision = Provenance::verify_trusted_binary_signature(
|
||||
Provenance::BinarySignature{chosen->variant_id, chosen->sha256,
|
||||
chosen->signature.value_or(std::string{}),
|
||||
chosen->public_key.value_or(std::string{})},
|
||||
*trusted);
|
||||
if (!decision || *decision != Provenance::TrustDecision::Verified) {
|
||||
std::cerr << "vbs install-binary: variant is not signed by a trusted key\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
std::filesystem::path prefix;
|
||||
if (opts.prefix_arg) {
|
||||
prefix = *opts.prefix_arg;
|
||||
} else {
|
||||
const std::string home = Void::Configuration::get_env_or("HOME", "");
|
||||
prefix = home.empty() ? std::filesystem::path{".local"}
|
||||
: (std::filesystem::path{home} / ".local");
|
||||
}
|
||||
const auto bin_dir = prefix / "bin";
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(bin_dir, ec);
|
||||
if (ec) {
|
||||
std::cerr << "vbs install-binary: cannot create '" << bin_dir.string()
|
||||
<< "': " << ec.message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
const auto destination = bin_dir / opts.name_arg;
|
||||
const auto staging = bin_dir / (opts.name_arg + ".tmp");
|
||||
const std::string url = registry_url + "/api/v1/packages/" +
|
||||
Void::Encoding::Url::encode(opts.name_arg) + "/" +
|
||||
Void::Encoding::Url::encode(version) + "/binaries/" +
|
||||
Void::Encoding::Url::encode(chosen->variant_id) + "/download";
|
||||
auto downloaded = Package::download_binary_artifact(url, chosen->sha256, staging, auth);
|
||||
if (!downloaded) {
|
||||
std::cerr << "vbs install-binary: " << downloaded.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::filesystem::permissions(staging,
|
||||
std::filesystem::perms::owner_exec |
|
||||
std::filesystem::perms::group_exec |
|
||||
std::filesystem::perms::others_exec,
|
||||
std::filesystem::perm_options::add, ec);
|
||||
std::filesystem::rename(staging, destination, ec);
|
||||
if (ec) {
|
||||
std::filesystem::remove(staging, ec);
|
||||
std::cerr << "vbs install-binary: cannot install '" << destination.string()
|
||||
<< "': " << ec.message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::cout << "installed " << opts.name_arg << ' ' << version << " (" << chosen->variant_id
|
||||
<< ") -> " << destination.string() << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct InitCmdOptions {
|
||||
std::string dir_arg;
|
||||
std::optional<std::string> name_arg;
|
||||
@@ -4921,6 +5350,13 @@ int main(int argc, char **argv) {
|
||||
add_opts.project_arg = cwd;
|
||||
RemoveCmdOptions remove_opts;
|
||||
remove_opts.project_arg = cwd;
|
||||
FmtCmdOptions fmt_opts;
|
||||
fmt_opts.project_arg = cwd;
|
||||
LintCmdOptions lint_opts;
|
||||
lint_opts.project_arg = cwd;
|
||||
TreeCmdOptions tree_opts;
|
||||
tree_opts.project_arg = cwd;
|
||||
InstallBinaryCmdOptions install_binary_opts;
|
||||
CompletionsCmdOptions completions_opts;
|
||||
ManCmdOptions man_opts;
|
||||
IdeCmdOptions ide_opts;
|
||||
@@ -5443,6 +5879,58 @@ int main(int argc, char **argv) {
|
||||
.positional("dependency", "Dependency name", remove_opts.name_arg);
|
||||
add_log_flags(remove_cmd);
|
||||
|
||||
auto &fmt_cmd = root.subcommand("fmt", "Format owned C/C++ sources with clang-format");
|
||||
fmt_cmd
|
||||
.option_default("--project", "-C", "Project directory", fmt_opts.project_arg, ".")
|
||||
.flag("--check", "", "Only check formatting (fail when files would change)", fmt_opts.check)
|
||||
.flag("--changed-only", "", "Only format files changed since HEAD", fmt_opts.changed_only)
|
||||
.positional_many("files", "Files or directories (default: the whole project)",
|
||||
fmt_opts.paths, false);
|
||||
add_log_flags(fmt_cmd);
|
||||
|
||||
auto &lint_cmd = root.subcommand("lint", "Run clang-tidy over the project's sources");
|
||||
lint_cmd
|
||||
.option_default("--project", "-C", "Project directory", lint_opts.project_arg, ".")
|
||||
.option("--build-dir", "-B", "Build directory holding compile_commands.json",
|
||||
lint_opts.build_arg)
|
||||
.flag("--fix", "", "Apply clang-tidy fixes", lint_opts.fix)
|
||||
.flag("--changed-only", "", "Only lint files changed since HEAD", lint_opts.changed_only)
|
||||
.flag("--warnings-as-errors", "", "Treat clang-tidy warnings as errors",
|
||||
lint_opts.warnings_as_errors)
|
||||
.positional_many("files", "Files or directories (default: the whole project)",
|
||||
lint_opts.paths, false);
|
||||
add_log_flags(lint_cmd);
|
||||
|
||||
auto &tree_cmd = root.subcommand("tree", "Print the resolved dependency tree from vbs.lock");
|
||||
tree_cmd
|
||||
.option_default("--project", "-C", "Project directory", tree_opts.project_arg, ".")
|
||||
.option("--lock", "", "Lockfile path (default: <project>/vbs.lock)", tree_opts.lock_arg)
|
||||
.flag("--duplicates", "", "Report packages resolved to multiple versions",
|
||||
tree_opts.duplicates);
|
||||
add_log_flags(tree_cmd);
|
||||
|
||||
auto &install_binary_cmd = root.subcommand(
|
||||
"install-binary", "Download and install a published binary variant");
|
||||
install_binary_cmd
|
||||
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
||||
install_binary_opts.registry_arg)
|
||||
.option("--version", "", "Release version (default: the newest published release)",
|
||||
install_binary_opts.version_arg)
|
||||
.option("--variant", "", "Binary variant id (default: matches the host os/arch)",
|
||||
install_binary_opts.variant_arg)
|
||||
.option("--prefix", "", "Install prefix (default: ~/.local, binary in <prefix>/bin)",
|
||||
install_binary_opts.prefix_arg)
|
||||
.option_default("--token-env", "", "Environment variable holding the registry token",
|
||||
install_binary_opts.token_env, "VBS_REGISTRY_TOKEN")
|
||||
.flag("--list", "", "List the available variants instead of installing",
|
||||
install_binary_opts.list)
|
||||
.option_many("--trusted-public-key", "", "Trusted Ed25519 public key (repeatable)",
|
||||
install_binary_opts.trusted_public_keys)
|
||||
.option_many("--trusted-key-file", "", "Trusted key file (repeatable)",
|
||||
install_binary_opts.trusted_key_files)
|
||||
.positional("name", "Package name", install_binary_opts.name_arg);
|
||||
add_log_flags(install_binary_cmd);
|
||||
|
||||
auto &ide_cmd =
|
||||
root.subcommand("ide", "Generate editor/IDE configs and query workspace metadata");
|
||||
auto configure_ide_common = [&](Void::Argparse::Parser &p) {
|
||||
@@ -5829,6 +6317,18 @@ int main(int argc, char **argv) {
|
||||
if (cmd == "remove") {
|
||||
return execute_remove_command(remove_opts);
|
||||
}
|
||||
if (cmd == "fmt") {
|
||||
return execute_fmt_command(fmt_opts);
|
||||
}
|
||||
if (cmd == "lint") {
|
||||
return execute_lint_command(lint_opts);
|
||||
}
|
||||
if (cmd == "tree") {
|
||||
return execute_tree_command(tree_opts);
|
||||
}
|
||||
if (cmd == "install-binary") {
|
||||
return execute_install_binary_command(install_binary_opts);
|
||||
}
|
||||
if (cmd == "ide") {
|
||||
return execute_ide_command(parsed.matched_command_path.at(1), ide_opts);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,12 @@ check_process(0 "--frozen" "" build --help)
|
||||
check_process(0 "--native-cache" "" build --help)
|
||||
check_process(2 "" "unsupported --native-cache" build --native-cache bogus)
|
||||
check_process(2 "" "invalid version range" add fmt@bad --no-lock)
|
||||
check_process(0 "Usage: vbs fmt " "" fmt --help)
|
||||
check_process(0 "Usage: vbs lint " "" lint --help)
|
||||
check_process(0 "Usage: vbs tree " "" tree --help)
|
||||
check_process(0 "Usage: vbs install-binary " "" install-binary --help)
|
||||
check_process(2 "" "missing required argument" install-binary)
|
||||
check_process(2 "" "--registry and a package name are required" install-binary foo)
|
||||
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)
|
||||
|
||||
@@ -4576,3 +4576,82 @@ VOID_TEST(FullV1Tests, native_cache_wrapper_is_lowered_into_compile_commands) {
|
||||
Void::Testing::expect(std::ranges::find(cached->arguments, std::string{"-std=c++26"}) !=
|
||||
cached->arguments.end());
|
||||
}
|
||||
|
||||
// === Dependency tree from the lockfile ===
|
||||
VOID_TEST(FullV1Tests, tree_prints_lock_entries_and_reports_duplicates) {
|
||||
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_tree_"};
|
||||
const auto dep = tmp / "dep";
|
||||
const auto app = tmp / "app";
|
||||
write_file(dep / "build.cpp", R"cpp(#include <Void/Build.hpp>
|
||||
void build(Void::Build::Project &p) { p.static_library("deplib").sources({"src/dep.cpp"}); }
|
||||
)cpp");
|
||||
write_file(dep / "src" / "dep.cpp", "int depfn() { return 1; }\n");
|
||||
write_file(app / "build.cpp", R"cpp(#include <Void/Build.hpp>
|
||||
void build(Void::Build::Project &p) {
|
||||
p.dependencies_file("vbs.deps.toml");
|
||||
p.executable("app").sources({"src/main.cpp"});
|
||||
}
|
||||
)cpp");
|
||||
write_file(app / "src" / "main.cpp", "int main() { return 0; }\n");
|
||||
write_file(app / "vbs.deps.toml", "[dependencies.dep]\npath = \"../dep\"\n");
|
||||
|
||||
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);
|
||||
};
|
||||
auto resolved = run_vbs({"deps", "resolve", "--project", app.string()});
|
||||
Void::Testing::expect(resolved.has_value() && resolved->succeeded());
|
||||
auto tree = run_vbs({"tree", "--project", app.string(), "--duplicates"});
|
||||
Void::Testing::expect(tree.has_value() && tree->succeeded());
|
||||
if (tree) {
|
||||
Void::Testing::expect(tree->stdout_data.find("dep source=path") != std::string::npos);
|
||||
Void::Testing::expect(tree->stdout_data.find("target (1 entry)") != std::string::npos);
|
||||
Void::Testing::expect(tree->stdout_data.find("no duplicate package versions") !=
|
||||
std::string::npos);
|
||||
}
|
||||
auto missing = run_vbs({"tree", "--project", (tmp / "none").string()});
|
||||
Void::Testing::expect(missing.has_value() && missing->exit_code == 1);
|
||||
}
|
||||
|
||||
// === Formatting: clang-format orchestration (skipped when the tool is absent) ===
|
||||
VOID_TEST(FullV1Tests, fmt_check_detects_unformatted_files_and_fixes_them) {
|
||||
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;
|
||||
}
|
||||
const auto clang_format = Platform::resolve_executable("clang-format");
|
||||
if (!clang_format) {
|
||||
return; // clang-format is not installed; the CI image ships it.
|
||||
}
|
||||
Void::FileSystem::TempDir tmp{"vbs_fmt_"};
|
||||
const auto proj = tmp / "proj";
|
||||
write_file(proj / "src" / "ugly.cpp", "int main(){return 0;}\n");
|
||||
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");
|
||||
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{300};
|
||||
return Platform::run_supervised(req);
|
||||
};
|
||||
auto check = run_vbs({"fmt", "--check", "--project", proj.string(), "src/ugly.cpp"});
|
||||
Void::Testing::expect(check.has_value() && check->exit_code == 1);
|
||||
auto fix = run_vbs({"fmt", "--project", proj.string(), "src/ugly.cpp"});
|
||||
Void::Testing::expect(fix.has_value() && fix->succeeded());
|
||||
auto fixed = Void::FileSystem::read_file(proj / "src" / "ugly.cpp");
|
||||
Void::Testing::require(fixed.has_value());
|
||||
Void::Testing::expect(fixed->find("int main() {") != std::string::npos);
|
||||
auto recheck = run_vbs({"fmt", "--check", "--project", proj.string(), "src/ugly.cpp"});
|
||||
Void::Testing::expect(recheck.has_value() && recheck->succeeded());
|
||||
}
|
||||
Reference in new issue
Block a user