4455 lines
201 KiB
C++
4455 lines
201 KiB
C++
#include <Void/Build.hpp>
|
|
#include <Void/Build/BootstrapConfig.hpp>
|
|
#include <Void/Build/Bridge/CMakeBridge.hpp>
|
|
#include <Void/Build/Config/BuildTree.hpp>
|
|
#include <Void/Build/Config/CmakeImport.hpp>
|
|
#include <Void/Build/Config/Frontend.hpp>
|
|
#include <Void/Build/Config/Presets.hpp>
|
|
#include <Void/Build/Config/Scaffold.hpp>
|
|
#include <Void/Build/Daemon/Daemon.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/Resolver.hpp>
|
|
#include <Void/Build/Package/Solver.hpp>
|
|
#include <Void/Build/Package/Toml.hpp>
|
|
#include <Void/Build/Platform/FileOps.hpp>
|
|
#include <Void/Build/Platform/Host.hpp>
|
|
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
|
#include <Void/Build/Provenance/Sbom.hpp>
|
|
#include <Void/Build/Provenance/Signing.hpp>
|
|
#include <Void/Build/Provenance/TrustedKeys.hpp>
|
|
#include <Void/Build/Provenance/Verification.hpp>
|
|
#include <Void/Build/Provider/PkgConfig.hpp>
|
|
#include <Void/Build/Provider/Provider.hpp>
|
|
#include <Void/Build/Provider/Translator.hpp>
|
|
#include <Void/Build/Report/Cdash.hpp>
|
|
#include <Void/Build/Report/Coverage.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/Data/StrictJson.hpp>
|
|
#include <Void/Log/ConsoleLogger.hpp>
|
|
#include <Void/Log/Formatter.hpp>
|
|
#include <Void/Log/Log.hpp>
|
|
#include <Void/Log/LoggingAdapter.hpp>
|
|
#include <Void/System/SignalWatcher.hpp>
|
|
#include <Void/System/TempDir.hpp>
|
|
#include <Void/Text/Semver.hpp>
|
|
#include <Void/Text/Str.hpp>
|
|
#include <Void/Text/Url.hpp>
|
|
#include <Void/Time/Stopwatch.hpp>
|
|
#include <unistd.h>
|
|
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <atomic>
|
|
#include <cctype>
|
|
#include <charconv>
|
|
#include <chrono>
|
|
#include <condition_variable>
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
#include <filesystem>
|
|
#include <format>
|
|
#include <functional>
|
|
#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;
|
|
|
|
// ANSI colors are enabled only for a terminal and are disabled by NO_COLOR or --no-color.
|
|
bool g_no_color = false;
|
|
|
|
bool color_enabled(int fd = 2) noexcept {
|
|
if (g_no_color || ::getenv("NO_COLOR") != nullptr) {
|
|
return false;
|
|
}
|
|
return ::isatty(fd) == 1;
|
|
}
|
|
|
|
std::string colorize_help(std::string_view text) {
|
|
if (!color_enabled(1)) {
|
|
return std::string{text};
|
|
}
|
|
constexpr std::string_view kReset = "\x1b[0m";
|
|
constexpr std::string_view kBold = "\x1b[1m";
|
|
constexpr std::string_view kCyan = "\x1b[36m";
|
|
std::string out;
|
|
out.reserve(text.size() + 64);
|
|
std::size_t pos = 0;
|
|
while (pos <= text.size()) {
|
|
const auto nl = text.find('\n', pos);
|
|
const auto end = nl == std::string_view::npos ? text.size() : nl;
|
|
const std::string_view line = text.substr(pos, end - pos);
|
|
const bool section_header =
|
|
!line.empty() && line.back() == ':' && line.find_first_not_of(" \t") == 0;
|
|
const bool usage = line.starts_with("Usage:");
|
|
const bool indented_entry = line.starts_with(" ") && !section_header &&
|
|
line.find_first_not_of(' ') != std::string_view::npos &&
|
|
line.find(" ") != std::string_view::npos;
|
|
if (section_header || usage) {
|
|
out += kBold;
|
|
out += line;
|
|
out += kReset;
|
|
} else if (indented_entry) {
|
|
const auto token_start = line.find_first_not_of(' ');
|
|
const auto token_end = line.find(' ', token_start);
|
|
out += line.substr(0, token_start);
|
|
out += kCyan;
|
|
out += line.substr(token_start, token_end - token_start);
|
|
out += kReset;
|
|
out += line.substr(token_end);
|
|
} else {
|
|
out += line;
|
|
}
|
|
if (nl == std::string_view::npos) {
|
|
break;
|
|
}
|
|
out += '\n';
|
|
pos = nl + 1;
|
|
}
|
|
return out;
|
|
}
|
|
|
|
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);
|
|
}
|
|
logger_ = std::make_unique<Void::Logging::ConsoleLogger>();
|
|
if (color_enabled()) {
|
|
auto formatter =
|
|
std::make_shared<Void::Logging::PatternFormatter>("[{level:,auto}] {message}");
|
|
formatter->set_color_policy(Void::Logging::ColorPolicy::defaults());
|
|
logger_->set_formatter(std::move(formatter));
|
|
}
|
|
reg_id_ = Void::Log::register_sink(Void::Log::make_sink(*logger_));
|
|
}
|
|
|
|
~ConsoleLogGuard() {
|
|
if (reg_id_ != 0) {
|
|
(void)Void::Log::detach_and_drain(reg_id_);
|
|
}
|
|
logger_.reset();
|
|
}
|
|
|
|
ConsoleLogGuard(const ConsoleLogGuard &) = delete;
|
|
ConsoleLogGuard &operator=(const ConsoleLogGuard &) = delete;
|
|
|
|
private:
|
|
std::unique_ptr<Void::Logging::ConsoleLogger> logger_;
|
|
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};
|
|
std::error_code ec;
|
|
std::vector<std::filesystem::path> sdk_candidates;
|
|
if (const auto self_exe = Platform::current_executable_path(); self_exe) {
|
|
const auto self_root = self_exe->parent_path().parent_path();
|
|
sdk_candidates.push_back(self_root / "libVoidBuildSdk.a");
|
|
sdk_candidates.push_back(self_root / "libVoidBuild_Sdk.a");
|
|
sdk_candidates.push_back(self_root / "lib" / "libVoidBuildSdk.a");
|
|
}
|
|
if (!Bootstrap::binary_dir.empty()) {
|
|
const auto bin_dir = std::filesystem::path{Bootstrap::binary_dir};
|
|
sdk_candidates.push_back(bin_dir / "libVoidBuild_Sdk.a");
|
|
sdk_candidates.push_back(bin_dir / "out" / "libVoidBuildSdk.a");
|
|
sdk_candidates.push_back(bin_dir / "profiles" / "debug" / "out" / "libVoidBuildSdk.a");
|
|
}
|
|
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", "sdk", "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;
|
|
}
|
|
|
|
using ResolvedDepMaterialization = Package::ResolvedDepMaterialization;
|
|
|
|
// Thin CLI adapter over the shared Package resolver (environment-provided registry defaults).
|
|
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::vector<std::string> &trusted_public_keys) {
|
|
Package::ResolveOptions options;
|
|
options.project_root = project_root;
|
|
options.build_root = build_root;
|
|
options.pinned_lock = pinned_lock;
|
|
options.offline = offline;
|
|
options.allow_upgrade = allow_upgrade;
|
|
options.trusted_public_keys = trusted_public_keys;
|
|
options.default_registry_url = Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");
|
|
options.registry_auth =
|
|
Package::RegistryAuth{Void::Configuration::get_env_or("VBS_REGISTRY_TOKEN", "")};
|
|
return Package::resolve_and_materialize_dependencies(ctx, merged_deps, options);
|
|
}
|
|
|
|
Void::Result::Result<std::vector<std::string>, Void::Result::Error>
|
|
combine_trusted_keys(const std::vector<std::string> &inline_keys,
|
|
const std::vector<std::string> &key_files,
|
|
const std::filesystem::path &project_root) {
|
|
std::vector<std::filesystem::path> files;
|
|
files.reserve(key_files.size());
|
|
for (const auto &file : key_files) {
|
|
files.emplace_back(file);
|
|
}
|
|
const std::string environment = Void::Configuration::get_env_or("VBS_TRUSTED_PUBLIC_KEYS", "");
|
|
std::optional<std::string_view> environment_value;
|
|
if (!environment.empty()) {
|
|
environment_value = environment;
|
|
}
|
|
auto loaded = Provenance::load_trusted_keys(files, project_root, environment_value);
|
|
if (!loaded) {
|
|
return std::unexpected{loaded.error()};
|
|
}
|
|
std::vector<std::string> combined = inline_keys;
|
|
for (auto &key : *loaded) {
|
|
if (std::ranges::find(combined, key) == combined.end()) {
|
|
combined.push_back(std::move(key));
|
|
}
|
|
}
|
|
return combined;
|
|
}
|
|
|
|
struct TestRunRecord {
|
|
std::string profile;
|
|
std::string name;
|
|
bool passed{false};
|
|
int exit_code{-1};
|
|
double elapsed_ms{0};
|
|
std::string output;
|
|
};
|
|
|
|
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> labels;
|
|
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;
|
|
std::optional<std::string> remote_cache_arg;
|
|
std::optional<std::string> remote_cache_token_env;
|
|
std::vector<std::string> members;
|
|
std::optional<std::string> changed_since;
|
|
std::optional<std::string> sbom_arg;
|
|
std::optional<std::string> sbom_format_arg;
|
|
std::optional<std::filesystem::path> lock_root;
|
|
std::optional<std::filesystem::path> state_dir;
|
|
std::vector<std::string> trusted_public_keys;
|
|
std::vector<std::string> trusted_key_files;
|
|
std::optional<std::string> target_os_arg;
|
|
std::optional<std::string> target_arch_arg;
|
|
std::optional<std::string> junit_arg;
|
|
std::optional<std::string> coverage_arg;
|
|
std::optional<std::string> cdash_arg;
|
|
std::optional<std::string> cdash_project_arg;
|
|
std::optional<std::string> cdash_build_arg;
|
|
std::optional<std::string> cdash_output_arg;
|
|
std::string test_timeout_arg{"300"};
|
|
bool publish_editor_selection{true};
|
|
bool no_cache{false};
|
|
bool locked{false};
|
|
bool offline{false};
|
|
bool native_foreign{false};
|
|
};
|
|
|
|
int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
|
const std::string cmd_name = run_tests ? "vbs test" : "vbs build";
|
|
int test_timeout_seconds = 300;
|
|
if (!Void::Str::to_int(opts.test_timeout_arg, test_timeout_seconds) ||
|
|
test_timeout_seconds <= 0 || test_timeout_seconds > 86400) {
|
|
std::cerr << cmd_name << ": invalid --test-timeout value '" << opts.test_timeout_arg
|
|
<< "' (expected 1..86400 seconds)\n";
|
|
return 2;
|
|
}
|
|
std::vector<TestRunRecord> test_records;
|
|
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");
|
|
auto trusted_keys =
|
|
combine_trusted_keys(opts.trusted_public_keys, opts.trusted_key_files, project_root);
|
|
if (!trusted_keys) {
|
|
std::cerr << cmd_name << ": " << trusted_keys.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
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(opts.state_dir ? *opts.state_dir : build_root / ".vbs");
|
|
if (!state) {
|
|
std::cerr << "vbs: " << state.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
const std::string remote_cache_url =
|
|
opts.remote_cache_arg
|
|
? *opts.remote_cache_arg
|
|
: std::string{Void::Configuration::get_env_or("VBS_REMOTE_CACHE", "")};
|
|
if (!remote_cache_url.empty()) {
|
|
State::RemoteCacheConfig remote_cfg;
|
|
remote_cfg.url = remote_cache_url;
|
|
const std::string token_env = opts.remote_cache_token_env
|
|
? *opts.remote_cache_token_env
|
|
: std::string{"VBS_REMOTE_CACHE_TOKEN"};
|
|
remote_cfg.bearer_token = Void::Configuration::get_env_or(token_env, "");
|
|
state->configure_remote_cache(std::move(remote_cfg));
|
|
Void::Log::info("Cache", "Using shared remote action cache at {}", remote_cache_url);
|
|
}
|
|
|
|
const auto lock_path = (opts.lock_root ? *opts.lock_root : 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;
|
|
}
|
|
|
|
const std::string target_os = opts.target_os_arg.value_or(Toolchain::host_os_name());
|
|
const std::string target_arch =
|
|
opts.target_arch_arg.value_or(Toolchain::host_architecture_name());
|
|
const bool windows_cross_target =
|
|
Void::Str::to_lower_ascii(target_os) == "windows" &&
|
|
Void::Str::to_lower_ascii(Toolchain::host_os_name()) != "windows";
|
|
|
|
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, target_os, target_arch);
|
|
} catch (const std::exception &ex) {
|
|
std::cerr << "vbs: " << ex.what() << '\n';
|
|
return 2;
|
|
}
|
|
if (opts.coverage_arg) {
|
|
// Instrument every compile and link so gcov data is produced when tests run.
|
|
// (GCC and Clang both accept --coverage.)
|
|
ctx.compile_options.push_back("--coverage");
|
|
ctx.link_options.push_back("--coverage");
|
|
}
|
|
|
|
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, *trusted_keys);
|
|
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 / "build.cpp", bec)) {
|
|
effective_dep.builder = "native";
|
|
} else 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" || effective_dep.builder == "native") {
|
|
Provider::ProviderRequest preq{effective_dep,
|
|
mat,
|
|
ctx,
|
|
*tc,
|
|
build_root / ".vbs" / "providers",
|
|
Provider::ProviderMode::FullBuild,
|
|
{},
|
|
fopts.sdk_include_dir,
|
|
fopts.sdk_source_dir,
|
|
fopts.sdk_library_path.empty()
|
|
? std::nullopt
|
|
: std::optional{fopts.sdk_library_path},
|
|
&(*state),
|
|
jobs};
|
|
if (opts.native_foreign &&
|
|
(effective_dep.builder == "cmake" || effective_dep.builder == "meson")) {
|
|
auto tr = Provider::resolve_foreign_with_translation(
|
|
preq, *state, Provider::TranslationPolicy::FallbackToForeignBuild);
|
|
if (!tr) {
|
|
std::cerr << "vbs: " << tr.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
Void::Log::info("Provider", "[{}] Imported {} target(s) from '{}' ({})",
|
|
prof_name, tr->exported.targets.size(), effective_dep.name,
|
|
tr->executed_natively
|
|
? "native-translated"
|
|
: (tr->exported.from_cache ? "cached" : "built"));
|
|
for (const auto &[k, v] : tr->exported.targets) {
|
|
imported_targets[k] = v;
|
|
}
|
|
} else {
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// pkg-config dependencies are resolved from the host environment (PKG_CONFIG_PATH /
|
|
// PKG_CONFIG_LIBDIR) instead of being fetched.
|
|
for (const auto &dep : *merged_deps) {
|
|
if (dep.record.source_kind != DependencySourceKind::PkgConfig) {
|
|
continue;
|
|
}
|
|
auto exported = Provider::resolve_pkgconfig(dep.record.name, dep.record.location,
|
|
Provider::pkgconfig_search_paths());
|
|
if (!exported) {
|
|
std::cerr << "vbs: " << exported.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
Void::Log::info("Provider", "[{}] Resolved pkg-config '{}' ({} target(s))",
|
|
prof_name, dep.record.location, exported->targets.size());
|
|
for (auto &[k, v] : exported->targets) {
|
|
imported_targets[k] = std::move(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.publish_editor_selection && (*opts.editor_profile == prof_name);
|
|
popts.reserved_ticket = *reserved_ticket;
|
|
popts.sdk_include_dir = fopts.sdk_include_dir;
|
|
popts.extra_build_sources = extra_build_sources;
|
|
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 (opts.sbom_arg) {
|
|
Provenance::SbomInput sbom;
|
|
sbom.project_name = project_root.filename().string();
|
|
sbom.tool_version = std::string{Bootstrap::version};
|
|
sbom.created_epoch = ctx.reproducibility_epoch;
|
|
const auto sbom_ctx_key = Package::make_lock_context_key(ctx, "target");
|
|
if (pinned_lock && pinned_lock->has_value()) {
|
|
const auto &document = (*pinned_lock)->document;
|
|
if (const auto it = document.contexts.find(sbom_ctx_key);
|
|
it != document.contexts.end()) {
|
|
for (const auto &entry : it->second.entries) {
|
|
if (entry.version.empty()) {
|
|
continue;
|
|
}
|
|
Provenance::SbomPackage package;
|
|
package.name =
|
|
entry.package_name.empty() ? entry.alias : entry.package_name;
|
|
package.version = entry.version;
|
|
package.download_location = entry.registry_authority.empty()
|
|
? entry.location
|
|
: entry.registry_authority;
|
|
package.sha256 = entry.sha256;
|
|
package.purl = "pkg:generic/" + package.name + "@" + package.version;
|
|
sbom.packages.push_back(std::move(package));
|
|
}
|
|
}
|
|
}
|
|
for (const auto &target : graph->targets) {
|
|
for (const auto &output : target.primary_outputs) {
|
|
auto digest = Util::sha256_file_hex(output);
|
|
if (!digest) {
|
|
continue;
|
|
}
|
|
Provenance::SbomFile file;
|
|
file.path = Platform::path_is_within(project_root, output)
|
|
? output.lexically_relative(project_root).generic_string()
|
|
: output.filename().string();
|
|
file.sha256 = std::move(*digest);
|
|
sbom.files.push_back(std::move(file));
|
|
}
|
|
}
|
|
try {
|
|
const auto format = opts.sbom_format_arg
|
|
? Provenance::parse_sbom_format(*opts.sbom_format_arg)
|
|
: Provenance::SbomFormat::Spdx;
|
|
auto generated = Provenance::generate_sbom(sbom, format);
|
|
if (!generated) {
|
|
std::cerr << "vbs: SBOM generation failed: " << generated.error().message()
|
|
<< '\n';
|
|
all_ok = false;
|
|
continue;
|
|
}
|
|
std::filesystem::path sbom_path{*opts.sbom_arg};
|
|
if (opts.profiles.size() > 1) {
|
|
sbom_path =
|
|
sbom_path.parent_path() / (sbom_path.stem().string() + "." + prof_name +
|
|
sbom_path.extension().string());
|
|
}
|
|
if (auto wrote = Platform::atomic_write_file(sbom_path, *generated, true); !wrote) {
|
|
std::cerr << "vbs: failed writing SBOM: " << wrote.error().message() << '\n';
|
|
all_ok = false;
|
|
continue;
|
|
}
|
|
Void::Log::info("Sbom", "[{}] Wrote {} SBOM to {}", prof_name,
|
|
Provenance::sbom_format_name(format), sbom_path.string());
|
|
} catch (const std::exception &ex) {
|
|
std::cerr << "vbs: " << ex.what() << '\n';
|
|
all_ok = false;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if (run_tests) {
|
|
std::optional<std::filesystem::path> wine;
|
|
if (windows_cross_target) {
|
|
// Cross-built Windows test binaries execute under Wine (Track C3 Wine-first).
|
|
auto resolved = Platform::resolve_executable("wine");
|
|
if (!resolved) {
|
|
std::cerr << "vbs test: Windows target tests require 'wine' in PATH\n";
|
|
all_ok = false;
|
|
} else {
|
|
wine = *resolved;
|
|
}
|
|
}
|
|
|
|
struct TestJob {
|
|
std::string name;
|
|
std::filesystem::path executable;
|
|
std::vector<std::string> resources;
|
|
std::vector<std::size_t> prerequisites;
|
|
};
|
|
std::vector<TestJob> test_jobs;
|
|
std::map<std::size_t, std::size_t> job_by_target; // graph target index -> job index
|
|
|
|
// Candidate test targets passing the target filter (labels never exclude fixture
|
|
// helpers - they are pulled in by the tests that require them).
|
|
std::vector<std::size_t> candidates;
|
|
for (std::size_t i = 0; i < graph->targets.size(); ++i) {
|
|
const auto &t = graph->targets[i];
|
|
if (t.kind != TargetKind::Test || t.primary_outputs.empty()) {
|
|
continue;
|
|
}
|
|
if (!opts.targets.empty() && !std::ranges::contains(opts.targets, t.name)) {
|
|
continue;
|
|
}
|
|
candidates.push_back(i);
|
|
}
|
|
std::map<std::string, std::vector<std::size_t>, std::less<>> setups_by_fixture;
|
|
std::map<std::string, std::vector<std::size_t>, std::less<>> cleanups_by_fixture;
|
|
for (const auto i : candidates) {
|
|
for (const auto &fixture : graph->targets[i].fixture_setup) {
|
|
setups_by_fixture[fixture].push_back(i);
|
|
}
|
|
for (const auto &fixture : graph->targets[i].fixture_cleanup) {
|
|
cleanups_by_fixture[fixture].push_back(i);
|
|
}
|
|
}
|
|
std::map<std::string, std::vector<std::size_t>, std::less<>> fixture_users;
|
|
std::set<std::size_t> adding; // recursion guard for fixture cycles
|
|
const auto add_prerequisite = [](TestJob &job, std::size_t prerequisite) {
|
|
if (!std::ranges::contains(job.prerequisites, prerequisite)) {
|
|
job.prerequisites.push_back(prerequisite);
|
|
}
|
|
};
|
|
std::function<std::size_t(std::size_t)> add_job =
|
|
[&](std::size_t target_index) -> std::size_t {
|
|
if (const auto it = job_by_target.find(target_index); it != job_by_target.end()) {
|
|
return it->second;
|
|
}
|
|
const auto &t = graph->targets[target_index];
|
|
const std::size_t job_index = test_jobs.size();
|
|
test_jobs.push_back(TestJob{t.name, t.primary_outputs.front(), t.resources, {}});
|
|
job_by_target[target_index] = job_index;
|
|
if (!adding.insert(target_index).second) {
|
|
return job_index; // Fixture cycle: stop recursing.
|
|
}
|
|
for (const auto &fixture : t.fixture_required) {
|
|
const auto setup_it = setups_by_fixture.find(fixture);
|
|
if (setup_it != setups_by_fixture.end() && !setup_it->second.empty()) {
|
|
add_prerequisite(test_jobs[job_index], add_job(setup_it->second.front()));
|
|
}
|
|
fixture_users[fixture].push_back(job_index);
|
|
}
|
|
adding.erase(target_index);
|
|
return job_index;
|
|
};
|
|
for (const auto i : candidates) {
|
|
const auto &t = graph->targets[i];
|
|
if (!opts.labels.empty() &&
|
|
!std::ranges::any_of(opts.labels, [&](const std::string &label) {
|
|
return std::ranges::contains(t.labels, label);
|
|
})) {
|
|
continue;
|
|
}
|
|
add_job(i);
|
|
}
|
|
// A fixture's cleanup runs after every test that used it (and after its setup).
|
|
for (const auto &[fixture, users] : fixture_users) {
|
|
const auto cleanup_it = cleanups_by_fixture.find(fixture);
|
|
if (cleanup_it == cleanups_by_fixture.end()) {
|
|
continue;
|
|
}
|
|
for (const auto cleanup_target : cleanup_it->second) {
|
|
const auto cleanup_job = add_job(cleanup_target);
|
|
for (const auto user : users) {
|
|
add_prerequisite(test_jobs[cleanup_job], user);
|
|
}
|
|
const auto setup_it = setups_by_fixture.find(fixture);
|
|
if (setup_it != setups_by_fixture.end() && !setup_it->second.empty()) {
|
|
add_prerequisite(test_jobs[cleanup_job],
|
|
job_by_target.at(setup_it->second.front()));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Tests run in parallel up to --jobs, except that tests sharing a resource are
|
|
// serialized (a resource is held exclusively while its test runs) and fixture
|
|
// prerequisites run first.
|
|
std::vector<std::optional<TestRunRecord>> records(test_jobs.size());
|
|
std::mutex test_mutex;
|
|
std::condition_variable test_cv;
|
|
std::set<std::string> held_resources;
|
|
std::vector<bool> claimed(test_jobs.size(), false);
|
|
std::vector<bool> completed(test_jobs.size(), false);
|
|
std::vector<bool> failed(test_jobs.size(), false);
|
|
std::size_t remaining = test_jobs.size();
|
|
const std::size_t worker_count = std::max<std::size_t>(
|
|
1, std::min<std::size_t>(
|
|
jobs == 0 ? std::max(1u, std::thread::hardware_concurrency()) : jobs,
|
|
std::max<std::size_t>(1, test_jobs.size())));
|
|
const auto prerequisites_done = [&](std::size_t i) {
|
|
return std::ranges::all_of(test_jobs[i].prerequisites,
|
|
[&](std::size_t p) { return completed[p]; });
|
|
};
|
|
const auto resources_free = [&](std::size_t i) {
|
|
return std::ranges::none_of(test_jobs[i].resources, [&](const std::string &r) {
|
|
return held_resources.contains(r);
|
|
});
|
|
};
|
|
const auto any_runnable = [&] {
|
|
for (std::size_t i = 0; i < test_jobs.size(); ++i) {
|
|
if (!claimed[i] && prerequisites_done(i) && resources_free(i)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
const auto worker = [&] {
|
|
for (;;) {
|
|
std::size_t index = 0;
|
|
{
|
|
std::unique_lock lock{test_mutex};
|
|
test_cv.wait(lock, [&] { return remaining == 0 || any_runnable(); });
|
|
if (remaining == 0) {
|
|
return;
|
|
}
|
|
for (; index < test_jobs.size(); ++index) {
|
|
if (!claimed[index] && prerequisites_done(index) &&
|
|
resources_free(index)) {
|
|
break;
|
|
}
|
|
}
|
|
claimed[index] = true;
|
|
// A failed fixture setup skips its dependents.
|
|
const bool blocked =
|
|
std::ranges::any_of(test_jobs[index].prerequisites,
|
|
[&](std::size_t p) { return failed[p]; });
|
|
if (blocked) {
|
|
Void::Log::warn("Test", "[{}] SKIPPED '{}' (fixture setup failed)",
|
|
prof_name, test_jobs[index].name);
|
|
completed[index] = true;
|
|
--remaining;
|
|
} else {
|
|
for (const auto &r : test_jobs[index].resources) {
|
|
held_resources.insert(r);
|
|
}
|
|
}
|
|
if (blocked) {
|
|
test_cv.notify_all();
|
|
continue;
|
|
}
|
|
}
|
|
const auto &job = test_jobs[index];
|
|
Void::Log::info("Test", "[{}] Running test target '{}'...", prof_name,
|
|
job.name);
|
|
const auto tsw = Void::Time::Stopwatch::started();
|
|
Platform::ProcessRequest treq;
|
|
if (wine) {
|
|
treq.executable = *wine;
|
|
treq.arguments = {job.executable.string()};
|
|
} else {
|
|
treq.executable = job.executable;
|
|
}
|
|
treq.working_directory = project_root;
|
|
treq.timeout = std::chrono::seconds{test_timeout_seconds};
|
|
auto tres = Platform::run_supervised(treq);
|
|
TestRunRecord record;
|
|
record.profile = prof_name;
|
|
record.name = job.name;
|
|
record.passed = tres.has_value() && tres->succeeded();
|
|
record.elapsed_ms = tsw.elapsed_ms();
|
|
if (tres) {
|
|
record.output = tres->stdout_data + tres->stderr_data;
|
|
record.exit_code = tres->exit_code;
|
|
} else {
|
|
record.output = tres.error().message();
|
|
}
|
|
const bool passed = record.passed;
|
|
if (!passed) {
|
|
Void::Log::error("Test", "[{}] FAILED '{}' ({:.0f} ms)", prof_name,
|
|
job.name, tsw.elapsed_ms());
|
|
} else {
|
|
Void::Log::info("Test", "[{}] PASSED '{}' ({:.0f} ms)", prof_name, job.name,
|
|
tsw.elapsed_ms());
|
|
}
|
|
{
|
|
std::lock_guard lock{test_mutex};
|
|
for (const auto &r : job.resources) {
|
|
held_resources.erase(r);
|
|
}
|
|
records[index] = std::move(record);
|
|
completed[index] = true;
|
|
failed[index] = !passed;
|
|
--remaining;
|
|
}
|
|
test_cv.notify_all();
|
|
}
|
|
};
|
|
std::vector<std::thread> pool;
|
|
pool.reserve(worker_count);
|
|
if (!windows_cross_target || wine.has_value()) {
|
|
for (std::size_t i = 0; i < worker_count; ++i) {
|
|
pool.emplace_back(worker);
|
|
}
|
|
for (auto &thread : pool) {
|
|
thread.join();
|
|
}
|
|
}
|
|
for (auto &record : records) {
|
|
if (!record) {
|
|
continue;
|
|
}
|
|
if (!record->passed) {
|
|
std::cerr << "vbs test: FAILED '" << record->name << "'\n";
|
|
if (!record->output.empty()) {
|
|
std::cerr << record->output << '\n';
|
|
}
|
|
all_ok = false;
|
|
} else {
|
|
std::cout << "vbs test: PASSED '" << record->name << "'\n";
|
|
}
|
|
test_records.push_back(std::move(*record));
|
|
}
|
|
}
|
|
}
|
|
|
|
// lcov coverage report from the gcov data produced by the instrumented test binaries.
|
|
if (run_tests && opts.coverage_arg) {
|
|
const auto gcda = Report::collect_gcda_files(build_root);
|
|
std::error_code cov_ec;
|
|
const auto source_root = std::filesystem::weakly_canonical(project_root, cov_ec);
|
|
auto cov = Report::write_coverage_report(gcda, *opts.coverage_arg, source_root);
|
|
if (!cov) {
|
|
std::cerr << "vbs test: " << cov.error().message() << '\n';
|
|
all_ok = false;
|
|
} else {
|
|
const double percent =
|
|
cov->lines_found == 0
|
|
? 0.0
|
|
: 100.0 * static_cast<double>(cov->lines_hit) /
|
|
static_cast<double>(cov->lines_found);
|
|
Void::Log::info("Test", "Coverage {:.1f}% ({}/{} lines) across {} file(s) -> {}", percent,
|
|
cov->lines_hit, cov->lines_found, cov->files,
|
|
(std::filesystem::path{*opts.coverage_arg} / "coverage.info").string());
|
|
}
|
|
}
|
|
|
|
// JUnit XML report for CI systems (aggregated across selected profiles).
|
|
if (opts.junit_arg && !opts.junit_arg->empty() && !test_records.empty()) {
|
|
const auto xml_escape = [](std::string_view text) {
|
|
std::string out;
|
|
out.reserve(text.size());
|
|
for (const char c : text) {
|
|
switch (c) {
|
|
case '&':
|
|
out += "&";
|
|
break;
|
|
case '<':
|
|
out += "<";
|
|
break;
|
|
case '>':
|
|
out += ">";
|
|
break;
|
|
case '"':
|
|
out += """;
|
|
break;
|
|
case '\'':
|
|
out += "'";
|
|
break;
|
|
default:
|
|
if (static_cast<unsigned char>(c) >= 0x20 || c == '\n' || c == '\t') {
|
|
out.push_back(c);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return out;
|
|
};
|
|
std::size_t failures = 0;
|
|
for (const auto &record : test_records) {
|
|
if (!record.passed) {
|
|
++failures;
|
|
}
|
|
}
|
|
std::string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
|
xml += std::format("<testsuites name=\"vbs\" tests=\"{}\" failures=\"{}\">\n",
|
|
test_records.size(), failures);
|
|
std::string current_profile;
|
|
auto open_suite = [&] {
|
|
if (!current_profile.empty()) {
|
|
xml += " </testsuite>\n";
|
|
}
|
|
std::size_t suite_tests = 0;
|
|
std::size_t suite_failures = 0;
|
|
for (const auto &record : test_records) {
|
|
if (record.profile == current_profile) {
|
|
++suite_tests;
|
|
if (!record.passed) {
|
|
++suite_failures;
|
|
}
|
|
}
|
|
}
|
|
xml += std::format(" <testsuite name=\"{}\" tests=\"{}\" failures=\"{}\">\n",
|
|
xml_escape(current_profile), suite_tests, suite_failures);
|
|
};
|
|
for (const auto &record : test_records) {
|
|
if (record.profile != current_profile) {
|
|
current_profile = record.profile;
|
|
open_suite();
|
|
}
|
|
xml += std::format(" <testcase classname=\"{}\" name=\"{}\" time=\"{:.3f}\"",
|
|
xml_escape(record.profile), xml_escape(record.name),
|
|
record.elapsed_ms / 1000.0);
|
|
if (record.passed) {
|
|
xml += "/>\n";
|
|
} else {
|
|
xml += std::format(">\n <failure message=\"exited with status "
|
|
"{}\">{}</failure>\n </testcase>\n",
|
|
record.exit_code, xml_escape(record.output));
|
|
}
|
|
}
|
|
if (!current_profile.empty()) {
|
|
xml += " </testsuite>\n";
|
|
}
|
|
xml += "</testsuites>\n";
|
|
if (auto written = Platform::atomic_write_file(*opts.junit_arg, xml, false); !written) {
|
|
std::cerr << "vbs test: cannot write JUnit report: " << written.error().message()
|
|
<< '\n';
|
|
all_ok = false;
|
|
}
|
|
}
|
|
|
|
// CDash Test.xml report (and optional submission) for CI dashboards.
|
|
if (run_tests && !test_records.empty() &&
|
|
(opts.cdash_arg.has_value() || opts.cdash_output_arg.has_value())) {
|
|
Report::CdashReportOptions cdash;
|
|
cdash.build_name = opts.cdash_build_arg.value_or("vbs");
|
|
cdash.os_name = Toolchain::host_os_name();
|
|
const std::time_t now =
|
|
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
|
std::tm tm{};
|
|
::gmtime_r(&now, &tm);
|
|
cdash.build_stamp =
|
|
std::format("{:04d}{:02d}{:02d}-{:02d}{:02d}-Experimental", tm.tm_year + 1900,
|
|
tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
|
|
for (const auto &record : test_records) {
|
|
cdash.tests.push_back(Report::CdashTestResult{
|
|
record.name, record.passed, record.elapsed_ms / 1000.0, record.output});
|
|
}
|
|
if (opts.cdash_output_arg) {
|
|
if (auto written = Platform::atomic_write_file(
|
|
*opts.cdash_output_arg, Report::render_cdash_test_xml(cdash), false);
|
|
!written) {
|
|
std::cerr << "vbs test: cannot write CDash report: " << written.error().message()
|
|
<< '\n';
|
|
all_ok = false;
|
|
}
|
|
}
|
|
if (opts.cdash_arg) {
|
|
const std::string project =
|
|
opts.cdash_project_arg.value_or(project_root.filename().string());
|
|
if (auto submitted = Report::submit_cdash_report(*opts.cdash_arg, project, cdash);
|
|
!submitted) {
|
|
std::cerr << "vbs test: " << submitted.error().message() << '\n';
|
|
all_ok = false;
|
|
} else {
|
|
Void::Log::info("Test", "Submitted CDash test report to {} (project '{}')",
|
|
*opts.cdash_arg, project);
|
|
}
|
|
}
|
|
}
|
|
|
|
Void::Log::debug("Build", "Total wall time: {:.2f}s", total_sw.elapsed_ms() / 1000.0);
|
|
return all_ok ? 0 : 1;
|
|
}
|
|
|
|
int execute_workspace(BuildCmdOptions opts, bool run_tests) {
|
|
const std::filesystem::path project_root = std::filesystem::absolute(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_sources;
|
|
for (const auto &source : opts.extra_build_sources) {
|
|
extra_sources.emplace_back(source);
|
|
}
|
|
const auto fopts = make_frontend_opts(project_root, build_root, extra_sources);
|
|
auto compiled = Config::compile_descriptor(fopts);
|
|
if (!compiled) {
|
|
std::cerr << "vbs: " << compiled.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto workspace = Config::evaluate_workspace(*compiled, fopts);
|
|
if (!workspace) {
|
|
std::cerr << "vbs: " << workspace.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
if (workspace->members.empty()) {
|
|
std::cerr << "vbs: workspace declares no members\n";
|
|
return 1;
|
|
}
|
|
|
|
std::map<std::string, std::filesystem::path, std::less<>> member_dirs;
|
|
for (const auto &member : workspace->members) {
|
|
std::filesystem::path dir = member.path;
|
|
if (!dir.is_absolute()) {
|
|
dir = project_root / dir;
|
|
}
|
|
std::error_code ec;
|
|
const auto canonical = std::filesystem::weakly_canonical(dir, ec);
|
|
if (ec || !std::filesystem::is_directory(canonical)) {
|
|
std::cerr << "vbs: workspace member '" << member.name << "' path '" << dir.string()
|
|
<< "' is not a directory\n";
|
|
return 1;
|
|
}
|
|
member_dirs[member.name] = canonical;
|
|
const std::string env_name = "VBS_WORKSPACE_MEMBER_" + member.name;
|
|
#if defined(_WIN32)
|
|
(void)_putenv_s(env_name.c_str(), canonical.c_str());
|
|
#else
|
|
(void)::setenv(env_name.c_str(), canonical.c_str(), 1);
|
|
#endif
|
|
}
|
|
|
|
std::set<std::string> selected;
|
|
if (!opts.members.empty()) {
|
|
for (const auto &name : opts.members) {
|
|
if (!member_dirs.contains(name)) {
|
|
std::cerr << "vbs: unknown workspace member '" << name << "'\n";
|
|
return 2;
|
|
}
|
|
selected.insert(name);
|
|
}
|
|
} else if (opts.changed_since) {
|
|
auto git = Platform::resolve_executable("git");
|
|
if (!git) {
|
|
std::cerr << "vbs: --changed-since requires git in PATH\n";
|
|
return 1;
|
|
}
|
|
Platform::ProcessRequest req;
|
|
req.executable = *git;
|
|
req.arguments = {"-C", project_root.string(), "diff", "--name-only", *opts.changed_since};
|
|
auto proc = Platform::run_supervised(req);
|
|
if (!proc || !proc->succeeded()) {
|
|
std::cerr << "vbs: git diff --name-only " << *opts.changed_since
|
|
<< " failed: " << (proc ? proc->stderr_data : proc.error().message()) << '\n';
|
|
return 1;
|
|
}
|
|
std::size_t pos = 0;
|
|
while (pos < proc->stdout_data.size()) {
|
|
const auto nl = proc->stdout_data.find('\n', pos);
|
|
const auto line = proc->stdout_data.substr(
|
|
pos, nl == std::string::npos ? std::string::npos : nl - pos);
|
|
if (!line.empty()) {
|
|
const auto changed = std::filesystem::weakly_canonical(project_root / line);
|
|
std::string best;
|
|
std::size_t best_len = 0;
|
|
for (const auto &[name, dir] : member_dirs) {
|
|
if (Platform::path_is_within(dir, changed) && dir.string().size() > best_len) {
|
|
best = name;
|
|
best_len = dir.string().size();
|
|
}
|
|
}
|
|
if (!best.empty()) {
|
|
selected.insert(best);
|
|
}
|
|
}
|
|
if (nl == std::string::npos) {
|
|
break;
|
|
}
|
|
pos = nl + 1;
|
|
}
|
|
if (selected.empty()) {
|
|
std::cout << "vbs: no workspace members changed since " << *opts.changed_since << '\n';
|
|
return 0;
|
|
}
|
|
} else {
|
|
for (const auto &[name, dir] : member_dirs) {
|
|
selected.insert(name);
|
|
}
|
|
}
|
|
|
|
bool all_ok = true;
|
|
for (const auto &member : workspace->members) {
|
|
if (!selected.contains(member.name)) {
|
|
continue;
|
|
}
|
|
BuildCmdOptions member_opts = opts;
|
|
member_opts.project_arg = member_dirs.at(member.name).string();
|
|
member_opts.build_arg = (build_root / "members" / member.name).string();
|
|
member_opts.lock_root = project_root;
|
|
member_opts.state_dir = build_root / ".vbs";
|
|
member_opts.members.clear();
|
|
member_opts.changed_since.reset();
|
|
// Members must not overwrite each other's project-root compile_commands.json alias.
|
|
member_opts.publish_editor_selection = false;
|
|
Void::Log::info("Workspace", "[{}] {}", member.name,
|
|
run_tests ? "building and testing member" : "building member");
|
|
if (execute_build_or_test(std::move(member_opts), run_tests) != 0) {
|
|
all_ok = false;
|
|
}
|
|
}
|
|
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 PublishBinaryCmdOptions {
|
|
std::optional<std::string> registry_arg;
|
|
std::optional<std::string> name_arg;
|
|
std::optional<std::string> version_arg;
|
|
std::optional<std::string> variant_arg;
|
|
std::optional<std::string> file_arg;
|
|
std::optional<std::string> signing_key_arg;
|
|
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
|
};
|
|
|
|
int execute_publish_binary_command(const PublishBinaryCmdOptions &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 || !opts.variant_arg ||
|
|
!opts.file_arg) {
|
|
std::cerr << "vbs publish-binary: --registry, --name, --version, --variant, and --file "
|
|
"are required\n";
|
|
return 2;
|
|
}
|
|
Package::BinaryPublishOptions popts;
|
|
popts.registry_url = registry_url;
|
|
popts.package_name = *opts.name_arg;
|
|
popts.version = *opts.version_arg;
|
|
popts.variant_id = *opts.variant_arg;
|
|
popts.artifact_path = std::filesystem::path{*opts.file_arg};
|
|
popts.auth.bearer_token = Void::Configuration::get_env_or(opts.token_env, "");
|
|
if (opts.signing_key_arg) {
|
|
popts.signing_seed_path = std::filesystem::path{*opts.signing_key_arg};
|
|
}
|
|
Void::Log::info("Publish", "Uploading binary variant {}@{}/{} to {}...", popts.package_name,
|
|
popts.version, popts.variant_id, registry_url);
|
|
auto sha = Package::publish_binary_variant(popts);
|
|
if (!sha) {
|
|
std::cerr << "vbs publish-binary: " << sha.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "published binary " << popts.package_name << '@' << popts.version << '/'
|
|
<< popts.variant_id << " sha256=" << *sha << '\n';
|
|
return 0;
|
|
}
|
|
|
|
struct TokensCmdOptions {
|
|
std::optional<std::string> registry_arg;
|
|
std::optional<std::string> token_id_arg;
|
|
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
|
};
|
|
|
|
int execute_tokens_command(std::string_view sub, const TokensCmdOptions &opts) {
|
|
const std::string registry_url = opts.registry_arg
|
|
? *opts.registry_arg
|
|
: Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");
|
|
if (registry_url.empty()) {
|
|
std::cerr << "vbs tokens: --registry is required\n";
|
|
return 2;
|
|
}
|
|
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
|
|
|
if (sub == "revoke") {
|
|
if (!opts.token_id_arg || opts.token_id_arg->empty()) {
|
|
std::cerr << "vbs tokens revoke: --token-id is required\n";
|
|
return 2;
|
|
}
|
|
auto revoked = Package::revoke_token(registry_url, *opts.token_id_arg, auth);
|
|
if (!revoked) {
|
|
std::cerr << "vbs tokens revoke: " << revoked.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "revoked " << *opts.token_id_arg << '\n';
|
|
return 0;
|
|
}
|
|
|
|
auto tokens = Package::fetch_tokens(registry_url, auth);
|
|
if (!tokens) {
|
|
std::cerr << "vbs tokens: " << tokens.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
for (const auto &token : *tokens) {
|
|
std::cout << token.token_id << ' ' << (token.label.empty() ? "-" : token.label) << ' '
|
|
<< token.username << ' ';
|
|
for (std::size_t i = 0; i < token.scopes.size(); ++i) {
|
|
std::cout << (i > 0 ? "," : "") << token.scopes[i];
|
|
}
|
|
std::cout << ' ' << (token.revoked ? "revoked" : "active") << '\n';
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
struct CompdbEntriesCmdOptions {
|
|
std::string project_arg;
|
|
std::optional<std::string> build_arg;
|
|
std::optional<std::string> file_arg;
|
|
std::string limit_arg{"50"};
|
|
};
|
|
|
|
int execute_compdb_entries_command(const CompdbEntriesCmdOptions &opts) {
|
|
int parsed_limit = 0;
|
|
if (!Void::Str::to_int(opts.limit_arg, parsed_limit) || parsed_limit < 0 ||
|
|
parsed_limit > 500) {
|
|
std::cerr << "vbs compdb entries: invalid --limit value '" << opts.limit_arg << "'\n";
|
|
return 2;
|
|
}
|
|
const auto limit = static_cast<std::size_t>(parsed_limit);
|
|
const std::filesystem::path project_root{opts.project_arg};
|
|
const std::filesystem::path build_root =
|
|
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
|
|
|
|
auto selection = Editor::read_selection_state(project_root);
|
|
if (!selection) {
|
|
std::cerr << "vbs compdb entries: " << selection.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::filesystem::path compdb_path;
|
|
if (selection->has_value()) {
|
|
compdb_path = (*selection)->selected_compdb_path;
|
|
} else {
|
|
std::error_code ec;
|
|
const auto root_alias = build_root / "compile_commands.json";
|
|
if (std::filesystem::exists(root_alias, ec)) {
|
|
compdb_path = root_alias;
|
|
}
|
|
}
|
|
if (compdb_path.empty()) {
|
|
std::cerr << "vbs compdb entries: no compilation database is published; "
|
|
"run 'vbs compdb export' first\n";
|
|
return 1;
|
|
}
|
|
|
|
Editor::CompdbQuery query;
|
|
query.file_filter = opts.file_arg.value_or(std::string{});
|
|
query.limit = limit;
|
|
auto queried = Editor::query_compdb_entries(compdb_path, query);
|
|
if (!queried) {
|
|
std::cerr << "vbs compdb entries: " << queried.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "# " << queried->compdb_path.string() << " (" << queried->total
|
|
<< " matching, showing " << queried->entries.size() << ")\n";
|
|
for (const auto &entry : queried->entries) {
|
|
std::cout << entry.file << '\n';
|
|
if (!entry.arguments.empty()) {
|
|
std::cout << " ";
|
|
for (const auto &argument : entry.arguments) {
|
|
std::cout << argument << ' ';
|
|
}
|
|
std::cout << '\n';
|
|
} else if (!entry.command.empty()) {
|
|
std::cout << " " << entry.command << '\n';
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
struct WorkerCmdOptions {
|
|
std::optional<std::string> registry_arg;
|
|
std::optional<std::string> action_key_arg;
|
|
std::optional<std::string> record_arg;
|
|
bool queue_mode{false};
|
|
bool once{false};
|
|
std::string idle_timeout_arg{"0"};
|
|
std::string project_arg;
|
|
std::optional<std::string> build_arg;
|
|
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
|
std::string lease_seconds_arg{"60"};
|
|
std::string exec_timeout_arg{"600"};
|
|
std::string parallel_arg{"1"};
|
|
};
|
|
|
|
int execute_worker_command(const WorkerCmdOptions &opts) {
|
|
if (!opts.registry_arg || (!opts.record_arg && !opts.queue_mode) ||
|
|
(!opts.action_key_arg && !opts.queue_mode)) {
|
|
std::cerr << "vbs worker: --registry and --action-key (or --queue) are required; "
|
|
"--record is optional in queue mode\n";
|
|
return 2;
|
|
}
|
|
int lease_seconds = 60;
|
|
if (!Void::Str::to_int(opts.lease_seconds_arg, lease_seconds) || lease_seconds <= 0 ||
|
|
lease_seconds > 3600) {
|
|
std::cerr << "vbs worker: invalid --lease-seconds value '" << opts.lease_seconds_arg
|
|
<< "'\n";
|
|
return 2;
|
|
}
|
|
int exec_timeout_seconds = 600;
|
|
if (!Void::Str::to_int(opts.exec_timeout_arg, exec_timeout_seconds) ||
|
|
exec_timeout_seconds <= 0 || exec_timeout_seconds > 86400) {
|
|
std::cerr << "vbs worker: invalid --exec-timeout value '" << opts.exec_timeout_arg << "'\n";
|
|
return 2;
|
|
}
|
|
const std::string registry = *opts.registry_arg;
|
|
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
|
|
|
const std::filesystem::path project_root{opts.project_arg};
|
|
const std::filesystem::path build_root =
|
|
opts.build_arg ? std::filesystem::path{*opts.build_arg} : (project_root / "build");
|
|
auto state = State::StateStore::open(build_root / ".vbs");
|
|
if (!state) {
|
|
std::cerr << "vbs worker: " << state.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
const std::string platform =
|
|
Toolchain::host_os_name() + "-" + Toolchain::host_architecture_name();
|
|
auto registration = Package::register_worker(registry, platform, auth);
|
|
if (!registration) {
|
|
std::cerr << "vbs worker: " << registration.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
Void::Log::info("Worker", "Registered as {}", registration->worker_id);
|
|
|
|
State::RemoteCacheConfig remote;
|
|
remote.url = registry;
|
|
remote.bearer_token = auth.bearer_token;
|
|
state->configure_remote_cache(remote);
|
|
|
|
// Executes an action spec fetched from the CAS (command + inputs + output paths) and
|
|
// returns the resulting record JSON, or nullopt when there is no executable spec.
|
|
const auto execute_remote_action =
|
|
[&](const Package::LeasedAction &leased) -> std::optional<std::string> {
|
|
auto remote_json = state->fetch_remote_action(leased.action_key);
|
|
if (!remote_json) {
|
|
Void::Log::warn("Worker", "Fetching action spec {}: {}", leased.action_key,
|
|
remote_json.error().message());
|
|
return std::nullopt;
|
|
}
|
|
if (!remote_json->has_value()) {
|
|
return std::nullopt;
|
|
}
|
|
auto parsed = Void::Json::Strict::parse(**remote_json);
|
|
const auto *spec =
|
|
parsed ? std::get_if<Void::Json::Strict::Value::Object>(&parsed->value) : nullptr;
|
|
if (spec == nullptr) {
|
|
return std::nullopt;
|
|
}
|
|
const Void::Json::Strict::Value::Array *command = nullptr;
|
|
if (const auto command_it = spec->find("command"); command_it != spec->end()) {
|
|
command = std::get_if<Void::Json::Strict::Value::Array>(&command_it->second.value);
|
|
}
|
|
if (command == nullptr || command->empty()) {
|
|
return std::nullopt; // Not an executable action spec.
|
|
}
|
|
std::vector<std::string> argv;
|
|
for (const auto &entry : *command) {
|
|
const auto *arg = std::get_if<std::string>(&entry.value);
|
|
if (arg == nullptr) {
|
|
return std::nullopt;
|
|
}
|
|
argv.push_back(*arg);
|
|
}
|
|
std::filesystem::path working_directory = project_root;
|
|
if (const auto wd_it = spec->find("working_directory"); wd_it != spec->end()) {
|
|
if (const auto *wd = std::get_if<std::string>(&wd_it->second.value)) {
|
|
working_directory = std::filesystem::path{*wd};
|
|
}
|
|
}
|
|
std::error_code wd_ec;
|
|
std::filesystem::create_directories(working_directory, wd_ec);
|
|
|
|
if (const auto inputs_it = spec->find("inputs"); inputs_it != spec->end()) {
|
|
const auto *inputs =
|
|
std::get_if<Void::Json::Strict::Value::Object>(&inputs_it->second.value);
|
|
if (inputs != nullptr) {
|
|
for (const auto &[path, ref] : *inputs) {
|
|
const auto *ref_object =
|
|
std::get_if<Void::Json::Strict::Value::Object>(&ref.value);
|
|
if (ref_object == nullptr) {
|
|
continue;
|
|
}
|
|
const std::string *sha = nullptr;
|
|
if (const auto sha_it = ref_object->find("sha256");
|
|
sha_it != ref_object->end()) {
|
|
sha = std::get_if<std::string>(&sha_it->second.value);
|
|
}
|
|
if (sha == nullptr) {
|
|
continue;
|
|
}
|
|
auto present = state->ensure_remote_blob(*sha);
|
|
if (!present) {
|
|
std::cerr << "vbs worker: fetching input blob " << *sha << ": "
|
|
<< present.error().message() << '\n';
|
|
return std::nullopt;
|
|
}
|
|
if (!*present) {
|
|
std::cerr << "vbs worker: input blob " << *sha
|
|
<< " is not available in the CAS\n";
|
|
return std::nullopt;
|
|
}
|
|
State::BlobRef blob_ref;
|
|
blob_ref.sha256 = *sha;
|
|
if (const auto size_it = ref_object->find("size");
|
|
size_it != ref_object->end()) {
|
|
if (const auto *size = std::get_if<std::int64_t>(&size_it->second.value)) {
|
|
blob_ref.size = static_cast<std::uint64_t>(*size);
|
|
}
|
|
}
|
|
if (const auto mode_it = ref_object->find("mode");
|
|
mode_it != ref_object->end()) {
|
|
if (const auto *mode = std::get_if<std::int64_t>(&mode_it->second.value)) {
|
|
blob_ref.mode = static_cast<std::uint32_t>(*mode);
|
|
}
|
|
}
|
|
const auto destination = working_directory / path;
|
|
std::filesystem::create_directories(destination.parent_path(), wd_ec);
|
|
if (auto materialized = state->materialize_blob(blob_ref, destination);
|
|
!materialized) {
|
|
std::cerr << "vbs worker: materializing '" << path
|
|
<< "': " << materialized.error().message() << '\n';
|
|
return std::nullopt;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Void::Log::info("Worker", "Executing action {} ({} argv, timeout {}s)...",
|
|
leased.action_key, argv.size(), exec_timeout_seconds);
|
|
Platform::ProcessRequest exec;
|
|
exec.executable = argv.front();
|
|
exec.arguments.assign(argv.begin() + 1, argv.end());
|
|
exec.working_directory = working_directory;
|
|
exec.timeout = std::chrono::seconds{exec_timeout_seconds};
|
|
auto executed = Platform::run_supervised(exec);
|
|
if (!executed || !executed->succeeded()) {
|
|
std::cerr << "vbs worker: action " << leased.action_key << " failed";
|
|
if (executed) {
|
|
std::cerr << " (exit " << executed->exit_code << ")\n";
|
|
if (!executed->stderr_data.empty()) {
|
|
std::cerr << executed->stderr_data << '\n';
|
|
}
|
|
} else {
|
|
std::cerr << ": " << executed.error().message() << '\n';
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
|
|
std::string outputs;
|
|
bool first = true;
|
|
if (const auto paths_it = spec->find("output_paths"); paths_it != spec->end()) {
|
|
const auto *paths =
|
|
std::get_if<Void::Json::Strict::Value::Array>(&paths_it->second.value);
|
|
if (paths != nullptr) {
|
|
for (const auto &entry : *paths) {
|
|
const auto *path = std::get_if<std::string>(&entry.value);
|
|
if (path == nullptr) {
|
|
continue;
|
|
}
|
|
auto blob = state->store_blob_from_file(working_directory / *path);
|
|
if (!blob) {
|
|
std::cerr << "vbs worker: storing output '" << *path
|
|
<< "': " << blob.error().message() << '\n';
|
|
return std::nullopt;
|
|
}
|
|
if (!first) {
|
|
outputs += ',';
|
|
}
|
|
first = false;
|
|
outputs += Util::json_quote(*path) +
|
|
std::format(":{{\"sha256\":{},\"size\":{},\"mode\":{}}}",
|
|
Util::json_quote(blob->sha256), blob->size, blob->mode);
|
|
}
|
|
}
|
|
}
|
|
return std::format(
|
|
"{{\"schema_version\":1,\"action_key\":{},\"exit_code\":{},\"outputs\":{{{}}}}}\n",
|
|
Util::json_quote(leased.action_key), executed->exit_code, outputs);
|
|
};
|
|
|
|
// Publishes the record's output blobs and the record itself, then reports the result.
|
|
const auto process_leased = [&](const Package::LeasedAction &leased) -> int {
|
|
const std::string &action_key = leased.action_key;
|
|
std::string record_text;
|
|
if (opts.record_arg) {
|
|
auto file_text = Void::FileSystem::read_file(*opts.record_arg);
|
|
if (!file_text) {
|
|
std::cerr << "vbs worker: " << file_text.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
record_text = *file_text;
|
|
} else {
|
|
// Continuous mode: use the local record when the action was built here, otherwise
|
|
// execute the action spec fetched from the CAS.
|
|
auto exported = state->export_action_record_json(action_key);
|
|
if (!exported) {
|
|
auto executed = execute_remote_action(leased);
|
|
if (!executed) {
|
|
Void::Log::warn("Worker", "Skipping {}: {}", action_key,
|
|
exported.error().message());
|
|
return 0;
|
|
}
|
|
record_text = std::move(*executed);
|
|
} else {
|
|
record_text = *exported;
|
|
}
|
|
}
|
|
|
|
auto record_json = Void::Json::Strict::parse(record_text);
|
|
const auto *record_object =
|
|
record_json ? std::get_if<Void::Json::Strict::Value::Object>(&record_json->value)
|
|
: nullptr;
|
|
if (record_object == nullptr) {
|
|
std::cerr << "vbs worker: action record must be a JSON object\n";
|
|
return 1;
|
|
}
|
|
|
|
if (const auto outputs_it = record_object->find("outputs");
|
|
outputs_it != record_object->end()) {
|
|
if (const auto *outputs =
|
|
std::get_if<Void::Json::Strict::Value::Object>(&outputs_it->second.value)) {
|
|
for (const auto &[path, ref] : *outputs) {
|
|
const auto *ref_object =
|
|
std::get_if<Void::Json::Strict::Value::Object>(&ref.value);
|
|
if (ref_object == nullptr) {
|
|
continue;
|
|
}
|
|
const auto sha_it = ref_object->find("sha256");
|
|
if (sha_it == ref_object->end()) {
|
|
continue;
|
|
}
|
|
const auto *sha = std::get_if<std::string>(&sha_it->second.value);
|
|
if (sha == nullptr) {
|
|
continue;
|
|
}
|
|
if (auto published = state->publish_remote_blob(*sha); !published) {
|
|
std::cerr << "vbs worker: publishing blob " << *sha << ": "
|
|
<< published.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (auto published = state->publish_remote_action(action_key, record_text); !published) {
|
|
std::cerr << "vbs worker: publishing action record: " << published.error().message()
|
|
<< '\n';
|
|
return 1;
|
|
}
|
|
if (auto submitted = Package::submit_action_result(registry, action_key, leased.lease_token,
|
|
record_text, auth);
|
|
!submitted) {
|
|
std::cerr << "vbs worker: " << submitted.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "worker " << registration->worker_id << " completed action " << action_key
|
|
<< '\n';
|
|
return 0;
|
|
};
|
|
|
|
if (opts.queue_mode && !opts.action_key_arg) {
|
|
// Continuous loop: lease, process, repeat; exits when the queue is empty (after the
|
|
// optional idle timeout) or on --once. --parallel runs several lease/execute loops so
|
|
// multiple workers drain the queue concurrently (the registry leases each action to
|
|
// exactly one worker).
|
|
int idle_timeout_seconds = 0;
|
|
if (!Void::Str::to_int(opts.idle_timeout_arg, idle_timeout_seconds) ||
|
|
idle_timeout_seconds < 0 || idle_timeout_seconds > 3600) {
|
|
std::cerr << "vbs worker: invalid --idle-timeout value '" << opts.idle_timeout_arg
|
|
<< "'\n";
|
|
return 2;
|
|
}
|
|
int parallel_workers = 1;
|
|
if (!Void::Str::to_int(opts.parallel_arg, parallel_workers) || parallel_workers < 1 ||
|
|
parallel_workers > 32) {
|
|
std::cerr << "vbs worker: invalid --parallel value '" << opts.parallel_arg
|
|
<< "' (expected 1..32)\n";
|
|
return 2;
|
|
}
|
|
std::atomic<bool> empty_reported{false};
|
|
std::atomic<bool> worker_failed{false};
|
|
const auto drain_queue = [&] {
|
|
const auto idle_deadline =
|
|
std::chrono::steady_clock::now() + std::chrono::seconds{idle_timeout_seconds};
|
|
int lease_failures = 0;
|
|
for (;;) {
|
|
if (worker_failed.load(std::memory_order_relaxed)) {
|
|
return;
|
|
}
|
|
auto leased = Package::lease_queued_action(registry, registration->worker_id,
|
|
lease_seconds, auth);
|
|
if (!leased) {
|
|
if (leased.error().kind() == Void::Result::ErrorKind::not_found) {
|
|
if (idle_timeout_seconds == 0 ||
|
|
std::chrono::steady_clock::now() >= idle_deadline) {
|
|
if (!empty_reported.exchange(true)) {
|
|
std::cout << "queue empty\n";
|
|
}
|
|
return;
|
|
}
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{250});
|
|
continue;
|
|
}
|
|
if (++lease_failures > 3) {
|
|
std::cerr << "vbs worker: giving up after repeated lease failures: "
|
|
<< leased.error().message() << '\n';
|
|
worker_failed.store(true);
|
|
return;
|
|
}
|
|
Void::Log::warn("Worker", "lease attempt {} failed: {}", lease_failures,
|
|
leased.error().message());
|
|
std::this_thread::sleep_for(std::chrono::milliseconds{100});
|
|
continue;
|
|
}
|
|
lease_failures = 0;
|
|
if (const int code = process_leased(*leased); code != 0) {
|
|
worker_failed.store(true);
|
|
return;
|
|
}
|
|
if (opts.once) {
|
|
return;
|
|
}
|
|
}
|
|
};
|
|
if (parallel_workers == 1) {
|
|
drain_queue();
|
|
} else {
|
|
std::vector<std::thread> pool;
|
|
pool.reserve(static_cast<std::size_t>(parallel_workers));
|
|
for (int i = 0; i < parallel_workers; ++i) {
|
|
pool.emplace_back(drain_queue);
|
|
}
|
|
for (auto &thread : pool) {
|
|
thread.join();
|
|
}
|
|
}
|
|
return worker_failed.load() ? 1 : 0;
|
|
}
|
|
|
|
auto direct = Package::lease_action(registry, *opts.action_key_arg, registration->worker_id,
|
|
lease_seconds, auth);
|
|
if (!direct) {
|
|
std::cerr << "vbs worker: " << direct.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
return process_leased(*direct);
|
|
}
|
|
|
|
struct MigrateCmdOptions {
|
|
std::string input_arg{"CMakeLists.txt"};
|
|
std::string output_arg{"build.cpp"};
|
|
std::string project_arg{"."};
|
|
bool force{false};
|
|
bool dry_run{false};
|
|
};
|
|
|
|
int execute_migrate_command(const MigrateCmdOptions &opts) {
|
|
auto imported = Config::import_cmake_lists(opts.input_arg, opts.project_arg);
|
|
if (!imported) {
|
|
std::cerr << "vbs migrate: " << imported.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
const std::string rendered = Config::render_build_cpp(*imported);
|
|
if (opts.dry_run) {
|
|
std::cout << rendered;
|
|
return 0;
|
|
}
|
|
std::error_code ec;
|
|
if (!opts.force && std::filesystem::exists(opts.output_arg, ec)) {
|
|
std::cerr << "vbs migrate: '" << opts.output_arg
|
|
<< "' exists (pass --force to overwrite)\n";
|
|
return 2;
|
|
}
|
|
auto written = Platform::atomic_write_file(opts.output_arg, rendered, false);
|
|
if (!written) {
|
|
std::cerr << "vbs migrate: " << written.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "wrote " << opts.output_arg << " (" << imported->targets.size() << " target(s), "
|
|
<< imported->notes.size() << " note(s))\n";
|
|
return 0;
|
|
}
|
|
|
|
struct PresetsCmdOptions {
|
|
std::string file_arg{"CMakePresets.json"};
|
|
std::string project_arg;
|
|
std::optional<std::string> name_arg;
|
|
};
|
|
|
|
int execute_presets_command(const PresetsCmdOptions &opts) {
|
|
auto presets = Config::load_cmake_presets(opts.file_arg, opts.project_arg);
|
|
if (!presets) {
|
|
std::cerr << "vbs presets: " << presets.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
if (opts.name_arg) {
|
|
const auto match =
|
|
std::ranges::find_if(*presets, [&](const Config::ImportedPreset &preset) {
|
|
return preset.name == *opts.name_arg;
|
|
});
|
|
if (match == presets->end()) {
|
|
std::cerr << "vbs presets: unknown preset '" << *opts.name_arg << "'\n";
|
|
return 1;
|
|
}
|
|
std::cout << Config::suggested_build_command(*match) << '\n';
|
|
return 0;
|
|
}
|
|
for (const auto &preset : *presets) {
|
|
std::cout << "preset=" << preset.name << " profile=" << preset.profile
|
|
<< " compiler=" << preset.compiler
|
|
<< " build_dir=" << (preset.build_dir ? *preset.build_dir : std::string{"-"})
|
|
<< " build_type=" << (preset.build_type.empty() ? "-" : preset.build_type)
|
|
<< '\n';
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
struct VerifyCmdOptions {
|
|
std::optional<std::string> name_arg;
|
|
std::optional<std::string> version_arg;
|
|
std::optional<std::string> file_arg;
|
|
std::optional<std::string> signature_arg;
|
|
std::optional<std::string> public_key_arg;
|
|
std::vector<std::string> trusted_public_keys;
|
|
std::vector<std::string> trusted_key_files;
|
|
};
|
|
|
|
int execute_verify_command(const VerifyCmdOptions &opts) {
|
|
if (!opts.name_arg || !opts.version_arg || !opts.file_arg || !opts.signature_arg ||
|
|
!opts.public_key_arg) {
|
|
std::cerr << "vbs verify: --name, --version, --file, --signature, and --public-key are "
|
|
"required\n";
|
|
return 2;
|
|
}
|
|
auto trusted = combine_trusted_keys(opts.trusted_public_keys, opts.trusted_key_files,
|
|
std::filesystem::current_path());
|
|
if (!trusted) {
|
|
std::cerr << "vbs verify: " << trusted.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
if (!trusted->empty()) {
|
|
std::string supplied = *opts.public_key_arg;
|
|
std::ranges::transform(supplied, supplied.begin(), [](char c) {
|
|
return static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
|
});
|
|
if (std::ranges::find(*trusted, supplied) == trusted->end()) {
|
|
std::cerr << "vbs verify: public key is not trusted\n";
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
auto digest = Util::sha256_file_hex(*opts.file_arg);
|
|
if (!digest) {
|
|
std::cerr << "vbs verify: " << digest.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto verified = Provenance::verify_package(*opts.name_arg, *opts.version_arg, *digest,
|
|
*opts.signature_arg, *opts.public_key_arg);
|
|
if (!verified) {
|
|
std::cerr << "vbs verify: " << verified.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
if (!*verified) {
|
|
std::cerr << "vbs verify: signature does not match " << *opts.name_arg << '@'
|
|
<< *opts.version_arg << " sha256=" << *digest << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "verified " << *opts.name_arg << '@' << *opts.version_arg << " sha256=" << *digest
|
|
<< '\n';
|
|
return 0;
|
|
}
|
|
|
|
struct LockCmdOptions {
|
|
std::string project_arg;
|
|
};
|
|
|
|
int execute_lock_show_command(const LockCmdOptions &opts) {
|
|
const auto lock_path = std::filesystem::path{opts.project_arg} / "vbs.lock";
|
|
auto pinned = Package::load_pinned_lock(lock_path);
|
|
if (!pinned) {
|
|
std::cerr << "vbs lock: " << pinned.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
if (!pinned->has_value()) {
|
|
std::cout << "no vbs.lock in " << opts.project_arg << '\n';
|
|
return 0;
|
|
}
|
|
std::cout << "revision " << (*pinned)->revision_hash << '\n';
|
|
for (const auto &[key, context] : (*pinned)->document.contexts) {
|
|
std::cout << "context " << key << " (profile=" << context.profile_name
|
|
<< " role=" << context.machine_role << ", " << context.entries.size()
|
|
<< " entrie(s))\n";
|
|
for (const auto &entry : context.entries) {
|
|
std::cout << " " << entry.alias;
|
|
if (!entry.package_name.empty()) {
|
|
std::cout << " -> " << entry.package_name << '@' << entry.version;
|
|
}
|
|
std::cout << " [" << entry.source_kind << ']';
|
|
if (!entry.sha256.empty()) {
|
|
std::cout << " sha256=" << entry.sha256.substr(0, 12);
|
|
}
|
|
if (entry.signature && entry.public_key) {
|
|
std::cout << " signed";
|
|
}
|
|
std::cout << '\n';
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
struct ReleasesCmdOptions {
|
|
std::optional<std::string> registry_arg;
|
|
std::optional<std::string> name_arg;
|
|
std::optional<std::string> version_arg;
|
|
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
|
};
|
|
|
|
int execute_releases_yank_command(const ReleasesCmdOptions &opts, bool unyank) {
|
|
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 releases yank: --registry, --name, and --version are required\n";
|
|
return 2;
|
|
}
|
|
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
|
auto state =
|
|
Package::set_release_yanked(registry_url, *opts.name_arg, *opts.version_arg, !unyank, auth);
|
|
if (!state) {
|
|
std::cerr << "vbs releases yank: " << state.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << (*state ? "yanked " : "unyanked ") << *opts.name_arg << '@' << *opts.version_arg
|
|
<< '\n';
|
|
return 0;
|
|
}
|
|
|
|
int execute_releases_list_command(const ReleasesCmdOptions &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) {
|
|
std::cerr << "vbs releases list: --registry and --name are required\n";
|
|
return 2;
|
|
}
|
|
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
|
auto releases = Package::fetch_package_releases(registry_url, *opts.name_arg, auth);
|
|
if (!releases) {
|
|
std::cerr << "vbs releases: " << releases.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
for (const auto &release : *releases) {
|
|
std::cout << release.version.to_string() << ' ' << release.source_sha256 << ' '
|
|
<< (release.yanked ? "yanked" : "active")
|
|
<< " binaries=" << release.binaries.size() << '\n';
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int execute_releases_show_command(const ReleasesCmdOptions &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 releases show: --registry, --name, and --version are required\n";
|
|
return 2;
|
|
}
|
|
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
|
auto release =
|
|
Package::fetch_release_detail(registry_url, *opts.name_arg, *opts.version_arg, auth);
|
|
if (!release) {
|
|
std::cerr << "vbs releases show: " << release.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "name=" << release->name << " version=" << release->version
|
|
<< " sha256=" << release->sha256 << " size=" << release->size_bytes
|
|
<< " yanked=" << (release->yanked ? "true" : "false")
|
|
<< " binaries=" << release->binary_count
|
|
<< " signed=" << (release->signature && release->public_key ? "yes" : "no") << '\n';
|
|
return 0;
|
|
}
|
|
|
|
struct BinariesCmdOptions {
|
|
std::optional<std::string> registry_arg;
|
|
std::optional<std::string> name_arg;
|
|
std::optional<std::string> version_arg;
|
|
std::optional<std::string> variant_arg;
|
|
std::optional<std::string> output_arg;
|
|
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
|
std::vector<std::string> trusted_public_keys;
|
|
std::vector<std::string> trusted_key_files;
|
|
};
|
|
|
|
int execute_binaries_command(std::string_view sub, const BinariesCmdOptions &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 binaries: --registry, --name, and --version are required\n";
|
|
return 2;
|
|
}
|
|
if (sub == "fetch" && (!opts.variant_arg || !opts.output_arg)) {
|
|
std::cerr << "vbs binaries fetch: --variant and --output are required\n";
|
|
return 2;
|
|
}
|
|
|
|
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
|
if (sub == "show") {
|
|
if (!opts.variant_arg) {
|
|
std::cerr << "vbs binaries show: --variant is required\n";
|
|
return 2;
|
|
}
|
|
auto detail = Package::fetch_binary_detail(registry_url, *opts.name_arg, *opts.version_arg,
|
|
*opts.variant_arg, auth);
|
|
if (!detail) {
|
|
std::cerr << "vbs binaries show: " << detail.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "variant=" << detail->variant_id << " sha256=" << detail->sha256
|
|
<< " size=" << detail->size_bytes
|
|
<< " yanked=" << (detail->yanked ? "true" : "false")
|
|
<< " signed=" << ((detail->signature && detail->public_key) ? "yes" : "no")
|
|
<< '\n';
|
|
return 0;
|
|
}
|
|
|
|
// Listing shows yanked variants (marked); fetch below only resolves non-yanked ones.
|
|
auto variants = Package::fetch_binary_variants(registry_url, *opts.name_arg, *opts.version_arg,
|
|
auth, sub == "list");
|
|
if (!variants) {
|
|
std::cerr << "vbs binaries: " << variants.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
if (sub == "list") {
|
|
for (const auto &variant : *variants) {
|
|
std::cout << variant.variant_id << ' ' << variant.sha256 << ' ' << variant.size_bytes
|
|
<< ' ' << ((variant.signature && variant.public_key) ? "signed" : "unsigned");
|
|
if (variant.yanked) {
|
|
std::cout << " yanked";
|
|
}
|
|
std::cout << '\n';
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
const auto match = std::ranges::find_if(*variants, [&](const Package::BinaryReleaseInfo &info) {
|
|
return info.variant_id == *opts.variant_arg;
|
|
});
|
|
if (match == variants->end()) {
|
|
std::cerr << "vbs binaries fetch: variant '" << *opts.variant_arg << "' not found\n";
|
|
return 1;
|
|
}
|
|
|
|
// When trusted keys are configured, require a verified signature before downloading.
|
|
auto trusted_keys = combine_trusted_keys(opts.trusted_public_keys, opts.trusted_key_files,
|
|
std::filesystem::current_path());
|
|
if (!trusted_keys) {
|
|
std::cerr << "vbs binaries fetch: " << trusted_keys.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
if (!trusted_keys->empty()) {
|
|
auto decision = Provenance::verify_trusted_binary_signature(
|
|
Provenance::BinarySignature{match->variant_id, match->sha256,
|
|
match->signature.value_or(std::string{}),
|
|
match->public_key.value_or(std::string{})},
|
|
*trusted_keys);
|
|
if (!decision) {
|
|
std::cerr << "vbs binaries fetch: " << decision.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
if (*decision != Provenance::TrustDecision::Verified) {
|
|
std::cerr << "vbs binaries fetch: variant '" << match->variant_id
|
|
<< "' is not signed by a trusted key ("
|
|
<< Provenance::trust_decision_name(*decision) << ")\n";
|
|
return 1;
|
|
}
|
|
}
|
|
const std::string url = registry_url + "/api/v1/packages/" +
|
|
Void::Encoding::Url::encode(*opts.name_arg) + "/" +
|
|
Void::Encoding::Url::encode(*opts.version_arg) + "/binaries/" +
|
|
Void::Encoding::Url::encode(match->variant_id) + "/download";
|
|
auto downloaded = Package::download_binary_artifact(url, match->sha256,
|
|
std::filesystem::path{*opts.output_arg},
|
|
Package::RegistryAuth{auth.bearer_token});
|
|
if (!downloaded) {
|
|
std::cerr << "vbs binaries fetch: " << downloaded.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << "fetched " << match->variant_id << " sha256=" << match->sha256 << " -> "
|
|
<< downloaded->string() << '\n';
|
|
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"};
|
|
std::optional<std::string> signing_key_arg;
|
|
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, "");
|
|
if (opts.signing_key_arg) {
|
|
popts.signing_seed_path = std::filesystem::path{*opts.signing_key_arg};
|
|
}
|
|
|
|
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;
|
|
std::optional<std::string> archive_arg;
|
|
std::string archive_format_arg{"tar"};
|
|
std::optional<std::string> signing_key_arg;
|
|
bool no_cmake_export{false};
|
|
bool no_native_export{false};
|
|
bool bundle_dependencies{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;
|
|
iopts.bundle_runtime_dependencies = opts.bundle_dependencies;
|
|
if (opts.archive_format_arg != "tar" && opts.archive_format_arg != "sh" &&
|
|
opts.archive_format_arg != "zip" && opts.archive_format_arg != "deb" &&
|
|
opts.archive_format_arg != "rpm" && opts.archive_format_arg != "wix" &&
|
|
opts.archive_format_arg != "dmg" && opts.archive_format_arg != "nuget") {
|
|
std::cerr << "vbs install: unsupported --archive-format '" << opts.archive_format_arg
|
|
<< "' (expected tar, sh, zip, deb, rpm, wix, dmg or nuget)\n";
|
|
return 2;
|
|
}
|
|
if (opts.archive_arg && !opts.archive_arg->empty()) {
|
|
iopts.archive_path = std::filesystem::path{*opts.archive_arg};
|
|
iopts.archive_format = opts.archive_format_arg;
|
|
if (opts.signing_key_arg) {
|
|
iopts.signing_seed_path = std::filesystem::path{*opts.signing_key_arg};
|
|
}
|
|
} else if (opts.signing_key_arg) {
|
|
std::cerr << "vbs install: --signing-key requires --archive\n";
|
|
return 2;
|
|
}
|
|
|
|
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 DaemonCmdOptions {
|
|
std::string project_arg;
|
|
std::optional<std::string> build_arg;
|
|
std::optional<std::string> socket_arg;
|
|
std::string profile_arg{"debug"};
|
|
std::vector<std::string> targets;
|
|
std::string jobs_arg{"0"};
|
|
std::string editor_arg{"all"};
|
|
std::optional<std::string> member_arg;
|
|
std::string graph_format_arg{"dot"};
|
|
std::optional<std::string> target_arg;
|
|
std::optional<std::string> action_kind_arg;
|
|
std::optional<std::string> pack_output_arg;
|
|
std::optional<std::string> prefix_arg;
|
|
std::optional<std::string> component_arg;
|
|
bool no_cmake_export{false};
|
|
bool no_native_export{false};
|
|
std::optional<std::string> input_arg;
|
|
std::optional<std::string> output_dir_arg;
|
|
std::string init_dir_arg{"."};
|
|
std::optional<std::string> init_name_arg;
|
|
bool init_library{false};
|
|
bool init_with_toml{false};
|
|
bool init_force{false};
|
|
std::string package_version_arg{"0.1.0"};
|
|
std::optional<std::string> file_filter_arg;
|
|
std::string limit_arg{"50"};
|
|
std::string timeout_ms_arg{"2000"};
|
|
bool force{false};
|
|
std::string max_bytes_arg{"0"};
|
|
std::string max_requests_arg{"0"};
|
|
};
|
|
|
|
std::filesystem::path resolve_daemon_socket(const DaemonCmdOptions &opts,
|
|
const std::filesystem::path &build_root) {
|
|
return opts.socket_arg ? std::filesystem::path{*opts.socket_arg}
|
|
: build_root / ".vbs" / "vbs-daemon.sock";
|
|
}
|
|
|
|
int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &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 socket_path = resolve_daemon_socket(opts, build_root);
|
|
|
|
if (sub == "run") {
|
|
std::size_t max_requests = 0;
|
|
const auto [ptr, ec] = std::from_chars(
|
|
opts.max_requests_arg.data(),
|
|
opts.max_requests_arg.data() + opts.max_requests_arg.size(), max_requests);
|
|
if (ec != std::errc{} ||
|
|
ptr != opts.max_requests_arg.data() + opts.max_requests_arg.size()) {
|
|
std::cerr << "vbs daemon run: invalid --max-requests value '" << opts.max_requests_arg
|
|
<< "'\n";
|
|
return 2;
|
|
}
|
|
Daemon::DaemonOptions daemon_opts;
|
|
daemon_opts.project_root = project_root;
|
|
daemon_opts.build_root = build_root;
|
|
daemon_opts.socket_path = socket_path;
|
|
daemon_opts.max_requests = max_requests;
|
|
auto server = Daemon::DaemonServer::create(std::move(daemon_opts));
|
|
if (!server) {
|
|
std::cerr << "vbs daemon: " << server.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
Void::Log::info("Daemon", "Serving '{}' (Ctrl+C to stop)...", socket_path.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 result = server->run(stop_src.get_token());
|
|
if (!result) {
|
|
std::cerr << "vbs daemon: " << result.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
std::string request_json;
|
|
if (sub == "status") {
|
|
request_json = R"({"op":"status"})";
|
|
} else if (sub == "stop") {
|
|
request_json = R"({"op":"shutdown"})";
|
|
} else if (sub == "recover") {
|
|
request_json = R"({"op":"recover"})";
|
|
} else if (sub == "gc") {
|
|
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 daemon gc: invalid --max-bytes value '" << opts.max_bytes_arg
|
|
<< "'\n";
|
|
return 2;
|
|
}
|
|
request_json = std::format(R"({{"op":"gc","max_bytes":{}}})", max_bytes);
|
|
} else if (sub == "describe") {
|
|
if (opts.profile_arg.empty()) {
|
|
std::cerr << "vbs daemon describe: --profile must not be empty\n";
|
|
return 2;
|
|
}
|
|
request_json = std::format(
|
|
R"({{"op":"describe","profile":{}{}}})", Util::json_quote(opts.profile_arg),
|
|
opts.member_arg ? std::format(",\"member\":{}", Util::json_quote(*opts.member_arg))
|
|
: std::string{});
|
|
} else if (sub == "graph") {
|
|
request_json = std::format(R"({{"op":"graph","profile":{},"format":{}}})",
|
|
Util::json_quote(opts.profile_arg),
|
|
Util::json_quote(opts.graph_format_arg));
|
|
} else if (sub == "actions") {
|
|
request_json =
|
|
std::format(R"({{"op":"actions","profile":{},"limit":{}{}}})",
|
|
Util::json_quote(opts.profile_arg), opts.limit_arg,
|
|
opts.action_kind_arg
|
|
? std::format(",\"kind\":{}", Util::json_quote(*opts.action_kind_arg))
|
|
: std::string{});
|
|
} else if (sub == "target_flags") {
|
|
if (!opts.target_arg || opts.target_arg->empty()) {
|
|
std::cerr << "vbs daemon target flags: --name must not be empty\n";
|
|
return 2;
|
|
}
|
|
request_json =
|
|
std::format(R"({{"op":"target_flags","profile":{},"target":{}{}}})",
|
|
Util::json_quote(opts.profile_arg), Util::json_quote(*opts.target_arg),
|
|
opts.file_filter_arg
|
|
? std::format(",\"file\":{}", Util::json_quote(*opts.file_filter_arg))
|
|
: std::string{});
|
|
} else if (sub == "target_info") {
|
|
if (!opts.target_arg || opts.target_arg->empty()) {
|
|
std::cerr << "vbs daemon target: --name must not be empty\n";
|
|
return 2;
|
|
}
|
|
request_json =
|
|
std::format(R"({{"op":"target_info","profile":{},"target":{}}})",
|
|
Util::json_quote(opts.profile_arg), Util::json_quote(*opts.target_arg));
|
|
} else if (sub == "info") {
|
|
request_json = R"({"op":"info"})";
|
|
} else if (sub == "clean") {
|
|
request_json = opts.force ? R"({"op":"clean","all":true})" : R"({"op":"clean"})";
|
|
} else if (sub == "pack") {
|
|
request_json = opts.pack_output_arg ? std::format(R"({{"op":"pack","output":{}}})",
|
|
Util::json_quote(*opts.pack_output_arg))
|
|
: R"({"op":"pack"})";
|
|
} else if (sub == "init") {
|
|
request_json = std::format(
|
|
R"({{"op":"init","dir":{},"library":{},"with_toml":{},"force":{}{}}})",
|
|
Util::json_quote(opts.init_dir_arg), opts.init_library ? "true" : "false",
|
|
opts.init_with_toml ? "true" : "false", opts.init_force ? "true" : "false",
|
|
opts.init_name_arg ? std::format(",\"name\":{}", Util::json_quote(*opts.init_name_arg))
|
|
: std::string{});
|
|
} else if (sub == "gen_tests") {
|
|
if (!opts.input_arg || !opts.output_dir_arg) {
|
|
std::cerr << "vbs daemon gen-tests: --input and --output-dir are required\n";
|
|
return 2;
|
|
}
|
|
request_json =
|
|
std::format(R"({{"op":"gen_tests","input":{},"output_dir":{}}})",
|
|
Util::json_quote(*opts.input_arg), Util::json_quote(*opts.output_dir_arg));
|
|
} else if (sub == "uninstall") {
|
|
if (!opts.prefix_arg || opts.prefix_arg->empty()) {
|
|
std::cerr << "vbs daemon uninstall: --prefix is required\n";
|
|
return 2;
|
|
}
|
|
request_json =
|
|
std::format(R"({{"op":"uninstall","prefix":{}}})", Util::json_quote(*opts.prefix_arg));
|
|
} else if (sub == "install") {
|
|
if (!opts.prefix_arg || opts.prefix_arg->empty()) {
|
|
std::cerr << "vbs daemon install: --prefix is required\n";
|
|
return 2;
|
|
}
|
|
request_json = std::format(
|
|
R"({{"op":"install","prefix":{},"package_version":{}{},"export_cmake":{},"export_native":{}}})",
|
|
Util::json_quote(*opts.prefix_arg), Util::json_quote(opts.package_version_arg),
|
|
opts.component_arg
|
|
? std::format(",\"component\":{}", Util::json_quote(*opts.component_arg))
|
|
: std::string{},
|
|
opts.no_cmake_export ? "false" : "true", opts.no_native_export ? "false" : "true");
|
|
} else if (sub == "editor_status") {
|
|
request_json = R"({"op":"editor_status"})";
|
|
} else if (sub == "workspace_members") {
|
|
request_json = R"({"op":"workspace_members"})";
|
|
} else if (sub == "ide_configs") {
|
|
request_json = R"({"op":"ide_configs"})";
|
|
} else if (sub == "deps") {
|
|
request_json = std::format(
|
|
R"({{"op":"deps","profile":{}{}}})", Util::json_quote(opts.profile_arg),
|
|
opts.member_arg ? std::format(",\"member\":{}", Util::json_quote(*opts.member_arg))
|
|
: std::string{});
|
|
} else if (sub == "compdb_generations") {
|
|
if (opts.profile_arg.empty()) {
|
|
std::cerr << "vbs daemon compdb generations: --profile must not be empty\n";
|
|
return 2;
|
|
}
|
|
request_json = std::format(R"({{"op":"compdb_generations","profile":{}}})",
|
|
Util::json_quote(opts.profile_arg));
|
|
} else if (sub == "compdb_entries") {
|
|
request_json =
|
|
std::format(R"({{"op":"compdb_entries","limit":{}{}}})", opts.limit_arg,
|
|
opts.file_filter_arg
|
|
? std::format(",\"file\":{}", Util::json_quote(*opts.file_filter_arg))
|
|
: std::string{});
|
|
} else if (sub == "watch_poll") {
|
|
request_json = opts.prefix_arg ? std::format(R"({{"op":"watch_poll","prefix":{}}})",
|
|
Util::json_quote(*opts.prefix_arg))
|
|
: std::string{R"({"op":"watch_poll"})"};
|
|
} else if (sub == "watch_wait") {
|
|
std::int64_t timeout_ms = 0;
|
|
const auto [ptr, ec] =
|
|
std::from_chars(opts.timeout_ms_arg.data(),
|
|
opts.timeout_ms_arg.data() + opts.timeout_ms_arg.size(), timeout_ms);
|
|
if (ec != std::errc{} || ptr != opts.timeout_ms_arg.data() + opts.timeout_ms_arg.size() ||
|
|
timeout_ms < 0 || timeout_ms > 5000) {
|
|
std::cerr << "vbs daemon ide wait: invalid --timeout-ms value '" << opts.timeout_ms_arg
|
|
<< "' (0..5000)\n";
|
|
return 2;
|
|
}
|
|
request_json = std::format(
|
|
R"({{"op":"watch_wait","timeout_ms":{}{}}})", timeout_ms,
|
|
opts.prefix_arg ? std::format(",\"prefix\":{}", Util::json_quote(*opts.prefix_arg))
|
|
: std::string{});
|
|
} else if (sub == "ide_generate") {
|
|
if (opts.profile_arg.empty()) {
|
|
std::cerr << "vbs daemon ide generate: --profile must not be empty\n";
|
|
return 2;
|
|
}
|
|
request_json = std::format(
|
|
R"({{"op":"ide_generate","profile":{},"editor":{},"force":{}{}}})",
|
|
Util::json_quote(opts.profile_arg), Util::json_quote(opts.editor_arg),
|
|
opts.force ? "true" : "false",
|
|
opts.member_arg ? std::format(",\"member\":{}", Util::json_quote(*opts.member_arg))
|
|
: std::string{});
|
|
} else if (sub == "compdb_use") {
|
|
if (opts.profile_arg.empty()) {
|
|
std::cerr << "vbs daemon compdb use: --profile must not be empty\n";
|
|
return 2;
|
|
}
|
|
request_json = std::format(R"({{"op":"compdb_use","profile":{}}})",
|
|
Util::json_quote(opts.profile_arg));
|
|
} else if (sub == "compdb_export") {
|
|
if (opts.profile_arg.empty()) {
|
|
std::cerr << "vbs daemon compdb export: --profile must not be empty\n";
|
|
return 2;
|
|
}
|
|
request_json = std::format(
|
|
R"({{"op":"compdb_export","profile":{}{}}})", Util::json_quote(opts.profile_arg),
|
|
opts.member_arg ? std::format(",\"member\":{}", Util::json_quote(*opts.member_arg))
|
|
: std::string{});
|
|
} else if (sub == "ide_query") {
|
|
if (opts.profile_arg.empty()) {
|
|
std::cerr << "vbs daemon ide query: --profile must not be empty\n";
|
|
return 2;
|
|
}
|
|
request_json = std::format(
|
|
R"({{"op":"ide_query","profile":{}{}}})", Util::json_quote(opts.profile_arg),
|
|
opts.member_arg ? std::format(",\"member\":{}", Util::json_quote(*opts.member_arg))
|
|
: std::string{});
|
|
} else if (sub == "build" || sub == "test") {
|
|
std::size_t jobs = 0;
|
|
const auto [ptr, ec] = std::from_chars(opts.jobs_arg.data(),
|
|
opts.jobs_arg.data() + opts.jobs_arg.size(), jobs);
|
|
if (ec != std::errc{} || ptr != opts.jobs_arg.data() + opts.jobs_arg.size() || jobs > 256) {
|
|
std::cerr << "vbs daemon " << sub << ": invalid --jobs value '" << opts.jobs_arg
|
|
<< "'\n";
|
|
return 2;
|
|
}
|
|
if (opts.profile_arg.empty()) {
|
|
std::cerr << "vbs daemon " << sub << ": --profile must not be empty\n";
|
|
return 2;
|
|
}
|
|
const std::string targets_json = Util::json_array(
|
|
opts.targets, [](const std::string &target) { return Util::json_quote(target); });
|
|
request_json = std::format(R"({{"op":"{}","profile":{},"targets":{},"jobs":{}}})", sub,
|
|
Util::json_quote(opts.profile_arg), targets_json, jobs);
|
|
} else {
|
|
std::cerr << "vbs daemon: unknown command '" << sub << "'\n";
|
|
return 2;
|
|
}
|
|
|
|
// Describe evaluates the whole project graph (descriptor compile, toolchain probe, lowering),
|
|
// which can exceed the 2 s default; the daemon bounds evaluation at 10 s.
|
|
const auto request_timeout =
|
|
(sub == "build" || sub == "test") ? std::chrono::milliseconds{std::chrono::hours{1}}
|
|
: (sub == "watch_poll" || sub == "editor_status") ? std::chrono::milliseconds{5000}
|
|
: sub == "compdb_use" ? std::chrono::milliseconds{10000}
|
|
: sub == "watch_wait" ? std::chrono::milliseconds{10000}
|
|
: sub == "describe" ? std::chrono::milliseconds{15000}
|
|
: (sub == "ide_query" || sub == "ide_generate" || sub == "compdb_export")
|
|
? std::chrono::milliseconds{30000}
|
|
: std::chrono::milliseconds{2000};
|
|
auto response = Daemon::request(socket_path, request_json, request_timeout);
|
|
if (!response) {
|
|
std::cerr << "vbs daemon: " << response.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
std::cout << *response << '\n';
|
|
const auto parsed = Void::Json::Strict::parse(*response);
|
|
if (!parsed) {
|
|
return 1;
|
|
}
|
|
const auto *object = std::get_if<Void::Json::Strict::Value::Object>(&parsed->value);
|
|
if (object == nullptr) {
|
|
return 1;
|
|
}
|
|
const auto ok = object->find("ok");
|
|
if (ok == object->end()) {
|
|
return 1;
|
|
}
|
|
const auto *flag = std::get_if<bool>(&ok->second.value);
|
|
return (flag != nullptr && *flag) ? 0 : 1;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
struct InitCmdOptions {
|
|
std::string dir_arg;
|
|
std::optional<std::string> name_arg;
|
|
bool library{false};
|
|
bool with_toml{false};
|
|
bool force{false};
|
|
};
|
|
|
|
int execute_init_command(const InitCmdOptions &opts) {
|
|
Config::ScaffoldOptions options;
|
|
options.target_dir = std::filesystem::path{opts.dir_arg};
|
|
options.name = opts.name_arg;
|
|
options.library = opts.library;
|
|
options.with_toml = opts.with_toml;
|
|
options.force = opts.force;
|
|
auto report = Config::scaffold_project(options);
|
|
if (!report) {
|
|
std::cerr << report.error().message() << '\n';
|
|
return report.error().kind() == Void::Result::ErrorKind::conflict ? 2 : 1;
|
|
}
|
|
Void::Log::info("Init", "Initialized VBS {} project '{}' in '{}'",
|
|
opts.library ? "library" : "application", report->project_name,
|
|
report->target_dir.string());
|
|
std::cout << "initialized " << report->project_name << " in " << report->target_dir.string()
|
|
<< '\n';
|
|
return 0;
|
|
}
|
|
|
|
struct CleanCmdOptions {
|
|
std::string build_arg;
|
|
bool clean_all{false};
|
|
};
|
|
|
|
int execute_clean_command(const CleanCmdOptions &opts) {
|
|
const std::filesystem::path build_root{opts.build_arg};
|
|
auto cleaned = Config::clean_build_tree(build_root, opts.clean_all);
|
|
if (!cleaned) {
|
|
std::cerr << "vbs clean: " << cleaned.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
if (!cleaned->build_root_exists) {
|
|
std::cout << "clean: nothing to remove in " << build_root.string() << '\n';
|
|
return 0;
|
|
}
|
|
if (cleaned->removed_entire_root) {
|
|
std::cout << "cleaned " << build_root.string() << " (all)\n";
|
|
return 0;
|
|
}
|
|
std::cout << "cleaned " << cleaned->removed_paths << " path(s) in " << build_root.string()
|
|
<< " (preserved .vbs cache/state)\n";
|
|
return 0;
|
|
}
|
|
|
|
int execute_doctor_command() {
|
|
std::cout << "VoidBuildSystem " << Bootstrap::version << " (" << Bootstrap::os << "/"
|
|
<< Bootstrap::architecture << ")\n";
|
|
std::cout << " " << (Platform::host_supported() ? "[ok] " : "[opt] ")
|
|
<< " host platform: " << Platform::host_os_name(Platform::host_os())
|
|
<< (Platform::host_supported() ? " (native process/file backends)"
|
|
: " (POSIX backends; macOS/Windows ports are planned)")
|
|
<< '\n';
|
|
#if defined(VBS_HAS_VOID_SQLITE)
|
|
std::cout << " [ok] Void::Sqlite: enabled (transactional state store)\n";
|
|
#else
|
|
std::cout << " [opt] Void::Sqlite: disabled (journaled JSON state store)\n";
|
|
#endif
|
|
#if defined(VBS_HAS_VOID_NET)
|
|
std::cout << " [ok] Void::Net: enabled (TLS-capable HTTP transport)\n";
|
|
#else
|
|
std::cout << " [opt] Void::Net: disabled (POSIX/curl transport)\n";
|
|
#endif
|
|
auto check_tool = [](std::string_view label, const char *bin, bool required) {
|
|
auto found = Platform::resolve_executable(bin);
|
|
std::cout << " " << (found ? "[ok] " : (required ? "[FAIL]" : "[opt] ")) << " " << label
|
|
<< ": " << (found ? found->string() : std::string{"not found"}) << '\n';
|
|
return found.has_value();
|
|
};
|
|
const bool has_gcc = check_tool("g++", "g++", true);
|
|
(void)check_tool("clang++", "clang++", false);
|
|
(void)check_tool("clang-scan-deps", "clang-scan-deps", false);
|
|
(void)check_tool("ar", "ar", true);
|
|
(void)check_tool("git", "git", false);
|
|
(void)check_tool("cmake", "cmake", false);
|
|
(void)check_tool("ninja", "ninja", false);
|
|
(void)check_tool("meson", "meson", false);
|
|
(void)check_tool("conan", "conan", false);
|
|
(void)check_tool("clang-format", "clang-format", false);
|
|
|
|
std::cout << " [ok] Void::Crypto built-in SHA-256: enabled\n";
|
|
std::cout << " [ok] Void::Archive built-in USTAR/PAX: enabled\n";
|
|
|
|
if (has_gcc) {
|
|
Void::FileSystem::TempDir tmp{"vbs_doc_"};
|
|
auto ctx =
|
|
default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(),
|
|
Toolchain::host_architecture_name());
|
|
if (auto tc = Toolchain::discover_and_probe(ctx, tmp.path()); tc) {
|
|
std::cout << " [ok] GCC probe: " << tc->version_banner
|
|
<< " (c++26=" << (tc->supports_cxx26 ? "yes" : "no")
|
|
<< ", reflection=" << (tc->supports_reflection ? "yes" : "no")
|
|
<< ", p1689=" << (tc->supports_p1689_scan ? "yes" : "no") << ")\n";
|
|
}
|
|
}
|
|
return has_gcc ? 0 : 1;
|
|
}
|
|
|
|
struct GraphCmdOptions {
|
|
std::string project_arg;
|
|
std::optional<std::string> build_arg;
|
|
std::string profile_name{"debug"};
|
|
std::optional<std::string> compiler_arg;
|
|
std::string format{"dot"};
|
|
};
|
|
|
|
int execute_graph_command(const GraphCmdOptions &opts) {
|
|
if (opts.format != "dot" && opts.format != "json") {
|
|
std::cerr << "vbs graph: unsupported --format '" << opts.format
|
|
<< "' (expected 'dot' or 'json')\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 graph: " << 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 graph: " << compiled.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto profs = Config::discover_profiles(*compiled, fopts);
|
|
if (!profs) {
|
|
std::cerr << "vbs graph: " << 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 graph: " << ex.what() << '\n';
|
|
return 2;
|
|
}
|
|
auto desc = Config::evaluate_project(*compiled, ctx, fopts);
|
|
if (!desc) {
|
|
std::cerr << "vbs graph: " << desc.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
if (opts.format == "json") {
|
|
std::cout << "{\"profile\":" << Util::json_quote(desc->profile.name) << ",\"targets\":";
|
|
std::cout << Util::json_array(desc->targets, [](const TargetRecord &t) {
|
|
return "{\"name\":" + Util::json_quote(t.name) +
|
|
",\"kind\":" + Util::json_quote(target_kind_name(t.kind)) + ",\"links\":" +
|
|
Util::json_array(t.links,
|
|
[](const LinkRecord &l) {
|
|
return Util::json_quote(
|
|
l.kind == LinkKind::Imported
|
|
? (l.dependency + "::" + l.target)
|
|
: l.target);
|
|
}) +
|
|
'}';
|
|
});
|
|
std::cout << "}\n";
|
|
return 0;
|
|
}
|
|
|
|
std::cout << "digraph vbs_targets {\n";
|
|
std::cout << " rankdir=LR;\n";
|
|
for (const auto &t : desc->targets) {
|
|
std::cout << " " << Util::json_quote(t.name) << " [label="
|
|
<< Util::json_quote(t.name + "\n(" + std::string{target_kind_name(t.kind)} + ")")
|
|
<< "];\n";
|
|
}
|
|
for (const auto &t : desc->targets) {
|
|
for (const auto &pre : t.prerequisites) {
|
|
std::cout << " " << Util::json_quote(t.name) << " -> " << Util::json_quote(pre)
|
|
<< " [style=dashed];\n";
|
|
}
|
|
for (const auto &l : t.links) {
|
|
const std::string dst =
|
|
l.kind == LinkKind::Imported ? (l.dependency + "::" + l.target) : l.target;
|
|
std::cout << " " << Util::json_quote(t.name) << " -> " << Util::json_quote(dst)
|
|
<< ";\n";
|
|
}
|
|
}
|
|
std::cout << "}\n";
|
|
return 0;
|
|
}
|
|
|
|
struct IdeCmdOptions {
|
|
std::string project_arg;
|
|
std::optional<std::string> build_arg;
|
|
std::string profile_name{"debug"};
|
|
std::optional<std::string> compiler_arg;
|
|
std::string editor_name{"all"};
|
|
std::optional<std::string> plugin_output_arg;
|
|
std::optional<std::string> plugin_vsix_arg;
|
|
bool force{false};
|
|
};
|
|
|
|
int execute_ide_command(std::string_view sub, const IdeCmdOptions &opts) {
|
|
Editor::IdeKind ide_kind = Editor::IdeKind::All;
|
|
if (sub == "generate" || sub == "plugin") {
|
|
auto parsed_kind = Editor::parse_ide_kind(opts.editor_name);
|
|
if (!parsed_kind) {
|
|
std::cerr << "vbs ide: " << parsed_kind.error().message() << '\n';
|
|
return 2;
|
|
}
|
|
ide_kind = *parsed_kind;
|
|
}
|
|
|
|
if (sub == "plugin") {
|
|
if (!opts.plugin_output_arg || opts.plugin_output_arg->empty()) {
|
|
std::cerr << "vbs ide plugin: --output is required\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");
|
|
Editor::IdePluginOptions plugin_opts;
|
|
plugin_opts.project_root = project_root;
|
|
plugin_opts.build_root = build_root;
|
|
plugin_opts.editor = ide_kind;
|
|
plugin_opts.output_dir = *opts.plugin_output_arg;
|
|
plugin_opts.force = opts.force;
|
|
if (opts.plugin_vsix_arg) {
|
|
if (ide_kind != Editor::IdeKind::VsCode) {
|
|
std::cerr << "vbs ide plugin: --vsix is only supported for vscode\n";
|
|
return 2;
|
|
}
|
|
plugin_opts.vsix_path = *opts.plugin_vsix_arg;
|
|
}
|
|
if (auto exe = Platform::current_executable_path(); exe) {
|
|
plugin_opts.vbs_executable = *exe;
|
|
}
|
|
auto report = Editor::generate_ide_plugin_assets(plugin_opts);
|
|
if (!report) {
|
|
std::cerr << "vbs ide plugin: " << report.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
for (const auto &written : report->written_files) {
|
|
std::cout << "wrote " << written.string() << '\n';
|
|
}
|
|
for (const auto &skipped : report->skipped_existing_files) {
|
|
std::cout << "preserved " << skipped.string() << " (pass --force to overwrite)\n";
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
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 ide: " << 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 ide: " << compiled.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
auto profs = Config::discover_profiles(*compiled, fopts);
|
|
if (!profs) {
|
|
std::cerr << "vbs ide: " << 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 ide: " << ex.what() << '\n';
|
|
return 2;
|
|
}
|
|
|
|
auto tc = Toolchain::discover_and_probe(ctx, build_root / ".vbs" / "probes");
|
|
if (!tc) {
|
|
std::cerr << "vbs ide: " << tc.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
auto desc = Config::evaluate_project(*compiled, ctx, fopts);
|
|
if (!desc) {
|
|
std::cerr << "vbs ide: " << desc.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
// MetadataOnly provider loading: inspect cached provider exports if already built; never
|
|
// run foreign configure/build/fetch. On unbuilt checkouts, synthesize empty placeholders so
|
|
// IDE configuration still succeeds before the initial build.
|
|
std::map<std::string, Graph::ImportedTargetInterface, std::less<>> imported_targets;
|
|
std::vector<Package::NormalizedDependency> toml_deps;
|
|
std::error_code ec;
|
|
for (const auto &df : desc->dependency_files) {
|
|
const auto p = std::filesystem::path{df}.is_absolute() ? std::filesystem::path{df}
|
|
: (project_root / df);
|
|
if (auto loaded = Package::load_dependencies_toml(p); loaded) {
|
|
toml_deps.insert(toml_deps.end(), loaded->begin(), loaded->end());
|
|
}
|
|
}
|
|
auto merged_deps = Package::merge_dependencies(desc->dependencies, toml_deps);
|
|
if (merged_deps && !merged_deps->empty()) {
|
|
std::optional<Package::PinnedLock> pinned_lock;
|
|
if (auto pl = Package::load_pinned_lock(project_root / "vbs.lock"); pl) {
|
|
pinned_lock = *pl;
|
|
}
|
|
auto resolved = resolve_and_materialize_deps(ctx, *merged_deps, project_root, build_root,
|
|
pinned_lock, true, false, {});
|
|
if (resolved) {
|
|
for (const auto &[dep_rec, mat] : resolved->materialized) {
|
|
DependencyRecord effective_dep = dep_rec;
|
|
if (effective_dep.builder.empty()) {
|
|
if (std::filesystem::is_regular_file(mat.source_dir / "build.cpp", ec)) {
|
|
effective_dep.builder = "native";
|
|
} else if (std::filesystem::is_regular_file(mat.source_dir / "CMakeLists.txt",
|
|
ec)) {
|
|
effective_dep.builder = "cmake";
|
|
} else if (std::filesystem::is_regular_file(mat.source_dir / "meson.build",
|
|
ec)) {
|
|
effective_dep.builder = "meson";
|
|
}
|
|
}
|
|
if (!effective_dep.builder.empty()) {
|
|
Provider::ProviderRequest preq{effective_dep,
|
|
mat,
|
|
ctx,
|
|
*tc,
|
|
build_root / ".vbs" / "providers",
|
|
Provider::ProviderMode::MetadataOnly,
|
|
{},
|
|
fopts.sdk_include_dir,
|
|
fopts.sdk_source_dir,
|
|
fopts.sdk_library_path.empty()
|
|
? std::nullopt
|
|
: std::optional{fopts.sdk_library_path},
|
|
nullptr,
|
|
0};
|
|
auto exp = Provider::resolve_foreign_provider(preq);
|
|
if (exp && !exp->stale_needs_build) {
|
|
for (const auto &[k, v] : exp->targets) {
|
|
imported_targets[k] = v;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for (const auto &t : desc->targets) {
|
|
for (const auto &link : t.links) {
|
|
if (link.kind == LinkKind::Imported) {
|
|
const std::string key = link.dependency + "::" + link.target;
|
|
if (!imported_targets.contains(key) && !imported_targets.contains(link.target)) {
|
|
Void::Log::warn(
|
|
"Ide",
|
|
"Dependency target '{}' is not built yet; run 'vbs build' to populate "
|
|
"imported include paths",
|
|
key);
|
|
imported_targets.emplace(
|
|
key, Graph::ImportedTargetInterface{
|
|
link.dependency, link.target, {}, {}, {}, {}, {}, {}, {}, {}, {}});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
sopts.materialize = false;
|
|
auto snap =
|
|
Snapshot::capture_snapshot(sopts, snap_inputs.explicit_files, snap_inputs.scan_roots);
|
|
if (!snap) {
|
|
std::cerr << "vbs ide: " << snap.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
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 ide: " << graph.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
const auto existing_sel = Editor::read_selection_state(project_root).value_or(std::nullopt);
|
|
Editor::PublishOptions popts;
|
|
popts.project_root = project_root;
|
|
popts.build_root = build_root;
|
|
popts.update_selection = !existing_sel.has_value();
|
|
popts.sdk_include_dir = fopts.sdk_include_dir;
|
|
auto pub = Editor::publish_profile_compdb(*graph, popts);
|
|
if (!pub) {
|
|
std::cerr << "vbs ide: " << pub.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
|
|
const auto root_compdb = build_root / "compile_commands.json";
|
|
const auto compdb_path =
|
|
std::filesystem::exists(root_compdb, ec) ? root_compdb : pub->compdb_path;
|
|
|
|
if (sub == "query") {
|
|
std::cout << Editor::format_ide_query_json(*graph, compdb_path, fopts.sdk_include_dir);
|
|
return 0;
|
|
}
|
|
|
|
std::filesystem::path vbs_exe{"vbs"};
|
|
if (const auto self_exe = Platform::current_executable_path(); self_exe) {
|
|
vbs_exe = *self_exe;
|
|
}
|
|
|
|
Editor::IdeConfigOptions ide_opts;
|
|
ide_opts.project_root = project_root;
|
|
ide_opts.build_root = build_root;
|
|
ide_opts.sdk_include_dir = fopts.sdk_include_dir;
|
|
ide_opts.vbs_executable = vbs_exe;
|
|
ide_opts.compdb_path = compdb_path;
|
|
ide_opts.editor = ide_kind;
|
|
ide_opts.force = opts.force;
|
|
|
|
auto rep = Editor::generate_ide_configs(*graph, ide_opts);
|
|
if (!rep) {
|
|
std::cerr << "vbs ide: " << rep.error().message() << '\n';
|
|
return 1;
|
|
}
|
|
for (const auto &w : rep->written_files) {
|
|
std::cout << "wrote " << w.string() << '\n';
|
|
}
|
|
for (const auto &s : rep->skipped_existing_files) {
|
|
std::cout << "preserved " << s.string() << " (pass --force to overwrite)\n";
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main(int argc, char **argv) {
|
|
const std::string cwd = std::filesystem::current_path().string();
|
|
bool show_version = false;
|
|
bool releases_unyank = 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;
|
|
PublishBinaryCmdOptions publish_binary_opts;
|
|
BinariesCmdOptions binaries_opts;
|
|
ReleasesCmdOptions releases_opts;
|
|
TokensCmdOptions tokens_opts;
|
|
LockCmdOptions lock_opts;
|
|
VerifyCmdOptions verify_opts;
|
|
PresetsCmdOptions presets_opts;
|
|
MigrateCmdOptions migrate_opts;
|
|
WorkerCmdOptions worker_opts;
|
|
worker_opts.project_arg = cwd;
|
|
CompdbEntriesCmdOptions compdb_entries_opts;
|
|
publish_opts.project_arg = cwd;
|
|
BridgeCmdOptions bridge_opts;
|
|
GcCmdOptions gc_opts;
|
|
gc_opts.build_arg = (std::filesystem::path{cwd} / "build").string();
|
|
// Separate copies: Argparse's option_default must not alias `default_value` with `out`
|
|
// (Void/Library reads the view after assigning to out).
|
|
const std::string gc_default_build = gc_opts.build_arg;
|
|
GenTestsCmdOptions gen_tests_opts;
|
|
InitCmdOptions init_opts;
|
|
init_opts.dir_arg = cwd;
|
|
CleanCmdOptions clean_opts;
|
|
clean_opts.build_arg = (std::filesystem::path{cwd} / "build").string();
|
|
const std::string clean_default_build = clean_opts.build_arg;
|
|
GraphCmdOptions graph_opts;
|
|
graph_opts.project_arg = cwd;
|
|
IdeCmdOptions ide_opts;
|
|
ide_opts.project_arg = cwd;
|
|
DaemonCmdOptions daemon_opts;
|
|
daemon_opts.project_arg = cwd;
|
|
|
|
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)
|
|
.flag("--no-color", "", "Disable ANSI colors", g_no_color);
|
|
};
|
|
|
|
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_many("--label", "", "Only run tests carrying this label", build_opts.labels)
|
|
.option("--compiler", "", "Override compiler family (gcc|clang)",
|
|
build_opts.compiler_arg)
|
|
.option("--target-os", "", "Target operating system (default: host, e.g. windows)",
|
|
build_opts.target_os_arg)
|
|
.option("--target-arch", "", "Target architecture (default: host, e.g. x86_64)",
|
|
build_opts.target_arch_arg)
|
|
.option_default("--test-timeout", "", "Per-test timeout in seconds (1..86400)",
|
|
build_opts.test_timeout_arg, "300")
|
|
.option("--junit", "", "Write a JUnit XML report of test results", build_opts.junit_arg)
|
|
.option("--coverage", "", "Build with --coverage and write an lcov report to this directory",
|
|
build_opts.coverage_arg)
|
|
.option("--cdash", "", "Upload a CDash test report to this base URL",
|
|
build_opts.cdash_arg)
|
|
.option("--cdash-project", "", "CDash project name (default: project directory name)",
|
|
build_opts.cdash_project_arg)
|
|
.option("--cdash-build", "", "CDash build name (default: vbs)",
|
|
build_opts.cdash_build_arg)
|
|
.option("--cdash-output", "", "Write the CDash Test.xml report to this file",
|
|
build_opts.cdash_output_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)
|
|
.option_many("--member", "", "Workspace member to build/test", build_opts.members)
|
|
.option("--changed-since", "", "Build/test workspace members changed since a git ref",
|
|
build_opts.changed_since)
|
|
.option("--sbom", "", "Write an SBOM after a successful build", build_opts.sbom_arg)
|
|
.option("--sbom-format", "", "SBOM format: spdx (default) or cyclonedx",
|
|
build_opts.sbom_format_arg)
|
|
.option("--remote-cache", "", "Shared HTTP action cache URL (or VBS_REMOTE_CACHE)",
|
|
build_opts.remote_cache_arg)
|
|
.option("--remote-cache-token-env", "",
|
|
"Environment variable holding the remote cache bearer token",
|
|
build_opts.remote_cache_token_env)
|
|
.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)
|
|
.flag("--native-foreign", "",
|
|
"Translate supported CMake/Meson dependencies to native VBS actions (Plan 20)",
|
|
build_opts.native_foreign)
|
|
.option_many("--trusted-public-key", "",
|
|
"Trusted Ed25519 package public key (hex; repeatable)",
|
|
build_opts.trusted_public_keys)
|
|
.option_many("--trusted-key-file", "",
|
|
"File with trusted Ed25519 public keys (repeatable)",
|
|
build_opts.trusted_key_files);
|
|
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)
|
|
.flag("--bundle-dependencies", "",
|
|
"Bundle runtime shared libraries of installed targets into <prefix>/lib",
|
|
install_opts.bundle_dependencies)
|
|
.option("--archive", "", "Write a deterministic installer archive of the prefix",
|
|
install_opts.archive_arg)
|
|
.option_default("--archive-format", "",
|
|
"Installer archive format: tar (default), sh, zip, deb, rpm, wix, dmg or nuget",
|
|
install_opts.archive_format_arg, "tar")
|
|
.option("--signing-key", "",
|
|
"Ed25519 seed file; signs the archive and writes .sha256/.sig/.pub",
|
|
install_opts.signing_key_arg);
|
|
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 &publish_binary_cmd = root.subcommand(
|
|
"publish-binary", "Publish a prebuilt binary variant to a VBS package registry");
|
|
publish_binary_cmd
|
|
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
|
publish_binary_opts.registry_arg)
|
|
.option("--name", "-n", "Package name", publish_binary_opts.name_arg)
|
|
.option("--version", "-v", "Release version", publish_binary_opts.version_arg)
|
|
.option("--variant", "", "Binary variant id", publish_binary_opts.variant_arg)
|
|
.option("--file", "-f", "Prebuilt artifact file", publish_binary_opts.file_arg)
|
|
.option("--signing-key", "", "Ed25519 signing seed file (64 hex characters)",
|
|
publish_binary_opts.signing_key_arg)
|
|
.option_default("--token-env", "", "Environment variable holding bearer token",
|
|
publish_binary_opts.token_env, "VBS_REGISTRY_TOKEN");
|
|
add_log_flags(publish_binary_cmd, false); // `-v` is `--version` on publish-binary.
|
|
|
|
auto &compdb_entries_root_cmd = root.subcommand(
|
|
"compdb-entries", "Query bounded entries from the published compile database");
|
|
compdb_entries_root_cmd
|
|
.option_default("--project", "-C", "Project directory", compdb_entries_opts.project_arg,
|
|
cwd)
|
|
.option("--build-dir", "-B", "Build directory", compdb_entries_opts.build_arg)
|
|
.option("--file", "", "Only entries whose source path ends with this value",
|
|
compdb_entries_opts.file_arg)
|
|
.option_default("--limit", "", "Maximum entries (0-500)", compdb_entries_opts.limit_arg,
|
|
"50");
|
|
add_log_flags(compdb_entries_root_cmd);
|
|
|
|
auto &verify_cmd =
|
|
root.subcommand("verify", "Verify a detached Ed25519 signature over a package artifact");
|
|
verify_cmd.option("--name", "-n", "Package name", verify_opts.name_arg)
|
|
.option("--version", "-v", "Package version", verify_opts.version_arg)
|
|
.option("--file", "-f", "Artifact file whose SHA-256 is signed", verify_opts.file_arg)
|
|
.option("--signature", "", "Detached signature hex", verify_opts.signature_arg)
|
|
.option("--public-key", "", "Signer public key hex", verify_opts.public_key_arg)
|
|
.option_many("--trusted-public-key", "",
|
|
"Require the signer key to be trusted (hex; repeatable)",
|
|
verify_opts.trusted_public_keys)
|
|
.option_many("--trusted-key-file", "", "File with trusted public keys (repeatable)",
|
|
verify_opts.trusted_key_files);
|
|
add_log_flags(verify_cmd, false); // `-v` is `--version` on verify.
|
|
|
|
auto &worker_cmd = root.subcommand(
|
|
"worker", "Run one remote-execution worker step (lease, publish, result upload)");
|
|
worker_cmd
|
|
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
|
worker_opts.registry_arg)
|
|
.option("--action-key", "", "Action key to lease and publish", worker_opts.action_key_arg)
|
|
.option("--record", "", "Action record JSON file to publish", worker_opts.record_arg)
|
|
.flag("--queue", "", "Lease the next action from the registry queue",
|
|
worker_opts.queue_mode)
|
|
.flag("--once", "", "Process at most one queued action", worker_opts.once)
|
|
.option_default("--idle-timeout", "",
|
|
"Seconds to wait for new queued work before exiting (0 = exit)",
|
|
worker_opts.idle_timeout_arg, "0")
|
|
.option_default("--project", "-C", "Project directory", worker_opts.project_arg, cwd)
|
|
.option("--build-dir", "-B", "Build directory", worker_opts.build_arg)
|
|
.option_default("--token-env", "", "Environment variable holding bearer token",
|
|
worker_opts.token_env, "VBS_REGISTRY_TOKEN")
|
|
.option_default("--lease-seconds", "", "Lease TTL in seconds (1..3600)",
|
|
worker_opts.lease_seconds_arg, "60")
|
|
.option_default("--exec-timeout", "", "Remote action timeout in seconds (1..86400)",
|
|
worker_opts.exec_timeout_arg, "600")
|
|
.option_default("--parallel", "", "Concurrent lease/execute loops in queue mode (1..32)",
|
|
worker_opts.parallel_arg, "1");
|
|
add_log_flags(worker_cmd);
|
|
|
|
auto &migrate_cmd = root.subcommand(
|
|
"migrate", "Generate a build.cpp scaffold from a CMakeLists.txt (bounded subset)");
|
|
migrate_cmd
|
|
.option_default("--input", "-i", "CMakeLists.txt path", migrate_opts.input_arg,
|
|
"CMakeLists.txt")
|
|
.option_default("--output", "-o", "Output build.cpp path", migrate_opts.output_arg,
|
|
"build.cpp")
|
|
.option_default("--project", "-C", "Project root", migrate_opts.project_arg, ".")
|
|
.flag("--force", "", "Overwrite an existing output file", migrate_opts.force)
|
|
.flag("--dry-run", "", "Print the scaffold instead of writing it", migrate_opts.dry_run);
|
|
add_log_flags(migrate_cmd);
|
|
|
|
auto &presets_cmd = root.subcommand(
|
|
"presets", "Import CMake configure presets (CMakePresets.json) as VBS equivalents");
|
|
presets_cmd
|
|
.option_default("--file", "-f", "CMakePresets.json path", presets_opts.file_arg,
|
|
"CMakePresets.json")
|
|
.option_default("--project", "-C", "Project root for ${sourceDir}",
|
|
presets_opts.project_arg, cwd)
|
|
.option("--name", "-n", "Print the VBS command for one preset", presets_opts.name_arg);
|
|
add_log_flags(presets_cmd);
|
|
|
|
auto &lock_cmd = root.subcommand("lock", "Inspect the project's vbs.lock");
|
|
auto &lock_show_cmd = lock_cmd.subcommand("show", "Print lockfile contexts and entries");
|
|
lock_show_cmd.option_default("--project", "-C", "Project directory", lock_opts.project_arg,
|
|
cwd);
|
|
add_log_flags(lock_show_cmd);
|
|
|
|
auto &tokens_cmd = root.subcommand("tokens", "Inspect API tokens in a package registry");
|
|
auto configure_tokens = [&](Void::Argparse::Parser &parser) {
|
|
parser
|
|
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
|
tokens_opts.registry_arg)
|
|
.option_default("--token-env", "", "Environment variable holding bearer token",
|
|
tokens_opts.token_env, "VBS_REGISTRY_TOKEN");
|
|
add_log_flags(parser);
|
|
};
|
|
auto &tokens_list_cmd = tokens_cmd.subcommand("list", "List token metadata");
|
|
configure_tokens(tokens_list_cmd);
|
|
auto &tokens_revoke_cmd = tokens_cmd.subcommand("revoke", "Revoke an API token");
|
|
configure_tokens(tokens_revoke_cmd);
|
|
tokens_revoke_cmd.option("--token-id", "", "Token id to revoke", tokens_opts.token_id_arg);
|
|
|
|
auto &releases_cmd =
|
|
root.subcommand("releases", "List published releases in a package registry");
|
|
auto &releases_list_cmd = releases_cmd.subcommand("list", "List a package's releases");
|
|
releases_list_cmd
|
|
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
|
releases_opts.registry_arg)
|
|
.option("--name", "-n", "Package name", releases_opts.name_arg)
|
|
.option_default("--token-env", "", "Environment variable holding bearer token",
|
|
releases_opts.token_env, "VBS_REGISTRY_TOKEN");
|
|
add_log_flags(releases_list_cmd);
|
|
|
|
auto &releases_show_cmd = releases_cmd.subcommand("show", "Show one release's details");
|
|
releases_show_cmd
|
|
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
|
releases_opts.registry_arg)
|
|
.option("--name", "-n", "Package name", releases_opts.name_arg)
|
|
.option("--version", "-v", "Release version", releases_opts.version_arg)
|
|
.option_default("--token-env", "", "Environment variable holding bearer token",
|
|
releases_opts.token_env, "VBS_REGISTRY_TOKEN");
|
|
add_log_flags(releases_show_cmd, false); // `-v` is `--version` on releases show.
|
|
|
|
auto &releases_yank_cmd = releases_cmd.subcommand("yank", "Yank or unyank a release");
|
|
releases_yank_cmd
|
|
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
|
releases_opts.registry_arg)
|
|
.option("--name", "-n", "Package name", releases_opts.name_arg)
|
|
.option("--version", "-v", "Release version", releases_opts.version_arg)
|
|
.option_default("--token-env", "", "Environment variable holding bearer token",
|
|
releases_opts.token_env, "VBS_REGISTRY_TOKEN")
|
|
.flag("--unyank", "", "Restore a yanked release", releases_unyank);
|
|
add_log_flags(releases_yank_cmd, false); // `-v` is `--version` on releases yank.
|
|
|
|
auto &binaries_cmd =
|
|
root.subcommand("binaries", "Inspect prebuilt binary variants in a package registry");
|
|
auto configure_binaries = [&](Void::Argparse::Parser &p) {
|
|
p.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
|
binaries_opts.registry_arg)
|
|
.option("--name", "-n", "Package name", binaries_opts.name_arg)
|
|
.option("--version", "-v", "Release version", binaries_opts.version_arg)
|
|
.option_default("--token-env", "", "Environment variable holding bearer token",
|
|
binaries_opts.token_env, "VBS_REGISTRY_TOKEN");
|
|
add_log_flags(p, false);
|
|
};
|
|
configure_binaries(binaries_cmd.subcommand(
|
|
"list", "List a release's binary variants (id, digest, size, signature state)"));
|
|
auto &binaries_show_cmd = binaries_cmd.subcommand("show", "Show one binary variant's metadata");
|
|
configure_binaries(binaries_show_cmd);
|
|
binaries_show_cmd.option("--variant", "", "Binary variant id", binaries_opts.variant_arg);
|
|
auto &binaries_fetch_cmd =
|
|
binaries_cmd.subcommand("fetch", "Download one binary variant artifact");
|
|
configure_binaries(binaries_fetch_cmd);
|
|
binaries_fetch_cmd.option("--variant", "", "Binary variant id", binaries_opts.variant_arg)
|
|
.option("--output", "-o", "Destination artifact path", binaries_opts.output_arg)
|
|
.option_many("--trusted-public-key", "",
|
|
"Required trusted Ed25519 signer key (hex; repeatable)",
|
|
binaries_opts.trusted_public_keys)
|
|
.option_many("--trusted-key-file", "", "File with trusted public keys (repeatable)",
|
|
binaries_opts.trusted_key_files);
|
|
|
|
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")
|
|
.option("--signing-key", "", "Ed25519 signing seed file (64 hex characters)",
|
|
publish_opts.signing_key_arg)
|
|
.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_default_build)
|
|
.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);
|
|
|
|
auto &init_cmd =
|
|
root.subcommand("init", "Scaffold a new ready-to-build C++26 VoidBuildSystem project");
|
|
init_cmd.option_default("--dir", "-C", "Target project directory", init_opts.dir_arg, cwd)
|
|
.option("--name", "-n", "Project/target name (defaults to directory name)",
|
|
init_opts.name_arg)
|
|
.flag("--library", "", "Scaffold a static library project instead of an executable",
|
|
init_opts.library)
|
|
.flag("--with-toml", "", "Include a vbs.deps.toml dependency manifest", init_opts.with_toml)
|
|
.flag("--force", "", "Overwrite existing build.cpp if present", init_opts.force);
|
|
add_log_flags(init_cmd);
|
|
|
|
auto &clean_cmd =
|
|
root.subcommand("clean", "Remove generated profile build artifacts (preserving cache)");
|
|
clean_cmd
|
|
.option_default("--build-dir", "-B", "Build directory", clean_opts.build_arg,
|
|
clean_default_build)
|
|
.flag("--all", "", "Also delete .vbs cache, snapshots, and state store",
|
|
clean_opts.clean_all);
|
|
add_log_flags(clean_cmd);
|
|
|
|
auto &doctor_cmd =
|
|
root.subcommand("doctor", "Check host compilers, tools, and VBS runtime capabilities");
|
|
add_log_flags(doctor_cmd);
|
|
|
|
auto &graph_cmd =
|
|
root.subcommand("graph", "Export target dependency graph in Graphviz DOT or JSON format");
|
|
graph_cmd.option_default("--project", "-C", "Project directory", graph_opts.project_arg, cwd)
|
|
.option("--build-dir", "-B", "Build output directory", graph_opts.build_arg)
|
|
.option_default("--profile", "-p", "Profile name", graph_opts.profile_name, "debug")
|
|
.option("--compiler", "", "Override compiler family (gcc|clang)", graph_opts.compiler_arg)
|
|
.option_default("--format", "-f", "Output format (dot|json)", graph_opts.format, "dot");
|
|
add_log_flags(graph_cmd);
|
|
|
|
auto &ide_cmd =
|
|
root.subcommand("ide", "Generate editor/IDE configs and query workspace metadata");
|
|
auto configure_ide_common = [&](Void::Argparse::Parser &p) {
|
|
p.option_default("--project", "-C", "Project directory", ide_opts.project_arg, cwd)
|
|
.option("--build-dir", "-B", "Build output directory", ide_opts.build_arg)
|
|
.option_default("--profile", "-p", "Profile name", ide_opts.profile_name, "debug")
|
|
.option("--compiler", "", "Override compiler family (gcc|clang)",
|
|
ide_opts.compiler_arg);
|
|
add_log_flags(p);
|
|
};
|
|
auto &ide_plugin_cmd = ide_cmd.subcommand("plugin", "Export editor extension assets (vscode)");
|
|
configure_ide_common(ide_plugin_cmd);
|
|
ide_plugin_cmd
|
|
.option_default("--editor", "-e", "Editor preset (vscode)", ide_opts.editor_name, "vscode")
|
|
.option("--output", "-o", "Output directory", ide_opts.plugin_output_arg)
|
|
.option("--vsix", "", "Package the VS Code extension as a .vsix (ZIP)",
|
|
ide_opts.plugin_vsix_arg)
|
|
.flag("--force", "", "Overwrite existing plugin files", ide_opts.force);
|
|
auto &ide_gen_cmd =
|
|
ide_cmd.subcommand("generate", "Generate .clangd, .vscode/, .zed/, and .idea/ IDE configs");
|
|
configure_ide_common(ide_gen_cmd);
|
|
ide_gen_cmd
|
|
.option_default("--editor", "-e", "Editor preset (all|clangd|vscode|clion|zed)",
|
|
ide_opts.editor_name, "all")
|
|
.flag("--force", "", "Overwrite existing IDE configuration files", ide_opts.force);
|
|
configure_ide_common(
|
|
ide_cmd.subcommand("query", "Emit versioned JSON workspace, target, and compdb metadata"));
|
|
|
|
auto &daemon_cmd = root.subcommand("daemon", "Run or control the persistent build daemon");
|
|
auto configure_daemon_common = [&](Void::Argparse::Parser &p) {
|
|
p.option_default("--project", "-C", "Project directory", daemon_opts.project_arg, cwd)
|
|
.option("--build-dir", "-B", "Build output directory", daemon_opts.build_arg)
|
|
.option("--socket", "", "Unix socket path (default: <build>/.vbs/vbs-daemon.sock)",
|
|
daemon_opts.socket_arg);
|
|
add_log_flags(p);
|
|
};
|
|
auto &daemon_run_cmd = daemon_cmd.subcommand("run", "Run the daemon in the foreground");
|
|
configure_daemon_common(daemon_run_cmd);
|
|
daemon_run_cmd.option_default("--max-requests", "", "Stop after N requests (0 = unlimited)",
|
|
daemon_opts.max_requests_arg, "0");
|
|
configure_daemon_common(daemon_cmd.subcommand("status", "Query the running daemon's status"));
|
|
configure_daemon_common(daemon_cmd.subcommand("stop", "Ask the running daemon to shut down"));
|
|
configure_daemon_common(
|
|
daemon_cmd.subcommand("recover", "Run interrupted-state recovery in the daemon"));
|
|
auto &daemon_gc_cmd = daemon_cmd.subcommand("gc", "Run CAS garbage collection in the daemon");
|
|
configure_daemon_common(daemon_gc_cmd);
|
|
daemon_gc_cmd.option_default("--max-bytes", "",
|
|
"Target maximum retained CAS bytes (0=unreferenced only)",
|
|
daemon_opts.max_bytes_arg, "0");
|
|
auto &daemon_describe_cmd =
|
|
daemon_cmd.subcommand("describe", "Describe a project's build graph via the daemon");
|
|
configure_daemon_common(daemon_describe_cmd);
|
|
daemon_describe_cmd
|
|
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
|
.option("--member", "", "Workspace member to describe (default: all)",
|
|
daemon_opts.member_arg);
|
|
auto &daemon_build_cmd = daemon_cmd.subcommand("build", "Build a project graph via the daemon");
|
|
configure_daemon_common(daemon_build_cmd);
|
|
daemon_build_cmd
|
|
.option_default("--profile", "-p", "Profile to build", daemon_opts.profile_arg, "debug")
|
|
.option_many("--target", "-t", "Target to build", daemon_opts.targets)
|
|
.option_default("--jobs", "-j", "Maximum parallel jobs (0 = hardware concurrency)",
|
|
daemon_opts.jobs_arg, "0");
|
|
auto &daemon_test_cmd =
|
|
daemon_cmd.subcommand("test", "Build and run declared test targets via the daemon");
|
|
configure_daemon_common(daemon_test_cmd);
|
|
daemon_test_cmd
|
|
.option_default("--profile", "-p", "Profile to build", daemon_opts.profile_arg, "debug")
|
|
.option_many("--target", "-t", "Target to build/test", daemon_opts.targets)
|
|
.option_default("--jobs", "-j", "Maximum parallel jobs (0 = hardware concurrency)",
|
|
daemon_opts.jobs_arg, "0");
|
|
auto &daemon_compdb_cmd =
|
|
daemon_cmd.subcommand("compdb", "Editor compilation database served by the daemon");
|
|
auto &daemon_compdb_generations_cmd = daemon_compdb_cmd.subcommand(
|
|
"generations", "List immutable editor generations for a profile");
|
|
configure_daemon_common(daemon_compdb_generations_cmd);
|
|
daemon_compdb_generations_cmd.option_default("--profile", "-p", "Profile to inspect",
|
|
daemon_opts.profile_arg, "debug");
|
|
auto &daemon_compdb_entries_cmd = daemon_compdb_cmd.subcommand(
|
|
"entries", "Query bounded compile_commands entries for editor extensions");
|
|
configure_daemon_common(daemon_compdb_entries_cmd);
|
|
daemon_compdb_entries_cmd
|
|
.option("--file", "", "Only entries whose source path ends with this value",
|
|
daemon_opts.file_filter_arg)
|
|
.option_default("--limit", "", "Maximum entries returned (0-500)", daemon_opts.limit_arg,
|
|
"50");
|
|
auto &daemon_compdb_use_cmd =
|
|
daemon_compdb_cmd.subcommand("use", "Select an already-published editor profile");
|
|
configure_daemon_common(daemon_compdb_use_cmd);
|
|
daemon_compdb_use_cmd.option_default("--profile", "-p", "Profile to select",
|
|
daemon_opts.profile_arg, "debug");
|
|
auto &daemon_compdb_export_cmd =
|
|
daemon_compdb_cmd.subcommand("export", "Publish the profile compilation database");
|
|
configure_daemon_common(daemon_compdb_export_cmd);
|
|
daemon_compdb_export_cmd
|
|
.option_default("--profile", "-p", "Profile to export", daemon_opts.profile_arg, "debug")
|
|
.option("--member", "", "Workspace member (required for workspace roots)",
|
|
daemon_opts.member_arg);
|
|
auto &daemon_info_cmd =
|
|
daemon_cmd.subcommand("info", "Show daemon paths, version, and host facts");
|
|
configure_daemon_common(daemon_info_cmd);
|
|
auto &daemon_clean_cmd = daemon_cmd.subcommand(
|
|
"clean", "Remove generated profile outputs (preserving the shared cache)");
|
|
configure_daemon_common(daemon_clean_cmd);
|
|
daemon_clean_cmd.flag("--all", "", "Also remove the entire build root (cache and state)",
|
|
daemon_opts.force);
|
|
auto &daemon_deps_cmd =
|
|
daemon_cmd.subcommand("deps", "Resolve and materialize dependencies via the daemon");
|
|
configure_daemon_common(daemon_deps_cmd);
|
|
daemon_deps_cmd
|
|
.option_default("--profile", "-p", "Profile to resolve", daemon_opts.profile_arg, "debug")
|
|
.option("--member", "", "Workspace member (required for workspace roots)",
|
|
daemon_opts.member_arg);
|
|
auto &daemon_pack_cmd =
|
|
daemon_cmd.subcommand("pack", "Create a deterministic source archive in the build root");
|
|
configure_daemon_common(daemon_pack_cmd);
|
|
daemon_pack_cmd.option("--output", "-o", "Archive path relative to the build root",
|
|
daemon_opts.pack_output_arg);
|
|
auto &daemon_install_cmd =
|
|
daemon_cmd.subcommand("install", "Build and stage an install prefix via the daemon");
|
|
configure_daemon_common(daemon_install_cmd);
|
|
daemon_install_cmd.option("--prefix", "", "Install prefix (required)", daemon_opts.prefix_arg)
|
|
.option_default("--package-version", "", "Exported package version",
|
|
daemon_opts.package_version_arg, "0.1.0")
|
|
.option("--component", "", "Install only a specific component", daemon_opts.component_arg)
|
|
.flag("--no-cmake-export", "", "Disable CMake Config.cmake export",
|
|
daemon_opts.no_cmake_export)
|
|
.flag("--no-native-export", "", "Disable native VBS package metadata export",
|
|
daemon_opts.no_native_export);
|
|
auto &daemon_init_cmd =
|
|
daemon_cmd.subcommand("init", "Scaffold a new VBS project inside the project root");
|
|
configure_daemon_common(daemon_init_cmd);
|
|
daemon_init_cmd
|
|
.option_default("--dir", "", "Target directory (relative to the project root)",
|
|
daemon_opts.init_dir_arg, ".")
|
|
.option("--name", "-n", "Project/target name (defaults to the directory name)",
|
|
daemon_opts.init_name_arg)
|
|
.flag("--library", "", "Scaffold a static library project", daemon_opts.init_library)
|
|
.flag("--with-toml", "", "Include a vbs.deps.toml manifest", daemon_opts.init_with_toml)
|
|
.flag("--force", "", "Overwrite an existing build.cpp", daemon_opts.init_force);
|
|
auto &daemon_gen_tests_cmd = daemon_cmd.subcommand(
|
|
"gen-tests", "Generate a native Void::Testing registration unit via the daemon");
|
|
configure_daemon_common(daemon_gen_tests_cmd);
|
|
daemon_gen_tests_cmd
|
|
.option("--input", "", "Input test .cpp file (inside the project root)",
|
|
daemon_opts.input_arg)
|
|
.option("--output-dir", "", "Output directory (inside the build root)",
|
|
daemon_opts.output_dir_arg);
|
|
auto &daemon_uninstall_cmd =
|
|
daemon_cmd.subcommand("uninstall", "Remove VBS-owned installed files via the daemon");
|
|
configure_daemon_common(daemon_uninstall_cmd);
|
|
daemon_uninstall_cmd.option("--prefix", "", "Install prefix (required)",
|
|
daemon_opts.prefix_arg);
|
|
auto &daemon_target_cmd =
|
|
daemon_cmd.subcommand("target", "Target metadata served by the daemon");
|
|
auto &daemon_target_info_cmd = daemon_target_cmd.subcommand(
|
|
"info", "Report one target's kind, sources, outputs, and runtime libraries");
|
|
configure_daemon_common(daemon_target_info_cmd);
|
|
daemon_target_info_cmd
|
|
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
|
.option("--name", "-n", "Target name", daemon_opts.target_arg);
|
|
auto &daemon_target_flags_cmd = daemon_target_cmd.subcommand(
|
|
"flags", "Report one target's bounded compile arguments per unit");
|
|
configure_daemon_common(daemon_target_flags_cmd);
|
|
daemon_target_flags_cmd
|
|
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
|
.option("--name", "-n", "Target name", daemon_opts.target_arg)
|
|
.option("--file", "", "Only units whose source path ends with this value",
|
|
daemon_opts.file_filter_arg);
|
|
auto &daemon_workspace_cmd =
|
|
daemon_cmd.subcommand("workspace", "Workspace metadata served by the daemon");
|
|
auto &daemon_workspace_members_cmd =
|
|
daemon_workspace_cmd.subcommand("members", "List declared workspace members");
|
|
configure_daemon_common(daemon_workspace_members_cmd);
|
|
auto &daemon_actions_cmd =
|
|
daemon_cmd.subcommand("actions", "List lowered build actions via the daemon");
|
|
configure_daemon_common(daemon_actions_cmd);
|
|
daemon_actions_cmd
|
|
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
|
.option("--kind", "", "Only actions of this kind (compile|link|archive|...)",
|
|
daemon_opts.action_kind_arg)
|
|
.option_default("--limit", "", "Maximum actions returned (0-1000)", daemon_opts.limit_arg,
|
|
"100");
|
|
auto &daemon_graph_cmd =
|
|
daemon_cmd.subcommand("graph", "Export the target dependency graph via the daemon");
|
|
configure_daemon_common(daemon_graph_cmd);
|
|
daemon_graph_cmd
|
|
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
|
.option_default("--format", "-f", "Output format (dot|json|mermaid)",
|
|
daemon_opts.graph_format_arg, "dot")
|
|
.option("--member", "", "Workspace member (required for workspace roots)",
|
|
daemon_opts.member_arg);
|
|
auto &daemon_ide_cmd = daemon_cmd.subcommand("ide", "Editor/IDE metadata served by the daemon");
|
|
configure_daemon_common(daemon_ide_cmd);
|
|
auto &daemon_ide_query_cmd =
|
|
daemon_ide_cmd.subcommand("query", "Emit IDE workspace/target/compdb metadata JSON");
|
|
configure_daemon_common(daemon_ide_query_cmd);
|
|
daemon_ide_query_cmd
|
|
.option_default("--profile", "-p", "Profile to query", daemon_opts.profile_arg, "debug")
|
|
.option("--member", "", "Workspace member (required for workspace roots)",
|
|
daemon_opts.member_arg);
|
|
auto &daemon_ide_status_cmd =
|
|
daemon_ide_cmd.subcommand("status", "Report the active editor selection and compdb state");
|
|
configure_daemon_common(daemon_ide_status_cmd);
|
|
auto &daemon_ide_configs_cmd =
|
|
daemon_ide_cmd.subcommand("configs", "Report which editor configuration files exist");
|
|
configure_daemon_common(daemon_ide_configs_cmd);
|
|
auto &daemon_ide_poll_cmd = daemon_ide_cmd.subcommand(
|
|
"poll", "Poll pending project file changes (editor extension protocol)");
|
|
configure_daemon_common(daemon_ide_poll_cmd);
|
|
daemon_ide_poll_cmd.option("--prefix", "", "Only report changed paths under this prefix",
|
|
daemon_opts.prefix_arg);
|
|
auto &daemon_ide_wait_cmd = daemon_ide_cmd.subcommand(
|
|
"wait", "Long-poll for project file changes (bounded, editor extension protocol)");
|
|
configure_daemon_common(daemon_ide_wait_cmd);
|
|
daemon_ide_wait_cmd
|
|
.option_default("--timeout-ms", "", "Maximum wait in milliseconds (0..5000)",
|
|
daemon_opts.timeout_ms_arg, "2000")
|
|
.option("--prefix", "", "Only report changed paths under this prefix",
|
|
daemon_opts.prefix_arg);
|
|
auto &daemon_ide_generate_cmd =
|
|
daemon_ide_cmd.subcommand("generate", "Write editor configuration files");
|
|
configure_daemon_common(daemon_ide_generate_cmd);
|
|
daemon_ide_generate_cmd
|
|
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
|
.option_default("--editor", "-e", "Editor preset (all|clangd|vscode|clion|zed)",
|
|
daemon_opts.editor_arg, "all")
|
|
.option("--member", "", "Workspace member (required for workspace roots)",
|
|
daemon_opts.member_arg)
|
|
.flag("--force", "", "Overwrite existing IDE configuration files", daemon_opts.force);
|
|
|
|
const auto parsed = root.parse_detailed(argc, argv);
|
|
if (parsed.is_help()) {
|
|
std::cout << colorize_help(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 << colorize_help(root.help());
|
|
return 0;
|
|
}
|
|
|
|
const std::string_view cmd = parsed.matched_command_path.front();
|
|
const bool machine_quiet_default =
|
|
(cmd == "describe") || (cmd == "graph") || (cmd == "doctor") ||
|
|
(cmd == "compdb" && parsed.matched_command_path.size() >= 2 &&
|
|
parsed.matched_command_path[1] == "show") ||
|
|
(cmd == "ide" && parsed.matched_command_path.size() >= 2 &&
|
|
parsed.matched_command_path[1] == "query");
|
|
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" || cmd == "test") {
|
|
const bool run_tests = cmd == "test";
|
|
if (Config::is_workspace_root(std::filesystem::path{build_opts.project_arg})) {
|
|
return execute_workspace(std::move(build_opts), run_tests);
|
|
}
|
|
return execute_build_or_test(std::move(build_opts), run_tests);
|
|
}
|
|
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 == "publish-binary") {
|
|
return execute_publish_binary_command(publish_binary_opts);
|
|
}
|
|
if (cmd == "binaries") {
|
|
return execute_binaries_command(parsed.matched_command_path.at(1), binaries_opts);
|
|
}
|
|
if (cmd == "releases") {
|
|
const std::string releases_sub = parsed.matched_command_path.at(1);
|
|
if (releases_sub == "show") {
|
|
return execute_releases_show_command(releases_opts);
|
|
}
|
|
if (releases_sub == "yank") {
|
|
return execute_releases_yank_command(releases_opts, releases_unyank);
|
|
}
|
|
return execute_releases_list_command(releases_opts);
|
|
}
|
|
if (cmd == "tokens") {
|
|
return execute_tokens_command(parsed.matched_command_path.at(1), tokens_opts);
|
|
}
|
|
if (cmd == "lock") {
|
|
return execute_lock_show_command(lock_opts);
|
|
}
|
|
if (cmd == "verify") {
|
|
return execute_verify_command(verify_opts);
|
|
}
|
|
if (cmd == "presets") {
|
|
return execute_presets_command(presets_opts);
|
|
}
|
|
if (cmd == "migrate") {
|
|
return execute_migrate_command(migrate_opts);
|
|
}
|
|
if (cmd == "worker") {
|
|
return execute_worker_command(worker_opts);
|
|
}
|
|
if (cmd == "compdb-entries") {
|
|
return execute_compdb_entries_command(compdb_entries_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);
|
|
}
|
|
if (cmd == "init") {
|
|
return execute_init_command(init_opts);
|
|
}
|
|
if (cmd == "clean") {
|
|
return execute_clean_command(clean_opts);
|
|
}
|
|
if (cmd == "doctor") {
|
|
return execute_doctor_command();
|
|
}
|
|
if (cmd == "graph") {
|
|
return execute_graph_command(graph_opts);
|
|
}
|
|
if (cmd == "ide") {
|
|
return execute_ide_command(parsed.matched_command_path.at(1), ide_opts);
|
|
}
|
|
if (cmd == "daemon") {
|
|
std::string daemon_sub = parsed.matched_command_path.at(1);
|
|
if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "query") {
|
|
daemon_sub = "ide_query";
|
|
} else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "generate") {
|
|
daemon_sub = "ide_generate";
|
|
} else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "status") {
|
|
daemon_sub = "editor_status";
|
|
} else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "poll") {
|
|
daemon_sub = "watch_poll";
|
|
} else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "wait") {
|
|
daemon_sub = "watch_wait";
|
|
} else if (daemon_sub == "compdb" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "export") {
|
|
daemon_sub = "compdb_export";
|
|
} else if (daemon_sub == "compdb" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "use") {
|
|
daemon_sub = "compdb_use";
|
|
} else if (daemon_sub == "workspace" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "members") {
|
|
daemon_sub = "workspace_members";
|
|
} else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "configs") {
|
|
daemon_sub = "ide_configs";
|
|
} else if (daemon_sub == "compdb" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "generations") {
|
|
daemon_sub = "compdb_generations";
|
|
} else if (daemon_sub == "target" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "info") {
|
|
daemon_sub = "target_info";
|
|
} else if (daemon_sub == "target" && parsed.matched_command_path.size() > 2 &&
|
|
parsed.matched_command_path[2] == "flags") {
|
|
daemon_sub = "target_flags";
|
|
}
|
|
return execute_daemon_command(daemon_sub, daemon_opts);
|
|
}
|
|
|
|
std::cerr << "vbs: unhandled subcommand '" << cmd << "'\n";
|
|
return 2;
|
|
}
|