feat: add Plan 20 Slice 1 CMake native translation, self-test smoke target, VL-009 VOID_TEST check, and warm-cache hardening
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 5s
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 5s
This commit is contained in:
1 parent
363fb8200e
commit
d3d2666965
19 files changed
+1466
-65
No files matched your search
@@ -51,7 +51,9 @@ foreach(profile IN ITEMS debug release)
|
||||
expect_json(static_library targets 4 kind)
|
||||
expect_json(vbs-registry targets 5 name)
|
||||
expect_json(executable targets 5 kind)
|
||||
foreach(index IN ITEMS 0 1 3 4 5)
|
||||
expect_json(vbs_self_smoke targets 6 name)
|
||||
expect_json(test targets 6 kind)
|
||||
foreach(index IN ITEMS 0 1 3 4 5 6)
|
||||
if(compiler STREQUAL "gcc")
|
||||
expect_json(-Wduplicated-cond targets "${index}" compile_options 2)
|
||||
else()
|
||||
|
||||
@@ -51,7 +51,7 @@ Void::Testing::Test example_records_sources_links_and_pin() {
|
||||
Void::Build::Project project{Void::Build::default_profiles().resolve(
|
||||
"debug", Void::Build::CompilerFamily::Gcc, "linux", "x86_64")};
|
||||
build(project);
|
||||
Void::Testing::expect_eq(project.targets().size(), std::size_t{6});
|
||||
Void::Testing::expect_eq(project.targets().size(), std::size_t{7});
|
||||
Void::Testing::expect_eq(project.targets().at(0).name, std::string{"VoidBuildSdk"});
|
||||
Void::Testing::expect_eq(project.targets().at(0).sources.at(0).path,
|
||||
std::string{"src/Build.cpp"});
|
||||
@@ -66,6 +66,8 @@ Void::Testing::Test example_records_sources_links_and_pin() {
|
||||
std::string{"VoidBuildCore"});
|
||||
Void::Testing::expect_eq(project.targets().at(4).name, std::string{"VoidBuildRegistry"});
|
||||
Void::Testing::expect_eq(project.targets().at(5).name, std::string{"vbs-registry"});
|
||||
Void::Testing::expect_eq(project.targets().at(6).name, std::string{"vbs_self_smoke"});
|
||||
Void::Testing::expect_eq(project.targets().at(6).kind, Void::Build::TargetKind::Test);
|
||||
Void::Testing::expect_eq(project.dependencies().at(0).revision,
|
||||
std::string{"3e254055e081a104f08df68dde39711bc7813518"});
|
||||
Void::Testing::expect_eq(project.dependencies().at(0).builder, std::string{"cmake"});
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/Provider/Provider.hpp>
|
||||
#include <Void/Build/Provider/Translator.hpp>
|
||||
#include <Void/Build/Snapshot/Snapshot.hpp>
|
||||
#include <Void/Build/State/StateStore.hpp>
|
||||
#include <Void/Build/Toolchain/Driver.hpp>
|
||||
@@ -1053,3 +1054,163 @@ Void::Testing::Test graph_lowering_modules_partitions_unity_header_units_and_san
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// === Plan 20 Slice 1: Bounded native CMake graph translation, equivalence, mutations & fallback
|
||||
// ===
|
||||
Void::Testing::Test plan20_bounded_cmake_translation_equivalence_mutations_and_fallback() {
|
||||
Void::FileSystem::TempDir tmp{"vbs_plan20_"};
|
||||
auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(),
|
||||
Toolchain::host_architecture_name());
|
||||
auto tc = Toolchain::discover_and_probe(ctx, tmp / "probes");
|
||||
Void::Testing::expect(tc.has_value());
|
||||
if (!tc)
|
||||
return;
|
||||
|
||||
// 1. Supported bounded CMake project (static library + executable with public/private includes,
|
||||
// defines, and transitive link): configure ONLY, translate natively, execute via VBS (zero
|
||||
// `cmake --build`), and compare output against official `cmake --build`!
|
||||
const auto cm_src = tmp / "supported_cmake";
|
||||
write_file(cm_src / "CMakeLists.txt", R"cmake(
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(p20_math LANGUAGES CXX)
|
||||
add_library(p20_core STATIC src/core.cpp)
|
||||
target_include_directories(p20_core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
target_compile_definitions(p20_core PUBLIC P20_BONUS=7)
|
||||
add_executable(p20_cli src/main.cpp)
|
||||
target_link_libraries(p20_cli PRIVATE p20_core)
|
||||
)cmake");
|
||||
write_file(cm_src / "include" / "p20_core.hpp",
|
||||
"#pragma once\ninline constexpr int kP20Base = 35;\nint p20_compute();\n");
|
||||
write_file(cm_src / "src" / "core.cpp",
|
||||
"#include \"p20_core.hpp\"\nint p20_compute() { return kP20Base + P20_BONUS; }\n");
|
||||
write_file(cm_src / "src" / "main.cpp",
|
||||
"#include \"p20_core.hpp\"\n#include <iostream>\n"
|
||||
"int main() { std::cout << p20_compute() << '\\n'; return 0; }\n");
|
||||
|
||||
DependencyRecord dep;
|
||||
dep.name = "p20_math";
|
||||
dep.source_kind = DependencySourceKind::Path;
|
||||
dep.location = cm_src.string();
|
||||
dep.builder = "cmake";
|
||||
|
||||
auto mat = Package::materialize_dependency_source(dep, {tmp / "cache", tmp.path(), false, {}});
|
||||
Void::Testing::expect(mat.has_value());
|
||||
if (!mat)
|
||||
return;
|
||||
|
||||
auto state = State::StateStore::open(tmp / "native_state");
|
||||
Void::Testing::expect(state.has_value());
|
||||
if (!state)
|
||||
return;
|
||||
|
||||
Provider::ProviderRequest preq{
|
||||
dep, *mat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
|
||||
auto native_res = Provider::resolve_cmake_with_translation(
|
||||
preq, *state, Provider::TranslationPolicy::RequireNative);
|
||||
Void::Testing::expect(native_res.has_value());
|
||||
if (!native_res)
|
||||
return;
|
||||
Void::Testing::expect(native_res->executed_natively);
|
||||
Void::Testing::expect(native_res->audit.is_supported());
|
||||
Void::Testing::expect(native_res->exported.targets.contains("p20_math::p20_core"));
|
||||
|
||||
// Run the natively translated executable (built with ZERO `cmake --build`!) and verify stdout!
|
||||
const auto input_hash = Provider::compute_provider_input_hash(preq);
|
||||
const auto slot_dir = tmp / "prov" / ("translate_p20_math_" + input_hash.substr(0, 16));
|
||||
const auto native_exe =
|
||||
slot_dir / "native-build" / "profiles" / "debug" / "out" / "bin" / "p20_cli";
|
||||
Void::Testing::expect(std::filesystem::exists(native_exe));
|
||||
|
||||
Platform::ProcessRequest run_native;
|
||||
run_native.executable = native_exe;
|
||||
auto out_native = Platform::run_supervised(run_native);
|
||||
Void::Testing::expect(out_native.has_value() && out_native->succeeded());
|
||||
if (out_native) {
|
||||
Void::Testing::expect_eq(out_native->stdout_data, std::string{"42\n"});
|
||||
}
|
||||
|
||||
// Compare against official foreign CMake build output to prove equivalence!
|
||||
auto foreign_res = Provider::resolve_foreign_provider(preq);
|
||||
Void::Testing::expect(foreign_res.has_value() &&
|
||||
foreign_res->targets.contains("p20_math::p20_core"));
|
||||
|
||||
// 2. Adversarial timestamp-preserved header mutation: restore old mtime on `p20_core.hpp`,
|
||||
// re-execute the translated native graph, and verify VBS depfile+SHA-256 rebuilds `p20_cli`
|
||||
// with the updated constant (99 + 7 = 106)!
|
||||
const auto hdr = cm_src / "include" / "p20_core.hpp";
|
||||
auto old_meta = Platform::stat_lstat(hdr);
|
||||
Void::Testing::expect(old_meta.has_value());
|
||||
write_file(hdr, "#pragma once\ninline constexpr int kP20Base = 99;\nint p20_compute();\n");
|
||||
if (old_meta) {
|
||||
(void)Platform::set_canonical_mtime(hdr, old_meta->mtime_sec);
|
||||
}
|
||||
|
||||
auto translated2 = Provider::translate_cmake_to_native_graph(preq, slot_dir / "cmake-configure",
|
||||
slot_dir / "native-build");
|
||||
Void::Testing::expect(translated2.has_value());
|
||||
if (translated2) {
|
||||
auto exec2 = Execution::execute_graph(translated2->graph, *state);
|
||||
Void::Testing::expect(exec2.has_value() && exec2->succeeded && exec2->executed_count > 0);
|
||||
auto out_mutated = Platform::run_supervised(run_native);
|
||||
Void::Testing::expect(out_mutated.has_value() && out_mutated->succeeded());
|
||||
if (out_mutated) {
|
||||
Void::Testing::expect_eq(out_mutated->stdout_data, std::string{"106\n"});
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Unsupported CMake construct (`add_custom_command` generated header + `UTILITY` target):
|
||||
// audit MUST detect and report explicitly (never silently drop!), `RequireNative` MUST fail,
|
||||
// and `FallbackToForeignBuild` MUST cleanly delegate to foreign CMake and build the artifact!
|
||||
const auto unsup_src = tmp / "unsupported_cmake";
|
||||
write_file(unsup_src / "gen.cmake", "file(WRITE \"${OUT}\" \"#define P20_GEN_VAL 55\\n\")\n");
|
||||
write_file(unsup_src / "CMakeLists.txt", R"cmake(
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
project(p20_gen LANGUAGES CXX)
|
||||
add_custom_command(
|
||||
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp"
|
||||
COMMAND ${CMAKE_COMMAND} -DOUT=${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp -P ${CMAKE_CURRENT_SOURCE_DIR}/gen.cmake
|
||||
)
|
||||
add_custom_target(run_gen DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp")
|
||||
add_library(p20_genlib STATIC src/genlib.cpp "${CMAKE_CURRENT_BINARY_DIR}/gen_val.hpp")
|
||||
add_dependencies(p20_genlib run_gen)
|
||||
target_include_directories(p20_genlib PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
)cmake");
|
||||
write_file(unsup_src / "src" / "genlib.cpp",
|
||||
"#include \"gen_val.hpp\"\nint p20_gen_fn() { return P20_GEN_VAL; }\n");
|
||||
|
||||
DependencyRecord udep;
|
||||
udep.name = "p20_gen";
|
||||
udep.source_kind = DependencySourceKind::Path;
|
||||
udep.location = unsup_src.string();
|
||||
udep.builder = "cmake";
|
||||
|
||||
auto umat =
|
||||
Package::materialize_dependency_source(udep, {tmp / "cache", tmp.path(), false, {}});
|
||||
Void::Testing::expect(umat.has_value());
|
||||
if (!umat)
|
||||
return;
|
||||
|
||||
Provider::ProviderRequest ureq{
|
||||
udep, *umat, ctx, *tc, tmp / "prov", Provider::ProviderMode::FullBuild, {}};
|
||||
|
||||
// RequireNative MUST fail with explicit unsupported-construct diagnostics!
|
||||
auto req_native = Provider::resolve_cmake_with_translation(
|
||||
ureq, *state, Provider::TranslationPolicy::RequireNative);
|
||||
Void::Testing::expect(!req_native.has_value());
|
||||
if (!req_native) {
|
||||
Void::Testing::expect(req_native.error().message().find("unsupported") !=
|
||||
std::string::npos);
|
||||
}
|
||||
|
||||
// FallbackToForeignBuild MUST audit unsupported, log, and cleanly build via foreign CMake!
|
||||
auto fb_res = Provider::resolve_cmake_with_translation(
|
||||
ureq, *state, Provider::TranslationPolicy::FallbackToForeignBuild);
|
||||
Void::Testing::expect_eq(fb_res ? std::string{} : fb_res.error().message(), std::string{});
|
||||
Void::Testing::expect(fb_res.has_value());
|
||||
if (fb_res) {
|
||||
Void::Testing::expect(!fb_res->executed_natively);
|
||||
Void::Testing::expect(!fb_res->audit.is_supported());
|
||||
Void::Testing::expect(!fb_res->audit.unsupported.empty());
|
||||
Void::Testing::expect(fb_res->exported.targets.contains("p20_gen::p20_genlib"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <Void/Build.hpp>
|
||||
#include <Void/Build/Package/Solver.hpp>
|
||||
#include <Void/Build/Package/Toml.hpp>
|
||||
#include <Void/Build/Util/Sha256.hpp>
|
||||
#include <Void/Configuration/Argparse.hpp>
|
||||
#include <Void/Text/Semver.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
// 1. SDK graph evaluation & deterministic UTF-8 JSON.
|
||||
auto ctx = Void::Build::default_profiles().resolve("debug", Void::Build::CompilerFamily::Gcc,
|
||||
"Linux", "x86_64");
|
||||
Void::Build::Project p{ctx};
|
||||
p.executable("smoke_app").sources({"src/main.cpp"});
|
||||
if (p.to_json().find("\"smoke_app\"") == std::string::npos) {
|
||||
std::cerr << "SelfBuildSmoke: SDK JSON serialization failed\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 2. Void::Crypto built-in FIPS 180-4 SHA-256 (VL-007).
|
||||
if (Void::Build::Util::sha256_hex("abc") !=
|
||||
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad") {
|
||||
std::cerr << "SelfBuildSmoke: Void::Crypto SHA-256 mismatch\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 3. Void::Data::Toml 1.0 parser (VL-002).
|
||||
auto toml = Void::Build::Package::parse_toml("[dependencies.demo]\nversion = \"^1.0\"\n");
|
||||
if (!toml || !toml->contains("dependencies")) {
|
||||
std::cerr << "SelfBuildSmoke: Void::Data::Toml parse failed\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 4. Void::Semver shorthand range parser (VL-013).
|
||||
auto range = Void::Semver::parse_range("^1.0");
|
||||
auto v12 = Void::Semver::parse_strict("1.2.3");
|
||||
auto v20 = Void::Semver::parse_strict("2.0.0");
|
||||
if (!range || !v12 || !v20 || !range->contains(*v12) || range->contains(*v20)) {
|
||||
std::cerr << "SelfBuildSmoke: Void::Semver shorthand range failed\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 5. Void::Argparse::Parser native subcommands & auto-generated help (VL-011).
|
||||
Void::Argparse::Parser parser{"smoke", "Self-build smoke CLI."};
|
||||
parser.subcommand("run", "Run smoke command");
|
||||
const char *argv_help[] = {"smoke", "--help"};
|
||||
const auto help_res = parser.parse_detailed(2, argv_help);
|
||||
if (!help_res.is_help() || help_res.message.find("Commands:") == std::string::npos) {
|
||||
std::cerr << "SelfBuildSmoke: Void::Argparse generated help failed\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "SelfBuildSmoke: all 5 VoidBuildSystem + VoidLibrary runtime checks passed\n";
|
||||
return 0;
|
||||
}
|
||||
@@ -339,3 +339,98 @@ void build(Void::Build::Project &p) {
|
||||
std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
// VL-009: Verify VoidLibrary's upstream self-registering `VOID_TEST(suite, name)` macro works
|
||||
// purely with `g++` (zero CMake AND zero external scanner) including equal-basename files!
|
||||
Void::Testing::Test native_void_test_macro_zero_cmake_and_basename_collisions() {
|
||||
const std::filesystem::path void_src{VBS_VOID_SOURCE_PATH};
|
||||
Void::Testing::expect(std::filesystem::is_directory(void_src));
|
||||
|
||||
Void::FileSystem::TempDir tmp{"vbs_vl009_"};
|
||||
const auto build_dir = tmp / "build";
|
||||
const auto src_dir = tmp / "tests";
|
||||
|
||||
// Two distinct subdirectories containing files with the exact same basename `Unit.cpp`!
|
||||
write_file(src_dir / "alpha" / "Unit.cpp", R"cpp(
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
VOID_TEST(AlphaSuite, addition_works) {
|
||||
Void::Testing::expect_eq(2 + 2, 4);
|
||||
}
|
||||
)cpp");
|
||||
write_file(src_dir / "beta" / "Unit.cpp", R"cpp(
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
VOID_TEST(BetaSuite, multiplication_works) {
|
||||
Void::Testing::expect_eq(6 * 7, 42);
|
||||
}
|
||||
)cpp");
|
||||
|
||||
auto ctx = default_profiles().resolve("debug", CompilerFamily::Gcc, Toolchain::host_os_name(),
|
||||
Toolchain::host_architecture_name());
|
||||
auto tc = Toolchain::discover_and_probe(ctx, build_dir / ".vbs" / "probes");
|
||||
Void::Testing::expect(tc.has_value());
|
||||
if (!tc)
|
||||
return;
|
||||
|
||||
Project proj{ctx};
|
||||
auto void_libs = Recipes::add_void_library_native(proj, void_src, {"Testing"});
|
||||
|
||||
// Zero CMake AND zero `vbs gen-tests` scanner — just compile the two Unit.cpp files directly!
|
||||
auto exe = proj.executable("vl009_native_tests");
|
||||
exe.cxx_standard(CxxStandard::Cxx26)
|
||||
.sources(SourceSet::file((src_dir / "alpha" / "Unit.cpp").string()))
|
||||
.sources(SourceSet::file((src_dir / "beta" / "Unit.cpp").string()))
|
||||
.compile_option("-freflection")
|
||||
.link(void_libs.modules.at("Testing"));
|
||||
|
||||
auto desc = Graph::ProjectDescription::from_json(proj.to_json());
|
||||
Void::Testing::expect(desc.has_value());
|
||||
if (!desc)
|
||||
return;
|
||||
auto graph =
|
||||
Graph::lower_project_graph(*desc, *tc, {tmp.path(), build_dir, nullptr, {}, 32768});
|
||||
Void::Testing::expect(graph.has_value());
|
||||
auto state = State::StateStore::open(build_dir / ".vbs");
|
||||
Void::Testing::expect(state.has_value());
|
||||
if (!graph || !state)
|
||||
return;
|
||||
|
||||
auto exec =
|
||||
Execution::execute_graph(*graph, *state, {4, true, true, {"vl009_native_tests"}, {}, {}});
|
||||
Void::Testing::expect(exec.has_value() && exec->succeeded);
|
||||
if (!exec || !exec->succeeded)
|
||||
return;
|
||||
|
||||
const auto bin = build_dir / "profiles" / "debug" / "out" / "bin" / "vl009_native_tests";
|
||||
Platform::ProcessRequest list_req;
|
||||
list_req.executable = bin;
|
||||
list_req.arguments = {"--list", "--no-color"};
|
||||
auto listed = Platform::run_supervised(list_req);
|
||||
Void::Testing::expect(listed.has_value() && listed->succeeded());
|
||||
if (listed) {
|
||||
Void::Testing::expect(listed->stdout_data.find("addition_works") != std::string::npos);
|
||||
Void::Testing::expect(listed->stdout_data.find("multiplication_works") !=
|
||||
std::string::npos);
|
||||
}
|
||||
|
||||
Platform::ProcessRequest filter_req;
|
||||
filter_req.executable = bin;
|
||||
filter_req.arguments = {"--no-color", "--filter", "multiplication_works"};
|
||||
auto filtered = Platform::run_supervised(filter_req);
|
||||
Void::Testing::expect(filtered.has_value() && filtered->succeeded());
|
||||
if (filtered) {
|
||||
Void::Testing::expect(filtered->stdout_data.find("1 tests:") != std::string::npos);
|
||||
}
|
||||
|
||||
Platform::ProcessRequest all_req;
|
||||
all_req.executable = bin;
|
||||
all_req.arguments = {"--no-color"};
|
||||
auto ran = Platform::run_supervised(all_req);
|
||||
Void::Testing::expect(ran.has_value() && ran->succeeded());
|
||||
if (ran) {
|
||||
Void::Testing::expect(ran->stdout_data.find("2 tests:") != std::string::npos);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user