commit:     bca5e4880d0bbe1b4a34fc0185885bbbcca76230
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 16 20:09:10 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Mon Jan 16 20:09:10 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=bca5e488

ProfilesCheck: check USE_EXPAND_VALUES_* in make.defaults

Related: https://github.com/pkgcore/pkgcheck/issues/524
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcheck/checks/profiles.py                    | 32 ++++++++++++++++++++++
 .../UnknownProfileUseExpand/expected.json          |  1 +
 .../UnknownProfileUseExpandValue/expected.json     |  2 ++
 .../UnknownProfileUseExpandValue/fix.patch         | 13 +++++++++
 4 files changed, 48 insertions(+)

diff --git a/src/pkgcheck/checks/profiles.py b/src/pkgcheck/checks/profiles.py
index 7929a10c..ed6d1263 100644
--- a/src/pkgcheck/checks/profiles.py
+++ b/src/pkgcheck/checks/profiles.py
@@ -110,6 +110,22 @@ class UnknownProfileUseExpand(results.ProfilesResult, 
results.Warning):
         return f"{self.path!r}: unknown USE_EXPAND group{s} in {self.var!r}: 
{groups}"
 
 
+class UnknownProfileUseExpandValue(results.ProfilesResult, results.Warning):
+    """Profile defines unknown default values for USE_EXPAND group."""
+
+    def __init__(self, path: str, group: str, values: Iterable[str]):
+        super().__init__()
+        self.path = path
+        self.group = group
+        self.values = tuple(values)
+
+    @property
+    def desc(self):
+        s = pluralism(self.values)
+        values = ", ".join(self.values)
+        return f"{self.path!r}: unknown value{s} for {self.group!r}: {values}"
+
+
 class UnknownProfileArch(results.ProfilesResult, results.Warning):
     """Profile includes unknown ARCH."""
 
@@ -168,6 +184,7 @@ class ProfilesCheck(Check):
             UnknownProfileUse,
             UnknownProfilePackageKeywords,
             UnknownProfileUseExpand,
+            UnknownProfileUseExpandValue,
             UnknownProfileArch,
             ProfileWarning,
             ProfileError,
@@ -313,6 +330,21 @@ class ProfilesCheck(Check):
                 yield UnknownProfileUseExpand(
                     pjoin(node.name, filename), use_group, sorted(unknown)
                 )
+        for key, val in vals.items():
+            if key.startswith("USE_EXPAND_VALUES_"):
+                use_group = key[18:]
+                if use_group in implicit_use_expands:
+                    continue
+                elif allowed_values := self.use_expand_groups.get(use_group, 
None):
+                    if unknown := set(val.split()) - allowed_values:
+                        yield UnknownProfileUseExpandValue(
+                            pjoin(node.name, filename), key, sorted(unknown)
+                        )
+                else:
+                    yield UnknownProfileUseExpand(pjoin(node.name, filename), 
key, [use_group])
+        for key in vals.keys() & self.use_expand_groups.keys():
+            if unknown := set(vals.get(key, "").split()) - 
self.use_expand_groups[key]:
+                yield UnknownProfileUseExpandValue(pjoin(node.name, filename), 
key, sorted(unknown))
         if arch := vals.get("ARCH", None):
             if arch not in self.keywords.arches:
                 yield UnknownProfileArch(pjoin(node.name, filename), arch)

diff --git 
a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/expected.json
 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/expected.json
index 5817a2e1..8e465239 100644
--- 
a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/expected.json
+++ 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/expected.json
@@ -1,2 +1,3 @@
 {"__class__": "UnknownProfileUseExpand", "path": "unknown_use/make.defaults", 
"var": "USE_EXPAND", "groups": ["PYTHON_SINGLE_TARGET"]}
 {"__class__": "UnknownProfileUseExpand", "path": "unknown_use/make.defaults", 
"var": "USE_EXPAND_UNPREFIXED", "groups": ["LUA_TARGETS"]}
+{"__class__": "UnknownProfileUseExpand", "path": "unknown_use/make.defaults", 
"var": "USE_EXPAND_VALUES_LUA_TARGETS", "groups": ["LUA_TARGETS"]}

diff --git 
a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpandValue/expected.json
 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpandValue/expected.json
new file mode 100644
index 00000000..6fcd75f7
--- /dev/null
+++ 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpandValue/expected.json
@@ -0,0 +1,2 @@
+{"__class__": "UnknownProfileUseExpandValue", "path": 
"unknown_use/make.defaults", "group": "PYTHON_TARGETS", "values": ["python3_9"]}
+{"__class__": "UnknownProfileUseExpandValue", "path": 
"unknown_use/make.defaults", "group": "USE_EXPAND_VALUES_PYTHON_TARGETS", 
"values": ["python3_9"]}

diff --git 
a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpandValue/fix.patch
 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpandValue/fix.patch
new file mode 100644
index 00000000..0d26d5df
--- /dev/null
+++ 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpandValue/fix.patch
@@ -0,0 +1,13 @@
+diff -Naur profiledir/profiles/unknown_use/make.defaults 
fixed/profiles/unknown_use/make.defaults
+diff --git a/testdata/repos/profiledir/profiles/unknown_use/make.defaults 
b/testdata/repos/profiledir/profiles/unknown_use/make.defaults
+index 6d789215..2c98efd3 100644
+--- profiledir/profiles/unknown_use/make.defaults
++++ fixed/profiles/unknown_use/make.defaults
+@@ -5,5 +5,5 @@
+ USE_EXPAND_UNPREFIXED="ARCH LUA_TARGETS PYTHON_TARGETS"
+ USE_EXPAND_VALUES_ARCH="amd64 x86"
+ USE_EXPAND_VALUES_LUA_TARGETS="lua5_1"
+-USE_EXPAND_VALUES_PYTHON_TARGETS="python3_9 python3_10"
+-PYTHON_TARGETS="python3_9 python3_10"
++USE_EXPAND_VALUES_PYTHON_TARGETS="python3_10"
++PYTHON_TARGETS="python3_10"

Reply via email to