Browse Source

Catalog doesn't do any solving, only the repo with the catalog's help

default_compile_flags
vector-of-bool 5 years ago
parent
commit
6f8b23691b
5 changed files with 36 additions and 66 deletions
  1. +0
    -2
      src/dds/catalog/catalog.hpp
  2. +0
    -36
      src/dds/catalog/catalog.test.cpp
  3. +9
    -3
      src/dds/dds.main.cpp
  4. +25
    -24
      src/dds/repo/repo.cpp
  5. +2
    -1
      src/dds/repo/repo.hpp

+ 0
- 2
src/dds/catalog/catalog.hpp View File

@@ -50,8 +50,6 @@ public:
auto content = dds::slurp_file(json_path);
import_json_str(content);
}

std::vector<package_id> solve_requirements(const std::vector<dependency>& deps) const;
};

} // namespace dds

+ 0
- 36
src/dds/catalog/catalog.test.cpp View File

@@ -90,39 +90,3 @@ TEST_CASE_METHOD(catalog_test_case, "Parse JSON repo") {
== dds::version_range_set{semver::version::parse("4.2.1"),
semver::version::parse("4.3.0")});
}

TEST_CASE_METHOD(catalog_test_case, "Simple solve") {
db.import_json_str(R"({
"version": 1,
"packages": {
"foo": {
"1.2.3": {
"depends": {
"bar": "~4.2.1"
},
"git": {
"url": "http://example.com",
"ref": "master"
}
}
},
"bar": {
"4.2.3": {
"depends": {},
"git": {
"url": "http://example.com",
"ref": "master"
}
}
}
}
})");
auto sln = db.solve_requirements({{"foo",
dds::version_range_set{semver::version::parse("1.0.0"),
semver::version::parse("2.0.0")}}});
REQUIRE(sln.size() == 2);
CHECK(sln[0].name == "foo");
CHECK(sln[0].version == semver::version::parse("1.2.3"));
CHECK(sln[1].name == "bar");
CHECK(sln[1].version == semver::version::parse("4.2.3"));
}

+ 9
- 3
src/dds/dds.main.cpp View File

@@ -529,13 +529,13 @@ struct cli_build {
// Download and build dependencies
// Build the dependencies
auto cat = cat_path.open();
auto solved_deps = cat.solve_requirements(man.dependencies);
params.dep_sdists = dds::repository::with_repository( //
this->repo_path.Get(),
dds::repo_flags::write_lock | dds::repo_flags::create_if_absent,
[&](dds::repository repo) {
// Download dependencies
for (const dds::package_id& pk : solved_deps) {
auto deps = repo.solve(man.dependencies, cat);
for (const dds::package_id& pk : deps) {
auto exists = !!repo.find(pk);
if (!exists) {
spdlog::info("Download dependency: {}", pk.to_string());
@@ -545,7 +545,13 @@ struct cli_build {
repo.add_sdist(tsd.sdist, dds::if_exists::throw_exc);
}
}
return repo.solve(man.dependencies);
return deps //
| ranges::views::transform([&](auto& id) {
auto ptr = repo.find(id);
assert(ptr);
return *ptr;
})
| ranges::to_vector;
});
}
dds::build(params, man);

+ 25
- 24
src/dds/repo/repo.cpp View File

@@ -1,5 +1,6 @@
#include "./repo.hpp"

#include <dds/catalog/catalog.hpp>
#include <dds/sdist.hpp>
#include <dds/solve/solve.hpp>
#include <dds/util/paths.hpp>
@@ -8,7 +9,9 @@
#include <spdlog/spdlog.h>

#include <range/v3/action/sort.hpp>
#include <range/v3/action/unique.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/concat.hpp>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp>

@@ -107,29 +110,27 @@ const sdist* repository::find(const package_id& pkg) const noexcept {
return &*found;
}

std::vector<sdist> repository::solve(const std::vector<dependency>& deps) const {
auto ids = dds::solve(deps,
[&](std::string_view name) -> std::vector<package_id> {
auto items = ranges::views::all(_sdists) //
| ranges::views::filter([&](const sdist& sd) {
return sd.manifest.pkg_id.name == name;
})
| ranges::views::transform(
[](const sdist& sd) { return sd.manifest.pkg_id; })
| ranges::to_vector;
ranges::sort(items, std::less<>{});
return items;
},
[&](const package_id& pkg_id) {
auto found = find(pkg_id);
assert(found);
std::vector<package_id> repository::solve(const std::vector<dependency>& deps,
const catalog& ctlg) const {
return dds::solve(deps,
[&](std::string_view name) -> std::vector<package_id> {
auto mine = ranges::views::all(_sdists) //
| ranges::views::filter([&](const sdist& sd) {
return sd.manifest.pkg_id.name == name;
})
| ranges::views::transform(
[](const sdist& sd) { return sd.manifest.pkg_id; });
auto avail = ctlg.by_name(name);
auto all = ranges::views::concat(mine, avail) | ranges::to_vector;
ranges::sort(all, std::less<>{});
ranges::unique(all, std::less<>{});
return all;
},
[&](const package_id& pkg_id) {
auto found = find(pkg_id);
if (found) {
return found->manifest.dependencies;
});
return ids //
| ranges::views::transform([&](const package_id& pk_id) {
auto found = find(pk_id);
assert(found);
return *found;
}) //
| ranges::to_vector;
}
return ctlg.dependencies_of(pkg_id);
});
}

+ 2
- 1
src/dds/repo/repo.hpp View File

@@ -2,6 +2,7 @@

#include <dds/sdist.hpp>
#include <dds/util/flock.hpp>
#include <dds/catalog/catalog.hpp>
#include <dds/util/fs.hpp>

#include <functional>
@@ -96,7 +97,7 @@ public:
return r;
}

std::vector<sdist> solve(const std::vector<dependency>& deps) const;
std::vector<package_id> solve(const std::vector<dependency>& deps, const catalog&) const;
};

} // namespace dds

Loading…
Cancel
Save