Skip to content

Commit

Permalink
ProfilesCheck: new check for UnmatchedProfilePackageUnmask
Browse files Browse the repository at this point in the history
Add missing check from repoman, for unmatched unmask of atom in
`package.mask` files. This checks for any unmask of package, which isn't
masked in parent profiles.

Resolves: #369
Signed-off-by: Arthur Zamarin <[email protected]>
  • Loading branch information
arthurzam committed Oct 4, 2022
1 parent 5414496 commit 03df2f5
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 4 deletions.
49 changes: 45 additions & 4 deletions src/pkgcheck/checks/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ def desc(self):
return f'{self.path!r}: unknown package: {self.atom!r}'


class UnmatchedProfilePackageUnmask(results.ProfilesResult, results.Warning):
"""The profile's files include a package.unmask (or similar) entry which
negates a non-existent mask, i.e. it undoes a mask which doesn't exist in
the parent profile.
No atoms matching this entry were found in the parent profile to unmask."""

def __init__(self, path, atom):
super().__init__()
self.path = path
self.atom = str(atom)

@property
def desc(self):
return f'{self.path!r}: unmask of not masked package: {self.atom!r}'


class UnknownProfilePackageUse(results.ProfilesResult, results.Warning):
"""Profile files include entries with USE flags that aren't used on any matching packages."""

Expand Down Expand Up @@ -129,7 +146,8 @@ class ProfilesCheck(Check):
_source = sources.ProfilesRepoSource
required_addons = (addons.UseAddon, addons.KeywordsAddon)
known_results = frozenset([
UnknownProfilePackage, UnknownProfilePackageUse, UnknownProfileUse,
UnknownProfilePackage, UnmatchedProfilePackageUnmask,
UnknownProfilePackageUse, UnknownProfileUse,
UnknownProfilePackageKeywords, UnknownProfileUseExpand,
ProfileWarning, ProfileError,
])
Expand All @@ -145,11 +163,19 @@ def __init__(self, *args, use_addon, keywords_addon):
self.profiles_dir = repo.config.profiles_base
self.use_expand_groups = frozenset(x.upper() for x in repo.config.use_expand_desc)

local_iuse = {use for pkg, (use, desc) in repo.config.use_local_desc}
local_iuse = {use for _pkg, (use, _desc) in repo.config.use_local_desc}
self.available_iuse = frozenset(
local_iuse | use_addon.global_iuse |
use_addon.global_iuse_expand | use_addon.global_iuse_implicit)

@staticmethod
def traverse_parents_tree(profile):
def _traverse(node):
for parent in node.parents:
yield parent
yield from _traverse(parent)
return set(_traverse(profile))

@verify_files(('parent', 'parents'),
('eapi', 'eapi'))
def _pull_attr(self, *args):
Expand All @@ -160,7 +186,7 @@ def _pull_attr(self, *args):
def _deprecated(self, filename, node, vals):
# make sure replacement profile exists
if vals is not None:
replacement, msg = vals
replacement, _msg = vals
try:
addons.profiles.ProfileNode(pjoin(self.profiles_dir, replacement))
except profiles_mod.ProfileError:
Expand Down Expand Up @@ -195,14 +221,29 @@ def _use(self, filename, node, vals):
pjoin(node.name, filename), unknown_enabled)

@verify_files(('packages', 'packages'),
('package.mask', 'masks'),
('package.unmask', 'unmasks'),
('package.deprecated', 'pkg_deprecated'))
def _pkg_atoms(self, filename, node, vals):
for x in iflatten_instance(vals, atom_cls):
if not self.search_repo.match(x):
yield UnknownProfilePackage(pjoin(node.name, filename), x)

@verify_files(('package.mask', 'masks'),)
def _pkg_masks(self, filename, node, vals):
all_parents = self.traverse_parents_tree(node)
all_masked = set().union(*(masked[1]
for p in all_parents if (masked := p.masks)))

unmasked, masked = vals
for x in masked:
if not self.search_repo.match(x):
yield UnknownProfilePackage(pjoin(node.name, filename), x)
for x in unmasked:
if not self.search_repo.match(x):
yield UnknownProfilePackage(pjoin(node.name, filename), x)
elif x not in all_masked:
yield UnmatchedProfilePackageUnmask(pjoin(node.name, filename), x)

@verify_files(('package.use', 'pkg_use'),
('package.use.force', 'pkg_use_force'),
('package.use.stable.force', 'pkg_use_stable_force'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"__class__": "UnmatchedProfilePackageUnmask", "path": "unmatched_unmasks/package.mask", "atom": "cat/pkg4"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
diff -Naur profiledir/profiles/unmatched_unmasks/package.mask fixed/profiles/unmatched_unmasks/package.mask
index fc6201bc..73b38bc7 100644
--- profiledir/profiles/unmatched_unmasks/package.mask
+++ fixed/profiles/unmatched_unmasks/package.mask
@@ -1,2 +1 @@
--cat/pkg4
-cat/pkg3
1 change: 1 addition & 0 deletions testdata/repos/profiledir/profiles/profiles.desc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ amd64 nonexistent exp

amd64 unknown_pkgs exp
amd64 unknown_kwds exp
amd64 unmatched_unmasks exp

amd64 unknown_use exp
amd64 unknown_use/unknown_stable_use exp
Expand Down
1 change: 1 addition & 0 deletions testdata/repos/profiledir/profiles/unmatched_unmasks/eapi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-cat/pkg4
-cat/pkg3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../unknown_pkgs

0 comments on commit 03df2f5

Please sign in to comment.