aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2017-07-15 00:17:49 +0000
committerZac Medico <zmedico@gentoo.org>2018-03-29 20:51:16 -0700
commitf3c815ac3dcff92ed2d49ac3243e6e62cfbc652a (patch)
treea0074c2dd9434abafa08d1e8a2ae4e34f7c9da8a
parentrepoman: Initial creation of a new linechecks sub module plugin system (diff)
downloadportage-f3c815ac3dcff92ed2d49ac3243e6e62cfbc652a.tar.gz
portage-f3c815ac3dcff92ed2d49ac3243e6e62cfbc652a.tar.bz2
portage-f3c815ac3dcff92ed2d49ac3243e6e62cfbc652a.zip
repoman: New linechecks module, assignment
-rw-r--r--repoman/pym/repoman/modules/linechecks/assignment/__init__.py27
-rw-r--r--repoman/pym/repoman/modules/linechecks/assignment/assignment.py31
2 files changed, 58 insertions, 0 deletions
diff --git a/repoman/pym/repoman/modules/linechecks/assignment/__init__.py b/repoman/pym/repoman/modules/linechecks/assignment/__init__.py
new file mode 100644
index 000000000..6223baa9f
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/assignment/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Assignment plug-in module for repoman LineChecks.
+Performs assignments checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+ 'name': 'assignment',
+ 'description': doc,
+ 'provides':{
+ 'assignment-check': {
+ 'name': "assignment",
+ 'sourcefile': "assignment",
+ 'class': "EbuildAssignment",
+ 'description': doc,
+ },
+ 'eapi3-check': {
+ 'name': "eapi3assignment",
+ 'sourcefile': "assignment",
+ 'class': "Eapi3EbuildAssignment",
+ 'description': doc,
+ },
+ }
+}
+
diff --git a/repoman/pym/repoman/modules/linechecks/assignment/assignment.py b/repoman/pym/repoman/modules/linechecks/assignment/assignment.py
new file mode 100644
index 000000000..496c9d092
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/assignment/assignment.py
@@ -0,0 +1,31 @@
+
+import re
+
+from portage.eapi import eapi_supports_prefix
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildAssignment(LineCheck):
+ """Ensure ebuilds don't assign to readonly variables."""
+
+ repoman_check_name = 'variable.readonly'
+ read_only_vars = 'A|CATEGORY|P|P[VNRF]|PVR|D|WORKDIR|FILESDIR|FEATURES|USE'
+ readonly_assignment = re.compile(r'^\s*(export\s+)?(%s)=' % read_only_vars)
+
+ def check(self, num, line):
+ match = self.readonly_assignment.match(line)
+ e = None
+ if match is not None:
+ e = self.errors['READONLY_ASSIGNMENT_ERROR']
+ return e
+
+
+class Eapi3EbuildAssignment(EbuildAssignment):
+ """Ensure ebuilds don't assign to readonly EAPI 3-introduced variables."""
+
+ read_only_vars = 'ED|EPREFIX|EROOT'
+ readonly_assignment = re.compile(r'\s*(export\s+)?(%s)=' % read_only_vars)
+
+ def check_eapi(self, eapi):
+ return eapi_supports_prefix(eapi)
+