[PATCH] depclean: do not eliminate upgrades (bug 707108)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] depclean: do not eliminate upgrades (bug 707108)

Zac Medico-2
For depclean actions, prefer choices where all packages have been
pulled into the graph, except for choices that eliminate upgrades.
This solves the test case for bug 707108, where depclean eliminated
a new slot of python that had been pulled in by a world update.

NOTE: There's a common perception (expressed in bug 705700) that
emerge is pulling in an "unecessary" python slot in cases when that
python slot is not enabled in PYTHON_TARGETS. However, the so-called
"unnecessary" slot is practically indistinguishable from a desirable
upgrade such as the missed llvm slot upgrade that was reported in
bug 706278. Therefore, be advised that emerge must pull in the
highest visible slot (regardless of PYTHON_TARGETS) in order to
ensure that a desirable upgrade is not missed.

Fixes: f7d83d75c6b0 ("dep_zapdeps: adjust || preference for slot upgrades (bug 706278)")
Bug: https://bugs.gentoo.org/707108
Bug: https://bugs.gentoo.org/706278
Bug: https://bugs.gentoo.org/705700
Signed-off-by: Zac Medico <[hidden email]>
---
 lib/portage/dep/dep_check.py                  | 48 +++++++++++--------
 lib/portage/tests/resolver/test_or_choices.py |  4 +-
 2 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/lib/portage/dep/dep_check.py b/lib/portage/dep/dep_check.py
index a7ae2cfa4..18a10b6ba 100644
--- a/lib/portage/dep/dep_check.py
+++ b/lib/portage/dep/dep_check.py
@@ -690,17 +690,12 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None,
  # choice_1 will not be promoted, so move on
  break
  if (
- # For removal actions, prefer choices where all packages
- # have been pulled into the graph.
- (graph_interface and graph_interface.removal_action and
- choice_1.all_in_graph and not choice_2.all_in_graph)
-
  # Prefer choices where all_installed_slots is True, except
  # in cases where we want to upgrade to a new slot as in
  # bug 706278. Don't compare new_slot_count here since that
  # would aggressively override the preference order defined
  # in the ebuild, breaking the test case for bug 645002.
- or (choice_1.all_installed_slots and
+ (choice_1.all_installed_slots and
  not choice_2.all_installed_slots and
  not choice_2.want_update)
  ):
@@ -712,20 +707,33 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None,
 
  intersecting_cps = cps.intersection(choice_2.cp_map)
  if not intersecting_cps:
- continue
- has_upgrade = False
- has_downgrade = False
- for cp in intersecting_cps:
- version_1 = choice_1.cp_map[cp]
- version_2 = choice_2.cp_map[cp]
- difference = vercmp(version_1.version, version_2.version)
- if difference != 0:
- if difference > 0:
- has_upgrade = True
- else:
- has_downgrade = True
- break
- if has_upgrade and not has_downgrade:
+ has_upgrade = False
+ has_downgrade = False
+ else:
+ has_upgrade = False
+ has_downgrade = False
+ for cp in intersecting_cps:
+ version_1 = choice_1.cp_map[cp]
+ version_2 = choice_2.cp_map[cp]
+ difference = vercmp(version_1.version, version_2.version)
+ if difference != 0:
+ if difference > 0:
+ has_upgrade = True
+ else:
+ has_downgrade = True
+ break
+
+ if (
+ # Prefer upgrades.
+ (has_upgrade and not has_downgrade)
+
+ # For removal actions, prefer choices where all packages
+ # have been pulled into the graph, except for choices that
+ # eliminate upgrades.
+ or (graph_interface and graph_interface.removal_action and
+ choice_1.all_in_graph and not choice_2.all_in_graph and
+ not (has_downgrade and not has_upgrade))
+ ):
  # promote choice_1 in front of choice_2
  choices.remove(choice_1)
  index_2 = choices.index(choice_2)
diff --git a/lib/portage/tests/resolver/test_or_choices.py b/lib/portage/tests/resolver/test_or_choices.py
index 78946ccec..10c613e39 100644
--- a/lib/portage/tests/resolver/test_or_choices.py
+++ b/lib/portage/tests/resolver/test_or_choices.py
@@ -387,13 +387,13 @@ class OrChoicesTestCase(TestCase):
  }
 
  test_cases = (
- # Demonstrate bug 707108, where a new python slot is erroneosly
+ # Test for bug 707108, where a new python slot was erroneously
  # removed by emerge --depclean.
  ResolverPlaygroundTestCase(
  [],
  options={"--depclean": True},
  success=True,
- cleanlist=['dev-lang/python-3.8'],
+ cleanlist=[],
  ),
  )
 
--
2.24.1