From 826c474777a1f0ff1c1051dbbf7196116e5a8cc9 Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Sun, 15 Jan 2023 20:51:16 +0200 Subject: [PATCH 1/5] ProfilesCheck: check for unknown ARCH in make.defaults Related: https://github.com/pkgcore/pkgcheck/issues/524 Signed-off-by: Arthur Zamarin --- src/pkgcheck/addons/__init__.py | 2 +- src/pkgcheck/checks/profiles.py | 25 ++++++++++++++++--- .../UnknownProfileArch/expected.json | 1 + .../UnknownProfileArch/fix.patch | 6 +++++ .../repos/profiledir/profiles/profiles.desc | 1 + .../profiledir/profiles/unknown_arch/eapi | 1 + .../profiles/unknown_arch/make.defaults | 1 + tests/scripts/test_pkgcheck_scan.py | 2 +- 8 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileArch/expected.json create mode 100644 testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileArch/fix.patch create mode 100644 testdata/repos/profiledir/profiles/unknown_arch/eapi create mode 100644 testdata/repos/profiledir/profiles/unknown_arch/make.defaults diff --git a/src/pkgcheck/addons/__init__.py b/src/pkgcheck/addons/__init__.py index 5a5be2d0a..566786695 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 8673ed7d6..00d7c0699 100644 --- a/src/pkgcheck/checks/profiles.py +++ b/src/pkgcheck/checks/profiles.py @@ -108,6 +108,19 @@ def desc(self): 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 @@ def _pkg_use(self, filename, node, vals): 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 000000000..17c7329f5 --- /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 000000000..87aa24a0b --- /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 53c9769be..eb18a172a 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 000000000..b8626c4cf --- /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 000000000..54c1ff779 --- /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 bba0547d6..84030760f 100644 --- a/tests/scripts/test_pkgcheck_scan.py +++ b/tests/scripts/test_pkgcheck_scan.py @@ -611,7 +611,7 @@ def test_scan_verify(self, repo, tmp_path): 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 From 9e43d725ce4c2049e53e9df444b47c388bf98573 Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Sun, 15 Jan 2023 22:31:16 +0200 Subject: [PATCH 2/5] ProfilesCheck: check for unknown USE & IUSE_IMPLICIT in make.defaults Related: https://github.com/pkgcore/pkgcheck/issues/524 Signed-off-by: Arthur Zamarin --- src/pkgcheck/checks/profiles.py | 7 +++++++ .../ProfilesCheck/UnknownProfileUse/expected.json | 1 + .../profiledir/ProfilesCheck/UnknownProfileUse/fix.patch | 4 +++- .../repos/profiledir/profiles/unknown_use/make.defaults | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 testdata/repos/profiledir/profiles/unknown_use/make.defaults diff --git a/src/pkgcheck/checks/profiles.py b/src/pkgcheck/checks/profiles.py index 00d7c0699..6d1135198 100644 --- a/src/pkgcheck/checks/profiles.py +++ b/src/pkgcheck/checks/profiles.py @@ -290,6 +290,13 @@ def _pkg_use(self, filename, node, vals): @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 36f7f55cd..b7b1c9883 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 1541f6273..d4003eb4e 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 000000000..4699667b2 --- /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" From 75664ae7e124d21b43245e6f6fcfbcd8a588950f Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Sun, 15 Jan 2023 23:02:52 +0200 Subject: [PATCH 3/5] ProfilesCheck: check for unknown USE_EXPAND_* in make.defaults Related: https://github.com/pkgcore/pkgcheck/issues/524 Signed-off-by: Arthur Zamarin --- src/pkgcheck/checks/profiles.py | 29 ++++++++++++++----- .../UnknownProfileUseExpand/expected.json | 2 ++ .../UnknownProfileUseExpand/fix.patch | 26 +++++++++++++++++ .../profiles/desc/python_targets.desc | 2 ++ .../profiles/unknown_use/make.defaults | 7 +++++ 5 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/expected.json create mode 100644 testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/fix.patch create mode 100644 testdata/repos/profiledir/profiles/desc/python_targets.desc diff --git a/src/pkgcheck/checks/profiles.py b/src/pkgcheck/checks/profiles.py index 6d1135198..7929a10c7 100644 --- a/src/pkgcheck/checks/profiles.py +++ b/src/pkgcheck/checks/profiles.py @@ -2,6 +2,7 @@ import os from collections import defaultdict +from typing import Iterable from pkgcore.ebuild import misc from pkgcore.ebuild import profiles as profiles_mod @@ -96,16 +97,17 @@ def desc(self): class UnknownProfileUseExpand(results.ProfilesResult, results.Warning): """Profile includes nonexistent USE_EXPAND group(s).""" - def __init__(self, path, groups): + def __init__(self, path: str, var: str, groups: Iterable[str]): super().__init__() self.path = path + self.var = var self.groups = tuple(groups) @property def desc(self): s = pluralism(self.groups) groups = ", ".join(self.groups) - return f"{self.path!r}: unknown USE_EXPAND group{s}: {groups}" + return f"{self.path!r}: unknown USE_EXPAND group{s} in {self.var!r}: {groups}" class UnknownProfileArch(results.ProfilesResult, results.Warning): @@ -181,7 +183,10 @@ def __init__(self, *args, use_addon: addons.UseAddon, keywords_addon: addons.Key self.keywords = keywords_addon self.search_repo = self.options.search_repo self.profiles_dir = repo.config.profiles_base - self.use_expand_groups = frozenset(x.upper() for x in repo.config.use_expand_desc) + self.use_expand_groups = { + use.upper(): frozenset({val.removeprefix(f"{use}_") for val, _desc in vals}) + for use, vals in repo.config.use_expand_desc.items() + } local_iuse = {use for _pkg, (use, _desc) in repo.config.use_local_desc} self.available_iuse = frozenset( @@ -289,7 +294,7 @@ def _pkg_use(self, filename, node, vals): yield UnknownProfilePackage(pjoin(node.name, filename), a) @verify_files(("make.defaults", "make_defaults")) - def _make_defaults(self, filename: str, node, vals: dict[str, str]): + def _make_defaults(self, filename: str, node: sources.ProfileNode, vals: dict[str, str]): if use_flags := { use.removeprefix("-") for use_group in ("USE", "IUSE_IMPLICIT") @@ -297,14 +302,22 @@ def _make_defaults(self, filename: str, node, vals: dict[str, str]): }: 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)) + implicit_use_expands = set(vals.get("USE_EXPAND_IMPLICIT", "").split()) + for use_group in ( + "USE_EXPAND", + "USE_EXPAND_HIDDEN", + "USE_EXPAND_UNPREFIXED", + ): + values = {use.removeprefix("-") for use in vals.get(use_group, "").split()} + if unknown := values - self.use_expand_groups.keys() - implicit_use_expands: + yield UnknownProfileUseExpand( + pjoin(node.name, filename), use_group, 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): + def feed(self, profile: sources.Profile): for f in profile.files.intersection(self.known_files): attr, func = self.known_files[f] with base.LogReports(*_logmap) as log_reports: diff --git a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/expected.json b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/expected.json new file mode 100644 index 000000000..5817a2e13 --- /dev/null +++ b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/expected.json @@ -0,0 +1,2 @@ +{"__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"]} diff --git a/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/fix.patch b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/fix.patch new file mode 100644 index 000000000..f3932558a --- /dev/null +++ b/testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpand/fix.patch @@ -0,0 +1,26 @@ +diff -Naur profiledir/profiles/desc/python_single_target.desc fixed/profiles/desc/python_single_target.desc +new file mode 100644 +index 00000000..dcf7e163 +--- /dev/null ++++ fixed/profiles/desc/python_single_target.desc +@@ -0,0 +1,3 @@ ++python3_10 - Build for Python 3.10 only ++python3_11 - Build for Python 3.11 only ++ +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 +@@ -1,9 +1,8 @@ + USE="defaults_use used" + IUSE_IMPLICIT="defaults_iuse_implicit used" + USE_EXPAND_IMPLICIT="ARCH ELIBC" +-USE_EXPAND="PYTHON_TARGETS PYTHON_SINGLE_TARGET" +-USE_EXPAND_UNPREFIXED="ARCH LUA_TARGETS PYTHON_TARGETS" ++USE_EXPAND="PYTHON_TARGETS" ++USE_EXPAND_UNPREFIXED="ARCH 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" diff --git a/testdata/repos/profiledir/profiles/desc/python_targets.desc b/testdata/repos/profiledir/profiles/desc/python_targets.desc new file mode 100644 index 000000000..752372974 --- /dev/null +++ b/testdata/repos/profiledir/profiles/desc/python_targets.desc @@ -0,0 +1,2 @@ +python3_10 - Build with Python 3.10 +python3_11 - Build with Python 3.11 diff --git a/testdata/repos/profiledir/profiles/unknown_use/make.defaults b/testdata/repos/profiledir/profiles/unknown_use/make.defaults index 4699667b2..9bcb7cb98 100644 --- a/testdata/repos/profiledir/profiles/unknown_use/make.defaults +++ b/testdata/repos/profiledir/profiles/unknown_use/make.defaults @@ -1,2 +1,9 @@ USE="defaults_use used" IUSE_IMPLICIT="defaults_iuse_implicit used" +USE_EXPAND_IMPLICIT="ARCH ELIBC" +USE_EXPAND="PYTHON_TARGETS PYTHON_SINGLE_TARGET" +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" From bca5e4880d0bbe1b4a34fc0185885bbbcca76230 Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Mon, 16 Jan 2023 22:09:10 +0200 Subject: [PATCH 4/5] ProfilesCheck: check USE_EXPAND_VALUES_* in make.defaults Related: https://github.com/pkgcore/pkgcheck/issues/524 Signed-off-by: Arthur Zamarin --- src/pkgcheck/checks/profiles.py | 32 +++++++++++++++++++ .../UnknownProfileUseExpand/expected.json | 1 + .../expected.json | 2 ++ .../UnknownProfileUseExpandValue/fix.patch | 13 ++++++++ 4 files changed, 48 insertions(+) create mode 100644 testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpandValue/expected.json create mode 100644 testdata/data/repos/profiledir/ProfilesCheck/UnknownProfileUseExpandValue/fix.patch diff --git a/src/pkgcheck/checks/profiles.py b/src/pkgcheck/checks/profiles.py index 7929a10c7..ed6d1263c 100644 --- a/src/pkgcheck/checks/profiles.py +++ b/src/pkgcheck/checks/profiles.py @@ -110,6 +110,22 @@ def desc(self): 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 @@ def _make_defaults(self, filename: str, node: sources.ProfileNode, vals: dict[st 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 5817a2e13..8e4652391 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 000000000..6fcd75f77 --- /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 000000000..0d26d5df8 --- /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" From 191300b597c948f40b7034213f68374fbcd73199 Mon Sep 17 00:00:00 2001 From: Arthur Zamarin Date: Mon, 16 Jan 2023 22:19:10 +0200 Subject: [PATCH 5/5] ProfilesCheck: check missing values for implicit in make.defaults Related: https://github.com/pkgcore/pkgcheck/issues/524 Signed-off-by: Arthur Zamarin --- src/pkgcheck/checks/profiles.py | 24 +++++++++++++++++++ .../expected.json | 1 + .../fix.patch | 12 ++++++++++ 3 files changed, 37 insertions(+) create mode 100644 testdata/data/repos/profiledir/ProfilesCheck/ProfileMissingImplicitExpandValues/expected.json create mode 100644 testdata/data/repos/profiledir/ProfilesCheck/ProfileMissingImplicitExpandValues/fix.patch diff --git a/src/pkgcheck/checks/profiles.py b/src/pkgcheck/checks/profiles.py index ed6d1263c..625a05d62 100644 --- a/src/pkgcheck/checks/profiles.py +++ b/src/pkgcheck/checks/profiles.py @@ -126,6 +126,21 @@ def desc(self): 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 @@ def _make_defaults(self, filename: str, node: sources.ProfileNode, vals: dict[st 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 000000000..4ce574cb7 --- /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 000000000..8b2783d86 --- /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"