object that simply returns boolean, and update consumers.
* Make check_required_use() take a callable for the iuse parameter,
and pass in Package.use.is_valid_flag or iuse.__contains__ as
appropriate.
relative_path + ": REQUIRED_USE" + \
" not supported with EAPI='%s'" % (eapi,))
try:
- iuse = repoman_settings._get_implicit_iuse()
- iuse.update(myaux["IUSE"].split())
- portage.dep.check_required_use(required_use, "", iuse)
+ portage.dep.check_required_use(required_use, (),
+ pkg.iuse.is_valid_flag)
except portage.exception.InvalidDependString as e:
stats["REQUIRED_USE.syntax"] = stats["REQUIRED_USE.syntax"] + 1
fails["REQUIRED_USE.syntax"].append(
class _iuse(object):
__slots__ = ("__weakref__", "all", "enabled", "disabled",
- "tokens") + ("_iuse_implicit_regex",)
+ "tokens") + ("_iuse_implicit_match",)
- def __init__(self, tokens, iuse_implicit_regex):
+ def __init__(self, tokens, iuse_implicit_match):
self.tokens = tuple(tokens)
- self._iuse_implicit_regex = iuse_implicit_regex
+ self._iuse_implicit_match = iuse_implicit_match
enabled = []
disabled = []
other = []
for flag in flags:
if not flag in self.all and \
- self._iuse_implicit_regex.match(flag) is None:
+ not self._iuse_implicit_match(flag):
return False
return True
missing_iuse = []
for flag in flags:
if not flag in self.all and \
- self._iuse_implicit_regex.match(flag) is None:
+ not self._iuse_implicit_match(flag):
missing_iuse.append(flag)
return missing_iuse
def _set_iuse(self, k, v):
self._pkg.iuse = self._pkg._iuse(
- v.split(), self._pkg.root_config.settings._iuse_implicit_re)
+ v.split(), self._pkg.root_config.settings._iuse_implicit_match)
def _set_slot(self, k, v):
self._pkg.slot = v
missing_licenses = []
have_eapi_mask = False
pkgsettings = self._frozen_config.pkgsettings[root]
- implicit_iuse = pkgsettings._get_implicit_iuse()
root_config = self._frozen_config.roots[root]
portdb = self._frozen_config.roots[root].trees["porttree"].dbapi
dbs = self._dynamic_config._filtered_trees[root]["dbs"]
eapi_has_required_use(pkg.metadata["EAPI"]):
required_use = pkg.metadata["REQUIRED_USE"]
use = pkg.use.enabled
- iuse = self._frozen_config.settings._get_implicit_iuse()
- iuse.update(pkg.iuse.all)
try:
required_use_is_sat = portage.dep.check_required_use(
- pkg.metadata["REQUIRED_USE"], use, iuse)
+ pkg.metadata["REQUIRED_USE"], use, pkg.iuse.is_valid_flag)
except portage.exception.InvalidDependString as e:
portage.writemsg("!!! Invalid REQUIRED_USE specified by " + \
"'%s': %s\n" % (pkg.cpv, str(e)), noiselevel=-1)
eapi_has_required_use(pkg.metadata["EAPI"]):
required_use = pkg.metadata["REQUIRED_USE"]
use = pkg.use.enabled
- iuse = pkgsettings._get_implicit_iuse()
- iuse.update(pkg.iuse.all)
try:
required_use_is_sat = portage.dep.check_required_use(
- required_use, use, iuse)
+ required_use, use, pkg.iuse.is_valid_flag)
except portage.exception.InvalidDependString:
mreasons.append("invalid: REQUIRED_USE")
else:
2) Check enabled/disabled flag states.
"""
- iuse_implicit_re = self.settings._iuse_implicit_re
+ iuse_implicit_match = self.settings._iuse_implicit_match
for cpv in cpv_iter:
try:
iuse, slot, use = self.aux_get(cpv, ["IUSE", "SLOT", "USE"])
missing_iuse = False
for x in atom.use.required:
if x not in iuse and x not in atom.use.missing_enabled \
- and x not in atom.use.missing_disabled and iuse_implicit_re.match(x) is None:
+ and x not in atom.use.missing_disabled and not iuse_implicit_match(x):
missing_iuse = True
break
if missing_iuse:
mylist.append(x)
return mylist
-def check_required_use(required_use, use, iuse):
+def check_required_use(required_use, use, iuse_match):
"""
Checks if the use flags listed in 'use' satisfy all
constraints specified in 'constraints'.
@type constraints: String
@param use: Enabled use flags
@param use: List
- @param iuse: Referenceable use flags
- @param iuse: List
+ @param iuse_match: Callable that takes a single flag argument and returns
+ True if the flag is matched, false otherwise,
+ @param iuse_match: Callable
@rtype: Bool
@return: Indicates if REQUIRED_USE constraints are satisfied
"""
flag = token
is_negated = False
- if not flag or not flag in iuse:
+ if not flag or not iuse_match(flag):
raise portage.exception.InvalidDependString(
_("malformed syntax: '%s'") % required_use)
class _iuse_implicit_match_cache(object):
- def __init__(self, iuse_implicit_re):
- self._iuse_implicit_re = iuse_implicit_re
+ def __init__(self, settings):
+ self._iuse_implicit_re = re.compile("^(%s)$" % \
+ "|".join(settings._get_implicit_iuse()))
self._cache = {}
- def match(self, flag):
+ def __call__(self, flag):
+ """
+ Returns True if the flag is matched, False otherwise.
+ """
try:
return self._cache[flag]
except KeyError:
- m = self._iuse_implicit_re.match(flag)
+ m = self._iuse_implicit_re.match(flag) is not None
self._cache[flag] = m
return m
self.packages = clone.packages
self.useforce_list = clone.useforce_list
self.usemask_list = clone.usemask_list
- self._iuse_implicit_re = clone._iuse_implicit_re
+ self._iuse_implicit_match = clone._iuse_implicit_match
self.user_profile_dir = copy.deepcopy(clone.user_profile_dir)
self.local_config = copy.deepcopy(clone.local_config)
if 'parse-eapi-ebuild-head' in self.features:
_validate_cache_for_unsupported_eapis = False
- self._iuse_implicit_re = _iuse_implicit_match_cache(
- re.compile("^(%s)$" % \
- "|".join(self._get_implicit_iuse())))
+ self._iuse_implicit_match = _iuse_implicit_match_cache(self)
for k in self._case_insensitive_vars:
if k in self:
use = set(self["USE"].split())
if explicit_iuse is None:
explicit_iuse = frozenset(x.lstrip("+-") for x in iuse.split())
- implicit_iuse_re = self._iuse_implicit_re
+ iuse_implicit_match = self._iuse_implicit_match
portage_iuse = self._get_implicit_iuse()
portage_iuse.update(explicit_iuse)
# Allow _* flags from USE_EXPAND wildcards to pass through here.
use.difference_update([x for x in use \
if (x not in explicit_iuse and \
- implicit_iuse_re.match(x) is None) and x[-2:] != '_*'])
+ not iuse_implicit_match(x)) and x[-2:] != '_*'])
# Use the calculated USE flags to regenerate the USE_EXPAND flags so
# that they are consistent. For optimal performance, use slice
)
for required_use, use, iuse, expected in test_cases:
- self.assertEqual(check_required_use(required_use, use, iuse), \
+ self.assertEqual(check_required_use(required_use, use, iuse.__contains__), \
expected, required_use + ", USE = " + " ".join(use))
for required_use, use, iuse in test_cases_xfail:
self.assertRaisesMsg(required_use + ", USE = " + " ".join(use), \
- InvalidDependString, check_required_use, required_use, use, iuse)
+ InvalidDependString, check_required_use, required_use, use, iuse.__contains__)