commit: e174fa3c960fef3ed6225fa9a43e14e0e11332b0
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 2 19:57:07 2023 +0000
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Mon Jan 2 19:57:07 2023 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=e174fa3c
domain: fix parsing of multiple USE_EXAPNDs
- add support for parsing of multiple USE_EXAPNDs
- fix error reporting when not USE_EXPAND has parsing error
- updates tests to catch warning thrown by parsing
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
src/pkgcore/ebuild/domain.py | 11 +++++++----
tests/ebuild/test_domain.py | 29 ++++++++++++++++++++++++++---
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/src/pkgcore/ebuild/domain.py b/src/pkgcore/ebuild/domain.py
index 9fef5f843..0dba49d5d 100644
--- a/src/pkgcore/ebuild/domain.py
+++ b/src/pkgcore/ebuild/domain.py
@@ -92,13 +92,16 @@ def package_use_splitter(iterable):
def f(tokens: list[str]):
i = iter(tokens)
- for idx, x in enumerate(i):
- if x.endswith(":"):
+ for idx, flag in enumerate(i):
+ if flag.endswith(":"):
# we encountered `USE_EXPAND:` , thus all following tokens
# are values of that.
- x = x.lower()[:-1]
+ x = flag.lower()[:-1]
l = tokens[0:idx]
for flag in i:
+ if flag.endswith(":"):
+ x = flag.lower()[:-1]
+ continue
if flag.startswith("-"):
flag = f"-{x}_{flag[1:]}"
else:
@@ -107,7 +110,7 @@ def package_use_splitter(iterable):
raise ParseError(f"token {flag} is not a valid use
flag")
l.append(flag)
return l
- elif not eapi_obj.is_valid_use_flag(x.lstrip("-")):
+ elif not eapi_obj.is_valid_use_flag(flag.lstrip("-")):
raise ParseError(f"token {flag} is not a valid use flag")
# if we made it here, there's no USE_EXPAND; thus just return the
original sequence
return tokens
diff --git a/tests/ebuild/test_domain.py b/tests/ebuild/test_domain.py
index 28706e254..e7b93b11b 100644
--- a/tests/ebuild/test_domain.py
+++ b/tests/ebuild/test_domain.py
@@ -62,6 +62,8 @@ class TestDomain:
*/* x_y1
# unrelated is there to verify that it's unaffected by the
USE_EXPAND
*/* unrelated X: -y1 y2
+ # multiple USE_EXPANDs
+ */* unrelated X: -y1 y2 Z: -z3 z4
"""
)
)
@@ -78,10 +80,31 @@ class TestDomain:
),
),
),
+ (
+ packages.AlwaysTrue,
+ (
+ ("x_y1", "z_z3"),
+ (
+ "unrelated",
+ "x_y2",
+ "z_z4",
+ ),
+ ),
+ ),
) == self.mk_domain().pkg_use
- def test_use_flag_parsing_enforcement(self):
+ def test_use_flag_parsing_enforcement(self, caplog):
(self.pusedir / "a").write_text("*/* X:")
- # TODO: need to catch the warning here, but I'm not sure how.
- # Meanwhile, ensure that the failed token is ignored.
assert ((packages.AlwaysTrue, ((), ())),) == self.mk_domain().pkg_use
+ assert caplog.text == "" # no problems with nothing after USE_EXPAND:
+ caplog.clear()
+
+ (self.pusedir / "a").write_text("*/* y $x")
+ assert () == self.mk_domain().pkg_use
+ assert "token $x is not a valid use flag" in caplog.text
+ caplog.clear()
+
+ (self.pusedir / "a").write_text("*/* y X: $z")
+ assert () == self.mk_domain().pkg_use
+ assert "token x_$z is not a valid use flag" in caplog.text
+ caplog.clear()