Skip to content

Commit

Permalink
UnusedInherits: add whitelist for weak usage by another eclass
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
arthurzam committed Nov 16, 2023
1 parent 1b246cf commit d837ae2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/pkgcheck/checks/codingstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,8 @@ def __init__(self, *args, eclass_addon):

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

self.weak_eclass_usage = {"elisp": ("readme.gentoo-r1",)}

This comment has been minimized.

Copy link
@thesamesam

thesamesam Nov 16, 2023

Member

Please add a comment above this describing what it's for / typical use case (e.g. conditional automagic inherit).


def get_eclass(self, export, pkg):
"""Return the eclass related to a given exported variable or function name."""
try:
Expand Down Expand Up @@ -920,8 +922,12 @@ def feed(self, pkg):

# allowed indirect inherits
indirect_allowed = set().union(*(self.eclass_cache[x].provides for x in pkg.inherit))
all_inherits = set().union(pkg.inherit, indirect_allowed, conditional)
# missing inherits
missing = used.keys() - pkg.inherit - indirect_allowed - conditional
missing = used.keys() - all_inherits

for eclass in all_inherits:
weak_used_eclasses.update(self.weak_eclass_usage.get(eclass, ()))

unused = set(pkg.inherit) - used.keys() - set(assigned_vars.values()) - weak_used_eclasses
# remove eclasses that use implicit phase functions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
EAPI=8

inherit elisp readme.gentoo-r1

DESCRIPTION="Ebuild with weak usage inheritance"
HOMEPAGE="https://github.com/pkgcore/pkgcheck"
SLOT="0"
LICENSE="BSD"
13 changes: 13 additions & 0 deletions testdata/repos/eclass/eclass/elisp.eclass
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# @ECLASS: elisp.eclass
# @MAINTAINER:
# Random Person <maintainer@random.email>
# @SUPPORTED_EAPIS: 8
# @BLURB: Stub eclass for testing the UnusedInherit result.

EXPORT_FUNCTIONS src_prepare

# @FUNCTION: elisp_src_prepare
# @USAGE:
# @DESCRIPTION:
# Public src_prepare stub function.
elisp_src_prepare() { :; }
11 changes: 11 additions & 0 deletions testdata/repos/eclass/eclass/readme.gentoo-r1.eclass
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @ECLASS: readme.gentoo-r1.eclass
# @MAINTAINER:
# Random Person <maintainer@random.email>
# @SUPPORTED_EAPIS: 8
# @BLURB: Stub eclass for testing the UnusedInherit result.

# @FUNCTION: readme.gentoo_create_doc
# @USAGE:
# @DESCRIPTION:
# stub function
readme.gentoo_create_doc() { :; }

0 comments on commit d837ae2

Please sign in to comment.