Skip to content

Commit d837ae2

Browse files
committed
UnusedInherits: add whitelist for weak usage by another eclass
Came up as example from elisp eclass, which has automagic calling of functions from readme.gentoo-r1 eclass if they are found in env. While weird, this is legal so let's add a simple whitelist support for this, so it would be simple to extend in future. Reported-by: Ulrich Müller <ulm@gentoo.org> Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 1b246cf commit d837ae2

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/pkgcheck/checks/codingstyle.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,8 @@ def __init__(self, *args, eclass_addon):
848848

849849
self.unused_eclass_skiplist = frozenset(common_mandatory_metadata_keys) - {"IUSE"}
850850

851+
self.weak_eclass_usage = {"elisp": ("readme.gentoo-r1",)}
852+
851853
def get_eclass(self, export, pkg):
852854
"""Return the eclass related to a given exported variable or function name."""
853855
try:
@@ -920,8 +922,12 @@ def feed(self, pkg):
920922

921923
# allowed indirect inherits
922924
indirect_allowed = set().union(*(self.eclass_cache[x].provides for x in pkg.inherit))
925+
all_inherits = set().union(pkg.inherit, indirect_allowed, conditional)
923926
# missing inherits
924-
missing = used.keys() - pkg.inherit - indirect_allowed - conditional
927+
missing = used.keys() - all_inherits
928+
929+
for eclass in all_inherits:
930+
weak_used_eclasses.update(self.weak_eclass_usage.get(eclass, ()))
925931

926932
unused = set(pkg.inherit) - used.keys() - set(assigned_vars.values()) - weak_used_eclasses
927933
# remove eclasses that use implicit phase functions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
EAPI=8
2+
3+
inherit elisp readme.gentoo-r1
4+
5+
DESCRIPTION="Ebuild with weak usage inheritance"
6+
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
7+
SLOT="0"
8+
LICENSE="BSD"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# @ECLASS: elisp.eclass
2+
# @MAINTAINER:
3+
# Random Person <maintainer@random.email>
4+
# @SUPPORTED_EAPIS: 8
5+
# @BLURB: Stub eclass for testing the UnusedInherit result.
6+
7+
EXPORT_FUNCTIONS src_prepare
8+
9+
# @FUNCTION: elisp_src_prepare
10+
# @USAGE:
11+
# @DESCRIPTION:
12+
# Public src_prepare stub function.
13+
elisp_src_prepare() { :; }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# @ECLASS: readme.gentoo-r1.eclass
2+
# @MAINTAINER:
3+
# Random Person <maintainer@random.email>
4+
# @SUPPORTED_EAPIS: 8
5+
# @BLURB: Stub eclass for testing the UnusedInherit result.
6+
7+
# @FUNCTION: readme.gentoo_create_doc
8+
# @USAGE:
9+
# @DESCRIPTION:
10+
# stub function
11+
readme.gentoo_create_doc() { :; }

0 commit comments

Comments
 (0)