Bläddra i källkod

Fix repo loading to support arbitrary filenames

default_compile_flags
vector-of-bool 5 år sedan
förälder
incheckning
498a8c055c
2 ändrade filer med 38 tillägg och 8 borttagningar
  1. +32
    -5
      src/dds/deps.cpp
  2. +6
    -3
      src/dds/deps.hpp

+ 32
- 5
src/dds/deps.cpp Visa fil

} }


std::vector<sdist> dds::find_dependencies(const repository& repo, const dependency& dep) { 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; std::vector<sdist> acc;
detail::do_find_deps(repo, dep, acc);
detail::do_find_deps(all_dists, dep, acc);
return 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) { if (!sdist_opt) {
throw std::runtime_error( throw std::runtime_error(
fmt::format("Unable to find dependency to satisfy requirement: {} {}", fmt::format("Unable to find dependency to satisfy requirement: {} {}",
dep.name, dep.name,
dep.version.to_string())); dep.version.to_string()));
} }
sdist& new_sd = *sdist_opt;
const sdist& new_sd = *sdist_opt;
for (const auto& inner_dep : new_sd.manifest.dependencies) { 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) { auto insert_point = std::partition_point(sd.begin(), sd.end(), [&](const sdist& cand) {
return cand.path < new_sd.path; return cand.path < new_sd.path;

+ 6
- 3
src/dds/deps.hpp Visa fil

#pragma once #pragma once


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


#include <semver/version.hpp> #include <semver/version.hpp>




namespace dds { namespace dds {


class repository;
struct sdist; struct sdist;


enum class version_strength { enum class version_strength {


namespace detail { 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 } // namespace detail


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

Laddar…
Avbryt
Spara