Gentoo Archives: gentoo-commits

From: Brian Dolbec <dolsen@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:repoman commit in: pym/repoman/modules/scan/depend/, pym/repoman/
Date: Sun, 31 Jan 2016 20:03:37
Message-Id: 1454185507.f2044f0420f1a44064cb149455007b0ffebe85a0.dolsen@gentoo
1 commit: f2044f0420f1a44064cb149455007b0ffebe85a0
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Sun Jan 3 20:38:11 2016 +0000
4 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
5 CommitDate: Sat Jan 30 20:25:07 2016 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=f2044f04
7
8 repoman: New DependChecks class plugin
9
10 Migrate code from _scan_ebuilds to the plugin system.
11
12 pym/repoman/modules/scan/depend/__init__.py | 24 +++++
13 pym/repoman/modules/scan/depend/depend.py | 132 ++++++++++++++++++++++++++++
14 pym/repoman/scanner.py | 119 ++-----------------------
15 3 files changed, 163 insertions(+), 112 deletions(-)
16
17 diff --git a/pym/repoman/modules/scan/depend/__init__.py b/pym/repoman/modules/scan/depend/__init__.py
18 new file mode 100644
19 index 0000000..ebc716c
20 --- /dev/null
21 +++ b/pym/repoman/modules/scan/depend/__init__.py
22 @@ -0,0 +1,24 @@
23 +# Copyright 2015-2016 Gentoo Foundation
24 +# Distributed under the terms of the GNU General Public License v2
25 +
26 +doc = """Depend plug-in module for repoman.
27 +Performs Dependency checks on ebuilds."""
28 +__doc__ = doc[:]
29 +
30 +
31 +module_spec = {
32 + 'name': 'depend',
33 + 'description': doc,
34 + 'provides':{
35 + 'depend-module': {
36 + 'name': "depend",
37 + 'sourcefile': "depend",
38 + 'class': "DependChecks",
39 + 'description': doc,
40 + 'functions': ['check'],
41 + 'func_desc': {
42 + },
43 + },
44 + }
45 +}
46 +
47
48 diff --git a/pym/repoman/modules/scan/depend/depend.py b/pym/repoman/modules/scan/depend/depend.py
49 new file mode 100644
50 index 0000000..8a0ff48
51 --- /dev/null
52 +++ b/pym/repoman/modules/scan/depend/depend.py
53 @@ -0,0 +1,132 @@
54 +
55 +from _emerge.Package import Package
56 +
57 +from repoman.check_missingslot import check_missingslot
58 +# import our initialized portage instance
59 +from repoman._portage import portage
60 +from repoman.qa_data import suspect_virtual, suspect_rdepend
61 +
62 +
63 +class DependChecks(object):
64 +
65 + def __init__(self, **kwargs):
66 + self.qatracker = kwargs.get('qatracker')
67 + self.portdb = kwargs.get('portdb')
68 +
69 + def check(self, **kwargs):
70 + ebuild = kwargs.get('ebuild')
71 + pkg = kwargs.get('pkg')
72 +
73 + unknown_pkgs = set()
74 +
75 + inherited_java_eclass = "java-pkg-2" in ebuild.inherited or \
76 + "java-pkg-opt-2" in ebuild.inherited,
77 + inherited_wxwidgets_eclass = "wxwidgets" in ebuild.inherited
78 + # operator_tokens = set(["||", "(", ")"])
79 + type_list, badsyntax = [], []
80 + for mytype in Package._dep_keys + ("LICENSE", "PROPERTIES", "PROVIDE"):
81 + mydepstr = ebuild.metadata[mytype]
82 +
83 + buildtime = mytype in Package._buildtime_keys
84 + runtime = mytype in Package._runtime_keys
85 + token_class = None
86 + if mytype.endswith("DEPEND"):
87 + token_class = portage.dep.Atom
88 +
89 + try:
90 + atoms = portage.dep.use_reduce(
91 + mydepstr, matchall=1, flat=True,
92 + is_valid_flag=pkg.iuse.is_valid_flag, token_class=token_class)
93 + except portage.exception.InvalidDependString as e:
94 + atoms = None
95 + badsyntax.append(str(e))
96 +
97 + if atoms and mytype.endswith("DEPEND"):
98 + if runtime and \
99 + "test?" in mydepstr.split():
100 + self.qatracker.add_error(
101 + mytype + '.suspect',
102 + "%s: 'test?' USE conditional in %s" %
103 + (ebuild.relative_path, mytype))
104 +
105 + for atom in atoms:
106 + if atom == "||":
107 + continue
108 +
109 + is_blocker = atom.blocker
110 +
111 + # Skip dependency.unknown for blockers, so that we
112 + # don't encourage people to remove necessary blockers,
113 + # as discussed in bug 382407. We use atom.without_use
114 + # due to bug 525376.
115 + if not is_blocker and \
116 + not self.portdb.xmatch("match-all", atom.without_use) and \
117 + not atom.cp.startswith("virtual/"):
118 + unknown_pkgs.add((mytype, atom.unevaluated_atom))
119 +
120 + if kwargs.get('catdir') != "virtual":
121 + if not is_blocker and \
122 + atom.cp in suspect_virtual:
123 + self.qatracker.add_error(
124 + 'virtual.suspect', ebuild.relative_path +
125 + ": %s: consider using '%s' instead of '%s'" %
126 + (mytype, suspect_virtual[atom.cp], atom))
127 + if not is_blocker and \
128 + atom.cp.startswith("perl-core/"):
129 + self.qatracker.add_error('dependency.perlcore',
130 + ebuild.relative_path +
131 + ": %s: please use '%s' instead of '%s'" %
132 + (mytype,
133 + atom.replace("perl-core/","virtual/perl-"),
134 + atom))
135 +
136 + if buildtime and \
137 + not is_blocker and \
138 + not inherited_java_eclass and \
139 + atom.cp == "virtual/jdk":
140 + self.qatracker.add_error(
141 + 'java.eclassesnotused', ebuild.relative_path)
142 + elif buildtime and \
143 + not is_blocker and \
144 + not inherited_wxwidgets_eclass and \
145 + atom.cp == "x11-libs/wxGTK":
146 + self.qatracker.add_error(
147 + 'wxwidgets.eclassnotused',
148 + "%s: %ss on x11-libs/wxGTK without inheriting"
149 + " wxwidgets.eclass" % (ebuild.relative_path, mytype))
150 + elif runtime:
151 + if not is_blocker and \
152 + atom.cp in suspect_rdepend:
153 + self.qatracker.add_error(
154 + mytype + '.suspect',
155 + ebuild.relative_path + ": '%s'" % atom)
156 +
157 + if atom.operator == "~" and \
158 + portage.versions.catpkgsplit(atom.cpv)[3] != "r0":
159 + qacat = 'dependency.badtilde'
160 + self.qatracker.add_error(
161 + qacat, "%s: %s uses the ~ operator"
162 + " with a non-zero revision: '%s'" %
163 + (ebuild.relative_path, mytype, atom))
164 +
165 + check_missingslot(atom, mytype, ebuild.eapi, self.portdb, self.qatracker,
166 + ebuild.relative_path, ebuild.metadata)
167 +
168 + type_list.extend([mytype] * (len(badsyntax) - len(type_list)))
169 +
170 + for m, b in zip(type_list, badsyntax):
171 + if m.endswith("DEPEND"):
172 + qacat = "dependency.syntax"
173 + else:
174 + qacat = m + ".syntax"
175 + self.qatracker.add_error(
176 + qacat, "%s: %s: %s" % (ebuild.relative_path, m, b))
177 + return {'continue': False, 'unknown_pkgs': unknown_pkgs, 'type_list': type_list}
178 +
179 + @property
180 + def runInPkgs(self):
181 + return (False, [])
182 +
183 + @property
184 + def runInEbuilds(self):
185 + return (True, [self.check])
186
187 diff --git a/pym/repoman/scanner.py b/pym/repoman/scanner.py
188 index 829dba1..8081c1e 100644
189 --- a/pym/repoman/scanner.py
190 +++ b/pym/repoman/scanner.py
191 @@ -19,13 +19,11 @@ from portage.dep import Atom
192 from portage.output import green
193 from repoman.checks.ebuilds.checks import run_checks
194 from repoman.checks.ebuilds.eclasses.ruby import RubyEclassChecks
195 -from repoman.check_missingslot import check_missingslot
196 from repoman.checks.ebuilds.use_flags import USEFlagChecks
197 from repoman.checks.ebuilds.variables.license import LicenseChecks
198 from repoman.checks.ebuilds.variables.restrict import RestrictChecks
199 from repoman.modules.commit import repochecks
200 from repoman.profile import check_profiles, dev_profile_keywords, setup_profile
201 -from repoman.qa_data import missingvars, suspect_virtual, suspect_rdepend
202 from repoman.repos import repo_metadata
203 from repoman.modules.scan.scan import scan
204 from repoman.modules.vcs.vcs import vcs_files_to_cps
205 @@ -304,7 +302,7 @@ class Scanner(object):
206 ('eapi', 'EAPIChecks'), ('ebuild_metadata', 'EbuildMetadata'),
207 ('thirdpartymirrors', 'ThirdPartyMirrors'),
208 ('description', 'DescriptionChecks'), (None, 'KeywordChecks'),
209 - ('arches', 'ArchChecks'),
210 + ('arches', 'ArchChecks'), ('depend', 'DependChecks'),
211 ]:
212 if mod[0]:
213 mod_class = MODULE_CONTROLLER.get_class(mod[0])
214 @@ -361,112 +359,9 @@ class Scanner(object):
215 badprovsyntax = False
216 # catpkg = catdir + "/" + y_ebuild
217
218 - inherited_java_eclass = "java-pkg-2" in dynamic_data['ebuild'].inherited or \
219 - "java-pkg-opt-2" in dynamic_data['ebuild'].inherited,
220 - inherited_wxwidgets_eclass = "wxwidgets" in dynamic_data['ebuild'].inherited
221 - # operator_tokens = set(["||", "(", ")"])
222 - type_list, badsyntax = [], []
223 - for mytype in Package._dep_keys + ("LICENSE", "PROPERTIES", "PROVIDE"):
224 - mydepstr = dynamic_data['ebuild'].metadata[mytype]
225 -
226 - buildtime = mytype in Package._buildtime_keys
227 - runtime = mytype in Package._runtime_keys
228 - token_class = None
229 - if mytype.endswith("DEPEND"):
230 - token_class = portage.dep.Atom
231 -
232 - try:
233 - atoms = portage.dep.use_reduce(
234 - mydepstr, matchall=1, flat=True,
235 - is_valid_flag=dynamic_data['pkg'].iuse.is_valid_flag, token_class=token_class)
236 - except portage.exception.InvalidDependString as e:
237 - atoms = None
238 - badsyntax.append(str(e))
239 -
240 - if atoms and mytype.endswith("DEPEND"):
241 - if runtime and \
242 - "test?" in mydepstr.split():
243 - self.qatracker.add_error(
244 - mytype + '.suspect',
245 - "%s: 'test?' USE conditional in %s" %
246 - (dynamic_data['ebuild'].relative_path, mytype))
247 -
248 - for atom in atoms:
249 - if atom == "||":
250 - continue
251 -
252 - is_blocker = atom.blocker
253 -
254 - # Skip dependency.unknown for blockers, so that we
255 - # don't encourage people to remove necessary blockers,
256 - # as discussed in bug 382407. We use atom.without_use
257 - # due to bug 525376.
258 - if not is_blocker and \
259 - not self.portdb.xmatch("match-all", atom.without_use) and \
260 - not atom.cp.startswith("virtual/"):
261 - unknown_pkgs.add((mytype, atom.unevaluated_atom))
262 -
263 - if dynamic_data['catdir'] != "virtual":
264 - if not is_blocker and \
265 - atom.cp in suspect_virtual:
266 - self.qatracker.add_error(
267 - 'virtual.suspect', dynamic_data['ebuild'].relative_path +
268 - ": %s: consider using '%s' instead of '%s'" %
269 - (mytype, suspect_virtual[atom.cp], atom))
270 - if not is_blocker and \
271 - atom.cp.startswith("perl-core/"):
272 - self.qatracker.add_error('dependency.perlcore',
273 - dynamic_data['ebuild'].relative_path +
274 - ": %s: please use '%s' instead of '%s'" %
275 - (mytype,
276 - atom.replace("perl-core/","virtual/perl-"),
277 - atom))
278 -
279 - if buildtime and \
280 - not is_blocker and \
281 - not inherited_java_eclass and \
282 - atom.cp == "virtual/jdk":
283 - self.qatracker.add_error(
284 - 'java.eclassesnotused', dynamic_data['ebuild'].relative_path)
285 - elif buildtime and \
286 - not is_blocker and \
287 - not inherited_wxwidgets_eclass and \
288 - atom.cp == "x11-libs/wxGTK":
289 - self.qatracker.add_error(
290 - 'wxwidgets.eclassnotused',
291 - "%s: %ss on x11-libs/wxGTK without inheriting"
292 - " wxwidgets.eclass" % (dynamic_data['ebuild'].relative_path, mytype))
293 - elif runtime:
294 - if not is_blocker and \
295 - atom.cp in suspect_rdepend:
296 - self.qatracker.add_error(
297 - mytype + '.suspect',
298 - dynamic_data['ebuild'].relative_path + ": '%s'" % atom)
299 -
300 - if atom.operator == "~" and \
301 - portage.versions.catpkgsplit(atom.cpv)[3] != "r0":
302 - qacat = 'dependency.badtilde'
303 - self.qatracker.add_error(
304 - qacat, "%s: %s uses the ~ operator"
305 - " with a non-zero revision: '%s'" %
306 - (dynamic_data['ebuild'].relative_path, mytype, atom))
307 -
308 - check_missingslot(atom, mytype, dynamic_data['ebuild'].eapi, self.portdb, self.qatracker,
309 - dynamic_data['ebuild'].relative_path, dynamic_data['ebuild'].metadata)
310 -
311 - type_list.extend([mytype] * (len(badsyntax) - len(type_list)))
312 -
313 - for m, b in zip(type_list, badsyntax):
314 - if m.endswith("DEPEND"):
315 - qacat = "dependency.syntax"
316 - else:
317 - qacat = m + ".syntax"
318 - self.qatracker.add_error(
319 - qacat, "%s: %s: %s" % (dynamic_data['ebuild'].relative_path, m, b))
320 -
321 - badlicsyntax = len([z for z in type_list if z == "LICENSE"])
322 - badprovsyntax = len([z for z in type_list if z == "PROVIDE"])
323 - baddepsyntax = len(type_list) != badlicsyntax + badprovsyntax
324 + badlicsyntax = len([z for z in dynamic_data['type_list'] if z == "LICENSE"])
325 + badprovsyntax = len([z for z in dynamic_data['type_list'] if z == "PROVIDE"])
326 + baddepsyntax = len(dynamic_data['type_list']) != badlicsyntax + badprovsyntax
327 badlicsyntax = badlicsyntax > 0
328 badprovsyntax = badprovsyntax > 0
329
330 @@ -629,7 +524,7 @@ class Scanner(object):
331 # aren't counted for *DEPEND.bad, so we
332 # ignore them here.
333 if not atom.blocker:
334 - unknown_pkgs.discard(
335 + dynamic_data['unknown_pkgs'].discard(
336 (mytype, atom.unevaluated_atom))
337
338 if not prof.sub_path:
339 @@ -674,9 +569,9 @@ class Scanner(object):
340 % (dynamic_data['ebuild'].relative_path, mytype, keyword,
341 prof, pformat(atoms, indent=6)))
342
343 - if not baddepsyntax and unknown_pkgs:
344 + if not baddepsyntax and dynamic_data['unknown_pkgs']:
345 type_map = {}
346 - for mytype, atom in unknown_pkgs:
347 + for mytype, atom in dynamic_data['unknown_pkgs']:
348 type_map.setdefault(mytype, set()).add(atom)
349 for mytype, atoms in type_map.items():
350 self.qatracker.add_error(