Reject inconsistent backtrack parameters
authorSebastian Luther <SebastianLuther@gmx.de>
Mon, 19 Sep 2011 13:07:08 +0000 (15:07 +0200)
committerZac Medico <zmedico@gentoo.org>
Tue, 20 Sep 2011 16:47:34 +0000 (09:47 -0700)
If backtracking masks a package that caused another package to
be masked, we declare this backtracking node as invalid. The
backtracker should be able to find another node that gives a
valid solution if one exists. This fixes bug 375573.

pym/_emerge/depgraph.py
pym/_emerge/resolver/backtracking.py
pym/portage/tests/resolver/test_backtracking.py

index 19773c2d9e9bed3992760f5b5a2fdb8223d09d5f..8b2bfd378c6a36609a0f28aab3e4c5f83d766c92 100644 (file)
@@ -1121,11 +1121,6 @@ class depgraph(object):
                                                                        all_match = False
                                                                        break
 
-                                                       if to_be_selected >= to_be_masked:
-                                                               # We only care about the parent atoms
-                                                               # when they trigger a downgrade.
-                                                               parent_atoms = set()
-
                                                        fallback_data.append((to_be_masked, parent_atoms))
 
                                                        if all_match:
index dcdaee0cb97bedef0a5da77d0952f2b940f98896..e072275fedce5e596bae284999f39640cf8d4368 100644 (file)
@@ -84,6 +84,9 @@ class Backtracker(object):
                Adds a newly computed backtrack parameter. Makes sure that it doesn't already exist and
                that we don't backtrack deeper than we are allowed by --backtrack.
                """
+               if not self._check_runtime_pkg_mask(node.parameter.runtime_pkg_mask):
+                       return
+
                if node.mask_steps <= self._max_depth and node not in self._nodes:
                        if explore:
                                self._unexplored_nodes.append(node)
@@ -105,6 +108,28 @@ class Backtracker(object):
        def __len__(self):
                return len(self._unexplored_nodes)
 
+       def _check_runtime_pkg_mask(self, runtime_pkg_mask):
+               """
+               If a package gets masked that caused other packages to be masked
+               before, we revert the mask for other packages (bug 375573).
+               """
+
+               for pkg in runtime_pkg_mask:
+
+                       if "missing dependency" in runtime_pkg_mask[pkg]:
+                               continue
+
+                       entry_is_valid = False
+
+                       for ppkg, patom in runtime_pkg_mask[pkg].get("slot conflict", set()):
+                               if ppkg not in runtime_pkg_mask:
+                                       entry_is_valid = True
+                                       break
+
+                       if not entry_is_valid:
+                               return False
+
+               return True
 
        def _feedback_slot_conflict(self, conflict_data):
                for pkg, parent_atoms in conflict_data:
index fc493062cb780b27235f3edc196a5e8e61f6024b..600f68216ead39cc3e9712d2b11f524c90e65928 100644 (file)
@@ -167,3 +167,46 @@ class BacktrackingTestCase(TestCase):
                                self.assertEqual(test_case.test_success, True, test_case.fail_msg)
                finally:
                        playground.cleanup()
+
+
+       def testBacktrackNoWrongRebuilds(self):
+               """
+               Ensure we remove backtrack masks if the reason for the mask gets masked itself.
+               """
+
+               ebuilds = {
+                       "dev-libs/A-1": { },
+                       "dev-libs/A-2": { },
+                       "dev-libs/B-1": { "RDEPEND": "dev-libs/D"},
+                       "dev-libs/C-1": { },
+                       "dev-libs/C-2": { "RDEPEND": ">=dev-libs/A-2" },
+                       "dev-libs/D-1": { "RDEPEND": "<dev-libs/A-2" },
+                       }
+
+               installed = {
+                       "dev-libs/A-1": { },
+                       "dev-libs/B-1": { "RDEPEND": "dev-libs/D" },
+                       "dev-libs/C-1": { },
+                       "dev-libs/D-1": { "RDEPEND": "<dev-libs/A-2" },
+                       }
+
+               world = [ "dev-libs/B", "dev-libs/C" ]
+
+               options = {'--update' : True, '--deep' : True, '--selective' : True}
+
+               test_cases = (
+                               ResolverPlaygroundTestCase(
+                                       ["@world"],
+                                       options = options,
+                                       mergelist = [],
+                                       success = True),
+                       )
+
+               playground = ResolverPlayground(ebuilds=ebuilds, installed=installed, world=world)
+
+               try:
+                       for test_case in test_cases:
+                               playground.run_TestCase(test_case)
+                               self.assertEqual(test_case.test_success, True, test_case.fail_msg)
+               finally:
+                       playground.cleanup()