diff options
Diffstat (limited to 'pym/portage/dep/__init__.py')
-rw-r--r-- | pym/portage/dep/__init__.py | 92 |
1 files changed, 87 insertions, 5 deletions
diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index ad68815a5..7e9a18ad3 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -2062,6 +2062,63 @@ def get_required_use_flags(required_use): return frozenset(used_flags) +class _RequiredUseLeaf(object): + + __slots__ = ('_satisfied', '_token') + + def __init__(self, token, satisfied): + self._token = token + self._satisfied = satisfied + + def tounicode(self): + return self._token + +class _RequiredUseBranch(object): + + __slots__ = ('_children', '_operator', '_parent', '_satisfied') + + def __init__(self, operator=None, parent=None): + self._children = [] + self._operator = operator + self._parent = parent + self._satisfied = False + + def __bool__(self): + return self._satisfied + + def tounicode(self): + + tokens = [] + if self._operator is not None: + tokens.append(self._operator) + + if self._parent is not None: + tokens.append("(") + + complex_nesting = False + node = self + while node != None and not complex_nesting: + if node._operator in ("||", "^^"): + complex_nesting = True + else: + node = node._parent + + if complex_nesting: + for child in self._children: + tokens.append(child.tounicode()) + else: + for child in self._children: + if not child._satisfied: + tokens.append(child.tounicode()) + + if self._parent is not None: + tokens.append(")") + + return " ".join(tokens) + + if sys.hexversion < 0x3000000: + __nonzero__ = __bool__ + def check_required_use(required_use, use, iuse_match): """ Checks if the use flags listed in 'use' satisfy all @@ -2108,10 +2165,17 @@ def check_required_use(required_use, use, iuse_match): mysplit = required_use.split() level = 0 stack = [[]] + tree = _RequiredUseBranch() + node = tree need_bracket = False for token in mysplit: if token == "(": + if not need_bracket: + child = _RequiredUseBranch(parent=node) + node._children.append(child) + node = child + need_bracket = False stack.append([]) level += 1 @@ -2127,18 +2191,27 @@ def check_required_use(required_use, use, iuse_match): if stack[level][-1] in ("||", "^^"): ignore = True op = stack[level].pop() - stack[level].append(is_satisfied(op, l)) + satisfied = is_satisfied(op, l) + stack[level].append(satisfied) + node._satisfied = satisfied elif not isinstance(stack[level][-1], bool) and \ stack[level][-1][-1] == "?": if is_active(stack[level][-1][:-1]): op = stack[level].pop() - stack[level].append(is_satisfied(op, l)) + satisfied = is_satisfied(op, l) + stack[level].append(satisfied) + node._satisfied = satisfied else: stack[level].pop() + node._satisfied = True ignore = True if l and not ignore: - stack[level].append(all(x for x in l)) + satisfied = False not in l + stack[level].append(satisfied) + node._satisfied = satisfied + + node = node._parent else: raise InvalidDependString( _("malformed syntax: '%s'") % required_use) @@ -2148,6 +2221,9 @@ def check_required_use(required_use, use, iuse_match): _("malformed syntax: '%s'") % required_use) need_bracket = True stack[level].append(token) + child = _RequiredUseBranch(operator=token, parent=node) + node._children.append(child) + node = child else: if need_bracket or "(" in token or ")" in token or \ "|" in token or "^" in token: @@ -2157,14 +2233,20 @@ def check_required_use(required_use, use, iuse_match): if token[-1] == "?": need_bracket = True stack[level].append(token) + child = _RequiredUseBranch(operator=token, parent=node) + node._children.append(child) + node = child else: - stack[level].append(is_active(token)) + satisfied = is_active(token) + stack[level].append(satisfied) + node._children.append(_RequiredUseLeaf(token, satisfied)) if level != 0 or need_bracket: raise InvalidDependString( _("malformed syntax: '%s'") % required_use) - return (False not in stack[0]) + tree._satisfied = False not in stack[0] + return tree def extract_affecting_use(mystr, atom): """ |