#include <dds/util/signal.hpp> | #include <dds/util/signal.hpp> | ||||
#include <range/v3/action/join.hpp> | #include <range/v3/action/join.hpp> | ||||
#include <range/v3/range/conversion.hpp> | |||||
#include <range/v3/view/concat.hpp> | #include <range/v3/view/concat.hpp> | ||||
#include <range/v3/view/group_by.hpp> | #include <range/v3/view/group_by.hpp> | ||||
#include <range/v3/view/transform.hpp> | #include <range/v3/view/transform.hpp> |
#include <dds/util/shlex.hpp> | #include <dds/util/shlex.hpp> | ||||
#include <dds/util/string.hpp> | #include <dds/util/string.hpp> | ||||
#include <range/v3/range/conversion.hpp> | |||||
#include <range/v3/view/filter.hpp> | #include <range/v3/view/filter.hpp> | ||||
#include <range/v3/view/transform.hpp> | #include <range/v3/view/transform.hpp> | ||||
#include <dds/util/log.hpp> | #include <dds/util/log.hpp> | ||||
#include <dds/util/time.hpp> | #include <dds/util/time.hpp> | ||||
#include <range/v3/range/conversion.hpp> | |||||
#include <range/v3/view/transform.hpp> | #include <range/v3/view/transform.hpp> | ||||
using namespace dds; | using namespace dds; |
#include <dds/util/string.hpp> | #include <dds/util/string.hpp> | ||||
#include <dds/util/time.hpp> | #include <dds/util/time.hpp> | ||||
#include <range/v3/range/conversion.hpp> | |||||
#include <range/v3/view/filter.hpp> | #include <range/v3/view/filter.hpp> | ||||
#include <range/v3/view/transform.hpp> | #include <range/v3/view/transform.hpp> | ||||
#include <dds/error/errors.hpp> | #include <dds/error/errors.hpp> | ||||
#include <dds/util/parallel.hpp> | #include <dds/util/parallel.hpp> | ||||
#include <range/v3/range/conversion.hpp> | |||||
#include <range/v3/view/concat.hpp> | #include <range/v3/view/concat.hpp> | ||||
#include <range/v3/view/filter.hpp> | #include <range/v3/view/filter.hpp> | ||||
#include <range/v3/view/join.hpp> | #include <range/v3/view/join.hpp> |
#include <dds/util/algo.hpp> | #include <dds/util/algo.hpp> | ||||
#include <dds/util/log.hpp> | #include <dds/util/log.hpp> | ||||
#include <range/v3/range/conversion.hpp> | |||||
#include <range/v3/view/concat.hpp> | #include <range/v3/view/concat.hpp> | ||||
#include <range/v3/view/filter.hpp> | #include <range/v3/view/filter.hpp> | ||||
#include <range/v3/view/transform.hpp> | #include <range/v3/view/transform.hpp> |
#include <dds/error/errors.hpp> | #include <dds/error/errors.hpp> | ||||
#include <dds/solve/solve.hpp> | #include <dds/solve/solve.hpp> | ||||
#include <dds/util/log.hpp> | #include <dds/util/log.hpp> | ||||
#include <dds/util/ranges.hpp> | |||||
#include <json5/parse_data.hpp> | #include <json5/parse_data.hpp> | ||||
#include <neo/assert.hpp> | #include <neo/assert.hpp> | ||||
}; | }; | ||||
std::vector<package_id> catalog::all() const noexcept { | 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, | _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::views::transform(pair_to_pkg_id) // | ||||
| ranges::to_vector; | | ranges::to_vector; | ||||
} | } | ||||
std::vector<package_id> catalog::by_name(std::string_view sv) const noexcept { | 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, | _stmt_cache, | ||||
R"( | R"( | ||||
SELECT name, version | SELECT name, version | ||||
FROM dds_cat_pkgs | FROM dds_cat_pkgs | ||||
WHERE name = ? | WHERE name = ? | ||||
)"_sql, | )"_sql, | ||||
std::tie(sv)) // | |||||
std::tie(sv))) // | |||||
| ranges::views::transform(pair_to_pkg_id) // | | ranges::views::transform(pair_to_pkg_id) // | ||||
| ranges::to_vector; | | ranges::to_vector; | ||||
} | } | ||||
std::vector<dependency> catalog::dependencies_of(const package_id& pkg) const noexcept { | std::vector<dependency> catalog::dependencies_of(const package_id& pkg) const noexcept { | ||||
dds_log(trace, "Lookup dependencies of {}@{}", pkg.name, pkg.version.to_string()); | 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, | _stmt_cache, | ||||
R"( | R"( | ||||
WITH this_pkg_id AS ( | WITH this_pkg_id AS ( | ||||
WHERE pkg_id IN this_pkg_id | WHERE pkg_id IN this_pkg_id | ||||
ORDER BY dep_name | ORDER BY dep_name | ||||
)"_sql, | )"_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) { | | ranges::views::transform([](auto&& pair) { | ||||
auto& [name, low, high] = pair; | auto& [name, low, high] = pair; | ||||
auto dep | auto dep |
#include <dds/source/root.hpp> | #include <dds/source/root.hpp> | ||||
#include <dds/util/algo.hpp> | #include <dds/util/algo.hpp> | ||||
#include <dds/util/log.hpp> | #include <dds/util/log.hpp> | ||||
#include <dds/util/ranges.hpp> | |||||
#include <range/v3/view/filter.hpp> | #include <range/v3/view/filter.hpp> | ||||
#include <range/v3/view/transform.hpp> | #include <range/v3/view/transform.hpp> | ||||
if (fs::is_directory(pf_libs_dir)) { | if (fs::is_directory(pf_libs_dir)) { | ||||
extend(ret, | 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( | | ranges::views::transform( | ||||
[&](auto p) { return library_root::from_directory(fs::canonical(p)); })); | [&](auto p) { return library_root::from_directory(fs::canonical(p)); })); | ||||
} | } |
#include <dds/source/dist.hpp> | #include <dds/source/dist.hpp> | ||||
#include <dds/util/log.hpp> | #include <dds/util/log.hpp> | ||||
#include <dds/util/paths.hpp> | #include <dds/util/paths.hpp> | ||||
#include <dds/util/ranges.hpp> | |||||
#include <dds/util/string.hpp> | #include <dds/util/string.hpp> | ||||
#include <range/v3/action/sort.hpp> | #include <range/v3/action/sort.hpp> | ||||
using namespace ranges; | 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> { | auto try_read_sdist = [](path_ref p) -> std::optional<sdist> { | ||||
if (starts_with(p.filename().string(), ".")) { | if (starts_with(p.filename().string(), ".")) { | ||||
return std::nullopt; | return std::nullopt; | ||||
} | } | ||||
}; | }; | ||||
return | |||||
auto entries = | |||||
// Get the top-level `name-version` dirs | // Get the top-level `name-version` dirs | ||||
fs::directory_iterator(root) // | |||||
view_safe(fs::directory_iterator(dirpath)) // | |||||
// // Convert each dir into an `sdist` object | // // Convert each dir into an `sdist` object | ||||
| transform(try_read_sdist) // | |||||
| ranges::views::transform(try_read_sdist) // | |||||
// // Drop items that failed to load | // // 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)}; | return {writeable, dirpath, std::move(entries)}; | ||||
} | } | ||||
#include <neo/assert.hpp> | #include <neo/assert.hpp> | ||||
#include <range/v3/algorithm/sort.hpp> | #include <range/v3/algorithm/sort.hpp> | ||||
#include <range/v3/range/conversion.hpp> | |||||
#include <range/v3/view/filter.hpp> | #include <range/v3/view/filter.hpp> | ||||
using namespace dds; | using namespace dds; |
#include "./root.hpp" | #include "./root.hpp" | ||||
#include <dds/util/ranges.hpp> | |||||
#include <range/v3/range/conversion.hpp> | #include <range/v3/range/conversion.hpp> | ||||
#include <range/v3/view/filter.hpp> | #include <range/v3/view/filter.hpp> | ||||
#include <range/v3/view/transform.hpp> | #include <range/v3/view/transform.hpp> | ||||
using namespace ranges::views; | using namespace ranges::views; | ||||
// Collect all source files from the directory | // Collect all source files from the directory | ||||
return // | return // | ||||
fs::recursive_directory_iterator(path) // | |||||
view_safe(fs::recursive_directory_iterator(path)) // | |||||
| filter([](auto&& entry) { return entry.is_regular_file(); }) // | | filter([](auto&& entry) { return entry.is_regular_file(); }) // | ||||
| transform([&](auto&& entry) { return source_file::from_path(entry, path); }) // | | transform([&](auto&& entry) { return source_file::from_path(entry, path); }) // | ||||
// source_file::from_path returns an optional. Drop nulls | // source_file::from_path returns an optional. Drop nulls |
#pragma once | |||||
namespace dds { | |||||
template <typename T> | |||||
constexpr auto& view_safe(T&& t) { | |||||
return t; | |||||
} | |||||
} // namespace dds |