commit: 98df7937359ff351d11285b3a66d722d07a28343 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> AuthorDate: Sat Jul 15 00:17:49 2017 +0000 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> CommitDate: Sat Jul 15 02:25:44 2017 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=98df7937
repoman: New linechecks module, assignment .../modules/linechecks/assignment/__init__.py | 27 +++++++++++++++++++ .../modules/linechecks/assignment/assignment.py | 30 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) 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..49fe98dea --- /dev/null +++ b/repoman/pym/repoman/modules/linechecks/assignment/assignment.py @@ -0,0 +1,30 @@ + +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.""" + + readonly_assignment = re.compile(r'\s*(export\s+)?(ED|EPREFIX|EROOT)=') + + def check_eapi(self, eapi): + return eapi_supports_prefix(eapi) +