Browse Source

Fix repo loading to support arbitrary filenames

default_compile_flags
vector-of-bool 5 years ago
parent
commit
498a8c055c
2 changed files with 38 additions and 8 deletions
  1. +32
    -5
      src/dds/deps.cpp
  2. +6
    -3
      src/dds/deps.hpp

+ 32
- 5
src/dds/deps.cpp View File

@@ -43,22 +43,49 @@ dependency dependency::parse_depends_string(std::string_view str) {
}

std::vector<sdist> dds::find_dependencies(const repository& repo, const dependency& dep) {
auto all_dists = repo.load_sdists();
detail::sort_sdists(all_dists);
std::vector<sdist> acc;
detail::do_find_deps(repo, dep, acc);
detail::do_find_deps(all_dists, dep, acc);
return acc;
}

void detail::do_find_deps(const repository& repo, const dependency& dep, std::vector<sdist>& sd) {
auto sdist_opt = repo.get_sdist(dep.name, dep.version.to_string());
auto tie_sdist(const sdist& sd) {
return std::tuple(sd.manifest.name, sd.manifest.version.to_string());
}

auto sdist_compare = [](const sdist& lhs, const sdist& rhs) {
return tie_sdist(lhs) < tie_sdist(rhs);
};

void detail::sort_sdists(std::vector<sdist>& sd) { std::sort(sd.begin(), sd.end(), sdist_compare); }

namespace {

const sdist* get_sdist(const std::vector<sdist>& sorted_sds, std::string_view name, std::string_view version) {
auto found = std::partition_point(sorted_sds.begin(), sorted_sds.end(), [&](const auto& candidate) {
return tie_sdist(candidate) < std::tie(name, version);
});
if (found->manifest.name == name && found->manifest.version.to_string() == version) {
return &*found;
}
return nullptr;
}
}

void detail::do_find_deps(const std::vector<sdist>& sdists,
const dependency& dep,
std::vector<sdist>& sd) {
auto sdist_opt = get_sdist(sdists, dep.name, dep.version.to_string());
if (!sdist_opt) {
throw std::runtime_error(
fmt::format("Unable to find dependency to satisfy requirement: {} {}",
dep.name,
dep.version.to_string()));
}
sdist& new_sd = *sdist_opt;
const sdist& new_sd = *sdist_opt;
for (const auto& inner_dep : new_sd.manifest.dependencies) {
do_find_deps(repo, inner_dep, sd);
do_find_deps(sdists, inner_dep, sd);
}
auto insert_point = std::partition_point(sd.begin(), sd.end(), [&](const sdist& cand) {
return cand.path < new_sd.path;

+ 6
- 3
src/dds/deps.hpp View File

@@ -1,6 +1,7 @@
#pragma once

#include <dds/build/plan/full.hpp>
#include <dds/repo/repo.hpp>

#include <semver/version.hpp>

@@ -8,7 +9,6 @@

namespace dds {

class repository;
struct sdist;

enum class version_strength {
@@ -27,7 +27,8 @@ struct dependency {

namespace detail {

void do_find_deps(const repository&, const dependency& dep, std::vector<sdist>& acc);
void do_find_deps(const std::vector<sdist>&, const dependency& dep, std::vector<sdist>& acc);
void sort_sdists(std::vector<sdist>& sds);

} // namespace detail

@@ -36,8 +37,10 @@ std::vector<sdist> find_dependencies(const repository& repo, const dependency& d
template <typename Iter, typename Snt>
inline std::vector<sdist> find_dependencies(const repository& repo, Iter it, Snt stop) {
std::vector<sdist> acc;
auto all_sds = repo.load_sdists();
detail::sort_sdists(all_sds);
while (it != stop) {
detail::do_find_deps(repo, *it++, acc);
detail::do_find_deps(all_sds, *it++, acc);
}
return acc;
}

Loading…
Cancel
Save