feat(workspace): add multi-package workspace builds with shared lock and CAS
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
- SDK: Workspace/workspace() declaration plus Project::workspace_dependency() - Frontend: workspace.cpp discovery/evaluation alongside build.cpp - Main: per-member builds sharing the root vbs.lock and build/.vbs CAS, --member and --changed-since selection - Cross-member native linking; member builds do not steal the root compile_commands.json alias - Path-dependency snapshots exclude generated editor metadata - Verified in Docker GCC 16: 8/8 CTest suites; 3-member workspace fixture with unified lockfile
This commit is contained in:
1 parent
09c0a91d1d
commit
2970fbe25c
12 files changed
+515
-19
No files matched your search
+143
-8
@@ -36,6 +36,7 @@
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
@@ -504,6 +505,11 @@ struct BuildCmdOptions {
|
||||
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::filesystem::path> lock_root;
|
||||
std::optional<std::filesystem::path> state_dir;
|
||||
bool publish_editor_selection{true};
|
||||
bool no_cache{false};
|
||||
bool locked{false};
|
||||
bool offline{false};
|
||||
@@ -587,7 +593,7 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto state = State::StateStore::open(build_root / ".vbs");
|
||||
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;
|
||||
@@ -608,7 +614,7 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
Void::Log::info("Cache", "Using shared remote action cache at {}", remote_cache_url);
|
||||
}
|
||||
|
||||
const auto lock_path = project_root / "vbs.lock";
|
||||
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';
|
||||
@@ -813,7 +819,8 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
Editor::PublishOptions popts;
|
||||
popts.project_root = project_root;
|
||||
popts.build_root = build_root;
|
||||
popts.update_selection = (*opts.editor_profile == prof_name);
|
||||
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;
|
||||
@@ -888,6 +895,130 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
|
||||
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;
|
||||
(void)::setenv(env_name.c_str(), canonical.c_str(), 1);
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -1997,6 +2128,9 @@ int main(int argc, char **argv) {
|
||||
.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("--remote-cache", "", "Shared HTTP action cache URL (or VBS_REMOTE_CACHE)",
|
||||
build_opts.remote_cache_arg)
|
||||
.option("--remote-cache-token-env", "",
|
||||
@@ -2229,11 +2363,12 @@ int main(int argc, char **argv) {
|
||||
: Void::Log::Level::Info);
|
||||
ConsoleLogGuard log_guard{log_level};
|
||||
|
||||
if (cmd == "build") {
|
||||
return execute_build_or_test(std::move(build_opts), false);
|
||||
}
|
||||
if (cmd == "test") {
|
||||
return execute_build_or_test(std::move(build_opts), true);
|
||||
if (cmd == "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);
|
||||
|
||||
Reference in new issue
Block a user