commit: d837ae22cc5381710f63d6600940d48a8e2875f5
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Thu Nov 16 19:51:44 2023 +0000
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Thu Nov 16 19:51:44 2023 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=d837ae22
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 <AT> gentoo.org>
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
src/pkgcheck/checks/codingstyle.py | 8 +++++++-
.../InheritsCheck/UnusedInherits/UnusedInherits-2.ebuild | 8 ++++++++
testdata/repos/eclass/eclass/elisp.eclass | 13 +++++++++++++
testdata/repos/eclass/eclass/readme.gentoo-r1.eclass | 11 +++++++++++
4 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/src/pkgcheck/checks/codingstyle.py
b/src/pkgcheck/checks/codingstyle.py
index 60f1ce98..90cb03b2 100644
--- a/src/pkgcheck/checks/codingstyle.py
+++ b/src/pkgcheck/checks/codingstyle.py
@@ -848,6 +848,8 @@ class InheritsCheck(Check):
self.unused_eclass_skiplist =
frozenset(common_mandatory_metadata_keys) - {"IUSE"}
+ self.weak_eclass_usage = {"elisp": ("readme.gentoo-r1",)}
+
def get_eclass(self, export, pkg):
"""Return the eclass related to a given exported variable or function
name."""
try:
@@ -920,8 +922,12 @@ class InheritsCheck(Check):
# 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
diff --git
a/testdata/repos/eclass/InheritsCheck/UnusedInherits/UnusedInherits-2.ebuild
b/testdata/repos/eclass/InheritsCheck/UnusedInherits/UnusedInherits-2.ebuild
new file mode 100644
index 00000000..320a61bd
--- /dev/null
+++ b/testdata/repos/eclass/InheritsCheck/UnusedInherits/UnusedInherits-2.ebuild
@@ -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"
diff --git a/testdata/repos/eclass/eclass/elisp.eclass
b/testdata/repos/eclass/eclass/elisp.eclass
new file mode 100644
index 00000000..e72964ea
--- /dev/null
+++ b/testdata/repos/eclass/eclass/elisp.eclass
@@ -0,0 +1,13 @@
+# @ECLASS: elisp.eclass
+# @MAINTAINER:
+# Random Person <[email protected]>
+# @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() { :; }
diff --git a/testdata/repos/eclass/eclass/readme.gentoo-r1.eclass
b/testdata/repos/eclass/eclass/readme.gentoo-r1.eclass
new file mode 100644
index 00000000..c7f61a09
--- /dev/null
+++ b/testdata/repos/eclass/eclass/readme.gentoo-r1.eclass
@@ -0,0 +1,11 @@
+# @ECLASS: readme.gentoo-r1.eclass
+# @MAINTAINER:
+# Random Person <[email protected]>
+# @SUPPORTED_EAPIS: 8
+# @BLURB: Stub eclass for testing the UnusedInherit result.
+
+# @FUNCTION: readme.gentoo_create_doc
+# @USAGE:
+# @DESCRIPTION:
+# stub function
+readme.gentoo_create_doc() { :; }