commit:     826c474777a1f0ff1c1051dbbf7196116e5a8cc9
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 15 18:51:16 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sun Jan 15 18:51:25 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=826c4747

ProfilesCheck: check for unknown ARCH in make.defaults

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

 src/pkgcheck/addons/__init__.py                    |  2 +-
 src/pkgcheck/checks/profiles.py                    | 25 ++++++++++++++++++----
 .../ProfilesCheck/UnknownProfileArch/expected.json |  1 +
 .../ProfilesCheck/UnknownProfileArch/fix.patch     |  6 ++++++
 testdata/repos/profiledir/profiles/profiles.desc   |  1 +
 .../repos/profiledir/profiles/unknown_arch/eapi    |  1 +
 .../profiledir/profiles/unknown_arch/make.defaults |  1 +
 tests/scripts/test_pkgcheck_scan.py                |  2 +-
 8 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/src/pkgcheck/addons/__init__.py b/src/pkgcheck/addons/__init__.py
index 5a5be2d0..56678669 100644
--- a/src/pkgcheck/addons/__init__.py
+++ b/src/pkgcheck/addons/__init__.py
@@ -89,7 +89,7 @@ class KeywordsAddon(base.Addon):
     def __init__(self, *args):
         super().__init__(*args)
         special = {"-*"}
-        self.arches = self.options.target_repo.known_arches
+        self.arches: frozenset[str] = self.options.target_repo.known_arches
         unstable = {"~" + x for x in self.arches}
         disabled = {"-" + x for x in chain(self.arches, unstable)}
         self.valid = special | self.arches | unstable | disabled

diff --git a/src/pkgcheck/checks/profiles.py b/src/pkgcheck/checks/profiles.py
index 8673ed7d..00d7c069 100644
--- a/src/pkgcheck/checks/profiles.py
+++ b/src/pkgcheck/checks/profiles.py
@@ -108,6 +108,19 @@ class UnknownProfileUseExpand(results.ProfilesResult, 
results.Warning):
         return f"{self.path!r}: unknown USE_EXPAND group{s}: {groups}"
 
 
+class UnknownProfileArch(results.ProfilesResult, results.Warning):
+    """Profile includes unknown ARCH."""
+
+    def __init__(self, path: str, arch: str):
+        super().__init__()
+        self.path = path
+        self.arch = arch
+
+    @property
+    def desc(self):
+        return f"{self.path!r}: unknown ARCH {self.arch!r}"
+
+
 class ProfileWarning(results.ProfilesResult, results.LogWarning):
     """Badly formatted data in various profile files."""
 
@@ -146,22 +159,23 @@ class ProfilesCheck(Check):
     _source = sources.ProfilesRepoSource
     required_addons = (addons.UseAddon, addons.KeywordsAddon)
     known_results = frozenset(
-        [
+        {
             UnknownProfilePackage,
             UnmatchedProfilePackageUnmask,
             UnknownProfilePackageUse,
             UnknownProfileUse,
             UnknownProfilePackageKeywords,
             UnknownProfileUseExpand,
+            UnknownProfileArch,
             ProfileWarning,
             ProfileError,
-        ]
+        }
     )
 
     # mapping between known files and verification methods
     known_files = {}
 
-    def __init__(self, *args, use_addon, keywords_addon):
+    def __init__(self, *args, use_addon: addons.UseAddon, keywords_addon: 
addons.KeywordsAddon):
         super().__init__(*args)
         repo = self.options.target_repo
         self.keywords = keywords_addon
@@ -275,10 +289,13 @@ class ProfilesCheck(Check):
                     yield UnknownProfilePackage(pjoin(node.name, filename), a)
 
     @verify_files(("make.defaults", "make_defaults"))
-    def _make_defaults(self, filename, node, vals):
+    def _make_defaults(self, filename: str, node, vals: dict[str, str]):
         if defined := set(vals.get("USE_EXPAND", "").split()):
             if unknown := defined - self.use_expand_groups:
                 yield UnknownProfileUseExpand(pjoin(node.name, filename), 
sorted(unknown))
+        if arch := vals.get("ARCH", None):
+            if arch not in self.keywords.arches:
+                yield UnknownProfileArch(pjoin(node.name, filename), arch)
 
     def feed(self, profile):
         for f in profile.files.intersection(self.known_files):

diff --git 
a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileArch/expected.json 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileArch/expected.json
new file mode 100644
index 00000000..17c7329f
--- /dev/null
+++ 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileArch/expected.json
@@ -0,0 +1 @@
+{"__class__": "UnknownProfileArch", "path": "unknown_arch/make.defaults", 
"arch": "unknown"}

diff --git 
a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileArch/fix.patch 
b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileArch/fix.patch
new file mode 100644
index 00000000..87aa24a0
--- /dev/null
+++ b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileArch/fix.patch
@@ -0,0 +1,6 @@
+diff -Naur profiledir/profiles/unknown_arch/make.defaults 
fixed/profiles/unknown_arch/make.defaults
+--- profiledir/profiles/unknown_arch/make.defaults     2019-11-12 
20:35:43.195830784 -0700
++++ fixed/profiles/unknown_arch/make.defaults  2019-11-12 20:45:16.582848028 
-0700
+@@ -1 +1 @@
+-ARCH="unknown"
++ARCH="amd64"

diff --git a/testdata/repos/profiledir/profiles/profiles.desc 
b/testdata/repos/profiledir/profiles/profiles.desc
index 53c9769b..eb18a172 100644
--- a/testdata/repos/profiledir/profiles/profiles.desc
+++ b/testdata/repos/profiledir/profiles/profiles.desc
@@ -6,6 +6,7 @@ amd64 nonexistent exp
 amd64 unknown_pkgs exp
 amd64 unknown_kwds exp
 amd64 unmatched_unmasks exp
+amd64 unknown_arch exp
 
 amd64 unknown_use exp
 amd64 unknown_use/unknown_stable_use exp

diff --git a/testdata/repos/profiledir/profiles/unknown_arch/eapi 
b/testdata/repos/profiledir/profiles/unknown_arch/eapi
new file mode 100644
index 00000000..b8626c4c
--- /dev/null
+++ b/testdata/repos/profiledir/profiles/unknown_arch/eapi
@@ -0,0 +1 @@
+4

diff --git a/testdata/repos/profiledir/profiles/unknown_arch/make.defaults 
b/testdata/repos/profiledir/profiles/unknown_arch/make.defaults
new file mode 100644
index 00000000..54c1ff77
--- /dev/null
+++ b/testdata/repos/profiledir/profiles/unknown_arch/make.defaults
@@ -0,0 +1 @@
+ARCH="unknown"

diff --git a/tests/scripts/test_pkgcheck_scan.py 
b/tests/scripts/test_pkgcheck_scan.py
index bba0547d..84030760 100644
--- a/tests/scripts/test_pkgcheck_scan.py
+++ b/tests/scripts/test_pkgcheck_scan.py
@@ -611,7 +611,7 @@ class TestPkgcheckScan:
         if repo not in self._results:
             self.test_scan_repo(repo, tmp_path, verbosity=0)
         if repo not in self._verbose_results:
-            self.test_scan_repo(repo, tmp_path, verbosity=0)
+            self.test_scan_repo(repo, tmp_path, verbosity=1)
         for check, keywords in self._checks[repo].items():
             for keyword in keywords:
                 # verify the expected results were seen during the repo scans

Reply via email to