Lines 201-230
Link Here
|
201 |
def findProviders(self, obj): |
201 |
def findProviders(self, obj): |
202 |
if not self._libs: |
202 |
if not self._libs: |
203 |
self.rebuild() |
203 |
self.rebuild() |
|
|
204 |
|
205 |
realpath_cache = {} |
206 |
def realpath(p): |
207 |
real_path = realpath_cache.get(p) |
208 |
if real_path is None: |
209 |
real_path = os.path.realpath(p) |
210 |
realpath_cache[p] = real_path |
211 |
return real_path |
212 |
|
204 |
rValue = {} |
213 |
rValue = {} |
205 |
if obj not in self._obj_properties: |
214 |
if obj not in self._obj_properties: |
206 |
obj = os.path.realpath(obj) |
215 |
obj = realpath(obj) |
207 |
if obj not in self._obj_properties: |
216 |
if obj not in self._obj_properties: |
208 |
raise KeyError("%s not in object list" % obj) |
217 |
raise KeyError("%s not in object list" % obj) |
209 |
arch, needed, path, soname = self._obj_properties[obj] |
218 |
arch, needed, path, soname = self._obj_properties[obj] |
210 |
path.extend(self._defpath) |
219 |
path.extend(self._defpath) |
211 |
path = [os.path.realpath(x) for x in path] |
220 |
path = set(realpath(x) for x in path) |
212 |
for x in needed: |
221 |
for x in needed: |
213 |
rValue[x] = set() |
222 |
rValue[x] = set() |
214 |
if x not in self._libs or arch not in self._libs[x]: |
223 |
if x not in self._libs or arch not in self._libs[x]: |
215 |
continue |
224 |
continue |
216 |
for y in self._libs[x][arch]["providers"]: |
225 |
for y in self._libs[x][arch]["providers"]: |
217 |
if x[0] == os.sep and os.path.realpath(x) == os.path.realpath(y): |
226 |
if x[0] == os.sep and realpath(x) == realpath(y): |
218 |
rValue[x].add(y) |
227 |
rValue[x].add(y) |
219 |
elif os.path.realpath(os.path.dirname(y)) in path: |
228 |
elif realpath(os.path.dirname(y)) in path: |
220 |
rValue[x].add(y) |
229 |
rValue[x].add(y) |
221 |
return rValue |
230 |
return rValue |
222 |
|
231 |
|
223 |
def findConsumers(self, obj): |
232 |
def findConsumers(self, obj): |
224 |
if not self._libs: |
233 |
if not self._libs: |
225 |
self.rebuild() |
234 |
self.rebuild() |
|
|
235 |
|
236 |
realpath_cache = {} |
237 |
def realpath(p): |
238 |
real_path = realpath_cache.get(p) |
239 |
if real_path is None: |
240 |
real_path = os.path.realpath(p) |
241 |
realpath_cache[p] = real_path |
242 |
return real_path |
243 |
|
226 |
if obj not in self._obj_properties: |
244 |
if obj not in self._obj_properties: |
227 |
obj = os.path.realpath(obj) |
245 |
obj = realpath(obj) |
228 |
if obj not in self._obj_properties: |
246 |
if obj not in self._obj_properties: |
229 |
raise KeyError("%s not in object list" % obj) |
247 |
raise KeyError("%s not in object list" % obj) |
230 |
rValue = set() |
248 |
rValue = set() |
Lines 233-242
Link Here
|
233 |
if obj in self._libs[soname][arch]["providers"]: |
251 |
if obj in self._libs[soname][arch]["providers"]: |
234 |
for x in self._libs[soname][arch]["consumers"]: |
252 |
for x in self._libs[soname][arch]["consumers"]: |
235 |
path = self._obj_properties[x][2] |
253 |
path = self._obj_properties[x][2] |
236 |
path = [os.path.realpath(y) for y in path+self._defpath] |
254 |
path = [realpath(y) for y in path+self._defpath] |
237 |
if soname[0] == os.sep and os.path.realpath(soname) == os.path.realpath(obj): |
255 |
if soname[0] == os.sep and realpath(soname) == realpath(obj): |
238 |
rValue.add(x) |
256 |
rValue.add(x) |
239 |
elif os.path.realpath(os.path.dirname(obj)) in path: |
257 |
elif realpath(os.path.dirname(obj)) in path: |
240 |
rValue.add(x) |
258 |
rValue.add(x) |
241 |
return rValue |
259 |
return rValue |
242 |
|
260 |
|
Lines 1995-2003
Link Here
|
1995 |
if os.path.islink(x) and os.path.realpath(x) in candidates and x not in mycontents: |
2013 |
if os.path.islink(x) and os.path.realpath(x) in candidates and x not in mycontents: |
1996 |
candidates.add(x) |
2014 |
candidates.add(x) |
1997 |
|
2015 |
|
|
|
2016 |
provider_cache = {} |
2017 |
consumer_cache = {} |
2018 |
|
1998 |
# ignore any libs that are only internally used by the package |
2019 |
# ignore any libs that are only internally used by the package |
1999 |
def has_external_consumers(lib, contents, otherlibs): |
2020 |
def has_external_consumers(lib, contents, otherlibs): |
2000 |
consumers = linkmap.findConsumers(lib) |
2021 |
consumers = consumer_cache.get(lib) |
|
|
2022 |
if consumers is None: |
2023 |
consumers = linkmap.findConsumers(lib) |
2024 |
consumer_cache[lib] = consumers |
2001 |
contents_without_libs = [x for x in contents if x not in otherlibs] |
2025 |
contents_without_libs = [x for x in contents if x not in otherlibs] |
2002 |
|
2026 |
|
2003 |
# just used by objects that will be autocleaned |
2027 |
# just used by objects that will be autocleaned |
Lines 2024-2033
Link Here
|
2024 |
continue |
2048 |
continue |
2025 |
# only preserve the lib if there is no other copy to use for each consumer |
2049 |
# only preserve the lib if there is no other copy to use for each consumer |
2026 |
keep = False |
2050 |
keep = False |
2027 |
for c in linkmap.findConsumers(lib): |
2051 |
|
|
|
2052 |
lib_consumers = consumer_cache.get(lib) |
2053 |
if lib_consumers is None: |
2054 |
lib_consumers = linkmap.findConsumers(lib) |
2055 |
consumer_cache[lib] = lib_consumers |
2056 |
|
2057 |
for c in lib_consumers: |
2028 |
localkeep = True |
2058 |
localkeep = True |
2029 |
providers = linkmap.findProviders(c) |
2059 |
providers = provider_cache.get(c) |
2030 |
|
2060 |
if providers is None: |
|
|
2061 |
providers = linkmap.findProviders(c) |
2062 |
provider_cache[c] = providers |
2063 |
|
2031 |
for soname in providers: |
2064 |
for soname in providers: |
2032 |
if lib in providers[soname]: |
2065 |
if lib in providers[soname]: |
2033 |
for p in providers[soname]: |
2066 |
for p in providers[soname]: |
Lines 2068-2075
Link Here
|
2068 |
os.symlink(linktarget, os.path.join(srcroot, x.lstrip(os.sep))) |
2101 |
os.symlink(linktarget, os.path.join(srcroot, x.lstrip(os.sep))) |
2069 |
if linktarget[0] != os.sep: |
2102 |
if linktarget[0] != os.sep: |
2070 |
linktarget = os.path.join(os.path.dirname(x), linktarget) |
2103 |
linktarget = os.path.join(os.path.dirname(x), linktarget) |
2071 |
candidates.add(linktarget) |
2104 |
if linktarget not in candidates: |
2072 |
candidates_stack.append(linktarget) |
2105 |
candidates.add(linktarget) |
|
|
2106 |
candidates_stack.append(linktarget) |
2073 |
else: |
2107 |
else: |
2074 |
shutil.copy2(os.path.join(destroot, x.lstrip(os.sep)), |
2108 |
shutil.copy2(os.path.join(destroot, x.lstrip(os.sep)), |
2075 |
os.path.join(srcroot, x.lstrip(os.sep))) |
2109 |
os.path.join(srcroot, x.lstrip(os.sep))) |