Implement VoidBuildSystem v1 (Plans 01-19) with VoidLibrary integration
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s

This commit is contained in:
faumaray committed 2026-11-26 20:45:54 +03:00
1 parent 3cac890ce9
commit ab64147f9d
114 files changed
+23777 -1392

No files matched your search

+773
View File
@@ -0,0 +1,773 @@
#include <Void/Build/Provider/Provider.hpp>
#include <Void/Build/Platform/FileOps.hpp>
#include <Void/Build/Platform/ProcessSupervisor.hpp>
#include <Void/Build/Util/Json.hpp>
#include <Void/Build/Util/Sha256.hpp>
#include <Void/Data/StrictJson.hpp>
#include <Void/System/Path.hpp>
#include <Void/System/Types.hpp>
#include <algorithm>
#include <format>
#include <set>
#include <type_traits>
namespace Void::Build::Provider {
namespace {
using JsonVal = Void::Json::Strict::Value;
Void::Result::Error make_error(Void::System::SystemErrorCode code, std::string msg) {
return Void::System::make_system_error(code, std::move(msg));
}
const JsonVal *find_key(const JsonVal::Object &obj, const std::string &k) {
const auto it = obj.find(k);
return it == obj.end() ? nullptr : &it->second;
}
std::string get_str(const JsonVal::Object &obj, const std::string &k) {
const auto *v = find_key(obj, k);
if (!v) {
return {};
}
const auto *s = std::get_if<std::string>(&v->value);
return s ? *s : std::string{};
}
bool get_bool(const JsonVal::Object &obj, const std::string &k, bool def = false) {
const auto *v = find_key(obj, k);
if (!v) {
return def;
}
const auto *b = std::get_if<bool>(&v->value);
return b ? *b : def;
}
std::vector<std::string> get_str_array(const JsonVal::Object &obj, const std::string &k) {
std::vector<std::string> out;
const auto *v = find_key(obj, k);
if (!v) {
return out;
}
if (const auto *arr = std::get_if<JsonVal::Array>(&v->value)) {
for (const auto &item : *arr) {
if (const auto *s = std::get_if<std::string>(&item.value)) {
out.push_back(*s);
}
}
}
return out;
}
std::optional<JsonVal> parse_json_file(const std::filesystem::path &path) {
auto text = Void::FileSystem::read_file(path);
if (!text) {
return std::nullopt;
}
auto parsed = Void::Json::Strict::parse(*text);
if (!parsed) {
return std::nullopt;
}
return std::move(*parsed);
}
std::string serialize_export(const ProviderExport &exp) {
using Util::json_array;
using Util::json_quote;
std::string out =
"{\"schema_version\":1,\"dependency_name\":" + json_quote(exp.dependency_name) +
",\"builder\":" + json_quote(exp.builder) +
",\"input_identity_hash\":" + json_quote(exp.input_identity_hash) + ",\"targets\":{";
bool first = true;
for (const auto &[tname, iface] : exp.targets) {
if (!first) {
out += ',';
}
first = false;
out += json_quote(tname) + ":{\"dependency_name\":" + json_quote(iface.dependency_name) +
",\"target_name\":" + json_quote(iface.target_name) + ",\"include_dirs\":" +
json_array(iface.include_dirs,
[](const std::pair<std::filesystem::path, bool> &inc) {
return "{\"path\":" + json_quote(inc.first.string()) +
",\"is_system\":" +
std::string{inc.second ? "true" : "false"} + '}';
}) +
",\"defines\":" + json_array(iface.defines, json_quote) +
",\"compile_options\":" + json_array(iface.compile_options, json_quote) +
",\"link_options\":" + json_array(iface.link_options, json_quote) +
",\"static_libraries\":" +
json_array(iface.static_libraries,
[](const std::filesystem::path &p) { return json_quote(p.string()); }) +
",\"shared_libraries\":" +
json_array(iface.shared_libraries,
[](const std::filesystem::path &p) { return json_quote(p.string()); }) +
",\"runtime_files\":" +
json_array(iface.runtime_files,
[](const std::filesystem::path &p) { return json_quote(p.string()); }) +
'}';
}
out += "}}\n";
return out;
}
std::optional<ProviderExport> load_cached_export(const std::filesystem::path &export_file,
std::string_view expected_hash) {
auto text = Void::FileSystem::read_file(export_file);
if (!text) {
return std::nullopt;
}
auto parsed = Void::Json::Strict::parse(*text);
if (!parsed) {
return std::nullopt;
}
const auto *root = std::get_if<JsonVal::Object>(&parsed->value);
if (!root) {
return std::nullopt;
}
if (get_str(*root, "input_identity_hash") != expected_hash) {
return std::nullopt;
}
ProviderExport exp;
exp.dependency_name = get_str(*root, "dependency_name");
exp.builder = get_str(*root, "builder");
exp.input_identity_hash = std::string{expected_hash};
exp.from_cache = true;
if (const auto *tv = find_key(*root, "targets")) {
if (const auto *tobj = std::get_if<JsonVal::Object>(&tv->value)) {
for (const auto &[k, val] : *tobj) {
const auto *io = std::get_if<JsonVal::Object>(&val.value);
if (!io) {
continue;
}
Graph::ImportedTargetInterface iface;
iface.dependency_name = get_str(*io, "dependency_name");
iface.target_name = get_str(*io, "target_name");
if (const auto *iv = find_key(*io, "include_dirs")) {
if (const auto *iarr = std::get_if<JsonVal::Array>(&iv->value)) {
for (const auto &item : *iarr) {
if (const auto *inc = std::get_if<JsonVal::Object>(&item.value)) {
iface.include_dirs.emplace_back(get_str(*inc, "path"),
get_bool(*inc, "is_system", false));
}
}
}
}
iface.defines = get_str_array(*io, "defines");
iface.compile_options = get_str_array(*io, "compile_options");
iface.link_options = get_str_array(*io, "link_options");
for (const auto &s : get_str_array(*io, "static_libraries")) {
iface.static_libraries.emplace_back(s);
}
for (const auto &s : get_str_array(*io, "shared_libraries")) {
iface.shared_libraries.emplace_back(s);
}
for (const auto &s : get_str_array(*io, "runtime_files")) {
iface.runtime_files.emplace_back(s);
}
// Verify materialized library artifacts still exist on disk!
std::error_code ec;
for (const auto &lib : iface.static_libraries) {
if (!std::filesystem::is_regular_file(lib, ec)) {
return std::nullopt;
}
}
for (const auto &lib : iface.shared_libraries) {
if (!std::filesystem::is_regular_file(lib, ec)) {
return std::nullopt;
}
}
exp.targets[k] = std::move(iface);
}
}
}
return exp;
}
std::string cmake_option_value(const OptionValue &v) {
return std::visit(
[](const auto &inner) -> std::string {
using T = std::remove_cvref_t<decltype(inner)>;
if constexpr (std::same_as<T, std::string>) {
return inner;
} else if constexpr (std::same_as<T, bool>) {
return inner ? "ON" : "OFF";
} else {
return std::to_string(inner);
}
},
v.value);
}
std::string meson_option_value(const OptionValue &v) {
return std::visit(
[](const auto &inner) -> std::string {
using T = std::remove_cvref_t<decltype(inner)>;
if constexpr (std::same_as<T, std::string>) {
return inner;
} else if constexpr (std::same_as<T, bool>) {
return inner ? "true" : "false";
} else {
return std::to_string(inner);
}
},
v.value);
}
// Imports CMake File API reply (index-*.json -> codemodel-v2 -> target-*.json).
Void::Result::Result<ProviderExport, Void::Result::Error>
run_cmake_provider(const ProviderRequest &request, const std::filesystem::path &build_dir,
const std::string &input_hash, std::stop_token stop) {
auto cmake_bin = Platform::resolve_executable("cmake");
if (!cmake_bin) {
return std::unexpected{make_error(Void::System::SystemErrorCode::not_found,
"CMake provider requires 'cmake' in PATH")};
}
std::error_code ec;
// Fresh build dir whenever input hash changed so foreign timestamp shortcuts cannot retain
// stale objects (Plan 13 acceptance #3).
std::filesystem::remove_all(build_dir, ec);
std::filesystem::create_directories(build_dir / ".cmake" / "api" / "v1" / "query", ec);
(void)Platform::atomic_write_file(
build_dir / ".cmake" / "api" / "v1" / "query" / "codemodel-v2", "", false);
// 1. Configure with isolated profile/toolchain context.
{
Platform::ProcessRequest req;
req.executable = *cmake_bin;
req.arguments = {"-S", request.source.source_dir.string(), "-B", build_dir.string()};
if (Platform::resolve_executable("ninja").has_value()) {
req.arguments.push_back("-G");
req.arguments.push_back("Ninja");
}
req.arguments.push_back("-DCMAKE_CXX_COMPILER=" + request.toolchain.cxx_compiler.string());
const std::string cfg =
(request.profile.name == "release" || request.profile.name == "Release") ? "Release"
: "Debug";
req.arguments.push_back("-DCMAKE_BUILD_TYPE=" + cfg);
for (const auto &[k, v] : request.dependency.options) {
req.arguments.push_back("-D" + k + "=" + cmake_option_value(v));
}
req.timeout = std::chrono::seconds{180};
auto proc = Platform::run_supervised(req, stop);
if (!proc || !proc->succeeded()) {
return std::unexpected{make_error(
Void::System::SystemErrorCode::io_error,
std::format("CMake configure failed for '{}':\n{}", request.dependency.name,
proc ? (proc->stderr_data + proc->stdout_data)
: proc.error().message()))};
}
}
// 2. Build all targets in isolated build directory.
{
Platform::ProcessRequest req;
req.executable = *cmake_bin;
req.arguments = {"--build", build_dir.string()};
req.timeout = std::chrono::seconds{300};
auto proc = Platform::run_supervised(req, stop);
if (!proc || !proc->succeeded()) {
return std::unexpected{
make_error(Void::System::SystemErrorCode::io_error,
std::format("CMake build failed for '{}':\n{}", request.dependency.name,
proc ? (proc->stderr_data + proc->stdout_data)
: proc.error().message()))};
}
}
// 3. Parse CMake File API reply -> codemodel-v2 -> per-target metadata.
const auto reply_dir = build_dir / ".cmake" / "api" / "v1" / "reply";
std::filesystem::path index_file;
for (const auto &ent : std::filesystem::directory_iterator(reply_dir, ec)) {
if (ent.is_regular_file() && ent.path().filename().string().starts_with("index-")) {
index_file = ent.path();
}
}
if (index_file.empty()) {
return std::unexpected{make_error(
Void::System::SystemErrorCode::io_error,
std::format("CMake File API reply missing for '{}'", request.dependency.name))};
}
auto index_json = parse_json_file(index_file);
if (!index_json) {
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
"failed parsing CMake File API index JSON")};
}
const auto *idx_obj = std::get_if<JsonVal::Object>(&index_json->value);
std::string codemodel_file;
if (idx_obj) {
if (const auto *objs = find_key(*idx_obj, "objects")) {
if (const auto *arr = std::get_if<JsonVal::Array>(&objs->value)) {
for (const auto &item : *arr) {
if (const auto *o = std::get_if<JsonVal::Object>(&item.value)) {
if (get_str(*o, "kind") == "codemodel") {
codemodel_file = get_str(*o, "jsonFile");
break;
}
}
}
}
}
}
if (codemodel_file.empty()) {
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
"CMake File API index missing codemodel object")};
}
auto cm_json = parse_json_file(reply_dir / codemodel_file);
if (!cm_json) {
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
"failed parsing CMake codemodel JSON")};
}
struct RawTarget {
std::string id;
std::string name;
std::string type;
std::vector<std::string> dep_ids;
Graph::ImportedTargetInterface iface;
};
std::map<std::string, RawTarget, std::less<>> raw_by_id;
if (const auto *cm_obj = std::get_if<JsonVal::Object>(&cm_json->value)) {
if (const auto *cfgs = find_key(*cm_obj, "configurations")) {
if (const auto *carr = std::get_if<JsonVal::Array>(&cfgs->value);
carr && !carr->empty()) {
if (const auto *cfg0 = std::get_if<JsonVal::Object>(&carr->front().value)) {
if (const auto *tgts = find_key(*cfg0, "targets")) {
if (const auto *tarr = std::get_if<JsonVal::Array>(&tgts->value)) {
for (const auto &tv : *tarr) {
const auto *to = std::get_if<JsonVal::Object>(&tv.value);
if (!to) {
continue;
}
const auto tfile = get_str(*to, "jsonFile");
auto tjson = parse_json_file(reply_dir / tfile);
if (!tjson) {
continue;
}
const auto *td = std::get_if<JsonVal::Object>(&tjson->value);
if (!td) {
continue;
}
RawTarget rt;
rt.id = get_str(*td, "id");
rt.name = get_str(*td, "name");
rt.type = get_str(*td, "type");
rt.iface.dependency_name = request.dependency.name;
rt.iface.target_name = rt.name;
// Extract artifacts.
if (const auto *arts = find_key(*td, "artifacts")) {
if (const auto *aarr =
std::get_if<JsonVal::Array>(&arts->value)) {
for (const auto &av : *aarr) {
if (const auto *ao =
std::get_if<JsonVal::Object>(&av.value)) {
const auto p = build_dir / get_str(*ao, "path");
if (rt.type == "STATIC_LIBRARY") {
rt.iface.static_libraries.push_back(p);
} else if (rt.type == "SHARED_LIBRARY") {
rt.iface.shared_libraries.push_back(p);
rt.iface.runtime_files.push_back(p);
}
}
}
}
}
// Extract compile groups (includes, defines).
if (const auto *cgs = find_key(*td, "compileGroups")) {
if (const auto *cgarr =
std::get_if<JsonVal::Array>(&cgs->value)) {
for (const auto &cgv : *cgarr) {
const auto *cgo =
std::get_if<JsonVal::Object>(&cgv.value);
if (!cgo) {
continue;
}
if (const auto *incs = find_key(*cgo, "includes")) {
if (const auto *iarr =
std::get_if<JsonVal::Array>(&incs->value)) {
for (const auto &iv : *iarr) {
if (const auto *io =
std::get_if<JsonVal::Object>(
&iv.value)) {
const std::filesystem::path ip{
get_str(*io, "path")};
const bool sys =
get_bool(*io, "isSystem", false);
if (!std::ranges::contains(
rt.iface.include_dirs,
std::pair{ip, sys})) {
rt.iface.include_dirs.emplace_back(
ip, sys);
}
}
}
}
}
if (const auto *defs = find_key(*cgo, "defines")) {
if (const auto *darr =
std::get_if<JsonVal::Array>(&defs->value)) {
for (const auto &dv : *darr) {
if (const auto *do_obj =
std::get_if<JsonVal::Object>(
&dv.value)) {
const auto d =
get_str(*do_obj, "define");
if (!d.empty() &&
!std::ranges::contains(
rt.iface.defines, d)) {
rt.iface.defines.push_back(d);
}
}
}
}
}
}
}
}
// Extract dependencies for transitive static archive ordering.
if (const auto *deps = find_key(*td, "dependencies")) {
if (const auto *darr =
std::get_if<JsonVal::Array>(&deps->value)) {
for (const auto &dv : *darr) {
if (const auto *do_obj =
std::get_if<JsonVal::Object>(&dv.value)) {
rt.dep_ids.push_back(get_str(*do_obj, "id"));
}
}
}
}
raw_by_id[rt.id] = std::move(rt);
}
}
}
}
}
}
}
// Resolve transitive static library link order across CMake targets.
ProviderExport exp;
exp.dependency_name = request.dependency.name;
exp.builder = "cmake";
exp.input_identity_hash = input_hash;
for (const auto &[id, rt] : raw_by_id) {
Graph::ImportedTargetInterface resolved = rt.iface;
std::set<std::string> visited{id};
std::vector<std::string> queue = rt.dep_ids;
for (std::size_t qi = 0; qi < queue.size(); ++qi) {
const auto &dep_id = queue[qi];
if (!visited.insert(dep_id).second) {
continue;
}
const auto dit = raw_by_id.find(dep_id);
if (dit == raw_by_id.end()) {
continue;
}
for (const auto &lib : dit->second.iface.static_libraries) {
resolved.static_libraries.push_back(lib);
}
for (const auto &lib : dit->second.iface.shared_libraries) {
resolved.shared_libraries.push_back(lib);
}
for (const auto &inc : dit->second.iface.include_dirs) {
if (!std::ranges::contains(resolved.include_dirs, inc)) {
resolved.include_dirs.push_back(inc);
}
}
for (const auto &sub : dit->second.dep_ids) {
queue.push_back(sub);
}
}
exp.targets[rt.name] = resolved;
exp.targets[request.dependency.name + "::" + rt.name] = resolved;
}
// Apply explicit user overrides if supplied.
for (const auto &[k, v] : request.explicit_overrides) {
exp.targets[k] = v;
}
return exp;
}
// Imports Meson introspection metadata (`meson-info/intro-targets.json`).
Void::Result::Result<ProviderExport, Void::Result::Error>
run_meson_provider(const ProviderRequest &request, const std::filesystem::path &build_dir,
const std::string &input_hash, std::stop_token stop) {
auto meson_bin = Platform::resolve_executable("meson");
if (!meson_bin) {
return std::unexpected{make_error(Void::System::SystemErrorCode::not_found,
"Meson provider requires 'meson' in PATH")};
}
std::error_code ec;
std::filesystem::remove_all(build_dir, ec);
std::filesystem::create_directories(build_dir.parent_path(), ec);
{
Platform::ProcessRequest req;
req.executable = *meson_bin;
req.arguments = {"setup", build_dir.string(), request.source.source_dir.string()};
const std::string btype =
(request.profile.name == "release" || request.profile.name == "Release") ? "release"
: "debug";
req.arguments.push_back("-Dbuildtype=" + btype);
for (const auto &[k, v] : request.dependency.options) {
req.arguments.push_back("-D" + k + "=" + meson_option_value(v));
}
req.environment.set_vars["CXX"] = request.toolchain.cxx_compiler.string();
req.timeout = std::chrono::seconds{180};
auto proc = Platform::run_supervised(req, stop);
if (!proc || !proc->succeeded()) {
return std::unexpected{
make_error(Void::System::SystemErrorCode::io_error,
std::format("Meson setup failed for '{}':\n{}", request.dependency.name,
proc ? (proc->stderr_data + proc->stdout_data)
: proc.error().message()))};
}
}
{
Platform::ProcessRequest req;
req.executable = *meson_bin;
req.arguments = {"compile", "-C", build_dir.string()};
req.timeout = std::chrono::seconds{300};
auto proc = Platform::run_supervised(req, stop);
if (!proc || !proc->succeeded()) {
return std::unexpected{make_error(
Void::System::SystemErrorCode::io_error,
std::format("Meson compile failed for '{}':\n{}", request.dependency.name,
proc ? (proc->stderr_data + proc->stdout_data)
: proc.error().message()))};
}
}
const auto intro_targets = build_dir / "meson-info" / "intro-targets.json";
auto parsed = parse_json_file(intro_targets);
if (!parsed) {
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
"failed parsing Meson intro-targets.json")};
}
ProviderExport exp;
exp.dependency_name = request.dependency.name;
exp.builder = "meson";
exp.input_identity_hash = input_hash;
if (const auto *arr = std::get_if<JsonVal::Array>(&parsed->value)) {
for (const auto &tv : *arr) {
const auto *to = std::get_if<JsonVal::Object>(&tv.value);
if (!to) {
continue;
}
const auto tname = get_str(*to, "name");
const auto ttype = get_str(*to, "type");
Graph::ImportedTargetInterface iface;
iface.dependency_name = request.dependency.name;
iface.target_name = tname;
for (const auto &fname : get_str_array(*to, "filename")) {
if (ttype == "static library") {
iface.static_libraries.emplace_back(fname);
} else if (ttype == "shared library") {
iface.shared_libraries.emplace_back(fname);
iface.runtime_files.emplace_back(fname);
}
}
// Collect include directories from target_sources parameters (-I...) plus source
// include/.
if (const auto *ts = find_key(*to, "target_sources")) {
if (const auto *tsarr = std::get_if<JsonVal::Array>(&ts->value)) {
for (const auto &tsv : *tsarr) {
if (const auto *tso = std::get_if<JsonVal::Object>(&tsv.value)) {
const auto params = get_str_array(*tso, "parameters");
for (std::size_t i = 0; i < params.size(); ++i) {
if (params[i].starts_with("-I") && params[i].size() > 2) {
std::filesystem::path p{params[i].substr(2)};
if (!p.is_absolute()) {
p = (build_dir / p).lexically_normal();
}
if (!std::ranges::contains(iface.include_dirs,
std::pair{p, false})) {
iface.include_dirs.emplace_back(p, false);
}
} else if (params[i] == "-I" && i + 1 < params.size()) {
std::filesystem::path p{params[++i]};
if (!p.is_absolute()) {
p = (build_dir / p).lexically_normal();
}
if (!std::ranges::contains(iface.include_dirs,
std::pair{p, false})) {
iface.include_dirs.emplace_back(p, false);
}
}
}
}
}
}
}
if (std::filesystem::is_directory(request.source.source_dir / "include", ec)) {
const auto inc = (request.source.source_dir / "include").lexically_normal();
if (!std::ranges::contains(iface.include_dirs, std::pair{inc, false})) {
iface.include_dirs.emplace_back(inc, false);
}
}
exp.targets[tname] = iface;
exp.targets[request.dependency.name + "::" + tname] = iface;
}
}
for (const auto &[k, v] : request.explicit_overrides) {
exp.targets[k] = v;
}
return exp;
}
Void::Result::Result<ProviderExport, Void::Result::Error>
run_conan_provider(const ProviderRequest &request, const std::filesystem::path &build_dir,
const std::string &input_hash, std::stop_token stop) {
auto conan_bin = Platform::resolve_executable("conan");
if (!conan_bin) {
return std::unexpected{
make_error(Void::System::SystemErrorCode::not_found,
std::format("Conan2 provider requires 'conan' in PATH for dependency '{}' "
"(prerequisite missing; refusing empty import)",
request.dependency.name))};
}
std::error_code ec;
std::filesystem::create_directories(build_dir, ec);
const auto host_profile = build_dir / "conan_host.profile";
const auto build_profile = build_dir / "conan_build.profile";
const std::string btype =
(request.profile.name == "release" || request.profile.name == "Release") ? "Release"
: "Debug";
const std::string prof_text =
std::format("[settings]\nos={}\narch={}\ncompiler={}\nbuild_type={}\n", request.profile.os,
request.profile.architecture, compiler_name(request.profile.compiler), btype);
(void)Platform::atomic_write_file(host_profile, prof_text, false);
(void)Platform::atomic_write_file(build_profile, prof_text, false);
Platform::ProcessRequest req;
req.executable = *conan_bin;
req.arguments = {"install",
"--requires",
request.dependency.package,
"--profile:host",
host_profile.string(),
"--profile:build",
build_profile.string(),
"--output-folder",
build_dir.string(),
"--format",
"json"};
req.timeout = std::chrono::seconds{300};
auto proc = Platform::run_supervised(req, stop);
if (!proc || !proc->succeeded()) {
return std::unexpected{
make_error(Void::System::SystemErrorCode::io_error,
std::format("Conan2 install failed for '{}':\n{}", request.dependency.name,
proc ? proc->stderr_data : proc.error().message()))};
}
ProviderExport exp;
exp.dependency_name = request.dependency.name;
exp.builder = "conan";
exp.input_identity_hash = input_hash;
for (const auto &[k, v] : request.explicit_overrides) {
exp.targets[k] = v;
}
return exp;
}
} // namespace
std::string compute_provider_input_hash(const ProviderRequest &request) {
Util::Sha256Hasher h;
h.update_length_prefixed("vbs-provider-v1");
h.update_length_prefixed(request.dependency.name);
h.update_length_prefixed(request.dependency.builder);
h.update_length_prefixed(request.source.content_identity_hash);
h.update_length_prefixed(request.profile.name);
h.update_length_prefixed(request.toolchain.identity_hash);
for (const auto &[k, v] : request.dependency.options) {
h.update_length_prefixed(k);
h.update_length_prefixed(cmake_option_value(v));
}
return h.finalize_hex();
}
Void::Result::Result<ProviderExport, Void::Result::Error>
resolve_foreign_provider(const ProviderRequest &request, std::stop_token stop) {
const std::string input_hash = compute_provider_input_hash(request);
const auto isolated_dir =
request.provider_build_root / request.dependency.name / input_hash.substr(0, 16);
const auto export_file = isolated_dir / "provider-export.json";
// Always try validated cache first (in BOTH FullBuild and MetadataOnly modes).
if (auto cached = load_cached_export(export_file, input_hash); cached) {
return *cached;
}
// Strict MetadataOnly boundary (D-026 / Plan 10 / Plan 13):
// NEVER invoke CMake configure, Meson setup, Conan install, or builds!
if (request.mode == ProviderMode::MetadataOnly) {
ProviderExport stale;
stale.dependency_name = request.dependency.name;
stale.builder = request.dependency.builder;
stale.input_identity_hash = input_hash;
stale.stale_needs_build = true;
stale.stale_diagnostic = std::format(
"cached {} provider metadata for '{}' is missing or stale (input={}); "
"run 'vbs build' to configure/build dependencies",
request.dependency.builder, request.dependency.name, input_hash.substr(0, 12));
return stale;
}
const auto lock_path = isolated_dir.parent_path() / (request.dependency.name + ".lock");
auto lock = Platform::FileLock::acquire(lock_path, Platform::LockMode::Exclusive);
if (!lock) {
return std::unexpected{lock.error()};
}
// Re-check cache after acquiring lock in case a peer just finished.
if (auto cached = load_cached_export(export_file, input_hash); cached) {
return *cached;
}
const auto tool_build_dir = isolated_dir / "build";
Void::Result::Result<ProviderExport, Void::Result::Error> res = std::unexpected{
make_error(Void::System::SystemErrorCode::invalid_argument,
std::format("unsupported foreign builder '{}'", request.dependency.builder))};
if (request.dependency.builder == "cmake") {
res = run_cmake_provider(request, tool_build_dir, input_hash, stop);
} else if (request.dependency.builder == "meson") {
res = run_meson_provider(request, tool_build_dir, input_hash, stop);
} else if (request.dependency.builder == "conan") {
res = run_conan_provider(request, tool_build_dir, input_hash, stop);
}
if (!res) {
return std::unexpected{res.error()};
}
// Publish validated provider export atomically!
if (auto w = Platform::atomic_write_file(export_file, serialize_export(*res), true); !w) {
return std::unexpected{w.error()};
}
return res;
}
} // namespace Void::Build::Provider