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

ProfilesCheck: check missing values for implicit 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                    | 24 ++++++++++++++++++++++
 .../expected.json                                  |  1 +
 .../ProfileMissingImplicitExpandValues/fix.patch   | 12 +++++++++++
 3 files changed, 37 insertions(+)

diff --git a/src/pkgcheck/checks/profiles.py b/src/pkgcheck/checks/profiles.py
index ed6d1263..625a05d6 100644
--- a/src/pkgcheck/checks/profiles.py
+++ b/src/pkgcheck/checks/profiles.py
@@ -126,6 +126,21 @@ class UnknownProfileUseExpandValue(results.ProfilesResult, 
results.Warning):
         return f"{self.path!r}: unknown value{s} for {self.group!r}: {values}"
 
 
+class ProfileMissingImplicitExpandValues(results.ProfilesResult, 
results.Warning):
+    """Profile is missing USE_EXPAND_VALUES for implicit USE_EXPAND group."""
+
+    def __init__(self, path: str, groups: Iterable[str]):
+        super().__init__()
+        self.path = path
+        self.groups = tuple(groups)
+
+    @property
+    def desc(self):
+        s = pluralism(self.groups)
+        groups = ", ".join(self.groups)
+        return f"{self.path!r}: missing USE_EXPAND_VALUES for USE_EXPAND 
group{s}: {groups}"
+
+
 class UnknownProfileArch(results.ProfilesResult, results.Warning):
     """Profile includes unknown ARCH."""
 
@@ -185,6 +200,7 @@ class ProfilesCheck(Check):
             UnknownProfilePackageKeywords,
             UnknownProfileUseExpand,
             UnknownProfileUseExpandValue,
+            ProfileMissingImplicitExpandValues,
             UnknownProfileArch,
             ProfileWarning,
             ProfileError,
@@ -345,6 +361,14 @@ class ProfilesCheck(Check):
         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 missing_values := {
+            use_group
+            for use_group in implicit_use_expands
+            if f"USE_EXPAND_VALUES_{use_group}" not in vals
+        }:
+            yield ProfileMissingImplicitExpandValues(
+                pjoin(node.name, filename), sorted(missing_values)
+            )
         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/ProfileMissingImplicitExpandValues/expected.json
 
b/testdata/data/repos/profiledir/ProfilesCheck/ProfileMissingImplicitExpandValues/expected.json
new file mode 100644
index 00000000..4ce574cb
--- /dev/null
+++ 
b/testdata/data/repos/profiledir/ProfilesCheck/ProfileMissingImplicitExpandValues/expected.json
@@ -0,0 +1 @@
+{"__class__": "ProfileMissingImplicitExpandValues", "path": 
"unknown_use/make.defaults", "groups": ["ELIBC"]}

diff --git 
a/testdata/data/repos/profiledir/ProfilesCheck/ProfileMissingImplicitExpandValues/fix.patch
 
b/testdata/data/repos/profiledir/ProfilesCheck/ProfileMissingImplicitExpandValues/fix.patch
new file mode 100644
index 00000000..8b2783d8
--- /dev/null
+++ 
b/testdata/data/repos/profiledir/ProfilesCheck/ProfileMissingImplicitExpandValues/fix.patch
@@ -0,0 +1,12 @@
+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
+--- profiledir/profiles/unknown_use/make.defaults
++++ fixed/profiles/unknown_use/make.defaults
+@@ -4,6 +4,7 @@
+ USE_EXPAND="PYTHON_TARGETS PYTHON_SINGLE_TARGET"
+ USE_EXPAND_UNPREFIXED="ARCH LUA_TARGETS PYTHON_TARGETS"
+ USE_EXPAND_VALUES_ARCH="amd64 x86"
++USE_EXPAND_VALUES_ELIBC="GNU"
+ USE_EXPAND_VALUES_LUA_TARGETS="lua5_1"
+ USE_EXPAND_VALUES_PYTHON_TARGETS="python3_9 python3_10"
+ PYTHON_TARGETS="python3_9 python3_10"

Reply via email to