aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2023-10-01 23:10:53 +0300
committerArthur Zamarin <arthurzam@gentoo.org>2023-10-01 23:10:53 +0300
commitef0ee73cdcfe27dc27e208afe36060e0e52a3165 (patch)
tree118c9dfeb0c14d34d79fe29301959c2f0e24f0ea
parentDuplicateFunctionDefinition: new check for duplicate global functions (diff)
downloadpkgcheck-ef0ee73cdcfe27dc27e208afe36060e0e52a3165.tar.gz
pkgcheck-ef0ee73cdcfe27dc27e208afe36060e0e52a3165.tar.bz2
pkgcheck-ef0ee73cdcfe27dc27e208afe36060e0e52a3165.zip
BannedEapiCommand: check for has_version --host-root
Catch ``has_version --host-root`` and ``best_version --host-root`` calls, which are not allowed in EAPI>=7. Resolves: https://github.com/pkgcore/pkgcheck/issues/630 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r--src/pkgcheck/checks/codingstyle.py9
-rw-r--r--testdata/data/repos/standalone/BadCommandsCheck/BannedEapiCommand/expected.json2
-rw-r--r--testdata/data/repos/standalone/BadCommandsCheck/BannedEapiCommand/fix.patch19
-rw-r--r--testdata/repos/standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-1.ebuild13
4 files changed, 41 insertions, 2 deletions
diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py
index d0b5d861..317841bc 100644
--- a/src/pkgcheck/checks/codingstyle.py
+++ b/src/pkgcheck/checks/codingstyle.py
@@ -91,6 +91,15 @@ class BadCommandsCheck(Check):
)
elif name in pkg.eapi.phases.values():
yield BannedPhaseCall(line=name, lineno=lineno + 1, pkg=pkg)
+ elif name in ("has_version", "best_version"):
+ if not pkg.eapi.options.query_host_root and any(
+ pkg.node_str(n) == "--host-root"
+ for n in node.children_by_field_name("argument")
+ ):
+ name = f"{name} --host-root"
+ yield BannedEapiCommand(
+ name, line=call, lineno=lineno + 1, eapi=pkg.eapi, pkg=pkg
+ )
class EendMissingArg(results.LineResult, results.Warning):
diff --git a/testdata/data/repos/standalone/BadCommandsCheck/BannedEapiCommand/expected.json b/testdata/data/repos/standalone/BadCommandsCheck/BannedEapiCommand/expected.json
index dee93d43..921d5893 100644
--- a/testdata/data/repos/standalone/BadCommandsCheck/BannedEapiCommand/expected.json
+++ b/testdata/data/repos/standalone/BadCommandsCheck/BannedEapiCommand/expected.json
@@ -1 +1,3 @@
{"__class__": "BannedEapiCommand", "category": "BadCommandsCheck", "package": "BannedEapiCommand", "version": "0", "line": "dohtml doc/*", "lineno": 9, "command": "dohtml", "eapi": "7"}
+{"__class__": "BannedEapiCommand", "category": "BadCommandsCheck", "package": "BannedEapiCommand", "version": "1", "line": "has_version --host-root stub/stub1", "lineno": 9, "command": "has_version --host-root", "eapi": "7"}
+{"__class__": "BannedEapiCommand", "category": "BadCommandsCheck", "package": "BannedEapiCommand", "version": "1", "line": "best_version --host-root stub/stub1:2", "lineno": 12, "command": "best_version --host-root", "eapi": "7"}
diff --git a/testdata/data/repos/standalone/BadCommandsCheck/BannedEapiCommand/fix.patch b/testdata/data/repos/standalone/BadCommandsCheck/BannedEapiCommand/fix.patch
index 180e7f03..d906bd2b 100644
--- a/testdata/data/repos/standalone/BadCommandsCheck/BannedEapiCommand/fix.patch
+++ b/testdata/data/repos/standalone/BadCommandsCheck/BannedEapiCommand/fix.patch
@@ -1,6 +1,6 @@
diff -Naur standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-0.ebuild fixed/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-0.ebuild
---- standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-0.ebuild 2019-10-01 15:48:21.121467232 -0600
-+++ fixed/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-0.ebuild 2019-10-01 15:50:51.970090195 -0600
+--- standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-0.ebuild
++++ fixed/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-0.ebuild
@@ -6,5 +6,6 @@
LICENSE="BSD"
@@ -9,3 +9,18 @@ diff -Naur standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-0.ebu
+ docinto html
+ dodoc doc/*
}
+
+diff -Naur standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-1.ebuild fixed/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-1.ebuild
+--- standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-1.ebuild
++++ fixed/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-1.ebuild
+@@ -6,8 +6,8 @@ SLOT="0"
+ LICENSE="BSD"
+
+ src_install() {
+- if has_version --host-root stub/stub1; then
++ if has_version -b stub/stub1; then
+ :
+ fi
+- H=$(best_version --host-root stub/stub1:2)
++ H=$(best_version -b stub/stub1:2)
+ }
diff --git a/testdata/repos/standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-1.ebuild b/testdata/repos/standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-1.ebuild
new file mode 100644
index 00000000..ea4fb45b
--- /dev/null
+++ b/testdata/repos/standalone/BadCommandsCheck/BannedEapiCommand/BannedEapiCommand-1.ebuild
@@ -0,0 +1,13 @@
+EAPI=7
+
+DESCRIPTION="Ebuild using banned has_version"
+HOMEPAGE="https://github.com/pkgcore/pkgcheck"
+SLOT="0"
+LICENSE="BSD"
+
+src_install() {
+ if has_version --host-root stub/stub1; then
+ :
+ fi
+ H=$(best_version --host-root stub/stub1:2)
+}