From c6feae3fe240bd683b96b794acf7b3ccb6de74a4 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 6 Sep 2007 18:08:27 +0000 Subject: [PATCH] In the topological sort for merge order, try to avoid selecting root nodes whenever possible. This helps ensure that the maximimum possible number of soft dependencies have been removed from the graph before their parent nodes have been selected. This is especially important when those dependencies are going to be rebuilt by revdep-rebuild or `emerge -e system` after the CHOST has been changed (like when building a stage3 from a stage2). With this patch, `emerge -e system` properly rebuilds dev-lang/python before sys-apps/file, which helps to avoid a potential build failure. (trunk r7727:7729) svn path=/main/branches/2.1.2/; revision=7745 --- bin/emerge | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/bin/emerge b/bin/emerge index 7f61abeb1..93f8f85fd 100755 --- a/bin/emerge +++ b/bin/emerge @@ -2294,6 +2294,26 @@ class depgraph: # failed to select any nodes. It is reset whenever nodes are # successfully selected. prefer_asap = True + + # By default, try to avoid selecting root nodes whenever possible. This + # helps ensure that the maximimum possible number of soft dependencies + # have been removed from the graph before their parent nodes have + # selected. This is especially important when those dependencies are + # going to be rebuilt by revdep-rebuild or `emerge -e system` after the + # CHOST has been changed (like when building a stage3 from a stage2). + accept_root_node = False + + # State of prefer_asap and accept_root_node flags for successive + # iterations that loosen the criteria for node selection. + # + # iteration prefer_asap accept_root_node + # 1 True False + # 2 False False + # 3 False True + # + # If no nodes are selected on the 3rd iteration, it is due to + # unresolved blockers or circular dependencies. + while not mygraph.empty(): selected_nodes = None if prefer_asap and asap_nodes: @@ -2328,7 +2348,8 @@ class depgraph: # found a non-root node selected_nodes = [node] break - if not selected_nodes: + if not selected_nodes and \ + (accept_root_node or ignore_priority is None): # settle for a root node selected_nodes = [nodes[0]] if not selected_nodes: @@ -2361,6 +2382,9 @@ class depgraph: for ignore_priority in xrange(DepPriority.SOFT, DepPriority.MEDIUM_SOFT + 1): for node in nodes: + if not accept_root_node and \ + not mygraph.parent_nodes(node): + continue selected_nodes = set() if gather_deps(ignore_priority, mergeable_nodes, selected_nodes, node): @@ -2376,6 +2400,12 @@ class depgraph: prefer_asap = False continue + if not selected_nodes and not accept_root_node: + # Maybe there are only root nodes left, so accept them + # for the next iteration. + accept_root_node = True + continue + if selected_nodes and ignore_priority > DepPriority.SOFT: # Try to merge ignored medium deps as soon as possible. for node in selected_nodes: @@ -2456,8 +2486,10 @@ class depgraph: 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. + # it's now safe to reset the prefer_asap and accept_root_node flags + # to their default states. prefer_asap = True + accept_root_node = False for node in selected_nodes: if node[-1] != "nomerge": -- 2.26.2