feat(workspace): add multi-package workspace builds with shared lock and CAS
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:
faumaray committed 2026-12-03 13:07:09 +03:00
1 parent 09c0a91d1d
commit 2970fbe25c
12 files changed
+515 -19

No files matched your search

+114
View File
@@ -28,6 +28,7 @@
#include <cstring>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <thread>
using namespace Void::Build;
@@ -100,6 +101,119 @@ std::filesystem::path locate_vbs_binary() {
} // namespace
VOID_TEST(FullV1Tests, workspace_members_shared_build_and_member_selection) {
const auto vbs_bin = locate_vbs_binary();
Void::Testing::expect(!vbs_bin.empty() && std::filesystem::exists(vbs_bin));
if (vbs_bin.empty() || !std::filesystem::exists(vbs_bin)) {
return;
}
Void::FileSystem::TempDir tmp{"vbs_ws_"};
const auto ws = tmp / "ws";
write_file(ws / "workspace.cpp", R"cpp(#include <Void/Build.hpp>
void workspace(Void::Build::Workspace &ws) {
ws.member("lib", "packages/lib");
ws.member("app", "packages/app");
ws.member("tests", "packages/tests");
}
)cpp");
write_file(ws / "packages" / "lib" / "include" / "core.hpp", "#pragma once\nint ws_core();\n");
write_file(ws / "packages" / "lib" / "src" / "core.cpp",
"#include \"core.hpp\"\nint ws_core() { return 7; }\n");
write_file(ws / "packages" / "lib" / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
p.static_library("libcore")
.sources({"src/core.cpp"})
.include_directory("include", Void::Build::Visibility::Public);
}
)cpp");
write_file(ws / "packages" / "app" / "src" / "main.cpp",
"#include \"core.hpp\"\nint main() { return ws_core() == 7 ? 0 : 1; }\n");
write_file(ws / "packages" / "app" / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
auto lib = p.workspace_dependency("lib").target("libcore");
p.executable("ws_app").sources({"src/main.cpp"}).link(lib);
}
)cpp");
write_file(ws / "packages" / "tests" / "src" / "test.cpp",
"#include \"core.hpp\"\nint main() { return ws_core() == 7 ? 0 : 1; }\n");
write_file(ws / "packages" / "tests" / "build.cpp", R"cpp(#include <Void/Build.hpp>
void build(Void::Build::Project &p) {
auto lib = p.workspace_dependency("lib").target("libcore");
p.test("ws_test").sources({"src/test.cpp"}).link(lib);
}
)cpp");
auto run_vbs = [&](std::vector<std::string> args) {
Platform::ProcessRequest req;
req.executable = vbs_bin;
req.arguments = std::move(args);
return Platform::run_supervised(req);
};
const auto build_dir = tmp / "build";
auto full = run_vbs({"test", "--project", ws.string(), "--build-dir", build_dir.string()});
Void::Testing::expect(full.has_value() && full->succeeded());
if (!full || !full->succeeded()) {
if (full) {
std::cerr << full->stderr_data << '\n';
}
return;
}
Platform::ProcessRequest app_req;
app_req.executable =
build_dir / "members" / "app" / "profiles" / "debug" / "out" / "bin" / "ws_app";
auto app_run = Platform::run_supervised(app_req);
Void::Testing::expect(app_run.has_value() && app_run->succeeded());
// The workspace root owns the unified lock; members never get their own lockfiles.
std::error_code ec;
Void::Testing::expect(std::filesystem::exists(ws / "vbs.lock", ec));
Void::Testing::expect(!std::filesystem::exists(ws / "packages" / "app" / "vbs.lock", ec));
Void::Testing::expect(!std::filesystem::exists(ws / "packages" / "lib" / "vbs.lock", ec));
const auto selected_build = tmp / "build_selected";
auto selected = run_vbs({"build", "--project", ws.string(), "--build-dir",
selected_build.string(), "--member", "app"});
Void::Testing::expect(selected.has_value() && selected->succeeded());
Void::Testing::expect(std::filesystem::exists(selected_build / "members" / "app" / "profiles" /
"debug" / "out" / "bin" / "ws_app"));
Void::Testing::expect(!std::filesystem::exists(selected_build / "members" / "tests"));
// --changed-since selects only the member owning the changed file.
auto git = Platform::resolve_executable("git");
Void::Testing::expect(git.has_value());
if (git) {
auto run_git = [&](std::vector<std::string> args) {
Platform::ProcessRequest req;
req.executable = *git;
req.arguments = {"-C", ws.string()};
req.arguments.insert(req.arguments.end(), args.begin(), args.end());
return Platform::run_supervised(req);
};
auto init = run_git({"init"});
Void::Testing::expect(init.has_value() && init->succeeded());
auto added = run_git({"add", "-A"});
Void::Testing::expect(added.has_value() && added->succeeded());
auto committed = run_git({"-c", "user.email=ws@example.invalid", "-c",
"user.name=Workspace", "commit", "-m", "init"});
Void::Testing::expect(committed.has_value() && committed->succeeded());
write_file(ws / "packages" / "app" / "src" / "main.cpp",
"#include \"core.hpp\"\nint main() { return ws_core() == 7 ? 0 : 2; }\n");
const auto changed_build = tmp / "build_changed";
auto changed = run_vbs({"build", "--project", ws.string(), "--build-dir",
changed_build.string(), "--changed-since", "HEAD"});
Void::Testing::expect(changed.has_value() && changed->succeeded());
Void::Testing::expect(std::filesystem::exists(
changed_build / "members" / "app" / "profiles" / "debug" / "out" / "bin" / "ws_app"));
Void::Testing::expect(!std::filesystem::exists(changed_build / "members" / "tests"));
}
}
// === Plan 09: CompDB projection, selection ticket races, user-file preservation, recovery ===
VOID_TEST(FullV1Tests, compdb_projection_ticket_races_and_user_file_preservation) {
Void::FileSystem::TempDir tmp{"vbs_compdb_"};