Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] dep_zapdeps: make package selections internally consistent (bug 600346)
Date: Sun, 20 Nov 2016 23:35:06
Message-Id: 1479684883-18635-1-git-send-email-zmedico@gentoo.org
1 When selecting packages to determine which choices have upgrades
2 or downgrades relative to other choices, make the package selections
3 internally consistent by choosing a package that satisfies all atoms
4 in the choice which match a package in the same slot.
5
6 Also, fix the Atom.match() method to handle _pkg_str instances,
7 since dep_zapdeps can pass in _pkg_str instances instead of Package
8 instances.
9
10 X-Gentoo-Bug: 600346
11 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=600346
12 ---
13 pym/portage/dep/__init__.py | 16 ++++++++++++----
14 pym/portage/dep/dep_check.py | 19 +++++++++++++++++++
15 2 files changed, 31 insertions(+), 4 deletions(-)
16
17 diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py
18 index 5dd1638..968ff5b 100644
19 --- a/pym/portage/dep/__init__.py
20 +++ b/pym/portage/dep/__init__.py
21 @@ -1603,10 +1603,18 @@ class Atom(_unicode):
22 if pkg.cp == self.cp:
23 return bool(match_from_list(self, [pkg]))
24 else:
25 - for provided_cp in pkg.provided_cps:
26 - if provided_cp == self.cp:
27 - return bool(match_from_list(
28 - self.replace(self.cp, provided_cp, 1), [pkg]))
29 + try:
30 + provided_cps = pkg.provided_cps
31 + except AttributeError:
32 + # Since _pkg_str instances lack PROVIDE metadata,
33 + # just ignore this case (PROVIDE has been deprecated
34 + # for years).
35 + pass
36 + else:
37 + for provided_cp in provided_cps:
38 + if provided_cp == self.cp:
39 + return bool(match_from_list(
40 + self.replace(self.cp, provided_cp, 1), [pkg]))
41 return False
42
43 _extended_cp_re_cache = {}
44 diff --git a/pym/portage/dep/dep_check.py b/pym/portage/dep/dep_check.py
45 index 9d2ca4b..d2a8800 100644
46 --- a/pym/portage/dep/dep_check.py
47 +++ b/pym/portage/dep/dep_check.py
48 @@ -5,6 +5,7 @@ from __future__ import unicode_literals
49
50 __all__ = ['dep_check', 'dep_eval', 'dep_wordreduce', 'dep_zapdeps']
51
52 +import collections
53 import logging
54 import operator
55
56 @@ -354,6 +355,7 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None):
57 all_use_satisfied = True
58 all_use_unmasked = True
59 conflict_downgrade = False
60 + slot_atoms = collections.defaultdict(list)
61 slot_map = {}
62 cp_map = {}
63 for atom in atoms:
64 @@ -418,9 +420,26 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None):
65 avail_slot = Atom("%s:%s" % (atom.cp, avail_pkg.slot))
66
67 slot_map[avail_slot] = avail_pkg
68 + slot_atoms[avail_slot].append(atom)
69 highest_cpv = cp_map.get(avail_pkg.cp)
70 if highest_cpv is None or \
71 vercmp(avail_pkg.version, highest_cpv.version) > 0:
72 + if (highest_cpv is not None and
73 + highest_cpv.slot == avail_pkg.slot):
74 + # If possible, make the package selection internally
75 + # consistent by choosing a package that satisfies all
76 + # atoms which match a package in the same slot. Later on,
77 + # the package version chosen here is used in the
78 + # has_upgrade/has_downgrade logic to prefer choices with
79 + # upgrades, and a package choice that is not internally
80 + # consistent will lead the has_upgrade/has_downgrade logic
81 + # to produce invalid results (see bug 600346).
82 + all_match_current = all(a.match(avail_pkg)
83 + for a in slot_atoms[avail_slot])
84 + all_match_previous = all(a.match(highest_cpv)
85 + for a in slot_atoms[avail_slot])
86 + if all_match_previous and not all_match_current:
87 + continue
88 cp_map[avail_pkg.cp] = avail_pkg
89
90 this_choice = _dep_choice(atoms=atoms, slot_map=slot_map,
91 --
92 2.7.4

Replies