| @@ -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> | |||
| @@ -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> | |||
| @@ -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; | |||
| @@ -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> | |||
| @@ -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> | |||
| @@ -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> | |||
| @@ -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 | |||
| @@ -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)); })); | |||
| } | |||
| @@ -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)}; | |||
| } | |||
| @@ -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; | |||
| @@ -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 | |||
| @@ -0,0 +1,10 @@ | |||
| #pragma once | |||
| namespace dds { | |||
| template <typename T> | |||
| constexpr auto& view_safe(T&& t) { | |||
| return t; | |||
| } | |||
| } // namespace dds | |||