From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id A368B158020 for ; Mon, 31 Oct 2022 18:20:33 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D6C34E0FB4; Mon, 31 Oct 2022 18:20:32 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B90F0E0FB4 for ; Mon, 31 Oct 2022 18:20:32 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8D73E341061 for ; Mon, 31 Oct 2022 18:20:31 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id B3E2655B for ; Mon, 31 Oct 2022 18:20:29 +0000 (UTC) From: "Arthur Zamarin" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arthur Zamarin" Message-ID: <1667240423.be9e91b4f8ebd49aeff8efd69cac8c61c54d5ba6.arthurzam@gentoo> Subject: [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/, ... X-VCS-Repository: proj/pkgcore/pkgcheck X-VCS-Files: src/pkgcheck/checks/codingstyle.py testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild X-VCS-Directories: testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/ testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/ testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/ src/pkgcheck/checks/ testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/ X-VCS-Committer: arthurzam X-VCS-Committer-Name: Arthur Zamarin X-VCS-Revision: be9e91b4f8ebd49aeff8efd69cac8c61c54d5ba6 X-VCS-Branch: master Date: Mon, 31 Oct 2022 18:20:29 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: df86c3f1-39fc-4c7f-ac62-8a0ad1d645be X-Archives-Hash: 8e90a86d0e8d7e2a86d8fac3c93c014a commit: be9e91b4f8ebd49aeff8efd69cac8c61c54d5ba6 Author: Arthur Zamarin gentoo org> AuthorDate: Fri Oct 28 13:57:38 2022 +0000 Commit: Arthur Zamarin gentoo org> CommitDate: Mon Oct 31 18:20:23 2022 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=be9e91b4 DoCompressedFilesCheck: new check for compressed do calls New check for catching passing compressed manpages to doman and newman, and passing compressed info to doinfo. Resolves: https://github.com/pkgcore/pkgcheck/issues/477 Signed-off-by: Arthur Zamarin gentoo.org> src/pkgcheck/checks/codingstyle.py | 49 ++++++++++++++++++++++ .../InstallCompressedInfo/expected.json | 2 + .../InstallCompressedManpage/expected.json | 4 ++ .../InstallCompressedInfo-0.ebuild | 11 +++++ .../InstallCompressedManpage-0.ebuild | 12 ++++++ 5 files changed, 78 insertions(+) diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py index b6ef8c34..4bf9932d 100644 --- a/src/pkgcheck/checks/codingstyle.py +++ b/src/pkgcheck/checks/codingstyle.py @@ -1118,3 +1118,52 @@ class LineLengthCheck(Check): lines.append(lineno) if lines: yield ExcessiveLineLength(lines=lines, pkg=pkg) + + +class InstallCompressedManpage(results.LineResult, results.Warning): + """Compressed manpages are not supported by ``doman`` or ``newman``.""" + + def __init__(self, func, **kwargs): + super().__init__(**kwargs) + self.func = func + + @property + def desc(self): + return f'line {self.lineno}: compressed manpage {self.line!r} passed to {self.func}' + + +class InstallCompressedInfo(results.LineResult, results.Warning): + """Compressed manpages are not supported by ``doinfo``.""" + + def __init__(self, func, **kwargs): + super().__init__(**kwargs) + self.func = func + + @property + def desc(self): + return f'line {self.lineno}: compressed info {self.line!r} passed to {self.func}' + + +class DoCompressedFilesCheck(Check): + """Scan ebuild for compressed files passed to ``do*`` or ``new**``.""" + + _source = sources.EbuildParseRepoSource + known_results = frozenset([InstallCompressedManpage, InstallCompressedInfo]) + + compresion_extentions = ('.Z', '.gz', '.bz2', '.lzma', '.lz', '.lzo', '.lz4', '.xz', '.zst') + functions = ImmutableDict({ + 'doman': InstallCompressedManpage, + 'newman': InstallCompressedManpage, + 'doinfo': InstallCompressedInfo, + }) + + def feed(self, pkg): + for node, _ in bash.cmd_query.captures(pkg.tree.root_node): + call_name = pkg.node_str(node.child_by_field_name('name')) + if call_name not in self.functions: + continue + for arg in node.children[1:]: + arg_name = pkg.node_str(arg).strip('\'\"') + lineno, _ = arg.start_point + if arg_name.endswith(self.compresion_extentions): + yield self.functions[call_name](call_name, lineno=lineno+1, line=arg_name, pkg=pkg) diff --git a/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json new file mode 100644 index 00000000..96e4e20c --- /dev/null +++ b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json @@ -0,0 +1,2 @@ +{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "${PN}.bz2", "lineno": 9, "func": "doinfo"} +{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "test.gz", "lineno": 9, "func": "doinfo"} diff --git a/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json new file mode 100644 index 00000000..b743d171 --- /dev/null +++ b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json @@ -0,0 +1,4 @@ +{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.2.bz2", "lineno": 9, "func": "doman"} +{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "test.gz", "lineno": 9, "func": "doman"} +{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.1.xz", "lineno": 10, "func": "newman"} +{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.xz", "lineno": 10, "func": "newman"} diff --git a/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild new file mode 100644 index 00000000..d82c952a --- /dev/null +++ b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild @@ -0,0 +1,11 @@ +EAPI=7 + +DESCRIPTION="Ebuild installing compressed info" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +SLOT="0" +LICENSE="BSD" + +src_install() { + doinfo 'test.gz' "${PN}.bz2" + doinfo "${PN}" +} diff --git a/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild new file mode 100644 index 00000000..7248d16a --- /dev/null +++ b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild @@ -0,0 +1,12 @@ +EAPI=7 + +DESCRIPTION="Ebuild installing compressed man pages" +HOMEPAGE="https://github.com/pkgcore/pkgcheck" +SLOT="0" +LICENSE="BSD" + +src_install() { + doman 'test.gz' "${PN}.2.bz2" + newman ${PN}.xz "${PN}.1.xz" + doman "${PN}" +}