repoman: update EAPI.definition check for PMS
authorZac Medico <zmedico@gentoo.org>
Sun, 15 Apr 2012 22:21:49 +0000 (15:21 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 15 Apr 2012 22:23:11 +0000 (15:23 -0700)
The plan is to update PMS section 8.3.1 as discussed here:

http://archives.gentoo.org/gentoo-pms/msg_ef7635aa655913f2386e64e385f5a6ae.xml

bin/repoman
man/repoman.1
pym/repoman/checks.py

index 42539241e7d83585c1e72949dfff05420fbb0e84..651c0bed4667cddc8910b640b83cc031e4b8f24f 100755 (executable)
@@ -326,7 +326,7 @@ qahelp={
        "LICENSE.virtual":"Virtuals that have a non-empty LICENSE variable",
        "DESCRIPTION.missing":"Ebuilds that have a missing or empty DESCRIPTION variable",
        "DESCRIPTION.toolong":"DESCRIPTION is over %d characters" % max_desc_len,
-       "EAPI.definition":"EAPI is defined after an inherit call (must be defined before)",
+       "EAPI.definition":"EAPI definition does not conform to PMS section 8.3.1 (first non-comment, non-blank line)",
        "EAPI.deprecated":"Ebuilds that use features that are deprecated in the current EAPI",
        "EAPI.incompatible":"Ebuilds that use features that are only available with a different EAPI",
        "EAPI.unsupported":"Ebuilds that have an unsupported EAPI version (you must upgrade portage)",
index 37babcd4bf7fd4a4db0ea7bc884d94d5dfcb52a9..0e0715c9d2cd5b4ba01af3d9a3463392ef53fb11 100644 (file)
@@ -146,7 +146,8 @@ Syntax error in DEPEND (usually an extra/missing space/parenthesis)
 Ebuilds that have a missing or empty DESCRIPTION variable
 .TP
 .B EAPI.definition
-EAPI is defined after an inherit call (must be defined before)
+EAPI definition does not conform to PMS section 8.3.1 (first
+non\-comment, non\-blank line)
 .TP
 .B EAPI.deprecated
 Ebuilds that use features that are deprecated in the current EAPI
index 50c017af2abdafb3e84f9e74348d4098a5d8a68d..c3d110f888a0fd8b958418e9f0e550b5142cc8b0 100644 (file)
@@ -283,21 +283,37 @@ class EbuildUselessCdS(LineCheck):
                        self.check_next_line = True
 
 class EapiDefinition(LineCheck):
-       """ Check that EAPI is defined before inherits"""
+       """
+       Check that EAPI assignment conforms to PMS section 8.3.1
+       (first non-comment, non-blank line).
+       """
        repoman_check_name = 'EAPI.definition'
+       ignore_comment = True
 
-       eapi_re = re.compile(r'^EAPI=')
-       inherit_re = re.compile(r'^\s*inherit\s')
+       # This pattern is specified by PMS section 8.3.1.
+       _eapi_re = re.compile(r"^[ \t]*EAPI=(['\"]?)([A-Za-z0-9+_.-]*)\1[ \t]*(#.*)?$")
 
        def new(self, pkg):
-               self.inherit_line = None
+               self._cached_eapi = pkg.metadata['EAPI']
+               self._parsed_eapi = None
+               self._eapi_line_num = None
 
        def check(self, num, line):
-               if self.eapi_re.match(line) is not None:
-                       if self.inherit_line is not None:
-                               return errors.EAPI_DEFINED_AFTER_INHERIT
-               elif self.inherit_re.match(line) is not None:
-                       self.inherit_line = line
+               if self._eapi_line_num is None and line.strip():
+                       self._eapi_line_num = num + 1
+                       m = self._eapi_re.match(line)
+                       if m is not None:
+                               self._parsed_eapi = m.group(2)
+
+       def end(self):
+               if self._parsed_eapi is None:
+                       if self._cached_eapi != "0":
+                               yield "valid EAPI assignment must occur on or before line: %d" % \
+                                       self._eapi_line_num
+               elif self._parsed_eapi != self._cached_eapi:
+                       yield ("bash returned EAPI '%s' which does not match "
+                               "assignment on line: %d") % \
+                               (self._cached_eapi, self._eapi_line_num)
 
 class EbuildPatches(LineCheck):
        """Ensure ebuilds use bash arrays for PATCHES to ensure white space safety"""