commit
[revdep-rebuild-reimplementation.git] / revdep.py
blob8ab1283f4c2bda9733f1382a6807219d1ffce2e2
1 # Copyright 2008 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 import os
5 from portage.sets.libs import LibraryConsumerSet
6 #from portage.dbapi.vartree import LinkageMap
7 from portage.sets import get_boolean
8 from portage.dbapi.vartree import dblink
9 from portage.versions import catsplit
11 __all__ = ["MissingLibraryConsumerSet"]
13 class MissingLibraryConsumerSet(LibraryConsumerSet):
14 description = "set of packages to emerge due to missing libraries"
15 _operations = ["merge"]
17 # TODO Redefine __init__() to accept user parameters.
19 def load(self):
20 atoms = set()
21 # brokenDependencies: binary -> list-of-unsatisfied-sonames,
22 # where binary is an installed binary/library and
23 # list-of-unsatisfied-sonames are sonames required by the binary but
24 # have no corresponding libraries to fulfill the dependency.
25 brokenDependencies = {}
27 # The following iterates over the contents of all installed packages
28 # in order to find providers for all binaries.
29 for cpv in self.dbapi.cpv_all():
30 if self.debug:
31 print
32 print cpv
33 mysplit = catsplit(cpv)
34 link = dblink(mysplit[0], mysplit[1], myroot=self.dbapi.root, \
35 mysettings=self.dbapi.settings, treetype='vartree', \
36 vartree=self.dbapi.vartree)
37 for path in link.getcontents():
38 try:
39 providers = self.dbapi.linkmap.findProviders(path)
40 except KeyError:
41 # For now, the KeyError will be ignored for non-binaries.
42 # Once the LinkageMap method is implemented, this will be
43 # unnecessary. See below.
44 continue
45 else:
46 if self.debug:
47 print '\t', "providers for %s:" % path
48 # Iterate over all providers
49 for key, value in providers.items():
50 if self.debug:
51 print '\t'*2, key, value
52 # TODO Check that the library exists on the filesystem.
54 # If there are no libraries to satisfy the soname (empty set),
55 # add the soname to the set of missing sonames for that
56 # consumer.
57 if value == set() and key != '':
58 # key != '' catches cases where findProviders(path)
59 # returns {'': set([])}, which means path has consumers
60 # but no providers eg /lib/ld-2.6.1.so.
61 brokenDependencies.setdefault(path, set()).add(key)
62 if self.debug:
63 print '\t'*3, "Added", path, "->", key
64 # print '\t'*3, providers
66 # TODO Rather than iterate over the contents of all packages, implement
67 # similar functionality as a new methond in the LinkageMap class by
68 # accessing _obj_properties and _libs.
69 # brokenDependencies = self.dbapi.linkmap.listBrokenDependencies()
71 # FIXME Currently, too many atoms are being emerged because binary
72 # packages are not being handled properly eg openoffice, nvidia-drivers,
73 # sun-jdk. I have to determine if libraries and lib paths should be
74 # masked using /etc/revdep-rebuild/* as done in revdep-rebuild or if
75 # there is a better way to identify and deal with these problematic
76 # packages.
78 atoms = self.mapPathsToAtoms(set(brokenDependencies.keys()))
80 if self.debug:
81 print
82 print "brokenDependencies:"
83 for x in sorted(brokenDependencies.keys()):
84 print x, "->", brokenDependencies[x]
85 print
86 print "atoms:"
87 for x in sorted(atoms):
88 print x
89 # print
90 # print "brokenDependencies' atoms:"
91 # # Warning: This might take forever.
92 # for x in sorted(brokenDependencies.keys()):
93 # print x, "->", self.mapPathsToAtoms(set([x]))
95 self._setAtoms(atoms)
97 def singleBuilder(self, options, settings, trees):
98 debug = get_boolean(options, "debug", True)
99 return MissingLibraryConsumerSet(trees["vartree"].dbapi, debug)
100 singleBuilder = classmethod(singleBuilder)