Prefer asap_nodes more aggressively over any other nodes whenever possible. If no...
authorZac Medico <zmedico@gentoo.org>
Mon, 2 Jul 2007 05:51:36 +0000 (05:51 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 2 Jul 2007 05:51:36 +0000 (05:51 -0000)
svn path=/main/branches/2.1.2/; revision=7127

bin/emerge

index 49907031f4b92d5901c4b669b9f62aaafe51e73a..dcfaa3d8e21c57557d002619602602159d152ac1 100755 (executable)
@@ -2067,20 +2067,25 @@ class depgraph:
                ignore_priority_soft_range.extend(
                        xrange(DepPriority.MIN, DepPriority.SOFT + 1))
                tree_mode = "--tree" in self.myopts
+               # Tracks whether or not the current iteration should prefer asap_nodes
+               # if available.  This is set to False when the previous iteration
+               # failed to select any nodes.  It is reset whenever nodes are
+               # successfully selected.
+               prefer_asap = True
                while not mygraph.empty():
                        selected_nodes = None
-                       if asap_nodes:
+                       if prefer_asap and asap_nodes:
                                """ASAP nodes are merged before their soft deps."""
-                               for node in asap_nodes[:]:
-                                       if not mygraph.contains(node):
-                                               asap_nodes.remove(node)
-                                               continue
+                               asap_nodes = [node for node in asap_nodes \
+                                       if mygraph.contains(node)]
+                               for node in asap_nodes:
                                        if not mygraph.child_nodes(node,
                                                ignore_priority=DepPriority.SOFT):
                                                selected_nodes = [node]
                                                asap_nodes.remove(node)
                                                break
-                       if not selected_nodes:
+                       if not selected_nodes and \
+                               not (prefer_asap and asap_nodes):
                                for ignore_priority in ignore_priority_soft_range:
                                        nodes = get_nodes(ignore_priority=ignore_priority)
                                        if nodes:
@@ -2124,6 +2129,8 @@ class depgraph:
                                                                return False
                                                return True
                                        mergeable_nodes = set(nodes)
+                                       if prefer_asap and asap_nodes:
+                                               nodes = asap_nodes
                                        for ignore_priority in xrange(DepPriority.SOFT,
                                                DepPriority.MEDIUM_SOFT + 1):
                                                for node in nodes:
@@ -2136,6 +2143,12 @@ class depgraph:
                                                if selected_nodes:
                                                        break
 
+                                       if prefer_asap and asap_nodes and not selected_nodes:
+                                               # We failed to find any asap nodes to merge, so ignore
+                                               # them for the next iteration.
+                                               prefer_asap = False
+                                               continue
+
                                        if selected_nodes and ignore_priority > DepPriority.SOFT:
                                                # Try to merge ignored medium deps as soon as possible.
                                                for node in selected_nodes:
@@ -2215,6 +2228,10 @@ class depgraph:
                                print "!!! disabling USE flags that trigger optional dependencies."
                                sys.exit(1)
 
+                       # At this point, we've succeeded in selecting one or more nodes, so
+                       # it's now safe to reset the prefer_asap to it's default state.
+                       prefer_asap = True
+
                        for node in selected_nodes:
                                retlist.append(list(node))
                                mygraph.remove(node)