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

Add expanding solvable provides for dependency matching #762

Merged
merged 4 commits into from
Jan 27, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions VERSION.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set (DEFAULT_LIBDNF_MAJOR_VERSION 0)
set (DEFAULT_LIBDNF_MINOR_VERSION 43)
set (DEFAULT_LIBDNF_MICRO_VERSION 1)
set (DEFAULT_LIBDNF_MINOR_VERSION 44)
set (DEFAULT_LIBDNF_MICRO_VERSION 0)

if(DEFINED LIBDNF_MAJOR_VERSION)
if(NOT ${DEFAULT_LIBDNF_MAJOR_VERSION} STREQUAL ${LIBDNF_MAJOR_VERSION})
Expand Down
4 changes: 2 additions & 2 deletions libdnf.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
%global dnf_conflict 4.2.13
%global swig_version 3.0.12
%global libdnf_major_version 0
%global libdnf_minor_version 43
%global libdnf_micro_version 1
%global libdnf_minor_version 44
%global libdnf_micro_version 0

# set sphinx package name according to distro
%global requires_python2_sphinx python2-sphinx
Expand Down
38 changes: 32 additions & 6 deletions libdnf/sack/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ valid_filter_num(int keyname, int cmp_type)
static bool
valid_filter_pkg(int keyname, int cmp_type)
{
if (!match_type_pkg(keyname))
if (!match_type_pkg(keyname) && !match_type_reldep(keyname))
return false;
return cmp_type == HY_EQ || cmp_type == HY_NEQ;
}
Expand Down Expand Up @@ -683,6 +683,7 @@ class Query::Impl {
void filterNevraStrict(int cmpType, const char **matches);
void initResult();
void filterPkg(const Filter & f, Map *m);
void filterDepSolvable(const Filter & f, Map * m);
void filterRcoReldep(const Filter & f, Map *m);
void filterName(const Filter & f, Map *m);
void filterEpoch(const Filter & f, Map *m);
Expand Down Expand Up @@ -1058,6 +1059,30 @@ Query::Impl::filterPkg(const Filter & f, Map *m)
map_init_clone(m, dnf_packageset_get_map(f.getMatches()[0].pset));
}

void
Query::Impl::filterDepSolvable(const Filter & f, Map * m)
{
assert(f.getMatchType() == _HY_PKG);
assert(f.getMatches().size() == 1);

dnf_sack_make_provides_ready(sack);
Pool * pool = dnf_sack_get_pool(sack);
Id rco_key = reldep_keyname2id(f.getKeyname());

IdQueue out;

const auto filter_pset = f.getMatches()[0].pset;
Id id = -1;
while ((id = filter_pset->next(id)) != -1) {
out.clear();
pool_whatmatchessolvable(pool, rco_key, id, out.getQueue(), -1);

for (int j = 0; j < out.size(); ++j) {
MAPSET(m, out[j]);
}
}
}

void
Query::Impl::filterRcoReldep(const Filter & f, Map *m)
{
Expand Down Expand Up @@ -1996,9 +2021,6 @@ Query::Impl::apply()
case HY_PKG_EMPTY:
/* used to set query empty by keeping Map m empty */
break;
case HY_PKG_CONFLICTS:
filterRcoReldep(f, &m);
break;
case HY_PKG_NAME:
filterName(f, &m);
break;
Expand Down Expand Up @@ -2038,13 +2060,17 @@ Query::Impl::apply()
assert(f.getMatchType() == _HY_RELDEP);
filterProvidesReldep(f, &m);
break;
case HY_PKG_CONFLICTS:
case HY_PKG_ENHANCES:
case HY_PKG_RECOMMENDS:
case HY_PKG_REQUIRES:
case HY_PKG_SUGGESTS:
case HY_PKG_SUPPLEMENTS:
assert(f.getMatchType() == _HY_RELDEP);
filterRcoReldep(f, &m);
if (f.getMatchType() == _HY_RELDEP)
filterRcoReldep(f, &m);
else {
filterDepSolvable(f, &m);
}
break;
case HY_PKG_REPONAME:
filterReponame(f, &m);
Expand Down
16 changes: 8 additions & 8 deletions python/hawkey/query-py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,13 @@ filter_add(HyQuery query, key_t keyname, int cmp_type, PyObject *match)
switch (keyname) {
case HY_PKG:
case HY_PKG_OBSOLETES:
case HY_PKG_OBSOLETES_BY_PRIORITY: {
case HY_PKG_OBSOLETES_BY_PRIORITY:
case HY_PKG_CONFLICTS:
case HY_PKG_REQUIRES:
case HY_PKG_ENHANCES:
case HY_PKG_RECOMMENDS:
case HY_PKG_SUGGESTS:
case HY_PKG_SUPPLEMENTS: {
// It could be a sequence of packages or reldep/strings. Lets try packages first.
auto pset = pyseq_to_packageset(match, query->getSack());
if (!pset) {
Expand All @@ -372,13 +378,7 @@ filter_add(HyQuery query, key_t keyname, int cmp_type, PyObject *match)

break;
}
case HY_PKG_CONFLICTS:
case HY_PKG_PROVIDES:
case HY_PKG_REQUIRES:
case HY_PKG_ENHANCES:
case HY_PKG_RECOMMENDS:
case HY_PKG_SUGGESTS:
case HY_PKG_SUPPLEMENTS: {
case HY_PKG_PROVIDES: {
auto reldeplist = pyseq_to_reldeplist(match, query->getSack(), cmp_type);
if (reldeplist == NULL)
return 1;
Expand Down
13 changes: 12 additions & 1 deletion python/hawkey/tests/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,23 @@ def test_obsoletes(self):
q = hawkey.Query(self.sack).filter(name="penny")
o = hawkey.Query(self.sack)
self.assertRaises(hawkey.QueryException, o.filter, obsoletes__gt=q)
self.assertRaises(hawkey.ValueException, o.filter, requires=q)

o = hawkey.Query(self.sack).filter(obsoletes=q)
self.assertLength(o, 1)
self.assertEqual(str(o[0]), "fool-1-5.noarch")

def test_requires_with_query(self):
q = hawkey.Query(self.sack).filter(name="fool")
o = hawkey.Query(self.sack).filter(requires=q)
Copy link
Member

Choose a reason for hiding this comment

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

Please could you also add requires=q.run()

self.assertLength(o, 1)
self.assertEqual(str(o[0]), "walrus-2-6.noarch")

def test_requires_with_package_list(self):
q = hawkey.Query(self.sack).filter(name="fool")
o = hawkey.Query(self.sack).filter(requires=q.run())
self.assertLength(o, 1)
self.assertEqual(str(o[0]), "walrus-2-6.noarch")

def test_subquery_evaluated(self):
q = hawkey.Query(self.sack).filter(name="penny")
self.assertFalse(q.evaluated)
Expand Down