From 439b2c8e8a09bc048de66d30905dbc086ee6796d Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 23 Sep 2012 16:22:35 -0700 Subject: [PATCH] Add _get_feature_flags(eapi_attrs) function. This will be useful for adding flags that behave specially in experimental EAPIs, such as the targetroot/sysroot flag which is planned for EAPI 5-hdepend. --- pym/_emerge/depgraph.py | 11 +++++++---- pym/_emerge/resolver/output.py | 2 +- pym/_emerge/resolver/output_helpers.py | 8 +++++--- pym/portage/eapi.py | 3 ++- pym/portage/package/ebuild/config.py | 16 +++++++++++++++- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index ac70d4315..9da202c62 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -23,13 +23,14 @@ from portage.dep import Atom, best_match_to_list, extract_affecting_use, \ check_required_use, human_readable_required_use, match_from_list, \ _repo_separator from portage.dep._slot_operator import ignore_built_slot_operator_deps -from portage.eapi import eapi_has_strong_blocks, eapi_has_required_use +from portage.eapi import eapi_has_strong_blocks, eapi_has_required_use, \ + _get_eapi_attrs from portage.exception import (InvalidAtom, InvalidDependString, PackageNotFound, PortageException) from portage.output import colorize, create_color_func, \ darkgreen, green bad = create_color_func("BAD") -from portage.package.ebuild.config import _feature_flags +from portage.package.ebuild.config import _get_feature_flags from portage.package.ebuild.getmaskingstatus import \ _getmaskingstatus, _MaskReason from portage._sets import SETPREFIX @@ -1229,20 +1230,22 @@ class depgraph(object): in ("y", "auto")) newuse = "--newuse" in self._frozen_config.myopts changed_use = "changed-use" == self._frozen_config.myopts.get("--reinstall") + feature_flags = _get_feature_flags( + _get_eapi_attrs(pkg.metadata["EAPI"])) if newuse or (binpkg_respect_use and not changed_use): flags = set(orig_iuse.symmetric_difference( cur_iuse).difference(forced_flags)) flags.update(orig_iuse.intersection(orig_use).symmetric_difference( cur_iuse.intersection(cur_use))) - flags.difference_update(_feature_flags) + flags.difference_update(feature_flags) if flags: return flags elif changed_use or binpkg_respect_use: flags = set(orig_iuse.intersection(orig_use).symmetric_difference( cur_iuse.intersection(cur_use))) - flags.difference_update(_feature_flags) + flags.difference_update(feature_flags) if flags: return flags return None diff --git a/pym/_emerge/resolver/output.py b/pym/_emerge/resolver/output.py index 05a3e8278..0f2111f6d 100644 --- a/pym/_emerge/resolver/output.py +++ b/pym/_emerge/resolver/output.py @@ -251,7 +251,7 @@ class Display(object): for key in use_expand: if key in self.use_expand_hidden: continue - self.verboseadd += _create_use_string(self.conf, key.upper(), + self.verboseadd += _create_use_string(pkg, self.conf, key.upper(), cur_iuse_map[key], iuse_forced[key], cur_use_map[key], old_iuse_map[key], old_use_map[key], self.is_new, diff --git a/pym/_emerge/resolver/output_helpers.py b/pym/_emerge/resolver/output_helpers.py index be4ea4acb..23b056c3e 100644 --- a/pym/_emerge/resolver/output_helpers.py +++ b/pym/_emerge/resolver/output_helpers.py @@ -14,10 +14,11 @@ import sys from portage import os from portage import _encodings, _unicode_encode from portage._sets.base import InternalPackageSet +from portage.eapi import _get_eapi_attrs from portage.output import (blue, bold, colorize, create_color_func, green, red, teal, turquoise, yellow) bad = create_color_func("BAD") -from portage.package.ebuild.config import _feature_flags +from portage.package.ebuild.config import _get_feature_flags from portage.util import shlex_split, writemsg from portage.util.SlotObject import SlotObject from portage.versions import catpkgsplit @@ -247,7 +248,7 @@ def _format_size(mysize): mystr=mystr[:mycount]+","+mystr[mycount:] return mystr+" kB" -def _create_use_string(conf, name, cur_iuse, iuse_forced, cur_use, +def _create_use_string(pkg, conf, name, cur_iuse, iuse_forced, cur_use, old_iuse, old_use, is_new, reinst_flags): @@ -267,6 +268,7 @@ def _create_use_string(conf, name, cur_iuse, iuse_forced, cur_use, any_iuse = cur_iuse.union(old_iuse) any_iuse = list(any_iuse) any_iuse.sort() + feature_flags = _get_feature_flags(_get_eapi_attrs(pkg.metadata["EAPI"])) for flag in any_iuse: flag_str = None isEnabled = False @@ -300,7 +302,7 @@ def _create_use_string(conf, name, cur_iuse, iuse_forced, cur_use, elif flag in old_use: flag_str = green("-" + flag) + "*" if flag_str: - if flag in _feature_flags: + if flag in feature_flags: flag_str = "{" + flag_str + "}" elif flag in iuse_forced: flag_str = "(" + flag_str + ")" diff --git a/pym/portage/eapi.py b/pym/portage/eapi.py index e02e017ee..b12d81de7 100644 --- a/pym/portage/eapi.py +++ b/pym/portage/eapi.py @@ -85,7 +85,7 @@ def eapi_allows_directories_on_profile_level_and_repository_level(eapi): _eapi_attrs = collections.namedtuple('_eapi_attrs', 'dots_in_PN dots_in_use_flags exports_EBUILD_PHASE_FUNC ' - 'iuse_defaults iuse_effective ' + 'feature_flag_test iuse_defaults iuse_effective ' 'repo_deps required_use required_use_at_most_one_of slot_operator slot_deps ' 'src_uri_arrows strong_blocks use_deps use_dep_defaults') @@ -111,6 +111,7 @@ def _get_eapi_attrs(eapi): dots_in_PN = (eapi is None or eapi_allows_dots_in_PN(eapi)), dots_in_use_flags = (eapi is None or eapi_allows_dots_in_use_flags(eapi)), exports_EBUILD_PHASE_FUNC = (eapi is None or eapi_exports_EBUILD_PHASE_FUNC(eapi)), + feature_flag_test = True, iuse_defaults = (eapi is None or eapi_has_iuse_defaults(eapi)), iuse_effective = (eapi is not None and eapi_has_iuse_effective(eapi)), repo_deps = (eapi is None or eapi_has_repo_deps(eapi)), diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index 684de16db..894d14cd3 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -60,7 +60,21 @@ from portage.package.ebuild._config.helper import ordered_by_atom_specificity, p if sys.hexversion >= 0x3000000: basestring = str -_feature_flags = frozenset(["test"]) +_feature_flags_cache = {} + +def _get_feature_flags(eapi_attrs): + cache_key = (eapi_attrs.feature_flag_test,) + flags = _feature_flags_cache.get(cache_key) + if flags is not None: + return flags + + flags = [] + if eapi_attrs.feature_flag_test: + flags.append("test") + + flags = frozenset(flags) + _feature_flags_cache[cache_key] = flags + return flags def autouse(myvartree, use_cache=1, mysettings=None): warnings.warn("portage.autouse() is deprecated", -- 2.26.2