1 |
Author: grobian |
2 |
Date: 2008-05-04 11:25:08 +0000 (Sun, 04 May 2008) |
3 |
New Revision: 10174 |
4 |
|
5 |
Modified: |
6 |
main/branches/prefix/pym/portage/dbapi/vartree.py |
7 |
Log: |
8 |
Add Mach-O LinkageMap implementation |
9 |
|
10 |
Modified: main/branches/prefix/pym/portage/dbapi/vartree.py |
11 |
=================================================================== |
12 |
--- main/branches/prefix/pym/portage/dbapi/vartree.py 2008-05-04 09:14:18 UTC (rev 10173) |
13 |
+++ main/branches/prefix/pym/portage/dbapi/vartree.py 2008-05-04 11:25:08 UTC (rev 10174) |
14 |
@@ -222,6 +222,91 @@ |
15 |
rValue.add(x) |
16 |
return rValue |
17 |
|
18 |
+class LinkageMapMachoO(object): |
19 |
+ def __init__(self, vardbapi): |
20 |
+ self._dbapi = vardbapi |
21 |
+ self._libs = {} |
22 |
+ self._obj_properties = {} |
23 |
+ self._defpath = getlibpaths() |
24 |
+ |
25 |
+ def rebuild(self): |
26 |
+ libs = {} |
27 |
+ obj_properties = {} |
28 |
+ lines = [] |
29 |
+ for cpv in self._dbapi.cpv_all(): |
30 |
+ lines += grabfile(self._dbapi.getpath(cpv, filename="NEEDED.MACHO.2")) |
31 |
+ |
32 |
+ for l in lines: |
33 |
+ if l.strip() == "": |
34 |
+ continue |
35 |
+ fields = l.strip("\n").split(";") |
36 |
+ if len(fields) < 3: |
37 |
+ print "Error", fields |
38 |
+ # insufficient field length |
39 |
+ continue |
40 |
+ |
41 |
+ # Linking an object to a library is registered by recording |
42 |
+ # the install_name of the library in the object. |
43 |
+ obj = os.path.realpath(fields[0]) |
44 |
+ install_name = os.path.realpath(fields[1]) |
45 |
+ needed = fields[2].split(",") |
46 |
+ |
47 |
+ # build an internal structure that contains for each |
48 |
+ # install_name, what libs have that install_name |
49 |
+ # (providers), which should be just a single lib since it is |
50 |
+ # an absolute path, consumers are those objects that |
51 |
+ # reference the install_name |
52 |
+ if install_name: |
53 |
+ libs.setdefault(install_name, {"providers": [], "consumers": []}) |
54 |
+ libs[install_name]["providers"].append(obj) |
55 |
+ for x in needed: |
56 |
+ libs.setdefault(x, {"providers": [], "consumers": []}) |
57 |
+ libs[x]["consumers"].append(obj) |
58 |
+ obj_properties[obj] = (needed, install_name) |
59 |
+ |
60 |
+ self._libs = libs |
61 |
+ self._obj_properties = obj_properties |
62 |
+ |
63 |
+ def listLibraryObjects(self): |
64 |
+ rValue = [] |
65 |
+ if not self._libs: |
66 |
+ self.rebuild() |
67 |
+ for install_name in self._libs: |
68 |
+ rValue.extend(self._libs[install_name]["providers"]) |
69 |
+ return rValue |
70 |
+ |
71 |
+ # the missing documentation, part X. |
72 |
+ # This function appears to return all (valid) providers for all |
73 |
+ # needed entries that the given object has. |
74 |
+ def findProviders(self, obj): |
75 |
+ if not self._libs: |
76 |
+ self.rebuild() |
77 |
+ obj = os.path.realpath(obj) |
78 |
+ rValue = {} |
79 |
+ if obj not in self._obj_properties: |
80 |
+ raise KeyError("%s not in object list" % obj) |
81 |
+ needed, install_name = self._obj_properties[obj] |
82 |
+ |
83 |
+ for x in needed: |
84 |
+ rValue[x] = set() |
85 |
+ if x not in self._libs: |
86 |
+ continue |
87 |
+ for y in self._libs[x]["providers"]: |
88 |
+ if os.path.realpath(x) == y: |
89 |
+ rValue[x].add(y) |
90 |
+ return rValue |
91 |
+ |
92 |
+ def findConsumers(self, obj): |
93 |
+ if not self._libs: |
94 |
+ self.rebuild() |
95 |
+ obj = os.path.realpath(obj) |
96 |
+ rValue = set() |
97 |
+ for install_name in self._libs: |
98 |
+ if obj in self._libs[install_name]["providers"]: |
99 |
+ for x in self._libs[install_name]["consumers"]: |
100 |
+ rValue.add(x) |
101 |
+ return rValue |
102 |
+ |
103 |
class LibraryPackageMap(object): |
104 |
""" This class provides a library->consumer mapping generated from VDB data """ |
105 |
def __init__(self, filename, vardbapi): |
106 |
|
107 |
-- |
108 |
gentoo-commits@l.g.o mailing list |