1 --- libs.py.2.2_rc6 2008-08-01 15:41:14.000000000 -0500
2 +++ pym/portage/sets/libs.py 2008-08-14 01:49:42.000000000 -0500
4 # Distributed under the terms of the GNU General Public License v2
5 # $Id: libs.py 10759 2008-06-22 04:04:50Z zmedico $
10 +from portage.dbapi.vartree import dblink
11 +from portage.versions import catsplit
12 from portage.sets.base import PackageSet
13 from portage.sets import get_boolean
14 from portage.versions import catpkgsplit
16 +__all__ = ["LibraryConsumerSet", "PreservedLibraryConsumerSet",
17 + "MissingLibraryConsumerSet"]
19 class LibraryConsumerSet(PackageSet):
20 _operations = ["merge", "unmerge"]
23 debug = get_boolean(options, "debug", False)
24 return PreservedLibraryConsumerSet(trees["vartree"].dbapi, debug)
25 singleBuilder = classmethod(singleBuilder)
28 +class MissingLibraryConsumerSet(LibraryConsumerSet):
31 + This class is the set of packages to emerge due to missing libraries.
33 + This class scans binaries for missing and broken shared library dependencies
34 + and fixes them by emerging the packages containing the broken binaries.
36 + The user may also emerge packages containing consumers of specified
37 + libraries by passing the name or a python regular expression through the
38 + environment variable, LIBRARY. Due to a limitation in passing flags to
39 + package sets through the portage cli, the user must set environment
40 + variables to modify the behaviour of this package set. So if the
41 + environment variable LIBRARY is set, the behaviour of this set changes.
45 + description = "The set of packages to emerge due to missing libraries."
46 + _operations = ["merge"]
48 + def __init__(self, vardbapi, debug=False):
49 + super(MissingLibraryConsumerSet, self).__init__(vardbapi, debug)
50 + # FIXME Since we can't get command line arguments from the user, the
51 + # soname can be passed through an environment variable for now.
52 + self.libraryRegexp = os.getenv("LIBRARY")
53 + self.root = self.dbapi.root
54 + self.linkmap = self.dbapi.linkmap
57 + # brokenDependencies: object -> set-of-unsatisfied-dependencies, where
58 + # object is an installed binary/library and
59 + # set-of-unsatisfied-dependencies are sonames or libraries required by
60 + # the object but have no corresponding libraries to fulfill the
62 + brokenDependencies = {}
65 + # If the LIBRARY environment variable is set, the resulting package set
66 + # will be packages containing consumers of the libraries matched by the
68 + if self.libraryRegexp:
69 + atoms = self.findAtomsOfLibraryConsumers(self.libraryRegexp)
70 + self._setAtoms(atoms)
73 + print "atoms to be emerged:"
74 + for x in sorted(atoms):
79 + timeStart = time.time()
80 + self.linkmap.rebuild()
82 + timeRebuild = time.time() - timeStart
84 + # Get the list of broken dependencies from LinkageMap.
86 + timeStart = time.time()
87 + brokenDependencies = self.linkmap.listBrokenBinaries()
89 + timeListBrokenBinaries = time.time() - timeStart
91 + # Add broken libtool libraries into the brokenDependencies dict.
93 + timeStart = time.time()
94 + brokenDependencies.update(self.listBrokenLibtoolLibraries())
96 + timeLibtool = time.time() - timeStart
98 + # FIXME Too many atoms may be emerged because libraries in binary
99 + # packages are not being handled properly eg openoffice, nvidia-drivers,
100 + # sun-jdk. Certain binaries are run in an environment where additional
101 + # library paths are added via LD_LIBRARY_PATH. Since these paths aren't
102 + # registered in _obj_properties, they appear broken (and are if not run
103 + # in the correct environment). I have to determine if libraries and lib
104 + # paths should be masked using /etc/revdep-rebuild/* as done in
105 + # revdep-rebuild or if there is a better way to identify and deal with
106 + # these problematic packages (or if something entirely different should
107 + # be done). For now directory and library masks are used.
109 + # Remove masked directories and libraries.
111 + timeStart = time.time()
112 + if brokenDependencies:
113 + brokenDependencies = self.removeMaskedDependencies(brokenDependencies)
115 + timeMask = time.time() - timeStart
117 + # Determine atoms to emerge based on broken objects in
118 + # brokenDependencies.
120 + timeStart = time.time()
121 + if brokenDependencies:
122 + atoms = self.mapPathsToAtoms(set(brokenDependencies.keys()))
124 + timeAtoms = time.time() - timeStart
129 + print len(brokenDependencies), "brokenDependencies:"
130 + for x in sorted(brokenDependencies.keys()):
133 + print '\t', brokenDependencies[x]
135 + print "atoms to be emerged:"
136 + for x in sorted(atoms):
139 + print "Rebuild time:", timeRebuild
140 + print "Broken binaries time:", timeListBrokenBinaries
141 + print "Broken libtool time:", timeLibtool
142 + print "Remove mask time:", timeMask
143 + print "mapPathsToAtoms time:", timeAtoms
146 + self._setAtoms(atoms)
148 + def removeMaskedDependencies(self, dependencies):
150 + Remove all masked dependencies and return the updated mapping.
152 + @param dependencies: dependencies from which to removed masked
154 + @type dependencies: dict (example: {'/usr/bin/foo': set(['libfoo.so'])})
156 + @return: shallow copy of dependencies with masked items removed
159 + rValue = dependencies.copy()
160 + dirMask, libMask = self.getDependencyMasks()
162 + # Remove entries that are masked.
163 + if dirMask or libMask:
165 + print "The following are masked:"
166 + for binary, libSet in rValue.items():
167 + for directory in dirMask:
168 + # Check if the broken binary lies within the masked directory or
169 + # its subdirectories.
170 + # XXX Perhaps we should allow regexps as masks.
171 + if binary.startswith(directory):
174 + print "dirMask:",binary
176 + # Check if all the required libraries are masked.
177 + if binary in rValue and libSet.issubset(libMask):
180 + print "libMask:", binary, libSet & libMask
184 + print "Directory mask:", dirMask
186 + print "Library mask:", libMask
190 + def getDependencyMasks(self):
192 + Return all dependency masks as a tuple.
194 + @rtype: 2-tuple of sets of strings
195 + @return: 2-tuple in which the first component is a set of directory
196 + masks and the second component is a set of library masks
201 + _dirMask_re = re.compile(r'SEARCH_DIRS_MASK\s*=\s*"([^"]*)"')
202 + _libMask_re = re.compile(r'LD_LIBRARY_MASK\s*=\s*"([^"]*)"')
205 + # Reads the contents of /etc/revdep-rebuild/*
206 + libMaskDir = os.path.join(self.root, "etc", "revdep-rebuild")
207 + if os.path.exists(libMaskDir):
208 + for file in os.listdir(libMaskDir):
210 + f = open(os.path.join(libMaskDir, file), "r")
212 + lines.extend(f.readlines())
215 + except IOError: # OSError?
217 + # The following parses SEARCH_DIRS_MASK and LD_LIBRARY_MASK variables
218 + # from /etc/revdep-rebuild/*
220 + matchDir = _dirMask_re.match(line)
221 + matchLib = _libMask_re.match(line)
223 + dirMask.update(set(matchDir.group(1).split()))
225 + libMask.update(set(matchLib.group(1).split()))
227 + # These directories contain specially evaluated libraries.
228 + # app-emulation/vmware-workstation-6.0.1.55017
229 + dirMask.add('/opt/vmware/workstation/lib')
230 + # app-emulation/vmware-server-console-1.0.6.91891
231 + dirMask.add('/opt/vmware/server/console/lib')
232 + # www-client/mozilla-firefox-2.0.0.15
233 + dirMask.add('/usr/lib/mozilla-firefox/plugins')
234 + dirMask.add('/usr/lib64/mozilla-firefox/plugins')
235 + # app-office/openoffice-2.4.1
236 + dirMask.add('/opt/OpenOffice')
237 + dirMask.add('/usr/lib/openoffice')
238 + # dev-libs/libmix-2.05 libmix.so is missing soname entry
239 + libMask.add('libmix.so')
241 + return (dirMask, libMask)
243 + def findAtomsOfLibraryConsumers(self, searchString):
245 + Return atoms containing consumers of libraries matching the argument.
247 + @param searchString: a string used to search for libraries
248 + @type searchString: string to be compiled as a regular expression
249 + (example: 'libfoo.*')
250 + @rtype: set of strings
251 + @return: the returned set of atoms are valid to be used by package sets
256 + matchedLibraries = set()
257 + libraryObjects = []
258 + _librarySearch_re = re.compile(searchString)
260 + # Find libraries matching searchString.
261 + libraryObjects = self.linkmap.listLibraryObjects()
262 + for library in libraryObjects:
263 + m = _librarySearch_re.search(library)
265 + matchedLibraries.add(library)
266 + consumers.update(self.linkmap.findConsumers(library))
270 + print "Consumers of the following libraries will be emerged:"
271 + for x in matchedLibraries:
275 + # The following prevents emerging the packages that own the matched
276 + # libraries. Note that this will prevent updating the packages owning
277 + # the libraries if there are newer versions available in the installed
278 + # slot. See bug #30095
279 + atoms = self.mapPathsToAtoms(consumers)
280 + libraryOwners = self.mapPathsToAtoms(matchedLibraries)
281 + atoms.difference_update(libraryOwners)
285 + def listBrokenLibtoolLibraries(self):
287 + Find broken libtool libraries and their missing dependencies.
289 + @rtype: dict (example: {'/lib/libfoo.la': set(['/lib/libbar.la'])})
290 + @return: The return value is a library -> set-of-libraries mapping, where
291 + library is a broken library and the set consists of dependencies
292 + needed by library that do not exist on the filesystem.
298 + _la_re = re.compile(r".*\.la$")
299 + _dependency_libs_re = re.compile(r"^dependency_libs\s*=\s*'(.*)'")
301 + # Loop over the contents of all packages.
302 + for cpv in self.dbapi.cpv_all():
303 + mysplit = catsplit(cpv)
304 + link = dblink(mysplit[0], mysplit[1], myroot=self.dbapi.root, \
305 + mysettings=self.dbapi.settings, treetype='vartree', \
306 + vartree=self.dbapi.vartree)
307 + for file in link.getcontents():
308 + # Check if the file ends with '.la'.
309 + matchLib = _la_re.match(file)
311 + # Read the lines from the library.
314 + f = open(file, "r")
316 + lines.extend(f.readlines())
321 + # Find the line listing the dependencies.
323 + matchLine = _dependency_libs_re.match(line)
325 + dependencies = matchLine.group(1).split()
326 + # For each dependency that is a pathname (begins with
327 + # os.sep), check that it exists on the filesystem. If it
328 + # does not exist, then add the library and the missing
329 + # dependency to rValue.
330 + for dependency in dependencies:
331 + if dependency[0] == os.sep and \
332 + not os.path.isfile(dependency):
333 + rValue.setdefault(file, set()).add(dependency)
337 + def singleBuilder(self, options, settings, trees):
338 + debug = get_boolean(options, "debug", False)
339 + return MissingLibraryConsumerSet(trees["vartree"].dbapi, debug)
340 + singleBuilder = classmethod(singleBuilder)