summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Luther <SebastianLuther@gmx.de>2010-08-18 19:42:11 +0200
committerZac Medico <zmedico@gentoo.org>2010-08-18 13:22:36 -0700
commit1d92b35e2b24c7f0269a295ac78887132a96a643 (patch)
treec913c7992c968288b90e220872846c6354bf2d96
parentbe566615893722905b4163882c8146ef7de6ba63 (diff)
downloadportage-1d92b35e2b24c7f0269a295ac78887132a96a643.tar.gz
portage-1d92b35e2b24c7f0269a295ac78887132a96a643.tar.bz2
portage-1d92b35e2b24c7f0269a295ac78887132a96a643.zip
extract_affecting_use: Fix the same bug as in use_reduce
-rw-r--r--pym/portage/dep/__init__.py35
-rw-r--r--pym/portage/tests/dep/testExtractAffectingUSE.py2
2 files changed, 31 insertions, 6 deletions
diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py
index 8bbcd3e59..de688a16e 100644
--- a/pym/portage/dep/__init__.py
+++ b/pym/portage/dep/__init__.py
@@ -1810,27 +1810,50 @@ def extract_affecting_use(mystr, atom):
if level > 0:
level -= 1
l = stack.pop()
+ is_single = (len(l) == 1 or (len(l)==2 and (l[0] == "||" or l[0][-1] == "?")))
+
+ def ends_in_any_of_dep(k):
+ return k>=0 and stack[k] and stack[k][-1] == "||"
+
+ def ends_in_operator(k):
+ return k>=0 and stack[k] and (stack[k][-1] == "||" or stack[k][-1][-1] == "?")
+
+ def special_append():
+ """
+ Use extend instead of append if possible. This kills all redundant brackets.
+ """
+ if is_single and (not stack[level] or not stack[level][-1][-1] == "?"):
+ if len(l) == 1 and isinstance(l[0], list):
+ # l = [[...]]
+ stack[level].extend(l[0])
+ else:
+ stack[level].extend(l)
+ else:
+ stack[level].append(l)
if l:
- if not stack[level] or (stack[level][-1] != "||" and not stack[level][-1][-1] == "?"):
- #Optimize: ( ( ... ) ) -> ( ... )
+ if not ends_in_any_of_dep(level-1) and not ends_in_operator(level):
+ #Optimize: ( ( ... ) ) -> ( ... ). Make sure there is no '||' hanging around.
stack[level].extend(l)
- elif len(l) == 1 and stack[level][-1] == "||":
+ elif not stack[level]:
+ #An '||' in the level above forces us to keep to brackets.
+ special_append()
+ elif len(l) == 1 and ends_in_any_of_dep(level):
#Optimize: || ( A ) -> A
stack[level].pop()
- stack[level].extend(l)
+ special_append()
elif len(l) == 2 and (l[0] == "||" or l[0][-1] == "?") and stack[level][-1] in (l[0], "||"):
#Optimize: || ( || ( ... ) ) -> || ( ... )
# foo? ( foo? ( ... ) ) -> foo? ( ... )
# || ( foo? ( ... ) ) -> foo? ( ... )
stack[level].pop()
- stack[level].extend(l)
+ special_append()
if l[0][-1] == "?":
affecting_use.add(flag(l[0]))
else:
if stack[level] and stack[level][-1][-1] == "?":
affecting_use.add(flag(stack[level][-1]))
- stack[level].append(l)
+ special_append()
else:
if stack[level] and (stack[level][-1] == "||" or stack[level][-1][-1] == "?"):
stack[level].pop()
diff --git a/pym/portage/tests/dep/testExtractAffectingUSE.py b/pym/portage/tests/dep/testExtractAffectingUSE.py
index 79ac9fc73..f998bbbb7 100644
--- a/pym/portage/tests/dep/testExtractAffectingUSE.py
+++ b/pym/portage/tests/dep/testExtractAffectingUSE.py
@@ -34,6 +34,8 @@ class TestExtractAffectingUSE(TestCase):
("( ab? ( || ( ( A ) || ( b? ( ( ( || ( B ( C ) ) ) ) ) ) ) ) )", "C", ("ab", "b")),
("a? ( A )", "B", []),
+
+ ("a? ( || ( A B ) )", "B", ["a"]),
)
test_cases_xfail = (