1 --- libs.py.2.2_rc6 2008-08-01 15:41:14.000000000 -0500
2 +++ pym/portage/sets/libs.py 2008-08-11 22:43:15.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):
78 + # Get the list of broken dependencies from LinkageMap.
80 + timeStart = time.time()
81 + brokenDependencies = self.linkmap.listBrokenBinaries()
83 + timeListBrokenBinaries = time.time() - timeStart
85 + # Add broken libtool libraries into the brokenDependencies dict.
87 + timeStart = time.time()
88 + brokenDependencies.update(self.listBrokenLibtoolLibraries())
90 + timeLibtool = time.time() - timeStart
92 + # FIXME Too many atoms may be emerged because libraries in binary
93 + # packages are not being handled properly eg openoffice, nvidia-drivers,
94 + # sun-jdk. Certain binaries are run in an environment where additional
95 + # library paths are added via LD_LIBRARY_PATH. Since these paths aren't
96 + # registered in _obj_properties, they appear broken (and are if not run
97 + # in the correct environment). I have to determine if libraries and lib
98 + # paths should be masked using /etc/revdep-rebuild/* as done in
99 + # revdep-rebuild or if there is a better way to identify and deal with
100 + # these problematic packages (or if something entirely different should
101 + # be done). For now directory and library masks are used.
103 + # Remove masked directories and libraries.
105 + timeStart = time.time()
106 + if brokenDependencies:
107 + brokenDependencies = self.removeMaskedDependencies(brokenDependencies)
109 + timeMask = time.time() - timeStart
111 + # Determine atoms to emerge based on broken objects in
112 + # brokenDependencies.
114 + timeStart = time.time()
115 + if brokenDependencies:
116 + atoms = self.mapPathsToAtoms(set(brokenDependencies.keys()))
118 + timeAtoms = time.time() - timeStart
123 + print len(brokenDependencies), "brokenDependencies:"
124 + for x in sorted(brokenDependencies.keys()):
127 + print '\t', brokenDependencies[x]
129 + print "atoms to be emerged:"
130 + for x in sorted(atoms):
133 + print "Broken binaries time:", timeListBrokenBinaries
134 + print "Broken libtool time:", timeLibtool
135 + print "Remove mask time:", timeMask
136 + print "mapPathsToAtoms time:", timeAtoms
139 + self._setAtoms(atoms)
141 + def removeMaskedDependencies(self, dependencies):
143 + Remove all masked dependencies and return the updated mapping.
145 + @param dependencies: dependencies from which to removed masked
147 + @type dependencies: dict (example: {'/usr/bin/foo': set(['libfoo.so'])})
149 + @return: shallow copy of dependencies with masked items removed
152 + rValue = dependencies.copy()
153 + dirMask, libMask = self.getDependencyMasks()
155 + # Remove entries that are masked.
156 + if dirMask or libMask:
158 + print "The following are masked:"
159 + for binary, libSet in rValue.items():
160 + for directory in dirMask:
161 + # Check if the broken binary lies within the masked directory or
162 + # its subdirectories.
163 + # XXX Perhaps we should allow regexps as masks.
164 + if binary.startswith(directory):
167 + print "dirMask:",binary
169 + # Check if all the required libraries are masked.
170 + if binary in rValue and libSet.issubset(libMask):
173 + print "libMask:", binary, libSet & libMask
177 + print "Directory mask:", dirMask
179 + print "Library mask:", libMask
183 + def getDependencyMasks(self):
185 + Return all dependency masks as a tuple.
187 + @rtype: 2-tuple of sets of strings
188 + @return: 2-tuple in which the first component is a set of directory
189 + masks and the second component is a set of library masks
194 + _dirMask_re = re.compile(r'SEARCH_DIRS_MASK\s*=\s*"([^"]*)"')
195 + _libMask_re = re.compile(r'LD_LIBRARY_MASK\s*=\s*"([^"]*)"')
198 + # Reads the contents of /etc/revdep-rebuild/*
199 + libMaskDir = os.path.join(self.root, "etc", "revdep-rebuild")
200 + if os.path.exists(libMaskDir):
201 + for file in os.listdir(libMaskDir):
203 + f = open(os.path.join(libMaskDir, file), "r")
205 + lines.extend(f.readlines())
208 + except IOError: # OSError?
210 + # The following parses SEARCH_DIRS_MASK and LD_LIBRARY_MASK variables
211 + # from /etc/revdep-rebuild/*
213 + matchDir = _dirMask_re.match(line)
214 + matchLib = _libMask_re.match(line)
216 + dirMask.update(set(matchDir.group(1).split()))
218 + libMask.update(set(matchLib.group(1).split()))
220 + # These directories contain specially evaluated libraries.
221 + # app-emulation/vmware-workstation-6.0.1.55017
222 + dirMask.add('/opt/vmware/workstation/lib')
223 + # app-emulation/vmware-server-console-1.0.6.91891
224 + dirMask.add('/opt/vmware/server/console/lib')
225 + # www-client/mozilla-firefox-2.0.0.15
226 + dirMask.add('/usr/lib/mozilla-firefox/plugins')
227 + dirMask.add('/usr/lib64/mozilla-firefox/plugins')
228 + # app-office/openoffice-2.4.1
229 + dirMask.add('/opt/OpenOffice')
230 + dirMask.add('/usr/lib/openoffice')
231 + # dev-libs/libmix-2.05 libmix.so is missing soname entry
232 + libMask.add('libmix.so')
234 + return (dirMask, libMask)
236 + def findAtomsOfLibraryConsumers(self, searchString):
238 + Return atoms containing consumers of libraries matching the argument.
240 + @param searchString: a string used to search for libraries
241 + @type searchString: string to be compiled as a regular expression
242 + (example: 'libfoo.*')
243 + @rtype: set of strings
244 + @return: the returned set of atoms are valid to be used by package sets
249 + matchedLibraries = set()
250 + libraryObjects = []
251 + _librarySearch_re = re.compile(searchString)
253 + # Find libraries matching searchString.
254 + libraryObjects = self.linkmap.listLibraryObjects()
255 + for library in libraryObjects:
256 + m = _librarySearch_re.search(library)
258 + matchedLibraries.add(library)
259 + consumers.update(self.linkmap.findConsumers(library))
263 + print "Consumers of the following libraries will be emerged:"
264 + for x in matchedLibraries:
268 + # The following prevents emerging the packages that own the matched
269 + # libraries. Note that this will prevent updating the packages owning
270 + # the libraries if there are newer versions available in the installed
271 + # slot. See bug #30095
272 + atoms = self.mapPathsToAtoms(consumers)
273 + libraryOwners = self.mapPathsToAtoms(matchedLibraries)
274 + atoms.difference_update(libraryOwners)
278 + def listBrokenLibtoolLibraries(self):
280 + Find broken libtool libraries and their missing dependencies.
282 + @rtype: dict (example: {'/lib/libfoo.la': set(['/lib/libbar.la'])})
283 + @return: The return value is a library -> set-of-libraries mapping, where
284 + library is a broken library and the set consists of dependencies
285 + needed by library that do not exist on the filesystem.
291 + _la_re = re.compile(r".*\.la$")
292 + _dependency_libs_re = re.compile(r"^dependency_libs\s*=\s*'(.*)'")
294 + # Loop over the contents of all packages.
295 + for cpv in self.dbapi.cpv_all():
296 + mysplit = catsplit(cpv)
297 + link = dblink(mysplit[0], mysplit[1], myroot=self.dbapi.root, \
298 + mysettings=self.dbapi.settings, treetype='vartree', \
299 + vartree=self.dbapi.vartree)
300 + for file in link.getcontents():
301 + # Check if the file ends with '.la'.
302 + matchLib = _la_re.match(file)
304 + # Read the lines from the library.
307 + f = open(file, "r")
309 + lines.extend(f.readlines())
314 + # Find the line listing the dependencies.
316 + matchLine = _dependency_libs_re.match(line)
318 + dependencies = matchLine.group(1).split()
319 + # For each dependency that is a pathname (begins with
320 + # os.sep), check that it exists on the filesystem. If it
321 + # does not exist, then add the library and the missing
322 + # dependency to rValue.
323 + for dependency in dependencies:
324 + if dependency[0] == os.sep and \
325 + not os.path.isfile(dependency):
326 + rValue.setdefault(file, set()).add(dependency)
330 + def singleBuilder(self, options, settings, trees):
331 + debug = get_boolean(options, "debug", False)
332 + return MissingLibraryConsumerSet(trees["vartree"].dbapi, debug)
333 + singleBuilder = classmethod(singleBuilder)