[M5+] drop curated linkdb JSON; SQLite overlay is the single source

This commit is contained in:
2026-05-13 23:28:36 +00:00
parent 5db915e576
commit 653b9fbb8d
12 changed files with 193 additions and 656 deletions

View File

@@ -1,6 +1,7 @@
#include <catch2/catch_test_macros.hpp>
import cargoxx.cli;
import cargoxx.linkdb;
import cargoxx.manifest;
import cargoxx.lockfile;
import cargoxx.util;
@@ -8,6 +9,8 @@ import std;
using cargoxx::cli::cmd_build;
using cargoxx::cli::cmd_new;
using cargoxx::linkdb::Database;
using cargoxx::linkdb::Recipe;
using cargoxx::util::ErrorCode;
namespace manifest = cargoxx::manifest;
namespace lockfile = cargoxx::lockfile;
@@ -43,6 +46,13 @@ auto add_dep(const std::filesystem::path& root, const std::string& name,
REQUIRE(manifest::write(*m, path).has_value());
}
auto seed_recipe(const std::filesystem::path& overlay, const std::string& package,
const std::string& version_range, const Recipe& r) {
auto db = Database::open(overlay);
REQUIRE(db.has_value());
REQUIRE(db->add_manual(package, version_range, r).has_value());
}
} // namespace
TEST_CASE("cmd_build generates files for a no-deps binary project",
@@ -82,12 +92,19 @@ TEST_CASE("cmd_build generates files for a library project", "[cli][build]") {
REQUIRE(cmake_text.find("add_executable") == std::string::npos);
}
TEST_CASE("cmd_build resolves a curated dep into find_package + targets",
TEST_CASE("cmd_build resolves a manually-seeded dep into find_package + targets",
"[cli][build]") {
auto parent = fresh_dir();
REQUIRE(cmd_new("app", false, parent).has_value());
auto root = parent / "app";
add_dep(root, "fmt", "10.2.0");
seed_recipe(overlay_path(parent), "fmt", ">=10.0.0",
Recipe{
.nixpkgs_attr = "fmt_10",
.find_package = "fmt CONFIG REQUIRED",
.targets = {"fmt::fmt"},
.source = "manual",
});
auto r = cmd_build(root, true, false, std::nullopt, overlay_path(parent));
REQUIRE(r.has_value());
@@ -100,35 +117,33 @@ TEST_CASE("cmd_build resolves a curated dep into find_package + targets",
REQUIRE(flake_text.find("pkgs.fmt_10") != std::string::npos);
}
TEST_CASE("cmd_build resolves a componentized dep", "[cli][build]") {
auto parent = fresh_dir();
REQUIRE(cmd_new("app", false, parent).has_value());
auto root = parent / "app";
add_dep(root, "abseil-cpp", "20240116.0", {"strings", "base"});
auto r = cmd_build(root, true, false, std::nullopt, overlay_path(parent));
REQUIRE(r.has_value());
auto cmake_text = read_file(root / "build" / "CMakeLists.txt");
REQUIRE(cmake_text.find("find_package(absl CONFIG REQUIRED)") !=
std::string::npos);
REQUIRE(cmake_text.find("absl::strings") != std::string::npos);
REQUIRE(cmake_text.find("absl::base") != std::string::npos);
}
TEST_CASE("cmd_build synthesizes a lockfile entry per dep", "[cli][build]") {
auto parent = fresh_dir();
REQUIRE(cmd_new("app", false, parent).has_value());
auto root = parent / "app";
add_dep(root, "fmt", "10.2.0");
add_dep(root, "spdlog", "1.13.0");
seed_recipe(overlay_path(parent), "fmt", ">=10.0.0",
Recipe{
.nixpkgs_attr = "fmt_10",
.find_package = "fmt CONFIG REQUIRED",
.targets = {"fmt::fmt"},
.source = "manual",
});
seed_recipe(overlay_path(parent), "spdlog", "*",
Recipe{
.nixpkgs_attr = "spdlog",
.find_package = "spdlog CONFIG REQUIRED",
.targets = {"spdlog::spdlog"},
.source = "manual",
});
auto r = cmd_build(root, true, false, std::nullopt, overlay_path(parent));
REQUIRE(r.has_value());
auto lock = lockfile::parse(root / "Cargoxx.lock");
REQUIRE(lock.has_value());
REQUIRE(lock->packages.size() == 3); // root + fmt + spdlog
REQUIRE(lock->packages.size() == 3);
REQUIRE(lock->packages[0].name == "app");
REQUIRE(lock->packages[0].dependencies.size() == 2);
}
@@ -172,6 +187,13 @@ TEST_CASE("cmd_build is idempotent — second run produces identical files",
REQUIRE(cmd_new("app", false, parent).has_value());
auto root = parent / "app";
add_dep(root, "fmt", "10.2.0");
seed_recipe(overlay_path(parent), "fmt", ">=10.0.0",
Recipe{
.nixpkgs_attr = "fmt_10",
.find_package = "fmt CONFIG REQUIRED",
.targets = {"fmt::fmt"},
.source = "manual",
});
REQUIRE(cmd_build(root, true, false, std::nullopt, overlay_path(parent)).has_value());
auto first_cmake = read_file(root / "build" / "CMakeLists.txt");