From: Zac Medico Date: Tue, 27 May 2008 04:04:28 +0000 (-0000) Subject: Fix USE dep matching support in match_from_list() so that it checks X-Git-Tag: v2.2_pre8~98 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=95b33fccd8ece8f5dc36eaa82f614ca3aff62335;p=portage.git Fix USE dep matching support in match_from_list() so that it checks to make sure the package supports all specified IUSE. This involves updating all Package, FakeVartree, and BlockerDB constructor arguments to implement a Package.root_config attribute that's used to access implicit IUSE. svn path=/main/trunk/; revision=10440 --- diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index c4689300c..9f3a2200b 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -399,6 +399,7 @@ class search(object): self.spinner = spinner self.verbose = verbose self.searchdesc = searchdesc + self.root_config = root_config self.setconfig = root_config.setconfig def fake_portdb(): @@ -470,7 +471,7 @@ class search(object): elif built: pkg_type = "binary" return visible(self.settings, - Package(type_name=pkg_type, root=self.settings["ROOT"], + Package(type_name=pkg_type, root_config=self.root_config, cpv=cpv, built=built, installed=installed, metadata=metadata)) def _xmatch(self, level, atom): @@ -729,6 +730,7 @@ class RootConfig(object): def __init__(self, settings, trees, setconfig): self.trees = trees self.settings = settings + self.iuse_implicit = tuple(sorted(settings._get_implicit_iuse())) self.root = self.settings["ROOT"] self.setconfig = setconfig self.sets = self.setconfig.getSets() @@ -741,7 +743,7 @@ def create_world_atom(pkg_key, metadata, args_set, root_config): in world since system atoms can only match one slot while world atoms can be greedy with respect to slots. Unslotted system packages will not be stored in world.""" - pkg = Package(cpv=pkg_key, metadata=metadata) + pkg = Package(cpv=pkg_key, root_config=root_config, metadata=metadata) arg_atom = args_set.findAtomForPackage(pkg) if not arg_atom: return None @@ -977,11 +979,14 @@ class FakeVartree(portage.vartree): user doesn't necessarily need write access to the vardb in cases where global updates are necessary (updates are performed when necessary if there is not a matching ebuild in the tree).""" - def __init__(self, real_vartree, portdb, - db_keys, pkg_cache, acquire_lock=1): + def __init__(self, root_config, pkg_cache=None, acquire_lock=1): + if pkg_cache is None: + pkg_cache = {} + real_vartree = root_config.trees["vartree"] + portdb = root_config.trees["porttree"].dbapi self.root = real_vartree.root self.settings = real_vartree.settings - mykeys = db_keys[:] + mykeys = list(Package.metadata_keys) for required_key in ("COUNTER", "SLOT"): if required_key not in mykeys: mykeys.append(required_key) @@ -1022,7 +1027,7 @@ class FakeVartree(portage.vartree): if pkg is None: pkg = Package(built=True, cpv=cpv, installed=True, metadata=metadata, - root=self.root, type_name="installed") + root_config=root_config, type_name="installed") self._pkg_cache[pkg] = pkg self.dbapi.cpv_inject(pkg) real_dbapi.flush_cache() @@ -1159,7 +1164,7 @@ def get_mask_info(root_config, cpv, pkgsettings, if metadata is None: mreasons = ["corruption"] else: - pkg = Package(type_name=pkg_type, root=root_config.root, + pkg = Package(type_name=pkg_type, root_config=root_config, cpv=cpv, built=built, installed=installed, metadata=metadata) mreasons = get_masking_status(pkg, pkgsettings, root_config) return metadata, mreasons @@ -1267,9 +1272,9 @@ class Blocker(Task): class Package(Task): __slots__ = ("built", "cpv", "depth", "installed", "metadata", "onlydeps", "operation", - "root", "type_name", - "category", "cp", "cpv_split", - "pf", "pv_split", "slot", "slot_atom", "use") + "root_config", "type_name", + "category", "cp", "cpv_split", "iuse", + "pf", "pv_split", "root", "slot", "slot_atom", "use") metadata_keys = [ "CHOST", "COUNTER", "DEPEND", "EAPI", "IUSE", "KEYWORDS", @@ -1278,6 +1283,7 @@ class Package(Task): def __init__(self, **kwargs): Task.__init__(self, **kwargs) + self.root = self.root_config.root self.metadata = self._metadata_wrapper(self, self.metadata) self.cp = portage.cpv_getkey(self.cpv) self.slot_atom = portage.dep.Atom("%s:%s" % (self.cp, self.slot)) @@ -1286,13 +1292,51 @@ class Package(Task): self.pv_split = self.cpv_split[1:] class _use(object): + + __slots__ = ("__weakref__", "enabled") + def __init__(self, use): self.enabled = frozenset(use) + class _iuse(object): + + __slots__ = ("__weakref__", "all", "enabled", "disabled", "iuse_implicit", "regex", "tokens") + + def __init__(self, tokens, iuse_implicit): + self.tokens = tuple(tokens) + self.iuse_implicit = iuse_implicit + enabled = [] + disabled = [] + other = [] + for x in tokens: + prefix = x[:1] + if prefix == "+": + enabled.append(x[1:]) + elif prefix == "-": + disabled.append(x[1:]) + else: + other.append(x) + self.enabled = frozenset(enabled) + self.disabled = frozenset(disabled) + self.all = frozenset(chain(enabled, disabled, other)) + + def __getattribute__(self, name): + if name == "regex": + try: + return object.__getattribute__(self, "regex") + except AttributeError: + all = object.__getattribute__(self, "all") + iuse_implicit = object.__getattribute__(self, "iuse_implicit") + self.regex = re.compile("^(%s)$" % "|".join( + chain((re.escape(x) for x in all), iuse_implicit))) + return object.__getattribute__(self, name) + class _metadata_wrapper(dict): """ Detect metadata updates and synchronize Package attributes. """ + _wrapped_keys = frozenset(["IUSE", "SLOT", "USE"]) + def __init__(self, pkg, metadata): dict.__init__(self) self._pkg = pkg @@ -1306,10 +1350,18 @@ class Package(Task): def __setitem__(self, k, v): dict.__setitem__(self, k, v) - if k == "USE": - self._pkg.use = self._pkg._use(v.split()) - elif k == "SLOT": - self._pkg.slot = v + if k in self._wrapped_keys: + getattr(self, "_set_" + k.lower())(k, v) + + def _set_iuse(self, k, v): + self._pkg.iuse = self._pkg._iuse( + v.split(), self._pkg.root_config.iuse_implicit) + + def _set_slot(self, k, v): + self._pkg.slot = v + + def _set_use(self, k, v): + self._pkg.use = self._pkg._use(v.split()) def _get_hash_key(self): hash_key = getattr(self, "_hash_key", None) @@ -1547,9 +1599,10 @@ class BlockerCache(DictMixin): class BlockerDB(object): - def __init__(self, vartree, portdb): - self._vartree = vartree - self._portdb = portdb + def __init__(self, root_config): + self._root_config = root_config + self._vartree = root_config.trees["vartree"] + self._portdb = root_config.trees["porttree"].dbapi self._blocker_cache = \ BlockerCache(self._vartree.root, vartree.dbapi) self._dep_check_trees = { self._vartree.root : { @@ -1564,9 +1617,7 @@ class BlockerDB(object): settings = self._vartree.settings stale_cache = set(blocker_cache) fake_vartree = \ - FakeVartree(self._vartree, - self._portdb, Package.metadata_keys, {}, - acquire_lock=acquire_lock) + FakeVartree(self._root_config, acquire_lock=acquire_lock) vardb = fake_vartree.dbapi installed_pkgs = list(vardb) @@ -1842,9 +1893,8 @@ class depgraph(object): for tree in ("porttree", "bintree"): self.trees[myroot][tree] = trees[myroot][tree] self.trees[myroot]["vartree"] = \ - FakeVartree(trees[myroot]["vartree"], - trees[myroot]["porttree"].dbapi, - self._mydbapi_keys, self._pkg_cache) + FakeVartree(trees[myroot]["root_config"], + pkg_cache=self._pkg_cache) self.pkgsettings[myroot] = portage.config( clone=self.trees[myroot]["vartree"].settings) self._slot_pkg_map[myroot] = {} @@ -1855,14 +1905,10 @@ class depgraph(object): # have after new packages have been installed. fakedb = PackageVirtualDbapi(vardb.settings) if preload_installed_pkgs: - for cpv in vardb.cpv_all(): + for pkg in vardb: self.spinner.update() - metadata = dict(izip(self._mydbapi_keys, - vardb.aux_get(cpv, self._mydbapi_keys))) - pkg = Package(built=True, cpv=cpv, - installed=True, metadata=metadata, - root=myroot, type_name="installed") - self._pkg_cache[pkg] = pkg + # This triggers metadata updates via FakeVartree. + vardb.aux_get(pkg.cpv, []) fakedb.cpv_inject(pkg) self.mydbapi[myroot] = fakedb def graph_tree(): @@ -2506,7 +2552,7 @@ class depgraph(object): return 0, myfavorites metadata = dict(izip(self._mydbapi_keys, bindb.aux_get(mykey, self._mydbapi_keys))) - pkg = Package(type_name="binary", root=myroot, + pkg = Package(type_name="binary", root_config=root_config, cpv=mykey, built=True, metadata=metadata, onlydeps=onlydeps) self._pkg_cache[pkg] = pkg @@ -2546,7 +2592,7 @@ class depgraph(object): portdb.aux_get(mykey, self._mydbapi_keys))) pkgsettings.setcpv(mykey, mydb=metadata) metadata["USE"] = pkgsettings["PORTAGE_USE"] - pkg = Package(type_name="ebuild", root=myroot, + pkg = Package(type_name="ebuild", root_config=root_config, cpv=mykey, metadata=metadata, onlydeps=onlydeps) self._pkg_cache[pkg] = pkg args.append(PackageArg(arg=x, package=pkg, @@ -2895,7 +2941,8 @@ class depgraph(object): pkgsettings, db, pkg_type, built, installed, db_keys) if atom.use and not mreasons: missing_use.append(Package(built=built, cpv=cpv, - installed=installed, metadata=metadata, root=root)) + installed=installed, metadata=metadata, + root_config=root_config)) else: masked_packages.append( (root_config, pkgsettings, cpv, metadata, mreasons)) @@ -2978,6 +3025,7 @@ class depgraph(object): return ret def _select_pkg_highest_available_imp(self, root, atom, onlydeps=False): + root_config = self.roots[root] pkgsettings = self.pkgsettings[root] dbs = self._filtered_trees[root]["dbs"] vardb = self.roots[root].trees["vartree"].dbapi @@ -3063,7 +3111,8 @@ class depgraph(object): continue pkg = Package(built=built, cpv=cpv, installed=installed, metadata=metadata, - onlydeps=onlydeps, root=root, type_name=pkg_type) + onlydeps=onlydeps, root_config=root_config, + type_name=pkg_type) metadata = pkg.metadata if not built and ("?" in metadata["LICENSE"] or \ "?" in metadata["PROVIDE"]): @@ -3595,7 +3644,8 @@ class depgraph(object): uninst_task = Package(built=inst_pkg.built, cpv=inst_pkg.cpv, installed=inst_pkg.installed, metadata=inst_pkg.metadata, - operation="uninstall", root=inst_pkg.root, + operation="uninstall", + root_config=inst_pkg.root_config, type_name=inst_pkg.type_name) self._pkg_cache[uninst_task] = uninst_task # Enforce correct merge order with a hard dep. @@ -5207,9 +5257,10 @@ class depgraph(object): raise portage.exception.PackageNotFound(pkg_key) installed = action == "uninstall" built = pkg_type != "ebuild" + root_config = self.roots[myroot] pkg = Package(built=built, cpv=pkg_key, installed=installed, metadata=metadata, - operation=action, root=myroot, + operation=action, root_config=root_config, type_name=pkg_type) if pkg_type == "ebuild": pkgsettings = self.pkgsettings[myroot] @@ -5650,9 +5701,7 @@ class MergeTask(object): for root in trees: self.pkgsettings[root] = portage.config( clone=trees[root]["vartree"].settings) - self._blocker_db[root] = BlockerDB( - trees[root]["vartree"], - trees[root]["porttree"].dbapi) + self._blocker_db[root] = BlockerDB(trees[root]["root_config"]) self.curval = 0 self._spawned_pids = [] @@ -7788,9 +7837,7 @@ def action_depclean(settings, trees, ldpath_mtimes, dep_check_trees = {} dep_check_trees[myroot] = {} dep_check_trees[myroot]["vartree"] = \ - FakeVartree(trees[myroot]["vartree"], - trees[myroot]["porttree"].dbapi, - depgraph._mydbapi_keys, pkg_cache) + FakeVartree(trees[myroot]["root_config"], pkg_cache=pkg_cache) vardb = dep_check_trees[myroot]["vartree"].dbapi # Constrain dependency selection to the installed packages. dep_check_trees[myroot]["porttree"] = dep_check_trees[myroot]["vartree"] diff --git a/pym/portage/dep.py b/pym/portage/dep.py index ae6363d07..8c819138f 100644 --- a/pym/portage/dep.py +++ b/pym/portage/dep.py @@ -890,11 +890,16 @@ def match_from_list(mydep, candidate_list): candidate_list = mylist mylist = [] for x in candidate_list: - # Note: IUSE intersection is neglected here since there - # is currently no way to access implicit IUSE. However, IUSE - # filtering can be added elsewhere in the chain. use = getattr(x, "use", None) if use is not None: + regex = x.iuse.regex + missing_iuse = False + for y in mydep.use.required: + if regex.match(y) is None: + missing_iuse = True + break + if missing_iuse: + continue if mydep.use.enabled.difference(use.enabled): continue if mydep.use.disabled.intersection(use.enabled):