depgraph: migrate implicit libc deps from Sched
authorZac Medico <zmedico@gentoo.org>
Sat, 30 Apr 2011 20:38:00 +0000 (13:38 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 30 Apr 2011 20:38:00 +0000 (13:38 -0700)
Now all the virtual/libc handling is done by the depgraph, which
will be helpful when fixing bug #364681.

pym/_emerge/Scheduler.py
pym/_emerge/depgraph.py

index dfccbc40768068e2ff8d86eec8be95d65262f009..df13b6b8447f091c56fb1a45a223e8d6d181edfa 100644 (file)
@@ -22,7 +22,6 @@ from portage import os
 from portage import _encodings
 from portage import _unicode_decode, _unicode_encode
 from portage.cache.mappings import slot_dict_class
-from portage.const import LIBC_PACKAGE_ATOM
 from portage.elog.messages import eerror
 from portage.localization import _
 from portage.output import colorize, create_color_func, red
@@ -476,7 +475,6 @@ class Scheduler(PollScheduler):
                self._find_system_deps()
                self._prune_digraph()
                self._prevent_builddir_collisions()
-               self._implicit_libc_deps()
                if '--debug' in self.myopts:
                        writemsg("\nscheduler digraph:\n\n", noiselevel=-1)
                        self._digraph.debug_print()
@@ -542,69 +540,6 @@ class Scheduler(PollScheduler):
                                        priority=DepPriority(buildtime=True))
                        cpv_map[pkg.cpv].append(pkg)
 
-       def _implicit_libc_deps(self):
-               """
-               Create implicit dependencies on libc, in order to ensure that libc
-               is installed as early as possible (see bug #303567). If the merge
-               list contains both a new-style virtual and an old-style PROVIDE
-               virtual, the new-style virtual is used.
-               """
-               implicit_libc_roots = set([self._running_root.root])
-               libc_set = InternalPackageSet([LIBC_PACKAGE_ATOM])
-               norm_libc_pkgs = {}
-               virt_libc_pkgs = {}
-               for pkg in self._mergelist:
-                       if not isinstance(pkg, Package):
-                               # a satisfied blocker
-                               continue
-                       if pkg.installed:
-                               continue
-                       if pkg.root in implicit_libc_roots and \
-                               pkg.operation == 'merge':
-                               if libc_set.findAtomForPackage(pkg):
-                                       if pkg.category == 'virtual':
-                                               d = virt_libc_pkgs
-                                       else:
-                                               d = norm_libc_pkgs
-                                       if pkg.root in d:
-                                               raise AssertionError(
-                                                       "found 2 libc matches: %s and %s" % \
-                                                       (d[pkg.root], pkg))
-                                       d[pkg.root] = pkg
-
-               # Prefer new-style virtuals over old-style PROVIDE virtuals.
-               libc_pkg_map = norm_libc_pkgs.copy()
-               libc_pkg_map.update(virt_libc_pkgs)
-
-               # Only add a dep when the version changes.
-               for libc_pkg in list(libc_pkg_map.values()):
-                       if libc_pkg.root_config.trees['vartree'].dbapi.cpv_exists(
-                               libc_pkg.cpv):
-                               del libc_pkg_map[pkg.root]
-
-               if not libc_pkg_map:
-                       return
-
-               libc_pkgs = set(libc_pkg_map.values())
-               earlier_libc_pkgs = set()
-
-               for pkg in self._mergelist:
-                       if not isinstance(pkg, Package):
-                               # a satisfied blocker
-                               continue
-                       if pkg.installed:
-                               continue
-                       if pkg.root in implicit_libc_roots and \
-                               pkg.operation == 'merge':
-                               if pkg in libc_pkgs:
-                                       earlier_libc_pkgs.add(pkg)
-                               else:
-                                       my_libc = libc_pkg_map.get(pkg.root)
-                                       if my_libc is not None and \
-                                               my_libc in earlier_libc_pkgs:
-                                               self._digraph.add(my_libc, pkg,
-                                                       priority=DepPriority(buildtime=True))
-
        class _pkg_failure(portage.exception.PortageException):
                """
                An instance of this class is raised by unmerge() when
index 7db5ae3f34541f505ab648e1b983f045251117e6..73b81e1d18fc63500c32fe0e9d4558c10edcbcb9 100644 (file)
@@ -4203,6 +4203,69 @@ class depgraph(object):
                        retlist.reverse()
                return retlist
 
+       def _implicit_libc_deps(self, mergelist, graph):
+               """
+               Create implicit dependencies on libc, in order to ensure that libc
+               is installed as early as possible (see bug #303567). If the merge
+               list contains both a new-style virtual and an old-style PROVIDE
+               virtual, the new-style virtual is used.
+               """
+               implicit_libc_roots = set([self._frozen_config._running_root.root])
+               libc_set = InternalPackageSet([portage.const.LIBC_PACKAGE_ATOM])
+               norm_libc_pkgs = {}
+               virt_libc_pkgs = {}
+               for pkg in mergelist:
+                       if not isinstance(pkg, Package):
+                               # a satisfied blocker
+                               continue
+                       if pkg.installed:
+                               continue
+                       if pkg.root in implicit_libc_roots and \
+                               pkg.operation == 'merge':
+                               if libc_set.findAtomForPackage(pkg):
+                                       if pkg.category == 'virtual':
+                                               d = virt_libc_pkgs
+                                       else:
+                                               d = norm_libc_pkgs
+                                       if pkg.root in d:
+                                               raise AssertionError(
+                                                       "found 2 libc matches: %s and %s" % \
+                                                       (d[pkg.root], pkg))
+                                       d[pkg.root] = pkg
+
+               # Prefer new-style virtuals over old-style PROVIDE virtuals.
+               libc_pkg_map = norm_libc_pkgs.copy()
+               libc_pkg_map.update(virt_libc_pkgs)
+
+               # Only add a dep when the version changes.
+               for libc_pkg in list(libc_pkg_map.values()):
+                       if libc_pkg.root_config.trees['vartree'].dbapi.cpv_exists(
+                               libc_pkg.cpv):
+                               del libc_pkg_map[pkg.root]
+
+               if not libc_pkg_map:
+                       return
+
+               libc_pkgs = set(libc_pkg_map.values())
+               earlier_libc_pkgs = set()
+
+               for pkg in mergelist:
+                       if not isinstance(pkg, Package):
+                               # a satisfied blocker
+                               continue
+                       if pkg.installed:
+                               continue
+                       if pkg.root in implicit_libc_roots and \
+                               pkg.operation == 'merge':
+                               if pkg in libc_pkgs:
+                                       earlier_libc_pkgs.add(pkg)
+                               else:
+                                       my_libc = libc_pkg_map.get(pkg.root)
+                                       if my_libc is not None and \
+                                               my_libc in earlier_libc_pkgs:
+                                               graph.add(my_libc, pkg,
+                                                       priority=DepPriority(buildtime=True))
+
        def schedulerGraph(self):
                """
                The scheduler graph is identical to the normal one except that
@@ -4220,6 +4283,8 @@ class depgraph(object):
 
                # NOTE: altlist initializes self._dynamic_config._scheduler_graph
                mergelist = self.altlist()
+               self._implicit_libc_deps(mergelist,
+                       self._dynamic_config._scheduler_graph)
                self.break_refs(mergelist)
                self.break_refs(self._dynamic_config._scheduler_graph.order)