LinkageMapPeCoff: sync with LinkageMapELF
authorFabian Groffen <grobian@gentoo.org>
Tue, 26 Jul 2011 17:27:55 +0000 (19:27 +0200)
committerFabian Groffen <grobian@gentoo.org>
Tue, 26 Jul 2011 17:27:55 +0000 (19:27 +0200)
pym/portage/util/_dyn_libs/LinkageMapPeCoff.py

index 25e8a45c279e12450b955a8dda4de99ea0bd672b..0a42784c5c0a00544ced1bde62690e9462e490fd 100644 (file)
@@ -128,7 +128,7 @@ class LinkageMapPeCoff(LinkageMapELF):
                root = self._root
                root_len = len(root) - 1
                self._clear_cache()
-               self._defpath.update(getlibpaths(self._root))
+               self._defpath.update(getlibpaths(self._root, env=self._dbapi.settings))
                libs = self._libs
                obj_properties = self._obj_properties
 
@@ -138,7 +138,7 @@ class LinkageMapPeCoff(LinkageMapELF):
                # overrides any data from previously installed files.
                if include_file is not None:
                        for line in grabfile(include_file):
-                               lines.append((include_file, line))
+                               lines.append((None, include_file, line))
 
                aux_keys = [self._needed_aux_key]
                can_lock = os.access(os.path.dirname(self._dbapi._dbroot), os.W_OK)
@@ -151,16 +151,16 @@ class LinkageMapPeCoff(LinkageMapELF):
                                needed_file = self._dbapi.getpath(cpv,
                                        filename=self._needed_aux_key)
                                for line in self._dbapi.aux_get(cpv, aux_keys)[0].splitlines():
-                                       lines.append((needed_file, line))
+                                       lines.append((cpv, needed_file, line))
                finally:
                        if can_lock:
                                self._dbapi.unlock()
 
                # have to call readpecoff for preserved libs here as they aren't 
                # registered in NEEDED.PECOFF.1 files
-               plibs = set()
+               plibs = {}
                if preserve_paths is not None:
-                       plibs.update(preserve_paths)
+                       plibs.update((x, None) for x in preserve_paths)
                if self._dbapi._plib_registry and \
                        self._dbapi._plib_registry.hasEntries():
                        for cpv, items in \
@@ -172,7 +172,7 @@ class LinkageMapPeCoff(LinkageMapELF):
                                        # already represented via the preserve_paths
                                        # parameter.
                                        continue
-                               plibs.update(items)
+                               plibs.update((x, cpv) for x in items)
                if plibs:
                        args = ["readpecoff", self._dbapi.settings.get('CHOST')]
                        args.extend(os.path.join(root, x.lstrip("." + os.sep)) \
@@ -204,8 +204,8 @@ class LinkageMapPeCoff(LinkageMapELF):
                                                        level=logging.ERROR, noiselevel=-1)
                                                continue
                                        fields[1] = fields[1][root_len:]
-                                       plibs.discard(fields[1])
-                                       lines.append(("readpecoff", ";".join(fields)))
+                                       owner = plibs.pop(fields[1], None)
+                                       lines.append((owner, "readpecoff", ";".join(fields)))
                                proc.wait()
 
                if plibs:
@@ -215,10 +215,14 @@ class LinkageMapPeCoff(LinkageMapELF):
                        # preserved library has an entry in self._obj_properties. This
                        # is important in order to prevent findConsumers from raising
                        # an unwanted KeyError.
-                       for x in plibs:
-                               lines.append(("plibs", ";".join(['', x, '', '', ''])))
+                       for x, cpv in plibs.items():
+                               lines.append((cpv, "plibs", ";".join(['', x, '', '', ''])))
 
-               for location, l in lines:
+               # Share identical frozenset instances when available,
+               # in order to conserve memory.
+               frozensets = {}
+
+               for owner, location, l in lines:
                        l = l.rstrip("\n")
                        if not l:
                                continue
@@ -231,21 +235,24 @@ class LinkageMapPeCoff(LinkageMapELF):
                        arch = fields[0]
                        obj = fields[1]
                        soname = fields[2]
-                       path = set([normalize_path(x) \
+                       path = frozenset(normalize_path(x) \
                                for x in filter(None, fields[3].replace(
                                "${ORIGIN}", os.path.dirname(obj)).replace(
-                               "$ORIGIN", os.path.dirname(obj)).split(":"))])
-                       needed = [x for x in fields[4].split(",") if x]
+                               "$ORIGIN", os.path.dirname(obj)).split(":")))
+                       path = frozensets.setdefault(path, path)
+                       needed = frozenset(x for x in fields[4].split(",") if x)
+                       needed = frozensets.setdefault(needed, needed)
 
                        obj_key = self._obj_key(obj)
                        indexed = True
                        myprops = obj_properties.get(obj_key)
                        if myprops is None:
                                indexed = False
-                               myprops = (arch, needed, path, soname, set())
+                               myprops = self._obj_properies_class(
+                                       arch, needed, path, soname, [], owner)
                                obj_properties[obj_key] = myprops
                        # All object paths are added into the obj_properties tuple.
-                       myprops[4].add(obj)
+                       myprops.alt_paths.append(obj)
 
                        # Don't index the same file more that once since only one
                        # set of data can be correct and therefore mixing data
@@ -262,13 +269,18 @@ class LinkageMapPeCoff(LinkageMapELF):
                                soname_map = arch_map.get(soname)
                                if soname_map is None:
                                        soname_map = self._soname_map_class(
-                                               providers=set(), consumers=set())
+                                               providers=[], consumers=[])
                                        arch_map[soname] = soname_map
-                               soname_map.providers.add(obj_key)
+                               soname_map.providers.append(obj_key)
                        for needed_soname in needed:
                                soname_map = arch_map.get(needed_soname)
                                if soname_map is None:
                                        soname_map = self._soname_map_class(
-                                               providers=set(), consumers=set())
+                                               providers=[], consumers=[])
                                        arch_map[needed_soname] = soname_map
-                               soname_map.consumers.add(obj_key)
+                               soname_map.consumers.append(obj_key)
+
+               for arch, sonames in libs.items():
+                       for soname_node in sonames.values():
+                               soname_node.providers = tuple(set(soname_node.providers))
+                               soname_node.consumers = tuple(set(soname_node.consumers))