1 |
commit: e174fa3c960fef3ed6225fa9a43e14e0e11332b0 |
2 |
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Jan 2 19:57:07 2023 +0000 |
4 |
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Jan 2 19:57:07 2023 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=e174fa3c |
7 |
|
8 |
domain: fix parsing of multiple USE_EXAPNDs |
9 |
|
10 |
- add support for parsing of multiple USE_EXAPNDs |
11 |
- fix error reporting when not USE_EXPAND has parsing error |
12 |
- updates tests to catch warning thrown by parsing |
13 |
|
14 |
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> |
15 |
|
16 |
src/pkgcore/ebuild/domain.py | 11 +++++++---- |
17 |
tests/ebuild/test_domain.py | 29 ++++++++++++++++++++++++++--- |
18 |
2 files changed, 33 insertions(+), 7 deletions(-) |
19 |
|
20 |
diff --git a/src/pkgcore/ebuild/domain.py b/src/pkgcore/ebuild/domain.py |
21 |
index 9fef5f843..0dba49d5d 100644 |
22 |
--- a/src/pkgcore/ebuild/domain.py |
23 |
+++ b/src/pkgcore/ebuild/domain.py |
24 |
@@ -92,13 +92,16 @@ def package_use_splitter(iterable): |
25 |
def f(tokens: list[str]): |
26 |
|
27 |
i = iter(tokens) |
28 |
- for idx, x in enumerate(i): |
29 |
- if x.endswith(":"): |
30 |
+ for idx, flag in enumerate(i): |
31 |
+ if flag.endswith(":"): |
32 |
# we encountered `USE_EXPAND:` , thus all following tokens |
33 |
# are values of that. |
34 |
- x = x.lower()[:-1] |
35 |
+ x = flag.lower()[:-1] |
36 |
l = tokens[0:idx] |
37 |
for flag in i: |
38 |
+ if flag.endswith(":"): |
39 |
+ x = flag.lower()[:-1] |
40 |
+ continue |
41 |
if flag.startswith("-"): |
42 |
flag = f"-{x}_{flag[1:]}" |
43 |
else: |
44 |
@@ -107,7 +110,7 @@ def package_use_splitter(iterable): |
45 |
raise ParseError(f"token {flag} is not a valid use flag") |
46 |
l.append(flag) |
47 |
return l |
48 |
- elif not eapi_obj.is_valid_use_flag(x.lstrip("-")): |
49 |
+ elif not eapi_obj.is_valid_use_flag(flag.lstrip("-")): |
50 |
raise ParseError(f"token {flag} is not a valid use flag") |
51 |
# if we made it here, there's no USE_EXPAND; thus just return the original sequence |
52 |
return tokens |
53 |
|
54 |
diff --git a/tests/ebuild/test_domain.py b/tests/ebuild/test_domain.py |
55 |
index 28706e254..e7b93b11b 100644 |
56 |
--- a/tests/ebuild/test_domain.py |
57 |
+++ b/tests/ebuild/test_domain.py |
58 |
@@ -62,6 +62,8 @@ class TestDomain: |
59 |
*/* x_y1 |
60 |
# unrelated is there to verify that it's unaffected by the USE_EXPAND |
61 |
*/* unrelated X: -y1 y2 |
62 |
+ # multiple USE_EXPANDs |
63 |
+ */* unrelated X: -y1 y2 Z: -z3 z4 |
64 |
""" |
65 |
) |
66 |
) |
67 |
@@ -78,10 +80,31 @@ class TestDomain: |
68 |
), |
69 |
), |
70 |
), |
71 |
+ ( |
72 |
+ packages.AlwaysTrue, |
73 |
+ ( |
74 |
+ ("x_y1", "z_z3"), |
75 |
+ ( |
76 |
+ "unrelated", |
77 |
+ "x_y2", |
78 |
+ "z_z4", |
79 |
+ ), |
80 |
+ ), |
81 |
+ ), |
82 |
) == self.mk_domain().pkg_use |
83 |
|
84 |
- def test_use_flag_parsing_enforcement(self): |
85 |
+ def test_use_flag_parsing_enforcement(self, caplog): |
86 |
(self.pusedir / "a").write_text("*/* X:") |
87 |
- # TODO: need to catch the warning here, but I'm not sure how. |
88 |
- # Meanwhile, ensure that the failed token is ignored. |
89 |
assert ((packages.AlwaysTrue, ((), ())),) == self.mk_domain().pkg_use |
90 |
+ assert caplog.text == "" # no problems with nothing after USE_EXPAND: |
91 |
+ caplog.clear() |
92 |
+ |
93 |
+ (self.pusedir / "a").write_text("*/* y $x") |
94 |
+ assert () == self.mk_domain().pkg_use |
95 |
+ assert "token $x is not a valid use flag" in caplog.text |
96 |
+ caplog.clear() |
97 |
+ |
98 |
+ (self.pusedir / "a").write_text("*/* y X: $z") |
99 |
+ assert () == self.mk_domain().pkg_use |
100 |
+ assert "token x_$z is not a valid use flag" in caplog.text |
101 |
+ caplog.clear() |