Skip to content

Commit 75664ae

Browse files
committed
ProfilesCheck: check for unknown USE_EXPAND_* in make.defaults
Related: #524 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 9e43d72 commit 75664ae

5 files changed

Lines changed: 58 additions & 8 deletions

File tree

src/pkgcheck/checks/profiles.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
from collections import defaultdict
5+
from typing import Iterable
56

67
from pkgcore.ebuild import misc
78
from pkgcore.ebuild import profiles as profiles_mod
@@ -96,16 +97,17 @@ def desc(self):
9697
class UnknownProfileUseExpand(results.ProfilesResult, results.Warning):
9798
"""Profile includes nonexistent USE_EXPAND group(s)."""
9899

99-
def __init__(self, path, groups):
100+
def __init__(self, path: str, var: str, groups: Iterable[str]):
100101
super().__init__()
101102
self.path = path
103+
self.var = var
102104
self.groups = tuple(groups)
103105

104106
@property
105107
def desc(self):
106108
s = pluralism(self.groups)
107109
groups = ", ".join(self.groups)
108-
return f"{self.path!r}: unknown USE_EXPAND group{s}: {groups}"
110+
return f"{self.path!r}: unknown USE_EXPAND group{s} in {self.var!r}: {groups}"
109111

110112

111113
class UnknownProfileArch(results.ProfilesResult, results.Warning):
@@ -181,7 +183,10 @@ def __init__(self, *args, use_addon: addons.UseAddon, keywords_addon: addons.Key
181183
self.keywords = keywords_addon
182184
self.search_repo = self.options.search_repo
183185
self.profiles_dir = repo.config.profiles_base
184-
self.use_expand_groups = frozenset(x.upper() for x in repo.config.use_expand_desc)
186+
self.use_expand_groups = {
187+
use.upper(): frozenset({val.removeprefix(f"{use}_") for val, _desc in vals})
188+
for use, vals in repo.config.use_expand_desc.items()
189+
}
185190

186191
local_iuse = {use for _pkg, (use, _desc) in repo.config.use_local_desc}
187192
self.available_iuse = frozenset(
@@ -289,22 +294,30 @@ def _pkg_use(self, filename, node, vals):
289294
yield UnknownProfilePackage(pjoin(node.name, filename), a)
290295

291296
@verify_files(("make.defaults", "make_defaults"))
292-
def _make_defaults(self, filename: str, node, vals: dict[str, str]):
297+
def _make_defaults(self, filename: str, node: sources.ProfileNode, vals: dict[str, str]):
293298
if use_flags := {
294299
use.removeprefix("-")
295300
for use_group in ("USE", "IUSE_IMPLICIT")
296301
for use in vals.get(use_group, "").split()
297302
}:
298303
if unknown := use_flags - self.available_iuse:
299304
yield UnknownProfileUse(pjoin(node.name, filename), sorted(unknown))
300-
if defined := set(vals.get("USE_EXPAND", "").split()):
301-
if unknown := defined - self.use_expand_groups:
302-
yield UnknownProfileUseExpand(pjoin(node.name, filename), sorted(unknown))
305+
implicit_use_expands = set(vals.get("USE_EXPAND_IMPLICIT", "").split())
306+
for use_group in (
307+
"USE_EXPAND",
308+
"USE_EXPAND_HIDDEN",
309+
"USE_EXPAND_UNPREFIXED",
310+
):
311+
values = {use.removeprefix("-") for use in vals.get(use_group, "").split()}
312+
if unknown := values - self.use_expand_groups.keys() - implicit_use_expands:
313+
yield UnknownProfileUseExpand(
314+
pjoin(node.name, filename), use_group, sorted(unknown)
315+
)
303316
if arch := vals.get("ARCH", None):
304317
if arch not in self.keywords.arches:
305318
yield UnknownProfileArch(pjoin(node.name, filename), arch)
306319

307-
def feed(self, profile):
320+
def feed(self, profile: sources.Profile):
308321
for f in profile.files.intersection(self.known_files):
309322
attr, func = self.known_files[f]
310323
with base.LogReports(*_logmap) as log_reports:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"__class__": "UnknownProfileUseExpand", "path": "unknown_use/make.defaults", "var": "USE_EXPAND", "groups": ["PYTHON_SINGLE_TARGET"]}
2+
{"__class__": "UnknownProfileUseExpand", "path": "unknown_use/make.defaults", "var": "USE_EXPAND_UNPREFIXED", "groups": ["LUA_TARGETS"]}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff -Naur profiledir/profiles/desc/python_single_target.desc fixed/profiles/desc/python_single_target.desc
2+
new file mode 100644
3+
index 00000000..dcf7e163
4+
--- /dev/null
5+
+++ fixed/profiles/desc/python_single_target.desc
6+
@@ -0,0 +1,3 @@
7+
+python3_10 - Build for Python 3.10 only
8+
+python3_11 - Build for Python 3.11 only
9+
+
10+
diff -Naur profiledir/profiles/unknown_use/make.defaults fixed/profiles/unknown_use/make.defaults
11+
diff --git a/testdata/repos/profiledir/profiles/unknown_use/make.defaults b/testdata/repos/profiledir/profiles/unknown_use/make.defaults
12+
index 6d789215..2c98efd3 100644
13+
--- profiledir/profiles/unknown_use/make.defaults
14+
+++ fixed/profiles/unknown_use/make.defaults
15+
@@ -1,9 +1,8 @@
16+
USE="defaults_use used"
17+
IUSE_IMPLICIT="defaults_iuse_implicit used"
18+
USE_EXPAND_IMPLICIT="ARCH ELIBC"
19+
-USE_EXPAND="PYTHON_TARGETS PYTHON_SINGLE_TARGET"
20+
-USE_EXPAND_UNPREFIXED="ARCH LUA_TARGETS PYTHON_TARGETS"
21+
+USE_EXPAND="PYTHON_TARGETS"
22+
+USE_EXPAND_UNPREFIXED="ARCH PYTHON_TARGETS"
23+
USE_EXPAND_VALUES_ARCH="amd64 x86"
24+
-USE_EXPAND_VALUES_LUA_TARGETS="lua5_1"
25+
USE_EXPAND_VALUES_PYTHON_TARGETS="python3_9 python3_10"
26+
PYTHON_TARGETS="python3_9 python3_10"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
python3_10 - Build with Python 3.10
2+
python3_11 - Build with Python 3.11
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
USE="defaults_use used"
22
IUSE_IMPLICIT="defaults_iuse_implicit used"
3+
USE_EXPAND_IMPLICIT="ARCH ELIBC"
4+
USE_EXPAND="PYTHON_TARGETS PYTHON_SINGLE_TARGET"
5+
USE_EXPAND_UNPREFIXED="ARCH LUA_TARGETS PYTHON_TARGETS"
6+
USE_EXPAND_VALUES_ARCH="amd64 x86"
7+
USE_EXPAND_VALUES_LUA_TARGETS="lua5_1"
8+
USE_EXPAND_VALUES_PYTHON_TARGETS="python3_9 python3_10"
9+
PYTHON_TARGETS="python3_9 python3_10"

0 commit comments

Comments
 (0)