[M5] cargoxx add without version (wildcard)

This commit is contained in:
2026-05-10 00:56:15 +00:00
parent 8b87d98083
commit b0818846b2
5 changed files with 41 additions and 18 deletions

View File

@@ -19,15 +19,10 @@ auto cmd_add(const fs::path& project_root, const std::string& name,
"", std::nullopt, std::nullopt,
});
}
if (version_spec.empty()) {
return std::unexpected(util::Error{
util::ErrorCode::ManifestVersionInvalid,
std::format("version required for '{}'", name),
"use the form 'cargoxx add <pkg>@<version>' "
"(auto-resolve against nixhub is deferred)",
std::nullopt, std::nullopt,
});
}
// Empty version → wildcard. The generated flake.nix tracks `nixos-unstable`
// and the linkdb resolver picks whichever recipe is listed first for the
// package. Concrete versions land when the resolver against nixhub.io ships.
const std::string effective_version = version_spec.empty() ? std::string{"*"} : version_spec;
auto manifest_path = project_root / "Cargoxx.toml";
auto m = manifest::parse(manifest_path);
@@ -50,13 +45,13 @@ auto cmd_add(const fs::path& project_root, const std::string& name,
if (!db) {
return std::unexpected(db.error());
}
if (auto check = db->resolve(name, version_spec, components); !check) {
if (auto check = db->resolve(name, effective_version, components); !check) {
return std::unexpected(check.error());
}
m->dependencies.push_back(manifest::Dependency{
.name = name,
.version_spec = version_spec,
.version_spec = effective_version,
.components = std::move(components),
});

View File

@@ -113,11 +113,12 @@ auto check(const Clause& c, const Version& v) -> bool {
auto satisfies(std::string_view version, std::string_view range) -> bool {
range = trim(range);
if (range == "*") {
version = trim(version);
if (range == "*" || version == "*") {
return true;
}
auto v = parse_version(trim(version));
auto v = parse_version(version);
if (!v) {
return false;
}