commit:     9e43d725ce4c2049e53e9df444b47c388bf98573
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 15 20:31:16 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sun Jan 15 20:31:16 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=9e43d725

ProfilesCheck: check for unknown USE & IUSE_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                                    | 7 +++++++
 .../repos/profiledir/ProfilesCheck/UnknownProfileUse/expected.json | 1 +
 .../repos/profiledir/ProfilesCheck/UnknownProfileUse/fix.patch     | 4 +++-
 testdata/repos/profiledir/profiles/unknown_use/make.defaults       | 2 ++
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/pkgcheck/checks/profiles.py b/src/pkgcheck/checks/profiles.py
index 00d7c069..6d113519 100644
--- a/src/pkgcheck/checks/profiles.py
+++ b/src/pkgcheck/checks/profiles.py
@@ -290,6 +290,13 @@ class ProfilesCheck(Check):
 
     @verify_files(("make.defaults", "make_defaults"))
     def _make_defaults(self, filename: str, node, vals: dict[str, str]):
+        if use_flags := {
+            use.removeprefix("-")
+            for use_group in ("USE", "IUSE_IMPLICIT")
+            for use in vals.get(use_group, "").split()
+        }:
+            if unknown := use_flags - self.available_iuse:
+                yield UnknownProfileUse(pjoin(node.name, filename), 
sorted(unknown))
         if defined := set(vals.get("USE_EXPAND", "").split()):
             if unknown := defined - self.use_expand_groups:
                 yield UnknownProfileUseExpand(pjoin(node.name, filename), 
sorted(unknown))

diff --git 
a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUse/expected.json 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUse/expected.json
index 36f7f55c..b7b1c988 100644
--- 
a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUse/expected.json
+++ 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUse/expected.json
@@ -1,3 +1,4 @@
+{"__class__": "UnknownProfileUse", "path": "unknown_use/make.defaults", 
"flags": ["defaults_iuse_implicit", "defaults_use"]}
 {"__class__": "UnknownProfileUse", "path": 
"unknown_use/unknown_stable_use/use.force", "flags": ["-use_force"]}
 {"__class__": "UnknownProfileUse", "path": 
"unknown_use/unknown_stable_use/use.stable.force", "flags": 
["use_stable_force"]}
 {"__class__": "UnknownProfileUse", "path": 
"unknown_use/unknown_stable_use_mask/use.mask", "flags": ["-use_mask"]}

diff --git 
a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUse/fix.patch 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUse/fix.patch
index 1541f627..d4003eb4 100644
--- a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUse/fix.patch
+++ b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUse/fix.patch
@@ -1,9 +1,11 @@
 diff -Naur profiledir/profiles/use.desc fixed/profiles/use.desc
 --- profiledir/profiles/use.desc       2020-11-23 10:54:01.018477444 -0700
 +++ fixed/profiles/use.desc    2020-11-23 11:54:08.071178614 -0700
-@@ -1 +1,5 @@
+@@ -1 +1,7 @@
  used - used global flag
 +use_force - use.force
 +use_mask - use.mask
 +use_stable_force - use.stable.force
 +use_stable_mask - use.stable.mask
++defaults_use - make.defaults USE
++defaults_iuse_implicit - make.defaults IUSE_IMPLICIT

diff --git a/testdata/repos/profiledir/profiles/unknown_use/make.defaults 
b/testdata/repos/profiledir/profiles/unknown_use/make.defaults
new file mode 100644
index 00000000..4699667b
--- /dev/null
+++ b/testdata/repos/profiledir/profiles/unknown_use/make.defaults
@@ -0,0 +1,2 @@
+USE="defaults_use used"
+IUSE_IMPLICIT="defaults_iuse_implicit used"

Reply via email to