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] depclean: do not eliminate upgrades (bug 707108)
Date: Sat, 01 Feb 2020 07:04:57
Message-Id: 20200201070214.113968-1-zmedico@gentoo.org
1 For depclean actions, prefer choices where all packages have been
2 pulled into the graph, except for choices that eliminate upgrades.
3 This solves the test case for bug 707108, where depclean eliminated
4 a new slot of python that had been pulled in by a world update.
5
6 NOTE: There's a common perception (expressed in bug 705700) that
7 emerge is pulling in an "unecessary" python slot in cases when that
8 python slot is not enabled in PYTHON_TARGETS. However, the so-called
9 "unnecessary" slot is practically indistinguishable from a desirable
10 upgrade such as the missed llvm slot upgrade that was reported in
11 bug 706278. Therefore, be advised that emerge must pull in the
12 highest visible slot (regardless of PYTHON_TARGETS) in order to
13 ensure that a desirable upgrade is not missed.
14
15 Fixes: f7d83d75c6b0 ("dep_zapdeps: adjust || preference for slot upgrades (bug 706278)")
16 Bug: https://bugs.gentoo.org/707108
17 Bug: https://bugs.gentoo.org/706278
18 Bug: https://bugs.gentoo.org/705700
19 Signed-off-by: Zac Medico <zmedico@g.o>
20 ---
21 lib/portage/dep/dep_check.py | 48 +++++++++++--------
22 lib/portage/tests/resolver/test_or_choices.py | 4 +-
23 2 files changed, 30 insertions(+), 22 deletions(-)
24
25 diff --git a/lib/portage/dep/dep_check.py b/lib/portage/dep/dep_check.py
26 index a7ae2cfa4..18a10b6ba 100644
27 --- a/lib/portage/dep/dep_check.py
28 +++ b/lib/portage/dep/dep_check.py
29 @@ -690,17 +690,12 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None,
30 # choice_1 will not be promoted, so move on
31 break
32 if (
33 - # For removal actions, prefer choices where all packages
34 - # have been pulled into the graph.
35 - (graph_interface and graph_interface.removal_action and
36 - choice_1.all_in_graph and not choice_2.all_in_graph)
37 -
38 # Prefer choices where all_installed_slots is True, except
39 # in cases where we want to upgrade to a new slot as in
40 # bug 706278. Don't compare new_slot_count here since that
41 # would aggressively override the preference order defined
42 # in the ebuild, breaking the test case for bug 645002.
43 - or (choice_1.all_installed_slots and
44 + (choice_1.all_installed_slots and
45 not choice_2.all_installed_slots and
46 not choice_2.want_update)
47 ):
48 @@ -712,20 +707,33 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None,
49
50 intersecting_cps = cps.intersection(choice_2.cp_map)
51 if not intersecting_cps:
52 - continue
53 - has_upgrade = False
54 - has_downgrade = False
55 - for cp in intersecting_cps:
56 - version_1 = choice_1.cp_map[cp]
57 - version_2 = choice_2.cp_map[cp]
58 - difference = vercmp(version_1.version, version_2.version)
59 - if difference != 0:
60 - if difference > 0:
61 - has_upgrade = True
62 - else:
63 - has_downgrade = True
64 - break
65 - if has_upgrade and not has_downgrade:
66 + has_upgrade = False
67 + has_downgrade = False
68 + else:
69 + has_upgrade = False
70 + has_downgrade = False
71 + for cp in intersecting_cps:
72 + version_1 = choice_1.cp_map[cp]
73 + version_2 = choice_2.cp_map[cp]
74 + difference = vercmp(version_1.version, version_2.version)
75 + if difference != 0:
76 + if difference > 0:
77 + has_upgrade = True
78 + else:
79 + has_downgrade = True
80 + break
81 +
82 + if (
83 + # Prefer upgrades.
84 + (has_upgrade and not has_downgrade)
85 +
86 + # For removal actions, prefer choices where all packages
87 + # have been pulled into the graph, except for choices that
88 + # eliminate upgrades.
89 + or (graph_interface and graph_interface.removal_action and
90 + choice_1.all_in_graph and not choice_2.all_in_graph and
91 + not (has_downgrade and not has_upgrade))
92 + ):
93 # promote choice_1 in front of choice_2
94 choices.remove(choice_1)
95 index_2 = choices.index(choice_2)
96 diff --git a/lib/portage/tests/resolver/test_or_choices.py b/lib/portage/tests/resolver/test_or_choices.py
97 index 78946ccec..10c613e39 100644
98 --- a/lib/portage/tests/resolver/test_or_choices.py
99 +++ b/lib/portage/tests/resolver/test_or_choices.py
100 @@ -387,13 +387,13 @@ class OrChoicesTestCase(TestCase):
101 }
102
103 test_cases = (
104 - # Demonstrate bug 707108, where a new python slot is erroneosly
105 + # Test for bug 707108, where a new python slot was erroneously
106 # removed by emerge --depclean.
107 ResolverPlaygroundTestCase(
108 [],
109 options={"--depclean": True},
110 success=True,
111 - cleanlist=['dev-lang/python-3.8'],
112 + cleanlist=[],
113 ),
114 )
115
116 --
117 2.24.1