Browse Source

Range v0.11 compatibility

default_compile_flags
vector-of-bool 4 years ago
parent
commit
fe92d539cd
12 changed files with 47 additions and 35 deletions
  1. +1
    -0
      src/dds.main.cpp
  2. +1
    -0
      src/dds/build/file_deps.cpp
  3. +1
    -0
      src/dds/build/plan/archive.cpp
  4. +1
    -0
      src/dds/build/plan/compile_exec.cpp
  5. +1
    -0
      src/dds/build/plan/full.cpp
  6. +1
    -0
      src/dds/build/plan/library.cpp
  7. +9
    -8
      src/dds/catalog/catalog.cpp
  8. +3
    -2
      src/dds/library/root.cpp
  9. +15
    -24
      src/dds/repo/repo.cpp
  10. +1
    -0
      src/dds/source/dist.cpp
  11. +3
    -1
      src/dds/source/root.cpp
  12. +10
    -0
      src/dds/util/ranges.hpp

+ 1
- 0
src/dds.main.cpp View File

@@ -12,6 +12,7 @@
#include <dds/util/signal.hpp>

#include <range/v3/action/join.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/concat.hpp>
#include <range/v3/view/group_by.hpp>
#include <range/v3/view/transform.hpp>

+ 1
- 0
src/dds/build/file_deps.cpp View File

@@ -6,6 +6,7 @@
#include <dds/util/shlex.hpp>
#include <dds/util/string.hpp>

#include <range/v3/range/conversion.hpp>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp>


+ 1
- 0
src/dds/build/plan/archive.cpp View File

@@ -5,6 +5,7 @@
#include <dds/util/log.hpp>
#include <dds/util/time.hpp>

#include <range/v3/range/conversion.hpp>
#include <range/v3/view/transform.hpp>

using namespace dds;

+ 1
- 0
src/dds/build/plan/compile_exec.cpp View File

@@ -8,6 +8,7 @@
#include <dds/util/string.hpp>
#include <dds/util/time.hpp>

#include <range/v3/range/conversion.hpp>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp>


+ 1
- 0
src/dds/build/plan/full.cpp View File

@@ -5,6 +5,7 @@
#include <dds/error/errors.hpp>
#include <dds/util/parallel.hpp>

#include <range/v3/range/conversion.hpp>
#include <range/v3/view/concat.hpp>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/join.hpp>

+ 1
- 0
src/dds/build/plan/library.cpp View File

@@ -3,6 +3,7 @@
#include <dds/util/algo.hpp>
#include <dds/util/log.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>

+ 9
- 8
src/dds/catalog/catalog.cpp View File

@@ -7,6 +7,7 @@
#include <dds/error/errors.hpp>
#include <dds/solve/solve.hpp>
#include <dds/util/log.hpp>
#include <dds/util/ranges.hpp>

#include <json5/parse_data.hpp>
#include <neo/assert.hpp>
@@ -372,31 +373,31 @@ auto pair_to_pkg_id = [](auto&& pair) {
};

std::vector<package_id> catalog::all() const noexcept {
return sqlite3::exec_iter<std::string, std::string>( //
return view_safe(sqlite3::exec_iter<std::string, std::string>( //
_stmt_cache,
"SELECT name, version FROM dds_cat_pkgs"_sql)
"SELECT name, version FROM dds_cat_pkgs"_sql))
| ranges::views::transform(pair_to_pkg_id) //
| ranges::to_vector;
}

std::vector<package_id> catalog::by_name(std::string_view sv) const noexcept {
return sqlite3::exec_iter<std::string, std::string>( //
return view_safe(sqlite3::exec_iter<std::string, std::string>( //
_stmt_cache,
R"(
SELECT name, version
FROM dds_cat_pkgs
WHERE name = ?
)"_sql,
std::tie(sv)) //
std::tie(sv))) //
| ranges::views::transform(pair_to_pkg_id) //
| ranges::to_vector;
}

