Skip to content

Commit

Permalink
Change serializing of pin
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Jan 18, 2024
1 parent 0324bd7 commit a1ffdfc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion libmamba/src/core/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ namespace mamba
// Even if we lock it, libsolv may still try to remove it with
// `SOLVER_FLAG_ALLOW_UNINSTALL`, so we flag it as not a real package to filter it out in
// the transaction
cons_solv.set_artificial(true);
cons_solv.set_type(solv::SolvableType::Pin);

// Necessary for attributes to be properly stored
installed->internalize();
Expand Down
4 changes: 2 additions & 2 deletions libmamba/src/core/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ namespace mamba
return;
}

// Artificial packages are packages that were added to implement a feature
// here are packages that were added to implement a feature
// (e.g. a pin) but do not represent a Conda package.
// They can appear in the transaction depending on libsolv flags.
// We use this attribute to filter them out.
if (const auto solv = pool.pool().get_solvable(id);
solv.has_value() && solv->artificial())
solv.has_value() && (solv->type() != solv::SolvableType::Package))
{
LOG_DEBUG << "Solution: Remove artificial " << pkginfo.str();
return;
Expand Down
27 changes: 10 additions & 17 deletions libmamba/src/solv-cpp/solvable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,28 +466,21 @@ namespace mamba::solv
return (repo != nullptr) && (repo == repo->pool->installed);
}

namespace
{
auto solvable_lookup_bool(const ::Solvable* s, ::Id key) -> bool
{
return ::solvable_lookup_num(const_cast<::Solvable*>(s), key, 0) != 0;
}

void solvable_set_bool(::Solvable* s, ::Id key, bool val)
{
::solvable_set_num(s, key, (val ? 1 : 0));
}
}

auto ObjSolvableViewConst::artificial() const -> bool
auto ObjSolvableViewConst::type() const -> SolvableType
{
using Num = std::underlying_type_t<SolvableType>;
// (Ab)using meaningless key
return solvable_lookup_bool(raw(), SOLVABLE_INSTALLSTATUS);
return static_cast<SolvableType>(::solvable_lookup_num(
const_cast<::Solvable*>(raw()),
SOLVABLE_INSTALLSTATUS,
static_cast<Num>(SolvableType::Package)
));
}

void ObjSolvableView::set_artificial(bool val) const
void ObjSolvableView::set_type(SolvableType val) const
{
using Num = std::underlying_type_t<SolvableType>;
// (Ab)using meaningless key
::solvable_set_num(raw(), SOLVABLE_INSTALLSTATUS, val);
::solvable_set_num(raw(), SOLVABLE_INSTALLSTATUS, static_cast<Num>(val));
}
}
26 changes: 15 additions & 11 deletions libmamba/src/solv-cpp/solvable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <string>
#include <string_view>
#include <utility>

#include <solv/pooltypes.h>

Expand All @@ -23,6 +22,16 @@ extern "C"

namespace mamba::solv
{
/**
* We use solvable for all sort of things, including virtual packages and pins.
*/
enum class SolvableType : unsigned long long
{
Package,
Virtualpackage,
Pin,
};

class ObjSolvableViewConst
{
public:
Expand Down Expand Up @@ -93,13 +102,8 @@ namespace mamba::solv
/** Whether the solvable is in the installed repo. */
auto installed() const -> bool;

/**
* Some artificial packages are added to produce extra features (e.g. pins).
*
* We flag them as such so that we avoid trying to install them.
* This as no effect on libsolv, it must be checked manually.
*/
auto artificial() const -> bool;
/** The type for which the solvable is used. */
auto type() const -> SolvableType;

private:

Expand Down Expand Up @@ -403,11 +407,11 @@ namespace mamba::solv
void add_track_features(const Range& features) const;

/**
* Mark package as artificial, i.e. that must not be installed.
* Mark mark the package as being of a specific type.
*
* @see ObjSolvableViewConst::artificial
* @see ObjSolvableViewConst::type
*/
void set_artificial(bool val) const;
void set_type(SolvableType val) const;
};

/***************************************
Expand Down
8 changes: 4 additions & 4 deletions libmamba/tests/src/solv-cpp/test_solvable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ TEST_SUITE("solv::ObjSolvable")
solv.set_url("https://conda.anaconda.org/conda-forge/linux-64");
solv.set_channel("conda-forge");
solv.set_subdir("linux-64");
solv.set_artificial(true);
solv.set_type(SolvableType::Virtualpackage);

SUBCASE("Empty without internalize")
{
Expand All @@ -67,7 +67,7 @@ TEST_SUITE("solv::ObjSolvable")
CHECK_EQ(solv.url(), "");
CHECK_EQ(solv.channel(), "");
CHECK_EQ(solv.subdir(), "");
CHECK_EQ(solv.artificial(), false);
CHECK_EQ(solv.type(), SolvableType::Package);
}

SUBCASE("Internalize and get attributes")
Expand All @@ -90,7 +90,7 @@ TEST_SUITE("solv::ObjSolvable")
CHECK_EQ(solv.url(), "https://conda.anaconda.org/conda-forge/linux-64");
CHECK_EQ(solv.channel(), "conda-forge");
CHECK_EQ(solv.subdir(), "linux-64");
CHECK_EQ(solv.artificial(), true);
CHECK_EQ(solv.type(), SolvableType::Virtualpackage);

SUBCASE("Override attribute")
{
Expand Down Expand Up @@ -118,7 +118,7 @@ TEST_SUITE("solv::ObjSolvable")
CHECK_EQ(solv.url(), "");
CHECK_EQ(solv.channel(), "");
CHECK_EQ(solv.subdir(), "");
CHECK_EQ(solv.artificial(), false);
CHECK_EQ(solv.type(), SolvableType::Package);
}

SUBCASE("Add dependency")
Expand Down

0 comments on commit a1ffdfc

Please sign in to comment.