Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify MPool Interface #3177

Merged
merged 16 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,13 @@ macro(libmamba_create_target target_name linkage output_name)

target_link_libraries(
${target_name}
PUBLIC
fmt::fmt-header-only
spdlog::spdlog_header_only
yaml-cpp::yaml-cpp
PUBLIC fmt::fmt-header-only spdlog::spdlog_header_only yaml-cpp::yaml-cpp
PRIVATE
reproc
reproc++
simdjson::simdjson_static
solv::libsolv_static
solv::libsolvext_static
PRIVATE reproc reproc++ simdjson::simdjson_static
)

if(UNIX)
Expand Down Expand Up @@ -589,8 +589,6 @@ macro(libmamba_create_target target_name linkage output_name)
# only version to avoid chasing after the correct fmt version mathching the one used
# in the bundle
spdlog::spdlog_header_only
solv::libsolv
solv::libsolvext
PRIVATE
${LibArchive_LIBRARIES}
${CURL_LIBRARIES}
Expand All @@ -600,6 +598,8 @@ macro(libmamba_create_target target_name linkage output_name)
reproc++
simdjson::simdjson
zstd::libzstd_shared
solv::libsolv
solv::libsolvext
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dance-crazy-carey-jim-carrey

)
endif()

Expand Down Expand Up @@ -749,8 +749,6 @@ install(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${LIBMAMBA_CMAKECONFIG_INSTALL_DIR}
)
# Need to install the FindLibsolv for the installed target to work
install(FILES "../cmake/modules/FindLibsolv.cmake" DESTINATION ${LIBMAMBA_CMAKECONFIG_INSTALL_DIR})

