1 |
commit: be9e91b4f8ebd49aeff8efd69cac8c61c54d5ba6 |
2 |
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Oct 28 13:57:38 2022 +0000 |
4 |
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Oct 31 18:20:23 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=be9e91b4 |
7 |
|
8 |
DoCompressedFilesCheck: new check for compressed do calls |
9 |
|
10 |
New check for catching passing compressed manpages to doman and newman, |
11 |
and passing compressed info to doinfo. |
12 |
|
13 |
Resolves: https://github.com/pkgcore/pkgcheck/issues/477 |
14 |
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> |
15 |
|
16 |
src/pkgcheck/checks/codingstyle.py | 49 ++++++++++++++++++++++ |
17 |
.../InstallCompressedInfo/expected.json | 2 + |
18 |
.../InstallCompressedManpage/expected.json | 4 ++ |
19 |
.../InstallCompressedInfo-0.ebuild | 11 +++++ |
20 |
.../InstallCompressedManpage-0.ebuild | 12 ++++++ |
21 |
5 files changed, 78 insertions(+) |
22 |
|
23 |
diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py |
24 |
index b6ef8c34..4bf9932d 100644 |
25 |
--- a/src/pkgcheck/checks/codingstyle.py |
26 |
+++ b/src/pkgcheck/checks/codingstyle.py |
27 |
@@ -1118,3 +1118,52 @@ class LineLengthCheck(Check): |
28 |
lines.append(lineno) |
29 |
if lines: |
30 |
yield ExcessiveLineLength(lines=lines, pkg=pkg) |
31 |
+ |
32 |
+ |
33 |
+class InstallCompressedManpage(results.LineResult, results.Warning): |
34 |
+ """Compressed manpages are not supported by ``doman`` or ``newman``.""" |
35 |
+ |
36 |
+ def __init__(self, func, **kwargs): |
37 |
+ super().__init__(**kwargs) |
38 |
+ self.func = func |
39 |
+ |
40 |
+ @property |
41 |
+ def desc(self): |
42 |
+ return f'line {self.lineno}: compressed manpage {self.line!r} passed to {self.func}' |
43 |
+ |
44 |
+ |
45 |
+class InstallCompressedInfo(results.LineResult, results.Warning): |
46 |
+ """Compressed manpages are not supported by ``doinfo``.""" |
47 |
+ |
48 |
+ def __init__(self, func, **kwargs): |
49 |
+ super().__init__(**kwargs) |
50 |
+ self.func = func |
51 |
+ |
52 |
+ @property |
53 |
+ def desc(self): |
54 |
+ return f'line {self.lineno}: compressed info {self.line!r} passed to {self.func}' |
55 |
+ |
56 |
+ |
57 |
+class DoCompressedFilesCheck(Check): |
58 |
+ """Scan ebuild for compressed files passed to ``do*`` or ``new**``.""" |
59 |
+ |
60 |
+ _source = sources.EbuildParseRepoSource |
61 |
+ known_results = frozenset([InstallCompressedManpage, InstallCompressedInfo]) |
62 |
+ |
63 |
+ compresion_extentions = ('.Z', '.gz', '.bz2', '.lzma', '.lz', '.lzo', '.lz4', '.xz', '.zst') |
64 |
+ functions = ImmutableDict({ |
65 |
+ 'doman': InstallCompressedManpage, |
66 |
+ 'newman': InstallCompressedManpage, |
67 |
+ 'doinfo': InstallCompressedInfo, |
68 |
+ }) |
69 |
+ |
70 |
+ def feed(self, pkg): |
71 |
+ for node, _ in bash.cmd_query.captures(pkg.tree.root_node): |
72 |
+ call_name = pkg.node_str(node.child_by_field_name('name')) |
73 |
+ if call_name not in self.functions: |
74 |
+ continue |
75 |
+ for arg in node.children[1:]: |
76 |
+ arg_name = pkg.node_str(arg).strip('\'\"') |
77 |
+ lineno, _ = arg.start_point |
78 |
+ if arg_name.endswith(self.compresion_extentions): |
79 |
+ yield self.functions[call_name](call_name, lineno=lineno+1, line=arg_name, pkg=pkg) |
80 |
|
81 |
diff --git a/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json |
82 |
new file mode 100644 |
83 |
index 00000000..96e4e20c |
84 |
--- /dev/null |
85 |
+++ b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json |
86 |
@@ -0,0 +1,2 @@ |
87 |
+{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "${PN}.bz2", "lineno": 9, "func": "doinfo"} |
88 |
+{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "test.gz", "lineno": 9, "func": "doinfo"} |
89 |
|
90 |
diff --git a/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json |
91 |
new file mode 100644 |
92 |
index 00000000..b743d171 |
93 |
--- /dev/null |
94 |
+++ b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json |
95 |
@@ -0,0 +1,4 @@ |
96 |
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.2.bz2", "lineno": 9, "func": "doman"} |
97 |
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "test.gz", "lineno": 9, "func": "doman"} |
98 |
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.1.xz", "lineno": 10, "func": "newman"} |
99 |
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.xz", "lineno": 10, "func": "newman"} |
100 |
|
101 |
diff --git a/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild |
102 |
new file mode 100644 |
103 |
index 00000000..d82c952a |
104 |
--- /dev/null |
105 |
+++ b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild |
106 |
@@ -0,0 +1,11 @@ |
107 |
+EAPI=7 |
108 |
+ |
109 |
+DESCRIPTION="Ebuild installing compressed info" |
110 |
+HOMEPAGE="https://github.com/pkgcore/pkgcheck" |
111 |
+SLOT="0" |
112 |
+LICENSE="BSD" |
113 |
+ |
114 |
+src_install() { |
115 |
+ doinfo 'test.gz' "${PN}.bz2" |
116 |
+ doinfo "${PN}" |
117 |
+} |
118 |
|
119 |
diff --git a/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild |
120 |
new file mode 100644 |
121 |
index 00000000..7248d16a |
122 |
--- /dev/null |
123 |
+++ b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild |
124 |
@@ -0,0 +1,12 @@ |
125 |
+EAPI=7 |
126 |
+ |
127 |
+DESCRIPTION="Ebuild installing compressed man pages" |
128 |
+HOMEPAGE="https://github.com/pkgcore/pkgcheck" |
129 |
+SLOT="0" |
130 |
+LICENSE="BSD" |
131 |
+ |
132 |
+src_install() { |
133 |
+ doman 'test.gz' "${PN}.2.bz2" |
134 |
+ newman ${PN}.xz "${PN}.1.xz" |
135 |
+ doman "${PN}" |
136 |
+} |