1614 lines
68 KiB
C++
1614 lines
68 KiB
C++
#include <Void/Build.hpp>
|
|
#include <Void/Build/BootstrapConfig.hpp>
|
|
#include <Void/Build/Bridge/CMakeBridge.hpp>
|
|
#include <Void/Build/Config/Frontend.hpp>
|
|
#include <Void/Build/Editor/CompDb.hpp>
|
|
#include <Void/Build/Execution/Scheduler.hpp>
|
|
#include <Void/Build/Graph/Graph.hpp>
|
|
#include <Void/Build/Install/Installer.hpp>
|
|
#include <Void/Build/Package/Archive.hpp>
|
|
#include <Void/Build/Package/Fetch.hpp>
|
|
#include <Void/Build/Package/Lockfile.hpp>
|
|
#include <Void/Build/Package/RegistryClient.hpp>
|
|
#include <Void/Build/Package/Solver.hpp>
|
|
#include <Void/Build/Package/Toml.hpp>
|
|
#include <Void/Build/Platform/FileOps.hpp>
|
|
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
|
#include <Void/Build/Provider/Provider.hpp>
|
|
#include <Void/Build/SelfHost/TestRegistryGen.hpp>
|
|
#include <Void/Build/Snapshot/Snapshot.hpp>
|
|
#include <Void/Build/State/StateStore.hpp>
|
|
#include <Void/Build/Toolchain/Driver.hpp>
|
|
#include <Void/Build/Util/Json.hpp>
|
|
#include <Void/Build/Util/Sha256.hpp>
|
|
#include <Void/Build/Watch/Watcher.hpp>
|
|
#include <Void/Configuration/Argparse.hpp>
|
|
#include <Void/Configuration/Env.hpp>
|
|
#include <Void/Log/Log.hpp>
|
|
#include <Void/System/SignalWatcher.hpp>
|
|
#include <Void/System/TempDir.hpp>
|
|
#include <Void/Text/Semver.hpp>
|
|
#include <Void/Text/Str.hpp>
|
|
#include <Void/Time/Stopwatch.hpp>
|
|
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <charconv>
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <format>
|
|
#include <iostream>
|
|
#include <map>
|
|
#include <mutex>
|
|
#include <optional>
|
|
#include <queue>
|
|
#include <set>
|
|
#include <stop_token>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
|
|
using namespace Void::Build;
|
|
|
|
class ConsoleLogGuard {
|
|
public:
|
|
explicit ConsoleLogGuard(Void::Log::Level level) {
|
|
Void::Log::set_min_level(level);
|
|
if (level > Void::Log::Level::Debug) {
|
|
// Suppress internal VoidLibrary FileSystem open-miss warnings on cold cache probes.
|
|
Void::Log::set_module_level("FileSystem", Void::Log::Level::Error);
|
|
}
|
|
reg_id_ =
|
|
Void::Log::register_sink([mutex = std::make_shared<std::mutex>()](
|
|
Void::Log::Level lvl, std::string_view module,
|
|
std::string_view message, const std::source_location &) {
|
|
std::lock_guard lock{*mutex};
|
|
switch (lvl) {
|
|
case Void::Log::Level::Trace:
|
|
std::cerr << "[vbs][TRACE][" << module << "] " << message << '\n' << std::flush;
|
|
break;
|
|
case Void::Log::Level::Debug:
|
|
std::cerr << "[vbs][DEBUG][" << module << "] " << message << '\n' << std::flush;
|
|
break;
|
|
case Void::Log::Level::Info:
|
|
std::cerr << "[vbs][" << module << "] " << message << '\n' << std::flush;
|
|
break;
|
|
case Void::Log::Level::Warning:
|
|
std::cerr << "[vbs][WARN][" << module << "] " << message << '\n' << std::flush;
|
|
break;
|
|
case Void::Log::Level::Error:
|
|
std::cerr << "[vbs][ERROR][" << module << "] " << message << '\n' << std::flush;
|
|
break;
|
|
case Void::Log::Level::Fatal:
|
|
std::cerr << "[vbs][FATAL][" << module << "] " << message << '\n' << std::flush;
|
|
break;
|
|
case Void::Log::Level::Disabled:
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
|
|
~ConsoleLogGuard() {
|
|
if (reg_id_ != 0) {
|
|
(void)Void::Log::detach_and_drain(reg_id_);
|
|
}
|
|
}
|
|
|
|
ConsoleLogGuard(const ConsoleLogGuard &) = delete;
|
|
ConsoleLogGuard &operator=(const ConsoleLogGuard &) = delete;
|
|
|
|
private:
|
|
Void::Log::RegistrationId reg_id_{0};
|
|
};
|
|
|
|
Config::FrontendOptions
|
|
make_frontend_opts(const std::filesystem::path &project_root,
|
|
const std::filesystem::path &build_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.sdk_source_dir = std::filesystem::path{Bootstrap::sdk_source_dir};
|
|
const auto bin_dir = std::filesystem::path{Bootstrap::binary_dir};
|
|
const std::array<std::filesystem::path, 3> sdk_candidates{
|
|
bin_dir / "libVoidBuild_Sdk.a",
|
|
bin_dir / "out" / "libVoidBuildSdk.a",
|
|
bin_dir / "profiles" / "debug" / "out" / "libVoidBuildSdk.a",
|
|
};
|
|
std::error_code ec;
|
|
for (const auto &candidate : sdk_candidates) {
|
|
if (std::filesystem::is_regular_file(candidate, ec)) {
|
|
opts.sdk_library_path = candidate;
|
|
break;
|
|
}
|
|
}
|
|
opts.extra_build_sources = extra_sources;
|
|
return opts;
|
|
}
|
|
|
|
struct SnapshotInputs {
|
|
std::vector<std::filesystem::path> explicit_files;
|
|
std::vector<std::filesystem::path> scan_roots;
|
|
};
|
|
|
|
// Derives snapshot scan roots and explicit files from conventional directories plus every
|
|
// target's declared include directories, sources, headers, and custom action inputs so
|
|
// projects with code outside `src/` (e.g. `recipes/`, `registry/`) snapshot completely.
|
|
SnapshotInputs collect_snapshot_inputs(const Graph::ProjectDescription &desc,
|
|
const std::filesystem::path &project_root) {
|
|
SnapshotInputs out;
|
|
std::error_code ec;
|
|
const auto canon_root = std::filesystem::weakly_canonical(project_root, ec);
|
|
const auto &root = ec ? project_root : canon_root;
|
|
|
|
std::set<std::filesystem::path> root_dirs;
|
|
std::set<std::filesystem::path> files;
|
|
|
|
auto add_dir_if_in_project = [&](const std::filesystem::path &dir) {
|
|
std::error_code dec;
|
|
const auto norm = dir.lexically_normal();
|
|
if (std::filesystem::is_directory(norm, dec) && Platform::path_is_within(root, norm) &&
|
|
norm != root) {
|
|
root_dirs.insert(norm);
|
|
}
|
|
};
|
|
|
|
for (const char *d : {"src", "source", "include", "tests"}) {
|
|
add_dir_if_in_project(root / d);
|
|
}
|
|
|
|
auto is_generated_ref = [](std::string_view p) {
|
|
return p.starts_with("$GEN/") || p.starts_with("gen/");
|
|
};
|
|
|
|
for (const auto &t : desc.targets) {
|
|
for (const auto &inc : t.include_directories) {
|
|
if (is_generated_ref(inc.path)) {
|
|
continue;
|
|
}
|
|
const std::filesystem::path p{inc.path};
|
|
add_dir_if_in_project(p.is_absolute() ? p : (root / p));
|
|
}
|
|
for (const auto &src : t.sources) {
|
|
if (is_generated_ref(src.path)) {
|
|
continue;
|
|
}
|
|
if (src.kind == SourceKind::File) {
|
|
const std::filesystem::path p{src.path};
|
|
const auto abs = (p.is_absolute() ? p : (root / p)).lexically_normal();
|
|
if (std::filesystem::is_regular_file(abs, ec)) {
|
|
files.insert(abs);
|
|
if (abs.has_parent_path()) {
|
|
add_dir_if_in_project(abs.parent_path());
|
|
}
|
|
}
|
|
} else if (src.kind == SourceKind::Glob) {
|
|
const auto star = src.path.find_first_of("*?[");
|
|
const std::string_view prefix = star == std::string::npos
|
|
? std::string_view{src.path}
|
|
: std::string_view{src.path}.substr(0, star);
|
|
const auto slash = prefix.rfind('/');
|
|
if (slash != std::string_view::npos && slash > 0) {
|
|
add_dir_if_in_project(root / std::filesystem::path{prefix.substr(0, slash)});
|
|
}
|
|
}
|
|
}
|
|
for (const auto &in : t.action_inputs) {
|
|
if (is_generated_ref(in)) {
|
|
continue;
|
|
}
|
|
const std::filesystem::path p{in};
|
|
const auto abs = (p.is_absolute() ? p : (root / p)).lexically_normal();
|
|
if (std::filesystem::is_regular_file(abs, ec)) {
|
|
files.insert(abs);
|
|
}
|
|
}
|
|
if (!t.precompiled_header.empty() && !is_generated_ref(t.precompiled_header)) {
|
|
const std::filesystem::path p{t.precompiled_header};
|
|
const auto abs = (p.is_absolute() ? p : (root / p)).lexically_normal();
|
|
if (std::filesystem::is_regular_file(abs, ec)) {
|
|
files.insert(abs);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Remove subdirectories already covered by an ancestor scan root.
|
|
for (const auto &d : root_dirs) {
|
|
bool covered = false;
|
|
for (const auto &other : root_dirs) {
|
|
if (other != d && Platform::path_is_within(other, d)) {
|
|
covered = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!covered) {
|
|
out.scan_roots.push_back(d);
|
|
}
|
|
}
|
|
// Only keep explicit files not already covered by a scan root.
|
|
for (const auto &f : files) {
|
|
bool covered = false;
|
|
for (const auto &d : out.scan_roots) {
|
|
if (Platform::path_is_within(d, f)) {
|
|
covered = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!covered) {
|
|
out.explicit_files.push_back(f);
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
struct ResolvedDepMaterialization {
|
|
Package::LockContextRecord lock_context;
|
|
std::vector<std::pair<DependencyRecord, Package::MaterializedSource>> materialized;
|
|
};
|
|
|
|
// Shared dependency resolution + live registry fetching + safe archive extraction + lock context
|
|
// builder for `vbs deps resolve|update`, `vbs build`, and `vbs test`.
|
|
Void::Result::Result<ResolvedDepMaterialization, Void::Result::Error> resolve_and_materialize_deps(
|
|
const ProfileContext &ctx, const std::vector<Package::NormalizedDependency> &merged_deps,
|
|
const std::filesystem::path &project_root, const std::filesystem::path &build_root,
|
|
const std::optional<Package::PinnedLock> &pinned_lock, bool offline, bool allow_upgrade) {
|
|
const std::string ctx_key = Package::make_lock_context_key(ctx, "target");
|
|
const std::string fp = Package::compute_declaration_fingerprint(ctx, "target", merged_deps);
|
|
|
|
ResolvedDepMaterialization out;
|
|
out.lock_context.context_key = ctx_key;
|
|
out.lock_context.profile_name = ctx.name;
|
|
out.lock_context.compiler = std::string{compiler_name(ctx.compiler)};
|
|
out.lock_context.os = ctx.os;
|
|
out.lock_context.architecture = ctx.architecture;
|
|
out.lock_context.machine_role = "target";
|
|
out.lock_context.declaration_fingerprint = fp;
|
|
|
|
// Collect existing lock pins (used unless `deps update` requested an upgrade).
|
|
Package::SolveOptions solve_opts;
|
|
std::map<Package::PackageId, Package::LockedSourceEntry> locked_pkg_entries;
|
|
if (!allow_upgrade && pinned_lock && pinned_lock->document.contexts.contains(ctx_key)) {
|
|
for (const auto &entry : pinned_lock->document.contexts.at(ctx_key).entries) {
|
|
if (entry.source_kind == "package" && !entry.package_name.empty()) {
|
|
const Package::PackageId pid{entry.registry_authority, entry.package_name};
|
|
locked_pkg_entries[pid] = entry;
|
|
if (auto ver = Void::Semver::parse_strict(entry.version); ver) {
|
|
solve_opts.pinned_versions[pid] = *ver;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 1. Solve all registry package dependencies together via PubGrub.
|
|
const std::string default_registry = Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");
|
|
Package::RegistryAuth reg_auth{Void::Configuration::get_env_or("VBS_REGISTRY_TOKEN", "")};
|
|
std::vector<Package::DependencyConstraint> root_constraints;
|
|
std::map<std::string, Package::PackageId, std::less<>> alias_to_pkg_id;
|
|
std::vector<const Package::NormalizedDependency *> package_deps;
|
|
|
|
for (const auto &nd : merged_deps) {
|
|
if (nd.record.source_kind != DependencySourceKind::Package) {
|
|
continue;
|
|
}
|
|
const std::string reg_url =
|
|
nd.record.registry_authority.empty() ? default_registry : nd.record.registry_authority;
|
|
if (reg_url.empty()) {
|
|
return std::unexpected{Void::System::make_system_error(
|
|
Void::System::SystemErrorCode::invalid_argument,
|
|
std::format("package dependency '{}' requires .registry(url) or VBS_REGISTRY_URL",
|
|
nd.record.name))};
|
|
}
|
|
const std::string pkg_name = nd.record.package.empty() ? nd.record.name : nd.record.package;
|
|
const Package::PackageId pid{reg_url, pkg_name};
|
|
alias_to_pkg_id[nd.record.name] = pid;
|
|
package_deps.push_back(&nd);
|
|
root_constraints.push_back(Package::DependencyConstraint{
|
|
pid, nd.record.version.empty() ? ">=0.0.0" : nd.record.version, nd.record.features,
|
|
"root(" + nd.record.name + ")"});
|
|
}
|
|
|
|
std::map<Package::PackageId, Package::SolvedPackage> solved_packages;
|
|
if (!root_constraints.empty()) {
|
|
Void::Log::info("Deps", "Solving {} registry package constraint(s)...",
|
|
root_constraints.size());
|
|
bool all_locked_cached = offline;
|
|
const auto pkg_cache_root = build_root / ".vbs" / "cache" / "packages";
|
|
if (all_locked_cached) {
|
|
for (const auto *nd : package_deps) {
|
|
const auto &pid = alias_to_pkg_id.at(nd->record.name);
|
|
const auto it = locked_pkg_entries.find(pid);
|
|
if (it == locked_pkg_entries.end() || it->second.sha256.empty() ||
|
|
!std::filesystem::is_directory(pkg_cache_root / it->second.sha256 / "src")) {
|
|
all_locked_cached = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (all_locked_cached) {
|
|
Void::Log::info("Deps", "Using offline cached locked package graph");
|
|
for (const auto *nd : package_deps) {
|
|
const auto &pid = alias_to_pkg_id.at(nd->record.name);
|
|
const auto &le = locked_pkg_entries.at(pid);
|
|
auto parsed_ver = Void::Semver::parse_strict(le.version);
|
|
if (!parsed_ver) {
|
|
return std::unexpected{Void::System::make_system_error(
|
|
Void::System::SystemErrorCode::invalid_argument,
|
|
std::format("corrupt locked version '{}' for package '{}'", le.version,
|
|
pid.name))};
|
|
}
|
|
Package::SolvedPackage sp;
|
|
sp.id = pid;
|
|
sp.version = *parsed_ver;
|
|
sp.source_sha256 = le.sha256;
|
|
solved_packages[pid] = std::move(sp);
|
|
}
|
|
} else {
|
|
if (offline) {
|
|
return std::unexpected{Void::System::make_system_error(
|
|
Void::System::SystemErrorCode::not_found,
|
|
"offline mode cannot query live package registry; populate cache first")};
|
|
}
|
|
Package::PackageIndex index;
|
|
std::set<Package::PackageId> fetched_ids;
|
|
std::queue<Package::PackageId> pending;
|
|
for (const auto &c : root_constraints) {
|
|
if (fetched_ids.insert(c.target).second) {
|
|
pending.push(c.target);
|
|
}
|
|
}
|
|
while (!pending.empty()) {
|
|
const auto pid = pending.front();
|
|
pending.pop();
|
|
Void::Log::debug("Deps", "Fetching release index for '{}' from {}", pid.name,
|
|
pid.registry_authority);
|
|
auto releases =
|
|
Package::fetch_package_releases(pid.registry_authority, pid.name, reg_auth);
|
|
if (!releases) {
|
|
return std::unexpected{releases.error()};
|
|
}
|
|
for (auto &rel : *releases) {
|
|
for (const auto &dep_c : rel.dependencies) {
|
|
if (fetched_ids.insert(dep_c.target).second) {
|
|
pending.push(dep_c.target);
|
|
}
|
|
}
|
|
index.add_release(std::move(rel));
|
|
}
|
|
}
|
|
|
|
auto solved = Package::solve_dependencies(root_constraints, index, solve_opts);
|
|
if (!solved) {
|
|
return std::unexpected{solved.error()};
|
|
}
|
|
solved_packages = std::move(solved->packages);
|
|
}
|
|
}
|
|
|
|
// 2. Materialize every dependency (registry packages + git/path/archive/conan).
|
|
const auto pkg_cache_root = build_root / ".vbs" / "cache" / "packages";
|
|
std::error_code ec;
|
|
for (const auto &nd : merged_deps) {
|
|
if (nd.record.source_kind == DependencySourceKind::Package) {
|
|
const auto &pid = alias_to_pkg_id.at(nd.record.name);
|
|
const auto &sp = solved_packages.at(pid);
|
|
const auto tar_path = pkg_cache_root / (sp.source_sha256 + ".tar");
|
|
const auto extract_dir = pkg_cache_root / sp.source_sha256 / "src";
|
|
|
|
if (!std::filesystem::is_directory(extract_dir, ec)) {
|
|
bool need_download = true;
|
|
if (std::filesystem::is_regular_file(tar_path, ec)) {
|
|
auto have_sha = Util::sha256_file_hex(tar_path);
|
|
if (have_sha && *have_sha == sp.source_sha256) {
|
|
need_download = false;
|
|
}
|
|
}
|
|
if (need_download) {
|
|
Void::Log::info("Fetch", "Downloading {}@{} from {}", pid.name,
|
|
sp.version.to_string(), pid.registry_authority);
|
|
auto dl = Package::download_release_archive(
|
|
pid.registry_authority, pid.name, sp.version.to_string(), sp.source_sha256,
|
|
tar_path, reg_auth);
|
|
if (!dl) {
|
|
return std::unexpected{dl.error()};
|
|
}
|
|
}
|
|
Void::Log::info("Fetch", "Extracting {}@{} ({})", pid.name, sp.version.to_string(),
|
|
sp.source_sha256.substr(0, 12));
|
|
auto ex = Package::extract_safe_tar(tar_path, extract_dir);
|
|
if (!ex) {
|
|
return std::unexpected{ex.error()};
|
|
}
|
|
} else {
|
|
Void::Log::debug("Fetch", "Using cached package {}@{} ({})", pid.name,
|
|
sp.version.to_string(), sp.source_sha256.substr(0, 12));
|
|
}
|
|
|
|
Package::MaterializedSource mat{nd.record.name, extract_dir, sp.source_sha256, false};
|
|
out.materialized.emplace_back(nd.record, std::move(mat));
|
|
|
|
Package::LockedSourceEntry le;
|
|
le.alias = nd.record.name;
|
|
le.source_kind = "package";
|
|
le.registry_authority = pid.registry_authority;
|
|
le.package_name = pid.name;
|
|
le.version = sp.version.to_string();
|
|
le.sha256 = sp.source_sha256;
|
|
le.builder = nd.record.builder;
|
|
le.features = nd.record.features;
|
|
le.build_dependency = nd.record.build_dependency;
|
|
out.lock_context.entries.push_back(std::move(le));
|
|
} else {
|
|
Package::FetchOptions fopt{build_root / ".vbs" / "cache", project_root, offline, {}};
|
|
auto mat = Package::materialize_dependency_source(nd.record, fopt);
|
|
if (!mat) {
|
|
return std::unexpected{mat.error()};
|
|
}
|
|
Package::LockedSourceEntry le;
|
|
le.alias = nd.record.name;
|
|
switch (nd.record.source_kind) {
|
|
case DependencySourceKind::Git:
|
|
le.source_kind = "git";
|
|
break;
|
|
case DependencySourceKind::Path:
|
|
le.source_kind = "path";
|
|
break;
|
|
case DependencySourceKind::Archive:
|
|
le.source_kind = "archive";
|
|
break;
|
|
case DependencySourceKind::Conan:
|
|
le.source_kind = "conan";
|
|
break;
|
|
case DependencySourceKind::Package:
|
|
le.source_kind = "package";
|
|
break;
|
|
case DependencySourceKind::Unspecified:
|
|
le.source_kind = "unspecified";
|
|
break;
|
|
}
|
|
le.location = nd.record.location;
|
|
le.revision = nd.record.revision;
|
|
le.sha256 = mat->content_identity_hash;
|
|
le.builder = nd.record.builder;
|
|
le.features = nd.record.features;
|
|
le.build_dependency = nd.record.build_dependency;
|
|
out.lock_context.entries.push_back(std::move(le));
|
|
out.materialized.emplace_back(nd.record, std::move(*mat));
|
|
}
|
|
}
|
|
|
|
return out;
|
|
}
|
|
|
|
struct BuildCmdOptions {
|
|
std::string project_arg;
|
|
std::optional<std::string> build_arg;
|
|
std::vector<std::string> profiles;
|
|
std::vector<std::string> targets;
|
|
std::vector<std::string> extra_build_sources;
|
|
std::optional<std::string> editor_profile;
|
|
std::optional<std::string> compiler_arg;
|
|
std::optional<std::string> jobs_arg;
|
|
bool no_cache{false};
|
|
bool locked{false};
|
|
bool offline{false};
|
|
};
|
|
|
|
int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
|
const std::string cmd_name = run_tests ? "vbs test" : "vbs build";
|
|
const auto total_sw = Void::Time::Stopwatch::started();
|
|
|
|
std::optional<CompilerFamily> compiler_override;
|
|
if (opts.compiler_arg) {
|
|
try {
|
|
compiler_override = parse_compiler(*opts.compiler_arg);
|
|
} catch (const std::exception &ex) {
|
|
std::cerr << cmd_name << ": " << ex.what() << '\n';
|
|
return 2;
|
|
}
|
|
}
|
|
std::size_t jobs = 0;
|
|
if (opts.jobs_arg) {
|
|
int parsed_jobs = 0;
|
|
if (!Void::Str::to_int(*opts.jobs_arg, parsed_jobs) || parsed_jobs < 0) {
|
|
std::cerr << cmd_name << ": invalid --jobs value '" << *opts.jobs_arg << "'\n";
|
|
return 2;
|
|
}
|
|
jobs = static_cast<std::size_t>(parsed_jobs);
|
|
}
|
|
|
|
const std::filesystem::path project_root{opts.project_arg};
|
|
const std::filesystem::path build_root =
|
|
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
|
|
std::vector<std::filesystem::path> extra_build_sources;
|
|
for (const auto &s : opts.extra_build_sources) {
|
|
extra_build_sources.emplace_back(s);
|
|
}
|
|
if (opts.profiles.empty()) {
|
|
opts.profiles.push_back("debug");
|
|
}
|
|
|
|
// D-010 / Plan 09: multi-profile builds MUST specify --editor-profile from selected profiles
|
|
// BEFORE doing any build work!
|
|
if (opts.profiles.size() > 1) {
|
|
if (!opts.editor_profile) {
|
|
std::cerr << "vbs: multi-profile build requires --editor-profile selecting one of "
|
|
"the requested profiles\n";
|
|
return 2;
|
|
}
|
|
if (!std::ranges::contains(opts.profiles, *opts.editor_profile)) {
|
|
std::cerr << "vbs: --editor-profile '" << *opts.editor_profile
|
|
<< "' must be one of the requested profiles\n";
|
|
return 2;
|
|
}
|
|
} else if (!opts.editor_profile) {
|
|
opts.editor_profile = opts.profiles.front();
|
|
}
|
|
|
|
// Reserve monotonic selection ticket on acceptance BEFORE expensive work!
|
|
auto reserved_ticket =
|
|
Editor::reserve_selection_ticket(project_root, build_root, *opts.editor_profile);
|
|
if (!reserved_ticket) {
|
|
std::cerr << "vbs: failed reserving editor ticket: " << reserved_ticket.error().message()
|
|
<< '\n';
|
|
return 1;
|
|
}
|
|
|
|
const auto fopts = make_frontend_opts(project_root, build_root, extra_build_sources);
|
|
Void::Log::info("Config", "Preparing build description in '{}'...", project_root.string());
|
|
const auto cfg_sw = Void::Time::Stopwatch::started();
|
|
auto compiled = Config::compile_descriptor(fopts);
|
|
if (!compiled) {
|
|
std::cerr << "vbs: " << compiled.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
Void::Log::info("Config", "Build description {} ({:.0f} ms)",
|
|
compiled->recompiled ? "compiled" : "up to date (cached)", cfg_sw.elapsed_ms());
|
|
|
|
auto profs = Config::discover_profiles(*compiled, fopts);
|
|
if (!profs) {
|
|
std::cerr << "vbs: " << profs.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
auto state = State::StateStore::open(build_root / ".vbs");
|
|
if (!state) {
|
|
std::cerr << "vbs: " << state.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
const auto lock_path = project_root / "vbs.lock";
|
|
auto pinned_lock = Package::load_pinned_lock(lock_path);
|
|
if (!pinned_lock) {
|
|
std::cerr << "vbs: " << pinned_lock.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
bool all_ok = true;
|
|
for (const auto &prof_name : opts.profiles) {
|
|
const auto prof_sw = Void::Time::Stopwatch::started();
|
|
ProfileContext ctx;
|
|
try {
|
|
ctx = profs->resolve(prof_name, compiler_override, Toolchain::host_os_name(),
|
|
Toolchain::host_architecture_name());
|
|
} catch (const std::exception &ex) {
|
|
std::cerr << "vbs: " << ex.what() << '\n';
|
|
return 2;
|
|
}
|
|
|
|
auto tc = Toolchain::discover_and_probe(ctx, build_root / ".vbs" / "probes");
|
|
if (!tc) {
|
|
std::cerr << "vbs: " << tc.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
Void::Log::info("Toolchain", "[{}] Using {} ({}) [{}]", prof_name,
|
|
compiler_name(tc->family), tc->cxx_compiler.string(), tc->version_banner);
|
|
|
|
const auto eval_sw = Void::Time::Stopwatch::started();
|
|
auto desc = Config::evaluate_project(*compiled, ctx, fopts);
|
|
if (!desc) {
|
|
std::cerr << "vbs: " << desc.error().message() << '\n';
|
|
(void)Editor::mark_profile_stale(
|
|
build_root, prof_name, Editor::GenerationStatus::Invalid, desc.error().message());
|
|
return 1;
|
|
}
|
|
Void::Log::info("Eval", "[{}] Evaluated {} target(s), {} dependenc(ies) ({:.0f} ms)",
|
|
prof_name, desc->targets.size(), desc->dependencies.size(),
|
|
eval_sw.elapsed_ms());
|
|
|
|
// Load & merge any TOML dependency manifests declared by build.cpp.
|
|
std::vector<Package::NormalizedDependency> toml_deps;
|
|
for (const auto &dep_file : desc->dependency_files) {
|
|
const auto p = std::filesystem::path{dep_file}.is_absolute()
|
|
? std::filesystem::path{dep_file}
|
|
: (project_root / dep_file);
|
|
Void::Log::debug("Deps", "[{}] Loading dependency manifest '{}'", prof_name,
|
|
p.string());
|
|
auto loaded = Package::load_dependencies_toml(p);
|
|
if (!loaded) {
|
|
std::cerr << "vbs: " << loaded.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
toml_deps.insert(toml_deps.end(), loaded->begin(), loaded->end());
|
|
}
|
|
auto merged_deps = Package::merge_dependencies(desc->dependencies, toml_deps);
|
|
if (!merged_deps) {
|
|
std::cerr << "vbs: " << merged_deps.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
// Validate/update lockfile context and materialize dependencies (including live registry).
|
|
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> imported_targets;
|
|
if (!merged_deps->empty()) {
|
|
Void::Log::info("Deps", "[{}] Resolving {} dependenc(ies)...", prof_name,
|
|
merged_deps->size());
|
|
const std::string ctx_key = Package::make_lock_context_key(ctx, "target");
|
|
const std::string fp =
|
|
Package::compute_declaration_fingerprint(ctx, "target", *merged_deps);
|
|
bool need_lock_publish = !pinned_lock->has_value();
|
|
if (pinned_lock->has_value()) {
|
|
auto valid =
|
|
Package::validate_locked_context((*pinned_lock)->document, ctx_key, fp);
|
|
if (!valid) {
|
|
if (opts.locked) {
|
|
std::cerr << "vbs: " << valid.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
Void::Log::info("Deps",
|
|
"[{}] Updating vbs.lock for changed dependency declarations...",
|
|
prof_name);
|
|
need_lock_publish = true;
|
|
}
|
|
} else if (opts.locked) {
|
|
std::cerr << "vbs: --locked requires an existing vbs.lock\n";
|
|
return 1;
|
|
}
|
|
|
|
auto resolved = resolve_and_materialize_deps(
|
|
ctx, *merged_deps, project_root, build_root, *pinned_lock, opts.offline, false);
|
|
if (!resolved) {
|
|
std::cerr << "vbs: " << resolved.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
for (const auto &[dep_rec, mat] : resolved->materialized) {
|
|
DependencyRecord effective_dep = dep_rec;
|
|
if (effective_dep.builder.empty() &&
|
|
effective_dep.source_kind == DependencySourceKind::Package) {
|
|
std::error_code bec;
|
|
if (std::filesystem::is_regular_file(mat.source_dir / "CMakeLists.txt", bec)) {
|
|
effective_dep.builder = "cmake";
|
|
} else if (std::filesystem::is_regular_file(mat.source_dir / "meson.build",
|
|
bec)) {
|
|
effective_dep.builder = "meson";
|
|
}
|
|
}
|
|
if (effective_dep.builder == "cmake" || effective_dep.builder == "meson" ||
|
|
effective_dep.builder == "conan") {
|
|
Provider::ProviderRequest preq{effective_dep,
|
|
mat,
|
|
ctx,
|
|
*tc,
|
|
build_root / ".vbs" / "providers",
|
|
Provider::ProviderMode::FullBuild,
|
|
{}};
|
|
auto exp = Provider::resolve_foreign_provider(preq);
|
|
if (!exp) {
|
|
std::cerr << "vbs: " << exp.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
Void::Log::info("Provider", "[{}] Imported {} target(s) from '{}' ({})",
|
|
prof_name, exp->targets.size(), effective_dep.name,
|
|
exp->from_cache ? "cached" : "built");
|
|
for (const auto &[k, v] : exp->targets) {
|
|
imported_targets[k] = v;
|
|
}
|
|
}
|
|
}
|
|
if (need_lock_publish) {
|
|
const std::string base_rev =
|
|
pinned_lock->has_value() ? (*pinned_lock)->revision_hash : std::string{};
|
|
auto pub_lock = Package::publish_lock_context_cas(
|
|
lock_path, base_rev, resolved->lock_context, opts.locked);
|
|
if (!pub_lock) {
|
|
std::cerr << "vbs: " << pub_lock.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
pinned_lock = *pub_lock;
|
|
Void::Log::info("Deps", "[{}] Updated vbs.lock (revision {})", prof_name,
|
|
(*pinned_lock)->revision_hash.substr(0, 12));
|
|
}
|
|
}
|
|
|
|
// Capture immutable snapshot over all declared & conventional project source trees.
|
|
const auto snap_sw = Void::Time::Stopwatch::started();
|
|
const auto snap_inputs = collect_snapshot_inputs(*desc, project_root);
|
|
Snapshot::SnapshotOptions sopts;
|
|
sopts.project_root = project_root;
|
|
sopts.snapshot_store_dir = build_root / ".vbs" / "snapshots";
|
|
sopts.reproducibility_epoch = ctx.reproducibility_epoch;
|
|
auto snap =
|
|
Snapshot::capture_snapshot(sopts, snap_inputs.explicit_files, snap_inputs.scan_roots);
|
|
if (!snap) {
|
|
std::cerr << "vbs: " << snap.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
Void::Log::info("Snapshot", "[{}] Captured snapshot {} ({} file(s), {:.0f} ms)", prof_name,
|
|
snap->snapshot_id.substr(0, 12), snap->entries.size(),
|
|
snap_sw.elapsed_ms());
|
|
|
|
const auto graph_sw = Void::Time::Stopwatch::started();
|
|
Graph::GraphLowerOptions gopts{project_root, build_root, &(*snap),
|
|
std::move(imported_targets), 32768};
|
|
auto graph = Graph::lower_project_graph(*desc, *tc, gopts);
|
|
if (!graph) {
|
|
std::cerr << "vbs: " << graph.error().message() << '\n';
|
|
(void)Editor::mark_profile_stale(
|
|
build_root, prof_name, Editor::GenerationStatus::Invalid, graph.error().message());
|
|
return 1;
|
|
}
|
|
Void::Log::info("Graph", "[{}] Lowered {} action(s) across {} target(s) ({:.0f} ms)",
|
|
prof_name, graph->actions.size(), graph->targets.size(),
|
|
graph_sw.elapsed_ms());
|
|
|
|
// Publish compdb BEFORE compilation (Plan 09: compile failure does NOT undo selection!).
|
|
Editor::PublishOptions popts;
|
|
popts.project_root = project_root;
|
|
popts.build_root = build_root;
|
|
popts.update_selection = (*opts.editor_profile == prof_name);
|
|
popts.reserved_ticket = *reserved_ticket;
|
|
if (auto pub_db = Editor::publish_profile_compdb(*graph, popts); pub_db) {
|
|
Void::Log::debug("CompDb", "[{}] Published compile_commands.json ({})", prof_name,
|
|
pub_db->compdb_path.string());
|
|
}
|
|
|
|
Execution::ExecutionOptions eopts;
|
|
eopts.jobs = jobs;
|
|
eopts.use_cache = !opts.no_cache;
|
|
eopts.selected_targets = opts.targets;
|
|
auto rep = Execution::execute_graph(*graph, *state, eopts);
|
|
if (!rep) {
|
|
std::cerr << "vbs: " << rep.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
if (!rep->succeeded) {
|
|
for (const auto &ar : rep->results) {
|
|
if (!ar.succeeded) {
|
|
std::cerr << "vbs: action '" << ar.action_id << "' failed: " << ar.error_message
|
|
<< '\n';
|
|
if (!ar.stderr_data.empty()) {
|
|
std::cerr << ar.stderr_data << '\n';
|
|
}
|
|
}
|
|
}
|
|
all_ok = false;
|
|
continue;
|
|
}
|
|
Void::Log::info("Build", "[{}] Finished in {:.2f}s ({} executed, {} cached)", prof_name,
|
|
prof_sw.elapsed_ms() / 1000.0, rep->executed_count, rep->cached_count);
|
|
std::cout << "vbs: [" << prof_name << "] built (" << rep->executed_count << " executed, "
|
|
<< rep->cached_count << " cached)\n";
|
|
|
|
if (run_tests) {
|
|
for (const auto &t : graph->targets) {
|
|
if (t.kind != TargetKind::Test || t.primary_outputs.empty()) {
|
|
continue;
|
|
}
|
|
if (!opts.targets.empty() && !std::ranges::contains(opts.targets, t.name)) {
|
|
continue;
|
|
}
|
|
Void::Log::info("Test", "[{}] Running test target '{}'...", prof_name, t.name);
|
|
const auto tsw = Void::Time::Stopwatch::started();
|
|
Platform::ProcessRequest treq;
|
|
treq.executable = t.primary_outputs.front();
|
|
treq.working_directory = project_root;
|
|
auto tres = Platform::run_supervised(treq);
|
|
if (!tres || !tres->succeeded()) {
|
|
Void::Log::error("Test", "[{}] FAILED '{}' ({:.0f} ms)", prof_name, t.name,
|
|
tsw.elapsed_ms());
|
|
std::cerr << "vbs test: FAILED '" << t.name << "'\n";
|
|
if (tres && !tres->stderr_data.empty()) {
|
|
std::cerr << tres->stderr_data << '\n';
|
|
}
|
|
all_ok = false;
|
|
} else {
|
|
Void::Log::info("Test", "[{}] PASSED '{}' ({:.0f} ms)", prof_name, t.name,
|
|
tsw.elapsed_ms());
|
|
std::cout << "vbs test: PASSED '" << t.name << "'\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Void::Log::debug("Build", "Total wall time: {:.2f}s", total_sw.elapsed_ms() / 1000.0);
|
|
return all_ok ? 0 : 1;
|
|
}
|
|
|
|
struct CompDbCmdOptions {
|
|
std::string project_arg;
|
|
std::optional<std::string> build_arg;
|
|
std::optional<std::string> profile_name;
|
|
std::vector<std::string> positional_profiles;
|
|
};
|
|
|
|
int execute_compdb_command(std::string_view sub, CompDbCmdOptions opts) {
|
|
if (sub == "use") {
|
|
if (opts.positional_profiles.size() > 1) {
|
|
std::cerr << "vbs compdb use: expected at most one positional profile argument\n";
|
|
return 2;
|
|
}
|
|
if (opts.positional_profiles.size() == 1) {
|
|
if (opts.profile_name && *opts.profile_name != opts.positional_profiles.front()) {
|
|
std::cerr << "vbs compdb use: conflicting profile specified via both --profile and "
|
|
"positional argument\n";
|
|
return 2;
|
|
}
|
|
opts.profile_name = opts.positional_profiles.front();
|
|
}
|
|
}
|
|
|
|
const std::filesystem::path project_root{opts.project_arg};
|
|
const std::filesystem::path build_root =
|
|
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
|
|
|
|
if (sub == "show") {
|
|
auto st = Editor::read_selection_state(project_root);
|
|
if (!st || !st->has_value()) {
|
|
std::cout << "no editor compilation database selected\n";
|
|
return 0;
|
|
}
|
|
std::cout << "profile=" << (*st)->selected_profile
|
|
<< " generation=" << (*st)->selected_generation_id << " ticket=" << (*st)->ticket
|
|
<< " path=" << (*st)->selected_compdb_path.string() << '\n';
|
|
return 0;
|
|
}
|
|
if (sub == "use") {
|
|
if (!opts.profile_name) {
|
|
std::cerr << "vbs compdb use: profile name required\n";
|
|
return 2;
|
|
}
|
|
auto st = Editor::select_editor_profile(project_root, build_root, *opts.profile_name);
|
|
if (!st) {
|
|
std::cerr << "vbs compdb use: " << st.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "selected editor profile '" << st->selected_profile << "' ("
|
|
<< st->selected_compdb_path.string() << ")\n";
|
|
return 0;
|
|
}
|
|
|
|
Watch::WatchLoopOptions wopts;
|
|
wopts.mode = Watch::WatchMode::MetadataOnly;
|
|
wopts.frontend = make_frontend_opts(project_root, build_root, {});
|
|
wopts.explicit_profile = opts.profile_name;
|
|
if (sub == "export") {
|
|
Void::Log::info("CompDb", "Exporting compile_commands.json in '{}'...",
|
|
project_root.string());
|
|
auto rep = Watch::run_reconcile_cycle(wopts, 0, false, std::nullopt);
|
|
if (!rep.compdb_published) {
|
|
std::cerr << "vbs compdb export: " << rep.diagnostic << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "exported compile_commands.json for profile '" << rep.profile_name << "'\n";
|
|
return 0;
|
|
}
|
|
|
|
Void::Log::info("CompDb", "Watching metadata in '{}' (Ctrl+C to stop)...",
|
|
project_root.string());
|
|
std::stop_source stop_src;
|
|
auto sig = Void::Process::SignalWatcher::create();
|
|
std::jthread sig_thread([&] {
|
|
if (sig) {
|
|
(void)sig->wait();
|
|
stop_src.request_stop();
|
|
}
|
|
});
|
|
auto res = Watch::run_watch_loop(wopts, stop_src.get_token());
|
|
return res ? 0 : 1;
|
|
}
|
|
|
|
struct DescribeCmdOptions {
|
|
std::string project_arg;
|
|
std::optional<std::string> build_arg;
|
|
std::string profile_name{"debug"};
|
|
std::optional<std::string> compiler_arg;
|
|
};
|
|
|
|
int execute_describe_command(const DescribeCmdOptions &opts) {
|
|
std::optional<CompilerFamily> compiler_override;
|
|
if (opts.compiler_arg) {
|
|
try {
|
|
compiler_override = parse_compiler(*opts.compiler_arg);
|
|
} catch (const std::exception &ex) {
|
|
std::cerr << "vbs describe: " << ex.what() << '\n';
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
const std::filesystem::path project_root{opts.project_arg};
|
|
const std::filesystem::path build_root =
|
|
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
|
|
const auto fopts = make_frontend_opts(project_root, build_root, {});
|
|
auto compiled = Config::compile_descriptor(fopts);
|
|
if (!compiled) {
|
|
std::cerr << "vbs describe: " << compiled.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto profs = Config::discover_profiles(*compiled, fopts);
|
|
if (!profs) {
|
|
std::cerr << "vbs describe: " << profs.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
try {
|
|
auto ctx = profs->resolve(opts.profile_name, compiler_override, Toolchain::host_os_name(),
|
|
Toolchain::host_architecture_name());
|
|
auto desc = Config::evaluate_project(*compiled, ctx, fopts);
|
|
if (!desc) {
|
|
std::cerr << "vbs describe: " << desc.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "{\"profile\":" << Util::json_quote(desc->profile.name)
|
|
<< ",\"targets\":" << desc->targets.size()
|
|
<< ",\"dependencies\":" << desc->dependencies.size() << "}\n";
|
|
return 0;
|
|
} catch (const std::exception &ex) {
|
|
std::cerr << "vbs describe: " << ex.what() << '\n';
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
struct WatchCmdOptions {
|
|
std::string project_arg;
|
|
std::optional<std::string> build_arg;
|
|
std::optional<std::string> profile_arg;
|
|
std::vector<std::string> targets;
|
|
};
|
|
|
|
int execute_watch_command(WatchCmdOptions opts) {
|
|
const std::filesystem::path project_root{opts.project_arg};
|
|
const std::filesystem::path build_root =
|
|
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
|
|
Watch::WatchLoopOptions wopts;
|
|
wopts.mode = Watch::WatchMode::FullBuild;
|
|
wopts.frontend = make_frontend_opts(project_root, build_root, {});
|
|
wopts.explicit_profile = opts.profile_arg;
|
|
wopts.selected_targets = std::move(opts.targets);
|
|
wopts.on_cycle = [](const Watch::WatchCycleReport &rep) {
|
|
if (rep.build_succeeded) {
|
|
Void::Log::info("Watch", "Cycle #{} [{}] OK ({} executed, {} cached)", rep.cycle_index,
|
|
rep.profile_name, rep.executed_actions, rep.cached_actions);
|
|
} else {
|
|
Void::Log::error("Watch", "Cycle #{} [{}] FAILED: {}", rep.cycle_index,
|
|
rep.profile_name, rep.diagnostic);
|
|
}
|
|
};
|
|
|
|
Void::Log::info("Watch", "Watching '{}' (Ctrl+C to stop)...", project_root.string());
|
|
std::stop_source stop_src;
|
|
auto sig = Void::Process::SignalWatcher::create();
|
|
std::jthread sig_thread([&] {
|
|
if (sig) {
|
|
(void)sig->wait();
|
|
stop_src.request_stop();
|
|
}
|
|
});
|
|
auto res = Watch::run_watch_loop(wopts, stop_src.get_token());
|
|
return res ? 0 : 1;
|
|
}
|
|
|
|
struct BridgeCmdOptions {
|
|
std::optional<std::string> req_arg;
|
|
std::optional<std::string> out_arg;
|
|
};
|
|
|
|
int execute_bridge_command(const BridgeCmdOptions &opts) {
|
|
if (!opts.req_arg || !opts.out_arg) {
|
|
std::cerr << "vbs bridge: --request and --output are required\n";
|
|
return 2;
|
|
}
|
|
Void::Log::info("Bridge", "Processing CMake bridge request '{}'", *opts.req_arg);
|
|
auto r = Bridge::execute_cmake_bridge(*opts.req_arg, *opts.out_arg);
|
|
if (!r) {
|
|
std::cerr << "vbs bridge: " << r.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
struct PackCmdOptions {
|
|
std::string project_arg;
|
|
std::string out_arg{"package.tar"};
|
|
};
|
|
|
|
int execute_pack_command(const PackCmdOptions &opts) {
|
|
Void::Log::info("Pack", "Creating deterministic source archive '{}' from '{}'...", opts.out_arg,
|
|
opts.project_arg);
|
|
auto sha = Package::create_source_package(opts.project_arg, opts.out_arg, 0);
|
|
if (!sha) {
|
|
std::cerr << "vbs pack: " << sha.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "packed " << opts.out_arg << " sha256=" << *sha << '\n';
|
|
return 0;
|
|
}
|
|
|
|
struct PublishCmdOptions {
|
|
std::string project_arg;
|
|
std::optional<std::string> registry_arg;
|
|
std::optional<std::string> name_arg;
|
|
std::optional<std::string> version_arg;
|
|
std::string description;
|
|
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
|
bool is_private{false};
|
|
};
|
|
|
|
int execute_publish_command(const PublishCmdOptions &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 || !opts.version_arg) {
|
|
std::cerr << "vbs publish: --registry, --name, and --version are required\n";
|
|
return 2;
|
|
}
|
|
|
|
Void::FileSystem::TempDir tmp{"vbs_publish_"};
|
|
const auto tar_path = tmp / (*opts.name_arg + "-" + *opts.version_arg + ".tar");
|
|
Void::Log::info("Publish", "Packing {}@{} from '{}'...", *opts.name_arg, *opts.version_arg,
|
|
opts.project_arg);
|
|
auto sha = Package::create_source_package(opts.project_arg, tar_path, 0);
|
|
if (!sha) {
|
|
std::cerr << "vbs publish: " << sha.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
Package::PublishOptions popts;
|
|
popts.registry_url = registry_url;
|
|
popts.package_name = *opts.name_arg;
|
|
popts.version = *opts.version_arg;
|
|
popts.archive_path = tar_path;
|
|
popts.description = opts.description;
|
|
popts.is_private = opts.is_private;
|
|
popts.auth.bearer_token = Void::Configuration::get_env_or(opts.token_env, "");
|
|
|
|
Void::Log::info("Publish", "Uploading {}@{} ({}) to {}...", *opts.name_arg, *opts.version_arg,
|
|
sha->substr(0, 12), registry_url);
|
|
auto receipt = Package::publish_package_archive(popts);
|
|
if (!receipt) {
|
|
std::cerr << "vbs publish: " << receipt.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << (receipt->already_published ? "already published " : "published ")
|
|
<< *opts.name_arg << "@" << *opts.version_arg << " sha256=" << receipt->sha256
|
|
<< '\n';
|
|
return 0;
|
|
}
|
|
|
|
struct InstallCmdOptions {
|
|
std::string project_arg;
|
|
std::optional<std::string> build_arg;
|
|
std::string profile_name{"debug"};
|
|
std::optional<std::string> compiler_arg;
|
|
std::optional<std::string> prefix_arg;
|
|
std::optional<std::string> pkg_name_arg;
|
|
std::string pkg_ver{"0.1.0"};
|
|
std::optional<std::string> component_arg;
|
|
bool no_cmake_export{false};
|
|
bool no_native_export{false};
|
|
};
|
|
|
|
int execute_install_command(const InstallCmdOptions &opts) {
|
|
if (!opts.prefix_arg || opts.prefix_arg->empty()) {
|
|
std::cerr << "vbs install: --prefix is required\n";
|
|
return 2;
|
|
}
|
|
|
|
std::optional<CompilerFamily> compiler_override;
|
|
if (opts.compiler_arg) {
|
|
try {
|
|
compiler_override = parse_compiler(*opts.compiler_arg);
|
|
} catch (const std::exception &ex) {
|
|
std::cerr << "vbs install: " << ex.what() << '\n';
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
const std::filesystem::path project_root{opts.project_arg};
|
|
const std::filesystem::path build_root =
|
|
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
|
|
|
|
Install::InstallOptions iopts;
|
|
iopts.prefix = *opts.prefix_arg;
|
|
iopts.package_version = opts.pkg_ver;
|
|
iopts.component = opts.component_arg;
|
|
iopts.export_cmake_config = !opts.no_cmake_export;
|
|
iopts.export_native_metadata = !opts.no_native_export;
|
|
|
|
std::error_code ec;
|
|
if (opts.pkg_name_arg && !opts.pkg_name_arg->empty()) {
|
|
iopts.package_name = *opts.pkg_name_arg;
|
|
} else {
|
|
const auto canon = std::filesystem::weakly_canonical(project_root, ec);
|
|
iopts.package_name = canon.filename().string();
|
|
if (iopts.package_name.empty()) {
|
|
iopts.package_name = "package";
|
|
}
|
|
}
|
|
|
|
Void::Log::info("Install", "Building profile '{}' before staging into '{}'...",
|
|
opts.profile_name, iopts.prefix.string());
|
|
const auto fopts = make_frontend_opts(project_root, build_root, {});
|
|
auto compiled = Config::compile_descriptor(fopts);
|
|
if (!compiled) {
|
|
std::cerr << "vbs install: " << compiled.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto profs = Config::discover_profiles(*compiled, fopts);
|
|
if (!profs) {
|
|
std::cerr << "vbs install: " << profs.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
ProfileContext ctx;
|
|
try {
|
|
ctx = profs->resolve(opts.profile_name, compiler_override, Toolchain::host_os_name(),
|
|
Toolchain::host_architecture_name());
|
|
} catch (const std::exception &ex) {
|
|
std::cerr << "vbs install: " << ex.what() << '\n';
|
|
return 2;
|
|
}
|
|
auto tc = Toolchain::discover_and_probe(ctx, build_root / ".vbs" / "probes");
|
|
if (!tc) {
|
|
std::cerr << "vbs install: " << tc.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto desc = Config::evaluate_project(*compiled, ctx, fopts);
|
|
if (!desc) {
|
|
std::cerr << "vbs install: " << desc.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
const auto snap_inputs = collect_snapshot_inputs(*desc, project_root);
|
|
Snapshot::SnapshotOptions sopts;
|
|
sopts.project_root = project_root;
|
|
sopts.snapshot_store_dir = build_root / ".vbs" / "snapshots";
|
|
sopts.reproducibility_epoch = ctx.reproducibility_epoch;
|
|
auto snap =
|
|
Snapshot::capture_snapshot(sopts, snap_inputs.explicit_files, snap_inputs.scan_roots);
|
|
if (!snap) {
|
|
std::cerr << "vbs install: " << snap.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto graph =
|
|
Graph::lower_project_graph(*desc, *tc, {project_root, build_root, &(*snap), {}, 32768});
|
|
if (!graph) {
|
|
std::cerr << "vbs install: " << graph.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto state = State::StateStore::open(build_root / ".vbs");
|
|
if (!state) {
|
|
std::cerr << "vbs install: " << state.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto exec = Execution::execute_graph(*graph, *state);
|
|
if (!exec || !exec->succeeded) {
|
|
std::cerr << "vbs install: build failed before staging\n";
|
|
if (!exec) {
|
|
std::cerr << exec.error().message() << '\n';
|
|
}
|
|
return 1;
|
|
}
|
|
Void::Log::info("Install", "Staging and installing package '{}' ({}) to '{}'...",
|
|
iopts.package_name, iopts.package_version, iopts.prefix.string());
|
|
auto inst = Install::install_project(*desc, *graph, iopts);
|
|
if (!inst) {
|
|
std::cerr << "vbs install: " << inst.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "installed " << inst->installed_files.size() << " files to "
|
|
<< inst->prefix.string() << " (manifest=" << inst->manifest_path.string() << ")\n";
|
|
return 0;
|
|
}
|
|
|
|
struct UninstallCmdOptions {
|
|
std::optional<std::string> prefix_arg;
|
|
};
|
|
|
|
int execute_uninstall_command(const UninstallCmdOptions &opts) {
|
|
if (!opts.prefix_arg || opts.prefix_arg->empty()) {
|
|
std::cerr << "vbs uninstall: --prefix is required\n";
|
|
return 2;
|
|
}
|
|
Void::Log::info("Install", "Uninstalling VBS-owned files from '{}'...", *opts.prefix_arg);
|
|
auto removed = Install::uninstall_prefix(*opts.prefix_arg);
|
|
if (!removed) {
|
|
std::cerr << "vbs uninstall: " << removed.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "uninstalled " << *removed << " VBS-owned files from " << *opts.prefix_arg << '\n';
|
|
return 0;
|
|
}
|
|
|
|
struct GcCmdOptions {
|
|
std::string build_arg;
|
|
std::string max_bytes_arg{"0"};
|
|
};
|
|
|
|
int execute_gc_command(const GcCmdOptions &opts) {
|
|
std::uint64_t max_bytes = 0;
|
|
const auto [ptr, ec] =
|
|
std::from_chars(opts.max_bytes_arg.data(),
|
|
opts.max_bytes_arg.data() + opts.max_bytes_arg.size(), max_bytes);
|
|
if (ec != std::errc{} || ptr != opts.max_bytes_arg.data() + opts.max_bytes_arg.size()) {
|
|
std::cerr << "vbs gc: invalid --max-bytes value '" << opts.max_bytes_arg << "'\n";
|
|
return 2;
|
|
}
|
|
Void::Log::info("GC", "Running state recovery and CAS garbage collection in '{}'...",
|
|
opts.build_arg);
|
|
auto st = State::StateStore::open(std::filesystem::path{opts.build_arg} / ".vbs");
|
|
if (!st) {
|
|
std::cerr << "vbs gc: " << st.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto stats = st->gc(max_bytes);
|
|
if (!stats) {
|
|
std::cerr << "vbs gc: " << stats.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "gc complete: removed=" << stats->removed_blobs
|
|
<< " freed_bytes=" << stats->freed_bytes << " retained=" << stats->retained_blobs
|
|
<< '\n';
|
|
return 0;
|
|
}
|
|
|
|
struct GenTestsCmdOptions {
|
|
std::optional<std::string> input_arg;
|
|
std::optional<std::string> out_arg;
|
|
};
|
|
|
|
int execute_gen_tests_command(const GenTestsCmdOptions &opts) {
|
|
if (!opts.input_arg || !opts.out_arg) {
|
|
std::cerr << "vbs gen-tests: --input and --output-dir are required\n";
|
|
return 2;
|
|
}
|
|
Void::Log::info("GenTests", "Scanning test cases in '{}'...", *opts.input_arg);
|
|
auto gen = SelfHost::generate_test_registration_unit(*opts.input_arg, *opts.out_arg);
|
|
if (!gen) {
|
|
std::cerr << "vbs gen-tests: " << gen.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << gen->generated_cpp.string() << " (" << gen->cases.size() << " tests)\n";
|
|
return 0;
|
|
}
|
|
|
|
struct DepsCmdOptions {
|
|
std::string project_arg;
|
|
std::optional<std::string> build_arg;
|
|
std::string profile_name{"debug"};
|
|
bool offline{false};
|
|
};
|
|
|
|
int execute_deps_command(std::string_view sub, const DepsCmdOptions &opts) {
|
|
const std::filesystem::path project_root{opts.project_arg};
|
|
const std::filesystem::path build_root =
|
|
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
|
|
const auto fopts = make_frontend_opts(project_root, build_root, {});
|
|
Void::Log::info("Deps", "{} dependencies for profile '{}' in '{}'...",
|
|
sub == "update" ? "Updating" : "Resolving", opts.profile_name,
|
|
project_root.string());
|
|
auto compiled = Config::compile_descriptor(fopts);
|
|
if (!compiled) {
|
|
std::cerr << "vbs deps: " << compiled.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto profs = Config::discover_profiles(*compiled, fopts);
|
|
if (!profs) {
|
|
std::cerr << "vbs deps: " << profs.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto ctx = profs->resolve(opts.profile_name, std::nullopt, Toolchain::host_os_name(),
|
|
Toolchain::host_architecture_name());
|
|
auto desc = Config::evaluate_project(*compiled, ctx, fopts);
|
|
if (!desc) {
|
|
std::cerr << "vbs deps: " << desc.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::vector<Package::NormalizedDependency> toml_deps;
|
|
for (const auto &df : desc->dependency_files) {
|
|
auto loaded = Package::load_dependencies_toml(project_root / df);
|
|
if (!loaded) {
|
|
std::cerr << "vbs deps: " << loaded.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
toml_deps.insert(toml_deps.end(), loaded->begin(), loaded->end());
|
|
}
|
|
auto merged = Package::merge_dependencies(desc->dependencies, toml_deps);
|
|
if (!merged) {
|
|
std::cerr << "vbs deps: " << merged.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
const auto lock_path = project_root / "vbs.lock";
|
|
auto existing = Package::load_pinned_lock(lock_path);
|
|
if (!existing) {
|
|
std::cerr << "vbs deps: " << existing.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
const std::string base_rev = existing->has_value() ? (*existing)->revision_hash : std::string{};
|
|
|
|
auto resolved = resolve_and_materialize_deps(ctx, *merged, project_root, build_root, *existing,
|
|
opts.offline, sub == "update");
|
|
if (!resolved) {
|
|
std::cerr << "vbs deps: " << resolved.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto pub =
|
|
Package::publish_lock_context_cas(lock_path, base_rev, resolved->lock_context, false);
|
|
if (!pub) {
|
|
std::cerr << "vbs deps: " << pub.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "updated vbs.lock revision=" << pub->revision_hash.substr(0, 12) << '\n';
|
|
return 0;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main(int argc, char **argv) {
|
|
const std::string cwd = std::filesystem::current_path().string();
|
|
bool show_version = false;
|
|
bool verbose = false;
|
|
bool quiet = false;
|
|
|
|
BuildCmdOptions build_opts;
|
|
build_opts.project_arg = cwd;
|
|
CompDbCmdOptions compdb_opts;
|
|
compdb_opts.project_arg = cwd;
|
|
DescribeCmdOptions describe_opts;
|
|
describe_opts.project_arg = cwd;
|
|
WatchCmdOptions watch_opts;
|
|
watch_opts.project_arg = cwd;
|
|
DepsCmdOptions deps_opts;
|
|
deps_opts.project_arg = cwd;
|
|
InstallCmdOptions install_opts;
|
|
install_opts.project_arg = cwd;
|
|
UninstallCmdOptions uninstall_opts;
|
|
PackCmdOptions pack_opts;
|
|
pack_opts.project_arg = cwd;
|
|
PublishCmdOptions publish_opts;
|
|
publish_opts.project_arg = cwd;
|
|
BridgeCmdOptions bridge_opts;
|
|
GcCmdOptions gc_opts;
|
|
gc_opts.build_arg = (std::filesystem::path{cwd} / "build").string();
|
|
GenTestsCmdOptions gen_tests_opts;
|
|
|
|
auto add_log_flags = [&](Void::Argparse::Parser &p, bool allow_short_v = true) {
|
|
p.flag("--verbose", allow_short_v ? "-v" : "", "Enable verbose debug logs", verbose)
|
|
.flag("--quiet", "-q", "Suppress progress logs (warnings and errors only)", quiet);
|
|
};
|
|
|
|
auto configure_build_or_test = [&](Void::Argparse::Parser &p) {
|
|
p.option_default("--project", "-C", "Project directory", build_opts.project_arg, cwd)
|
|
.option("--build-dir", "-B", "Build output directory", build_opts.build_arg)
|
|
.option_many("--profile", "-p", "Profile to build", build_opts.profiles)
|
|
.option_many("--target", "-t", "Target to build/test", build_opts.targets)
|
|
.option("--compiler", "", "Override compiler family (gcc|clang)",
|
|
build_opts.compiler_arg)
|
|
.option("--editor-profile", "", "Editor profile for compile_commands.json",
|
|
build_opts.editor_profile)
|
|
.option_many("--build-source", "", "Additional build description source",
|
|
build_opts.extra_build_sources)
|
|
.option("--jobs", "-j", "Maximum parallel compilation/link jobs", build_opts.jobs_arg)
|
|
.flag("--locked", "", "Require existing up-to-date vbs.lock", build_opts.locked)
|
|
.flag("--offline", "", "Disallow network fetches", build_opts.offline)
|
|
.flag("--no-cache", "", "Bypass action cache reads", build_opts.no_cache);
|
|
add_log_flags(p);
|
|
};
|
|
|
|
Void::Argparse::Parser root{"vbs",
|
|
"VoidBuildSystem — native C++ build system & package manager."};
|
|
root.require_subcommand(false).flag("--version", "-V", "Show version", show_version);
|
|
add_log_flags(root);
|
|
|
|
configure_build_or_test(
|
|
root.subcommand("build", "Configure and build selected profiles and targets"));
|
|
configure_build_or_test(root.subcommand("test", "Build and run declared test targets"));
|
|
|
|
auto &describe_cmd =
|
|
root.subcommand("describe", "Evaluate build.cpp and emit versioned graph summary JSON");
|
|
describe_cmd
|
|
.option_default("--project", "-C", "Project directory", describe_opts.project_arg, cwd)
|
|
.option("--build-dir", "-B", "Build output directory", describe_opts.build_arg)
|
|
.option_default("--profile", "-p", "Profile name", describe_opts.profile_name, "debug")
|
|
.option("--compiler", "", "Override compiler family (gcc|clang)",
|
|
describe_opts.compiler_arg);
|
|
add_log_flags(describe_cmd);
|
|
|
|
auto &compdb_cmd = root.subcommand(
|
|
"compdb", "Manage per-profile compile_commands.json selection and metadata projection");
|
|
auto configure_compdb_common = [&](Void::Argparse::Parser &p, bool with_profile) {
|
|
p.option_default("--project", "-C", "Project directory", compdb_opts.project_arg, cwd)
|
|
.option("--build-dir", "-B", "Build output directory", compdb_opts.build_arg);
|
|
if (with_profile) {
|
|
p.option("--profile", "-p", "Profile name", compdb_opts.profile_name);
|
|
}
|
|
add_log_flags(p);
|
|
};
|
|
auto &compdb_use =
|
|
compdb_cmd.subcommand("use", "Select active editor compilation database profile");
|
|
configure_compdb_common(compdb_use, true);
|
|
compdb_use.positional_many("profile", "Profile name (optional if --profile is given)",
|
|
compdb_opts.positional_profiles, false);
|
|
configure_compdb_common(
|
|
compdb_cmd.subcommand("show", "Show active editor compilation database selection"), false);
|
|
configure_compdb_common(
|
|
compdb_cmd.subcommand("export",
|
|
"Evaluate and export compile_commands.json without compiling"),
|
|
true);
|
|
configure_compdb_common(
|
|
compdb_cmd.subcommand("watch", "Watch project metadata and refresh compile_commands.json"),
|
|
true);
|
|
|
|
auto &watch_cmd =
|
|
root.subcommand("watch", "Watch project sources and rebuild on verified changes");
|
|
watch_cmd.option_default("--project", "-C", "Project directory", watch_opts.project_arg, cwd)
|
|
.option("--build-dir", "-B", "Build output directory", watch_opts.build_arg)
|
|
.option("--profile", "-p", "Profile to watch", watch_opts.profile_arg)
|
|
.option_many("--target", "-t", "Target to rebuild", watch_opts.targets);
|
|
add_log_flags(watch_cmd);
|
|
|
|
auto &deps_cmd = root.subcommand("deps", "Resolve or upgrade dependencies and update vbs.lock");
|
|
auto configure_deps_sub = [&](Void::Argparse::Parser &p) {
|
|
p.option_default("--project", "-C", "Project directory", deps_opts.project_arg, cwd)
|
|
.option("--build-dir", "-B", "Build output directory", deps_opts.build_arg)
|
|
.option_default("--profile", "-p", "Profile name", deps_opts.profile_name, "debug")
|
|
.flag("--offline", "", "Disallow network fetches", deps_opts.offline);
|
|
add_log_flags(p);
|
|
};
|
|
configure_deps_sub(deps_cmd.subcommand(
|
|
"resolve", "Resolve dependencies preserving pinned compatible versions"));
|
|
configure_deps_sub(
|
|
deps_cmd.subcommand("update", "Re-solve dependencies allowing compatible SemVer upgrades"));
|
|
|
|
auto &install_cmd =
|
|
root.subcommand("install", "Build, stage, and install declared products and exports");
|
|
install_cmd
|
|
.option_default("--project", "-C", "Project directory", install_opts.project_arg, cwd)
|
|
.option("--build-dir", "-B", "Build output directory", install_opts.build_arg)
|
|
.option_default("--profile", "-p", "Profile name", install_opts.profile_name, "debug")
|
|
.option("--compiler", "", "Override compiler family (gcc|clang)", install_opts.compiler_arg)
|
|
.option("--prefix", "", "Install destination prefix (required)", install_opts.prefix_arg)
|
|
.option("--package-name", "", "Exported package name", install_opts.pkg_name_arg)
|
|
.option_default("--package-version", "", "Exported package version", install_opts.pkg_ver,
|
|
"0.1.0")
|
|
.option("--component", "", "Install only a specific component", install_opts.component_arg)
|
|
.flag("--no-cmake-export", "", "Disable CMake Config.cmake export",
|
|
install_opts.no_cmake_export)
|
|
.flag("--no-native-export", "", "Disable native VBS package metadata export",
|
|
install_opts.no_native_export);
|
|
add_log_flags(install_cmd);
|
|
|
|
auto &uninstall_cmd =
|
|
root.subcommand("uninstall", "Safely remove only VBS-owned files recorded in the manifest");
|
|
uninstall_cmd.option("--prefix", "", "Installed prefix directory (required)",
|
|
uninstall_opts.prefix_arg);
|
|
add_log_flags(uninstall_cmd);
|
|
|
|
auto &pack_cmd = root.subcommand("pack", "Create a deterministic USTAR source archive (.tar)");
|
|
pack_cmd.option_default("--project", "-C", "Project directory", pack_opts.project_arg, cwd)
|
|
.option_default("--output", "-o", "Output archive path", pack_opts.out_arg, "package.tar");
|
|
add_log_flags(pack_cmd);
|
|
|
|
auto &publish_cmd =
|
|
root.subcommand("publish", "Pack and publish a release to a VBS package registry");
|
|
publish_cmd
|
|
.option_default("--project", "-C", "Project directory", publish_opts.project_arg, cwd)
|
|
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
|
publish_opts.registry_arg)
|
|
.option("--name", "-n", "Package name", publish_opts.name_arg)
|
|
.option("--version", "-v", "Strict SemVer release version", publish_opts.version_arg)
|
|
.option_default("--description", "-d", "Package description", publish_opts.description, "")
|
|
.option_default("--token-env", "", "Environment variable holding bearer token",
|
|
publish_opts.token_env, "VBS_REGISTRY_TOKEN")
|
|
.flag("--private", "", "Publish package as private", publish_opts.is_private);
|
|
add_log_flags(publish_cmd, false); // `-v` is `--version` on `publish`.
|
|
|
|
auto &bridge_cmd = root.subcommand("bridge", "CMake VbsDeps.cmake dependency bridge backend");
|
|
bridge_cmd.option("--request", "", "Path to bridge request JSON", bridge_opts.req_arg)
|
|
.option("--output", "", "Path to output CMake fragment", bridge_opts.out_arg);
|
|
add_log_flags(bridge_cmd);
|
|
|
|
auto &gc_cmd =
|
|
root.subcommand("gc", "Recover interrupted state and garbage-collect unreferenced blobs");
|
|
gc_cmd
|
|
.option_default("--build-dir", "-B", "Build directory", gc_opts.build_arg,
|
|
gc_opts.build_arg)
|
|
.option_default("--max-bytes", "",
|
|
"Target maximum retained CAS bytes (0=unreferenced only)",
|
|
gc_opts.max_bytes_arg, "0");
|
|
add_log_flags(gc_cmd);
|
|
|
|
auto &gen_tests_cmd =
|
|
root.subcommand("gen-tests", "Generate native Void::Testing registration unit (no CMake)");
|
|
gen_tests_cmd.option("--input", "", "Input test .cpp file", gen_tests_opts.input_arg)
|
|
.option("--output-dir", "", "Output directory for generated registration .cpp",
|
|
gen_tests_opts.out_arg);
|
|
add_log_flags(gen_tests_cmd);
|
|
|
|
const auto parsed = root.parse_detailed(argc, argv);
|
|
if (parsed.is_help()) {
|
|
std::cout << parsed.message;
|
|
return 0;
|
|
}
|
|
if (parsed.is_error()) {
|
|
std::cerr << "vbs: " << parsed.message << '\n';
|
|
return 2;
|
|
}
|
|
if (show_version) {
|
|
if (!parsed.matched_command_path.empty()) {
|
|
std::cerr << "vbs: --version cannot be combined with subcommands\n";
|
|
return 2;
|
|
}
|
|
std::cout << "vbs " << Bootstrap::version << '\n';
|
|
return 0;
|
|
}
|
|
if (parsed.matched_command_path.empty()) {
|
|
std::cout << root.help();
|
|
return 0;
|
|
}
|
|
|
|
const std::string_view cmd = parsed.matched_command_path.front();
|
|
const bool machine_quiet_default =
|
|
(cmd == "describe") || (cmd == "compdb" && parsed.matched_command_path.size() >= 2 &&
|
|
parsed.matched_command_path[1] == "show");
|
|
const Void::Log::Level log_level =
|
|
verbose ? Void::Log::Level::Debug
|
|
: ((quiet || machine_quiet_default) ? Void::Log::Level::Warning
|
|
: Void::Log::Level::Info);
|
|
ConsoleLogGuard log_guard{log_level};
|
|
|
|
if (cmd == "build") {
|
|
return execute_build_or_test(std::move(build_opts), false);
|
|
}
|
|
if (cmd == "test") {
|
|
return execute_build_or_test(std::move(build_opts), true);
|
|
}
|
|
if (cmd == "describe") {
|
|
return execute_describe_command(describe_opts);
|
|
}
|
|
if (cmd == "compdb") {
|
|
return execute_compdb_command(parsed.matched_command_path.at(1), std::move(compdb_opts));
|
|
}
|
|
if (cmd == "watch") {
|
|
return execute_watch_command(std::move(watch_opts));
|
|
}
|
|
if (cmd == "deps") {
|
|
return execute_deps_command(parsed.matched_command_path.at(1), deps_opts);
|
|
}
|
|
if (cmd == "install") {
|
|
return execute_install_command(install_opts);
|
|
}
|
|
if (cmd == "uninstall") {
|
|
return execute_uninstall_command(uninstall_opts);
|
|
}
|
|
if (cmd == "pack") {
|
|
return execute_pack_command(pack_opts);
|
|
}
|
|
if (cmd == "publish") {
|
|
return execute_publish_command(publish_opts);
|
|
}
|
|
if (cmd == "bridge") {
|
|
return execute_bridge_command(bridge_opts);
|
|
}
|
|
if (cmd == "gc") {
|
|
return execute_gc_command(gc_opts);
|
|
}
|
|
if (cmd == "gen-tests") {
|
|
return execute_gen_tests_command(gen_tests_opts);
|
|
}
|
|
|
|
std::cerr << "vbs: unhandled subcommand '" << cmd << "'\n";
|
|
return 2;
|
|
}
|