@@ -160,8 +160,8 @@ void catalog::store(const package_info& pkg) { | |||
sqlite3::exec(new_dep_st, | |||
std::forward_as_tuple(db_pkg_id, | |||
dep.name, | |||
dep.version.to_string(), | |||
"[placeholder]")); | |||
dep.version_range.low().to_string(), | |||
dep.version_range.high().to_string())); | |||
} | |||
} | |||
@@ -196,23 +196,11 @@ std::optional<package_info> catalog::get(const package_id& pk_id) const noexcept | |||
assert(git_url); | |||
assert(git_ref); | |||
auto deps = sqlite3::exec_iter<std::string, std::string>( // | |||
_stmt_cache, | |||
R"( | |||
SELECT dep_name, low | |||
FROM dds_cat_pkg_deps | |||
WHERE pkg_id = ? | |||
)"_sql, | |||
std::tie(pkg_id)) | |||
| ranges::views::transform([](auto&& pair) { | |||
const auto& [name, ver] = pair; | |||
return dependency{name, semver::version::parse(ver)}; | |||
}) // | |||
| ranges::to_vector; | |||
auto deps = dependencies_of(pk_id); | |||
return package_info{ | |||
pk_id, | |||
deps, | |||
std::move(deps), | |||
git_remote_listing{ | |||
*git_url, | |||
*git_ref, | |||
@@ -239,6 +227,7 @@ std::vector<package_id> catalog::by_name(std::string_view sv) const noexcept { | |||
std::vector<dependency> catalog::dependencies_of(const package_id& pkg) const noexcept { | |||
return sqlite3::exec_iter<std::string, | |||
std::string, | |||
std::string>( // | |||
_stmt_cache, | |||
R"( | |||
@@ -247,15 +236,17 @@ std::vector<dependency> catalog::dependencies_of(const package_id& pkg) const no | |||
FROM dds_cat_pkgs | |||
WHERE name = ? AND version = ? | |||
) | |||
SELECT dep_name, low | |||
SELECT dep_name, low, high | |||
FROM dds_cat_pkg_deps | |||
WHERE pkg_id IN this_pkg_id | |||
ORDER BY dep_name | |||
)"_sql, | |||
std::forward_as_tuple(pkg.name, pkg.version.to_string())) // | |||
| ranges::views::transform([](auto&& pair) { | |||
auto& [name, ver] = pair; | |||
return dependency{name, semver::version::parse(ver)}; | |||
auto& [name, low, high] = pair; | |||
return dependency{name, | |||
semver::range(semver::version::parse(low), | |||
semver::version::parse(high))}; | |||
}) // | |||
| ranges::to_vector; | |||
} | |||
@@ -310,7 +301,7 @@ void catalog::import_json_str(std::string_view content) { | |||
dep_name)); | |||
info.deps.push_back({ | |||
std::string(dep_name), | |||
semver::version::parse(std::string(dep_version)), | |||
semver::range::parse(std::string(dep_version)), | |||
}); | |||
} | |||
@@ -34,8 +34,8 @@ TEST_CASE_METHOD(catalog_test_case, "Package requirements") { | |||
db.store(dds::package_info{ | |||
dds::package_id{"foo", semver::version::parse("1.2.3")}, | |||
{ | |||
{"bar", semver::version::parse("1.2.5")}, | |||
{"baz", semver::version::parse("5.3.2")}, | |||
{"bar", semver::range::parse("=1.2.5")}, | |||
{"baz", semver::range::parse("^5.3.2")}, | |||
}, | |||
dds::git_remote_listing{"http://example.com", "master", std::nullopt}, | |||
}); | |||
@@ -55,7 +55,7 @@ TEST_CASE_METHOD(catalog_test_case, "Parse JSON repo") { | |||
"foo": { | |||
"1.2.3": { | |||
"depends": { | |||
"bar": "4.2.1" | |||
"bar": "~4.2.1" | |||
}, | |||
"git": { | |||
"url": "http://example.com", | |||
@@ -72,5 +72,5 @@ TEST_CASE_METHOD(catalog_test_case, "Parse JSON repo") { | |||
auto deps = db.dependencies_of(pkgs[0]); | |||
REQUIRE(deps.size() == 1); | |||
CHECK(deps[0].name == "bar"); | |||
CHECK(deps[0].version == semver::version::parse("4.2.1")); | |||
CHECK(deps[0].version_range == semver::range::parse("~4.2.1")); | |||
} |
@@ -227,7 +227,8 @@ struct cli_catalog { | |||
std::vector<dds::dependency> deps; | |||
for (const auto& dep : this->deps.Get()) { | |||
auto dep_id = dds::package_id::parse(dep); | |||
deps.push_back({dep_id.name, dep_id.version}); | |||
assert(false && "TODO"); | |||
// deps.push_back({dep_id.name, dep_id.version}); | |||
} | |||
dds::package_info info{ident, std::move(deps), {}}; | |||
@@ -540,7 +541,7 @@ struct cli_deps { | |||
int run() { | |||
const auto man = parent.load_package_manifest(); | |||
for (const auto& dep : man.dependencies) { | |||
std::cout << dep.name << " " << dep.version.to_string() << '\n'; | |||
std::cout << dep.name << " " << dep.version_range.to_string() << '\n'; | |||
} | |||
return 0; | |||
} | |||
@@ -566,22 +567,24 @@ struct cli_deps { | |||
dds::repo_flags::write_lock | dds::repo_flags::create_if_absent, | |||
[&](dds::repository repo) { | |||
for (auto& dep : man.dependencies) { | |||
auto exists = !!repo.find(dep.name, dep.version); | |||
if (!exists) { | |||
spdlog::info("Pull remote: {}@{}", dep.name, dep.version.to_string()); | |||
auto opt_pkg = catalog.get(dds::package_id{dep.name, dep.version}); | |||
if (opt_pkg) { | |||
auto tsd = dds::get_package_sdist(*opt_pkg); | |||
repo.add_sdist(tsd.sdist, dds::if_exists::ignore); | |||
} else { | |||
spdlog::error("No remote listing for {}@{}", | |||
dep.name, | |||
dep.version.to_string()); | |||
failed = true; | |||
} | |||
} else { | |||
spdlog::info("Okay: {} {}", dep.name, dep.version.to_string()); | |||
} | |||
assert(false && "Not ready yet"); | |||
// auto exists = !!repo.find(dep.name, dep.version_range); | |||
// if (!exists) { | |||
// spdlog::info("Pull remote: {}@{}", dep.name, | |||
// dep.version_range.to_string()); auto opt_pkg = | |||
// catalog.get(dds::package_id{dep.name, dep.version_range}); if | |||
// (opt_pkg) { | |||
// auto tsd = dds::get_package_sdist(*opt_pkg); | |||
// repo.add_sdist(tsd.sdist, dds::if_exists::ignore); | |||
// } else { | |||
// spdlog::error("No remote listing for {}@{}", | |||
// dep.name, | |||
// dep.version_range.to_string()); | |||
// failed = true; | |||
// } | |||
// } else { | |||
// spdlog::info("Okay: {} {}", dep.name, dep.version_range.to_string()); | |||
// } | |||
} | |||
}); | |||
if (failed) { |
@@ -29,17 +29,16 @@ dependency dependency::parse_depends_string(std::string_view str) { | |||
auto name = trim_view(std::string_view(str_begin, str_iter - str_begin)); | |||
auto version_str = trim_view(std::string_view(str_iter, str_end - str_iter)); | |||
semver::version version; | |||
try { | |||
version = semver::version::parse(version_str); | |||
} catch (const semver::invalid_version&) { | |||
throw std::runtime_error( | |||
fmt::format("Invalid version string '{}' in dependency declaration '{}' (Should be a " | |||
"semver string. See https://semver.org/ for info)", | |||
version_str, | |||
str)); | |||
auto rng = semver::range::parse_restricted(version_str); | |||
return dependency{std::string(name), rng}; | |||
} catch (const semver::invalid_range&) { | |||
throw std::runtime_error(fmt::format( | |||
"Invalid version range string '{}' in dependency declaration '{}' (Should be a " | |||
"semver range string. See https://semver.org/ for info)", | |||
version_str, | |||
str)); | |||
} | |||
return dependency{std::string(name), version}; | |||
} | |||
std::vector<sdist> dds::find_dependencies(const repository& repo, const dependency& dep) { | |||
@@ -49,12 +48,12 @@ std::vector<sdist> dds::find_dependencies(const repository& repo, const dependen | |||
} | |||
void detail::do_find_deps(const repository& repo, const dependency& dep, std::vector<sdist>& sd) { | |||
auto sdist_opt = repo.find(dep.name, dep.version); | |||
auto sdist_opt = repo.find(dep.name, dep.version_range.low()); | |||
if (!sdist_opt) { | |||
throw std::runtime_error( | |||
fmt::format("Unable to find dependency to satisfy requirement: {} {}", | |||
dep.name, | |||
dep.version.to_string())); | |||
dep.version_range.to_string())); | |||
} | |||
const sdist& new_sd = *sdist_opt; | |||
for (const auto& inner_dep : new_sd.manifest.dependencies) { |
@@ -2,6 +2,7 @@ | |||
#include <dds/build/plan/full.hpp> | |||
#include <semver/range.hpp> | |||
#include <semver/version.hpp> | |||
#include <string_view> | |||
@@ -19,8 +20,8 @@ enum class version_strength { | |||
}; | |||
struct dependency { | |||
std::string name; | |||
semver::version version; | |||
std::string name; | |||
semver::range version_range; | |||
static dependency parse_depends_string(std::string_view str); | |||
}; |