/* Crafter® Build Copyright (C) 2026 Catcrafts® Catcrafts.net LGPL-3.0-only. */ import std; import Crafter.Build; #include "../_shared/TestUtil.h" namespace fs = std::filesystem; using namespace std::chrono_literals; using namespace TestUtil; using namespace Crafter; int main() { try { fs::path src = fs::current_path() / "tests" / "Incremental" / "inner"; Configuration cfg = LoadFixture("Incremental", src); fs::path work = fs::current_path(); auto cold = BuildOnce(cfg); if (!cold.result.empty()) { std::println(std::cerr, "cold build failed:\n{}", cold.result); return 1; } fs::path buildDir = work / "build" / "hello-mod-x86_64-pc-linux-gnu-native"; fs::path greeterObj = buildDir / "Greeter.o"; fs::path mainObj = buildDir / "main_impl.o"; if (!fs::exists(greeterObj) || !fs::exists(mainObj)) { std::println(std::cerr, "expected .o files missing after cold build"); return 1; } auto greeter_t1 = fs::last_write_time(greeterObj); auto main_t1 = fs::last_write_time(mainObj); auto noop = BuildOnce(cfg); if (!noop.result.empty()) { std::println(std::cerr, "no-op rebuild failed:\n{}", noop.result); return 1; } if (fs::last_write_time(greeterObj) != greeter_t1) { std::println(std::cerr, "no-op rebuild regenerated Greeter.o"); return 1; } if (fs::last_write_time(mainObj) != main_t1) { std::println(std::cerr, "no-op rebuild regenerated main_impl.o"); return 1; } // Touch main.cpp: only main_impl.o should regenerate. fs::last_write_time(work / "main.cpp", std::chrono::file_clock::now() + 2s); auto touched = BuildOnce(cfg); if (!touched.result.empty()) { std::println(std::cerr, "rebuild after touch failed:\n{}", touched.result); return 1; } if (fs::last_write_time(greeterObj) != greeter_t1) { std::println(std::cerr, "touching main.cpp unnecessarily rebuilt Greeter.o"); return 1; } if (fs::last_write_time(mainObj) <= main_t1) { std::println(std::cerr, "touching main.cpp did NOT rebuild main_impl.o"); return 1; } return 0; } catch (const std::exception& e) { std::println(std::cerr, "test exception: {}", e.what()); return 1; } }