std::vector<dependency> catalog::dependencies_of(const package_id& pkg) const noexcept {
dds_log(trace, "Lookup dependencies of {}@{}", pkg.name, pkg.version.to_string());
return sqlite3::exec_iter<std::string,
std::string,
std::string>( //
return view_safe(sqlite3::exec_iter<std::string,
std::string,
std::string>( //
_stmt_cache,
R"(
WITH this_pkg_id AS (
@@ -409,7 +410,7 @@ std::vector<dependency> catalog::dependencies_of(const package_id& pkg) const no
WHERE pkg_id IN this_pkg_id
ORDER BY dep_name
)"_sql,
std::forward_as_tuple(pkg.name, pkg.version.to_string())) //
std::forward_as_tuple(pkg.name, pkg.version.to_string()))) //
| ranges::views::transform([](auto&& pair) {
auto& [name, low, high] = pair;
auto dep

+ 3
- 2
src/dds/library/root.cpp View File

@@ -5,6 +5,7 @@
#include <dds/source/root.hpp>
#include <dds/util/algo.hpp>
#include <dds/util/log.hpp>
#include <dds/util/ranges.hpp>

#include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp>
@@ -104,8 +105,8 @@ std::vector<library_root> dds::collect_libraries(path_ref root) {

if (fs::is_directory(pf_libs_dir)) {
extend(ret,
fs::directory_iterator(pf_libs_dir) //
| ranges::views::filter(has_library_dirs) //
view_safe(fs::directory_iterator(pf_libs_dir)) //
| ranges::views::filter(has_library_dirs) //
| ranges::views::transform(
[&](auto p) { return library_root::from_directory(fs::canonical(p)); }));
}

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

@@ -6,6 +6,7 @@
#include <dds/source/dist.hpp>
#include <dds/util/log.hpp>
#include <dds/util/paths.hpp>
#include <dds/util/ranges.hpp>
#include <dds/util/string.hpp>

#include <range/v3/action/sort.hpp>
@@ -19,12 +20,16 @@ using namespace dds;

using namespace ranges;

namespace {
void repository::_log_blocking(path_ref dirpath) noexcept {
dds_log(warn, "Another process has the repository directory locked [{}]", dirpath.string());
dds_log(warn, "Waiting for repository to be released...");
}

void repository::_init_repo_dir(path_ref dirpath) noexcept { fs::create_directories(dirpath); }

auto load_sdists(path_ref root) {
using namespace ranges;
using namespace ranges::views;
fs::path repository::default_local_path() noexcept { return dds_data_dir() / "repo"; }

repository repository::_open_for_directory(bool writeable, path_ref dirpath) {
auto try_read_sdist = [](path_ref p) -> std::optional<sdist> {
if (starts_with(p.filename().string(), ".")) {
return std::nullopt;
@@ -40,30 +45,16 @@ auto load_sdists(path_ref root) {
}
};

return
auto entries =
// Get the top-level `name-version` dirs
fs::directory_iterator(root) //
view_safe(fs::directory_iterator(dirpath)) //
// // Convert each dir into an `sdist` object
| transform(try_read_sdist) //
| ranges::views::transform(try_read_sdist) //
// // Drop items that failed to load
| filter([](auto&& opt) { return opt.has_value(); }) //
| transform([](auto&& opt) { return *opt; }) //
;
}

} // namespace
| ranges::views::filter([](auto&& opt) { return opt.has_value(); }) //
| ranges::views::transform([](auto&& opt) { return *opt; }) //
| to<sdist_set>();

void repository::_log_blocking(path_ref dirpath) noexcept {
dds_log(warn, "Another process has the repository directory locked [{}]", dirpath.string());
dds_log(warn, "Waiting for repository to be released...");
}

void repository::_init_repo_dir(path_ref dirpath) noexcept { fs::create_directories(dirpath); }

fs::path repository::default_local_path() noexcept { return dds_data_dir() / "repo"; }

repository repository::_open_for_directory(bool writeable, path_ref dirpath) {
sdist_set entries = load_sdists(dirpath) | to<sdist_set>();
return {writeable, dirpath, std::move(entries)};
}


+ 1
- 0
src/dds/source/dist.cpp View File

@@ -10,6 +10,7 @@

#include <neo/assert.hpp>
#include <range/v3/algorithm/sort.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/filter.hpp>

using namespace dds;

+ 3
- 1
src/dds/source/root.cpp View File

@@ -1,5 +1,7 @@
#include "./root.hpp"

#include <dds/util/ranges.hpp>

#include <range/v3/range/conversion.hpp>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp>
@@ -10,7 +12,7 @@ std::vector<source_file> source_root::collect_sources() const {
using namespace ranges::views;
// Collect all source files from the directory
return //
fs::recursive_directory_iterator(path) //
view_safe(fs::recursive_directory_iterator(path)) //
| filter([](auto&& entry) { return entry.is_regular_file(); }) //
| transform([&](auto&& entry) { return source_file::from_path(entry, path); }) //
// source_file::from_path returns an optional. Drop nulls

+ 10
- 0
src/dds/util/ranges.hpp View File

@@ -0,0 +1,10 @@
#pragma once

namespace dds {

template <typename T>
constexpr auto& view_safe(T&& t) {
return t;
}

} // namespace dds

Loading…
Cancel
Save