1 |
commit: 3ea468dde4de8ec14c9da1dd6d522a31cc443851 |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Jul 15 01:04:00 2017 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Mar 30 03:51:18 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3ea468dd |
7 |
|
8 |
repoman: New linechecks module, portage |
9 |
|
10 |
.../repoman/modules/linechecks/portage/__init__.py | 27 ++++++++++++++++ |
11 |
.../repoman/modules/linechecks/portage/internal.py | 37 ++++++++++++++++++++++ |
12 |
2 files changed, 64 insertions(+) |
13 |
|
14 |
diff --git a/repoman/pym/repoman/modules/linechecks/portage/__init__.py b/repoman/pym/repoman/modules/linechecks/portage/__init__.py |
15 |
new file mode 100644 |
16 |
index 000000000..d390c6054 |
17 |
--- /dev/null |
18 |
+++ b/repoman/pym/repoman/modules/linechecks/portage/__init__.py |
19 |
@@ -0,0 +1,27 @@ |
20 |
+# Copyright 2015-2016 Gentoo Foundation |
21 |
+# Distributed under the terms of the GNU General Public License v2 |
22 |
+ |
23 |
+doc = """Portage plug-in module for repoman LineChecks. |
24 |
+Performs checks for internal portage variable usage in ebuilds.""" |
25 |
+__doc__ = doc[:] |
26 |
+ |
27 |
+ |
28 |
+module_spec = { |
29 |
+ 'name': 'do', |
30 |
+ 'description': doc, |
31 |
+ 'provides':{ |
32 |
+ 'internal-check': { |
33 |
+ 'name': "portageinternal", |
34 |
+ 'sourcefile': "internal", |
35 |
+ 'class': "PortageInternal", |
36 |
+ 'description': doc, |
37 |
+ }, |
38 |
+ 'portageinternalvariableassignment-check': { |
39 |
+ 'name': "portageinternalvariableassignment", |
40 |
+ 'sourcefile': "internal", |
41 |
+ 'class': "PortageInternalVariableAssignment", |
42 |
+ 'description': doc, |
43 |
+ }, |
44 |
+ } |
45 |
+} |
46 |
+ |
47 |
|
48 |
diff --git a/repoman/pym/repoman/modules/linechecks/portage/internal.py b/repoman/pym/repoman/modules/linechecks/portage/internal.py |
49 |
new file mode 100644 |
50 |
index 000000000..869337221 |
51 |
--- /dev/null |
52 |
+++ b/repoman/pym/repoman/modules/linechecks/portage/internal.py |
53 |
@@ -0,0 +1,37 @@ |
54 |
+ |
55 |
+import re |
56 |
+ |
57 |
+from repoman.modules.linechecks.base import LineCheck |
58 |
+ |
59 |
+ |
60 |
+class PortageInternal(LineCheck): |
61 |
+ repoman_check_name = 'portage.internal' |
62 |
+ ignore_comment = True |
63 |
+ # Match when the command is preceded only by leading whitespace or a shell |
64 |
+ # operator such as (, {, |, ||, or &&. This prevents false positives in |
65 |
+ # things like elog messages, as reported in bug #413285. |
66 |
+ |
67 |
+ internal_portage_func_or_var = ( |
68 |
+ 'ecompress|ecompressdir|env-update|prepall|prepalldocs|preplib') |
69 |
+ re = re.compile( |
70 |
+ r'^(\s*|.*[|&{(]+\s*)\b(%s)\b' % internal_portage_func_or_var) |
71 |
+ |
72 |
+ def check(self, num, line): |
73 |
+ """Run the check on line and return error if there is one""" |
74 |
+ m = self.re.match(line) |
75 |
+ if m is not None: |
76 |
+ return ("'%s'" % m.group(2)) + " called on line: %d" |
77 |
+ |
78 |
+ |
79 |
+class PortageInternalVariableAssignment(LineCheck): |
80 |
+ repoman_check_name = 'portage.internal' |
81 |
+ internal_assignment = re.compile( |
82 |
+ r'\s*(export\s+)?(EXTRA_ECONF|EXTRA_EMAKE)\+?=') |
83 |
+ |
84 |
+ def check(self, num, line): |
85 |
+ match = self.internal_assignment.match(line) |
86 |
+ e = None |
87 |
+ if match is not None: |
88 |
+ e = 'Assignment to variable %s' % match.group(2) |
89 |
+ e += ' on line: %d' |
90 |
+ return e |