install(
EXPORT ${PROJECT_NAME}Targets
Expand Down
9 changes: 7 additions & 2 deletions libmamba/include/mamba/api/channel_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
namespace mamba
{
class Context;
class ChannelContext;
class MPool;
class MultiPackageCache;

expected_t<void, mamba_aggregated_error>
load_channels(Context& ctx, MPool& pool, MultiPackageCache& package_caches);
auto load_channels( //
Context& ctx,
ChannelContext& channel_context,
MPool& pool,
MultiPackageCache& package_caches
) -> expected_t<void, mamba_aggregated_error>;
}
#endif
9 changes: 4 additions & 5 deletions libmamba/include/mamba/core/palette.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace mamba
{

struct Palette
{
/** Something that is possible or exsists. */
Expand Down Expand Up @@ -45,21 +44,21 @@ namespace mamba
fmt::text_style progress_bar_extracted;

/** A Palette with no colors at all. */
static constexpr Palette no_color();
static constexpr auto no_color() -> Palette;
/** A Palette with terminal 4 bit colors. */
static constexpr Palette terminal();
static constexpr auto terminal() -> Palette;
};

/*******************************
* Implementation of Palette *
*******************************/

inline constexpr Palette Palette::no_color()
inline constexpr auto Palette::no_color() -> Palette
{
return {};
}

inline constexpr Palette Palette::terminal()
inline constexpr auto Palette::terminal() -> Palette
{
return {
/* .success= */ fmt::fg(fmt::terminal_color::green),
Expand Down
49 changes: 30 additions & 19 deletions libmamba/include/mamba/core/pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
#ifndef MAMBA_CORE_POOL_HPP
#define MAMBA_CORE_POOL_HPP

#include <functional>
#include <memory>
#include <optional>

#include <solv/pooltypes.h>

#include "mamba/core/error_handling.hpp"
#include "mamba/solver/libsolv/parameters.hpp"
#include "mamba/solver/libsolv/repo_info.hpp"
#include "mamba/specs/channel.hpp"
#include "mamba/specs/package_info.hpp"
#include "mamba/util/loop_control.hpp"

namespace mamba
{
class ChannelContext;
class Context;
class PrefixData;
class SubdirData;
Expand All @@ -40,6 +39,12 @@ namespace mamba
class MatchSpec;
}

namespace solver::libsolv
{
class Solver;
class UnSolvable;
}

/**
* Pool of solvable involved in resolving en environment.
*
Expand All @@ -52,26 +57,20 @@ namespace mamba
{
public:

MPool(Context& ctx, ChannelContext& channel_context);
~MPool();

void set_debuglevel();
void create_whatprovides();
using logger_type = std::function<void(solver::libsolv::LogLevel, std::string_view)>;

std::vector<Id> select_solvables(Id id, bool sorted = false) const;
Id matchspec2id(const specs::MatchSpec& ms);
MPool(specs::ChannelResolveParams channel_params);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MPool(specs::ChannelResolveParams channel_params);
explicit MPool(specs::ChannelResolveParams channel_params);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do it in the next PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it in the next PR

~MPool();

std::optional<specs::PackageInfo> id2pkginfo(Id solv_id) const;
std::optional<std::string> dep2str(Id dep_id) const;
[[nodiscard]] auto channel_params() const -> const specs::ChannelResolveParams&;

// TODO: (TMP) This is not meant to be public but is needed for a transition period
solv::ObjPool& pool();
const solv::ObjPool& pool() const;
void set_logger(logger_type callback);

auto add_repo_from_repodata_json(
const fs::u8path& path,
std::string_view url,
solver::libsolv::PipAsPythonDependency add = solver::libsolv::PipAsPythonDependency::No,
solver::libsolv::UseOnlyTarBz2 only_tar = solver::libsolv::UseOnlyTarBz2::No,
solver::libsolv::RepodataParser parser = solver::libsolv::RepodataParser::Mamba
) -> expected_t<solver::libsolv::RepoInfo>;

Expand Down Expand Up @@ -109,7 +108,7 @@ namespace mamba
void
set_repo_priority(solver::libsolv::RepoInfo repo, solver::libsolv::Priorities priorities);

void remove_repo(::Id repo_id, bool reuse_ids);
void remove_repo(solver::libsolv::RepoInfo repo);

template <typename Func>
void for_each_package_in_repo(solver::libsolv::RepoInfo repo, Func&&) const;
Expand All @@ -120,14 +119,20 @@ namespace mamba
template <typename Func>
void for_each_package_depending_on(const specs::MatchSpec& ms, Func&&);

ChannelContext& channel_context() const;
const Context& context() const;
/** A wrapper struct to fine-grain controll who can access the raw repr of the Pool. */
class Impl
{
[[nodiscard]] static auto get(MPool& pool) -> solv::ObjPool&;
[[nodiscard]] static auto get(const MPool& pool) -> const solv::ObjPool&;

friend class solver::libsolv::Solver;
friend class solver::libsolv::UnSolvable;
};

private:

struct MPoolData;


/**
* Make MPool behave like a shared_ptr (with move and copy).
*
Expand All @@ -142,6 +147,10 @@ namespace mamba
*/
std::shared_ptr<MPoolData> m_data;

friend class Impl;
auto pool() -> solv::ObjPool&;
[[nodiscard]] auto pool() const -> const solv::ObjPool&;

auto add_repo_from_packages_impl_pre(std::string_view name) -> solver::libsolv::RepoInfo;
void add_repo_from_packages_impl_loop(
const solver::libsolv::RepoInfo& repo,
Expand All @@ -167,6 +176,8 @@ namespace mamba
};

// TODO machinery functions in separate files
void add_spdlog_logger_to_pool(MPool& pool);

auto load_subdir_in_pool(const Context& ctx, MPool& pool, const SubdirData& subdir)
-> expected_t<solver::libsolv::RepoInfo>;

Expand Down
14 changes: 14 additions & 0 deletions libmamba/include/mamba/solver/libsolv/parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ namespace mamba::solver::libsolv
Yes = true,
};

enum class UseOnlyTarBz2
{
No = false,
Yes = true,
};

enum class LogLevel
{
Debug,
Warning,
Error,
Fatal,
};

struct Priorities
{
using value_type = int;
Expand Down
10 changes: 8 additions & 2 deletions libmamba/include/mamba/solver/libsolv/unsolvable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace mamba
{
class MPool;
class Palette;

namespace solv
{
Expand Down Expand Up @@ -46,8 +47,13 @@ namespace mamba::solver::libsolv

[[nodiscard]] auto problems_graph(const MPool& pool) const -> ProblemsGraph;

auto explain_problems_to(MPool& pool, std::ostream& out) const -> std::ostream&;
[[nodiscard]] auto explain_problems(MPool& pool) const -> std::string;
auto explain_problems_to( //
MPool& pool,
std::ostream& out,
const Palette& palette
) const -> std::ostream&;

[[nodiscard]] auto explain_problems(MPool& pool, const Palette& palette) const -> std::string;

private:

Expand Down
1 change: 0 additions & 1 deletion libmamba/libmambaConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ find_dependency(tl-expected)
find_dependency(nlohmann_json)
find_dependency(yaml-cpp)
find_dependency(reproc++)
find_dependency(Libsolv MODULE)

if(NOT (TARGET libmamba-dyn OR TARGET libmamba-static))
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
Expand Down
43 changes: 26 additions & 17 deletions libmamba/src/api/channel_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,26 @@
#include "mamba/core/pool.hpp"
#include "mamba/core/prefix_data.hpp"
#include "mamba/core/subdirdata.hpp"
#include "mamba/download/downloader.hpp"
#include "mamba/solver/libsolv/repo_info.hpp"
#include "mamba/specs/package_info.hpp"

namespace mamba
{
namespace
{
solver::libsolv::RepoInfo
create_repo_from_pkgs_dir(const Context& ctx, MPool& pool, const fs::u8path& pkgs_dir)
auto create_repo_from_pkgs_dir(
const Context& ctx,
ChannelContext& channel_context,
MPool& pool,
const fs::u8path& pkgs_dir
) -> solver::libsolv::RepoInfo
{
if (!fs::exists(pkgs_dir))
{
// TODO : us tl::expected mechanis
throw std::runtime_error("Specified pkgs_dir does not exist\n");
}
auto sprefix_data = PrefixData::create(pkgs_dir, pool.channel_context());
auto sprefix_data = PrefixData::create(pkgs_dir, channel_context);
if (!sprefix_data)
{
throw std::runtime_error("Specified pkgs_dir does not exist\n");
Expand Down Expand Up @@ -106,8 +109,13 @@ namespace mamba
}
}

expected_t<void, mamba_aggregated_error>
load_channels_impl(Context& ctx, MPool& pool, MultiPackageCache& package_caches, bool is_retry)
auto load_channels_impl(
Context& ctx,
ChannelContext& channel_context,
MPool& pool,
MultiPackageCache& package_caches,
bool is_retry
) -> expected_t<void, mamba_aggregated_error>
{
std::vector<SubdirData> subdirs;

Expand All @@ -121,12 +129,12 @@ namespace mamba

for (const auto& mirror : ctx.mirrored_channels)
{
for (auto channel : pool.channel_context().make_channel(mirror.first, mirror.second))
for (auto channel : channel_context.make_channel(mirror.first, mirror.second))
{
create_mirrors(channel, ctx.mirrors);
create_subdirs(
ctx,
pool.channel_context(),
channel_context,
channel,
package_caches,
subdirs,
Expand All @@ -145,7 +153,7 @@ namespace mamba
// TODO: C++20, replace with contains
if (ctx.mirrored_channels.find(location) == ctx.mirrored_channels.end())
{
for (auto channel : pool.channel_context().make_channel(location))
for (auto channel : channel_context.make_channel(location))
{
if (channel.is_package())
{
Expand All @@ -157,7 +165,7 @@ namespace mamba
create_mirrors(channel, ctx.mirrors);
create_subdirs(
ctx,
pool.channel_context(),
channel_context,
channel,
package_caches,
subdirs,
Expand Down Expand Up @@ -203,7 +211,7 @@ namespace mamba
LOG_INFO << "Creating repo from pkgs_dir for offline";
for (const auto& c : ctx.pkgs_dirs)
{
create_repo_from_pkgs_dir(ctx, pool, c);
create_repo_from_pkgs_dir(ctx, channel_context, pool, c);
}
}
std::string prev_channel;
Expand Down Expand Up @@ -255,22 +263,23 @@ namespace mamba
if (!ctx.offline && !is_retry)
{
LOG_WARNING << "Encountered malformed repodata.json cache. Redownloading.";
return load_channels_impl(ctx, pool, package_caches, true);
return load_channels_impl(ctx, channel_context, pool, package_caches, true);
}
error_list.push_back(mamba_error(
error_list.emplace_back(
"Could not load repodata. Cache corrupted?",
mamba_error_code::repodata_not_loaded
));
);
}
using return_type = expected_t<void, mamba_aggregated_error>;
return error_list.empty() ? return_type()
: return_type(make_unexpected(std::move(error_list)));
}
}

expected_t<void, mamba_aggregated_error>
load_channels(Context& ctx, MPool& pool, MultiPackageCache& package_caches)
auto
load_channels(Context& ctx, ChannelContext& channel_context, MPool& pool, MultiPackageCache& package_caches)
-> expected_t<void, mamba_aggregated_error>
{
return load_channels_impl(ctx, pool, package_caches, false);
return load_channels_impl(ctx, channel_context, pool, package_caches, false);
}
}
Loading
Loading