autounmask USE change comment: ensure that the first parent requires the change
authorSebastian Luther <SebastianLuther@gmx.de>
Fri, 28 Jan 2011 19:59:50 +0000 (20:59 +0100)
committerZac Medico <zmedico@gentoo.org>
Wed, 2 Feb 2011 23:14:36 +0000 (15:14 -0800)
Fixes bug 350515.

pym/_emerge/depgraph.py

index 4ad1746bd19b113654a6b235f96d0b868772218b..71bd9639624cfc9522290beefea1dee6d4a0fe06 100644 (file)
@@ -2188,11 +2188,14 @@ class depgraph(object):
 
                return selected_atoms
 
-       def _get_dep_chain(self, pkg, atom=None):
+       def _get_dep_chain(self, pkg, target_atom=None, unsatisfied_dependency=False):
                """
                Returns a list of (atom, node_type) pairs that represent a dep chain.
-               If atom is None, the first package shown is pkg's paretn.
-               If atom is not None the first package shown is pkg.
+               If target_atom is None, the first package shown is pkg's paretn.
+               If target_atom is not None the first package shown is pkg.
+               If unsatisfied_dependency is True, the first parent is select who's
+               dependency is not satisfied by 'pkg'. This is need for USE changes.
+               (Does not support target_atom.)
                """
                traversed_nodes = set()
                dep_chain = []
@@ -2200,11 +2203,11 @@ class depgraph(object):
                first = True
                child = None
                all_parents = self._dynamic_config._parent_atoms
-               
-               if atom is not None:
+
+               if target_atom is not None:
                        affecting_use = set()
                        for dep_str in "DEPEND", "RDEPEND", "PDEPEND":
-                               affecting_use.update(extract_affecting_use(pkg.metadata[dep_str], atom))
+                               affecting_use.update(extract_affecting_use(pkg.metadata[dep_str], target_atom))
                        affecting_use.difference_update(pkg.use.mask, node.use.force)
                        pkg_name = pkg.cpv
                        if affecting_use:
@@ -2216,9 +2219,8 @@ class depgraph(object):
                                                usedep.append("-"+flag)
                                pkg_name += "[%s]" % ",".join(usedep)
 
-                       
                        dep_chain.append(( _unicode_decode(pkg_name),  _unicode_decode(pkg.type_name)))
-       
+
                while node is not None:
                        traversed_nodes.add(node)
 
@@ -2239,7 +2241,7 @@ class depgraph(object):
                                                dep_strings.add(node.metadata["RDEPEND"])
                                        if priority.runtime_post:
                                                dep_strings.add(node.metadata["PDEPEND"])
-                               
+
                                affecting_use = set()
                                for dep_str in dep_strings:
                                        affecting_use.update(extract_affecting_use(dep_str, atom))
@@ -2258,7 +2260,6 @@ class depgraph(object):
                                                        usedep.append("-"+flag)
                                        pkg_name += "[%s]" % ",".join(usedep)
 
-                               
                                dep_chain.append(( _unicode_decode(pkg_name),  _unicode_decode(node.type_name)))
 
                        if node not in self._dynamic_config.digraph:
@@ -2281,13 +2282,25 @@ class depgraph(object):
                                                selected_parent = None
                                        break
                                else:
-                                       selected_parent = parent
-                                       child = node
+                                       if unsatisfied_dependency and node is pkg:
+                                               # Make sure that pkg doesn't satisfy parent's dependency.
+                                               # This ensures that we select the correct parent for use
+                                               # flag changes.
+                                               for ppkg, atom in all_parents[pkg]:
+                                                       if parent is ppkg:
+                                                               atom_set = InternalPackageSet(initial_atoms=(atom,))
+                                                               if not atom_set.findAtomForPackage(pkg):
+                                                                       selected_parent = parent
+                                                                       child = node
+                                                               break
+                                       else:
+                                               selected_parent = parent
+                                               child = node
                        node = selected_parent
                return dep_chain
 
-       def _get_dep_chain_as_comment(self, pkg):
-               dep_chain = self._get_dep_chain(pkg)
+       def _get_dep_chain_as_comment(self, pkg, unsatisfied_dependency=False):
+               dep_chain = self._get_dep_chain(pkg, unsatisfied_dependency=unsatisfied_dependency)
                display_list = []
                for node, node_type in dep_chain:
                        if node_type == "argument":
@@ -2297,7 +2310,7 @@ class depgraph(object):
 
                msg = "#" + ", ".join(display_list) + "\n"
                return msg
-                               
+
 
        def _show_unsatisfied_dep(self, root, atom, myparent=None, arg=None,
                check_backtrack=False):
@@ -4886,7 +4899,7 @@ class depgraph(object):
                                                adjustments.append(flag)
                                        else:
                                                adjustments.append("-" + flag)
-                               use_changes_msg.append(self._get_dep_chain_as_comment(pkg))
+                               use_changes_msg.append(self._get_dep_chain_as_comment(pkg, unsatisfied_dependency=True))
                                use_changes_msg.append("=%s %s\n" % (pkg.cpv, " ".join(adjustments)))
 
                license_msg = []