Add a check for redundant cd "${S}" statements on the first
authorZac Medico <zmedico@gentoo.org>
Thu, 1 Nov 2007 02:25:18 +0000 (02:25 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 1 Nov 2007 02:25:18 +0000 (02:25 -0000)
line of src_(compile|install|test) ebuild methods. Thanks to
Petteri Räty <betelgeuse@gentoo.org> for this patch.

svn path=/main/trunk/; revision=8351

bin/repoman
pym/repoman/checks.py
pym/repoman/errors.py

index fec17e1387f58dfbb5e043d793098635dcdf5985..1f10a91d976112562c9f621890d243140a8cfc02 100755 (executable)
@@ -45,12 +45,12 @@ del os.environ["PORTAGE_LEGACY_GLOBALS"]
 
 try:
        from repoman.checks import EbuildWhitespace, EbuildHeader, EbuildQuote, \
-               EbuildAssignment, EbuildNestedDie, EbuildUselessDodoc
+               EbuildAssignment, EbuildNestedDie, EbuildUselessDodoc, EbuildUselessCdS
 except ImportError:
        from os import path as osp
        sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), 'pym'))
        from repoman.checks import EbuildWhitespace, EbuildHeader, EbuildQuote, \
-               EbuildAssignment, EbuildNestedDie, EbuildUselessDodoc
+               EbuildAssignment, EbuildNestedDie, EbuildUselessDodoc, EbuildUselessCdS
 
 try:
        import cStringIO as StringIO
@@ -1371,7 +1371,7 @@ for x in scanlist:
                myear = time.gmtime(os.stat(path)[ST_MTIME])[0]
                contents = StringIO.StringIO(open(path, 'rb').read())
                for check in (EbuildWhitespace, EbuildQuote,
-                       EbuildAssignment, EbuildUselessDodoc):
+                       EbuildAssignment, EbuildUselessDodoc, EbuildUselessCdS):
                        c = check(contents)
                        errors = c.Run()
                        for e in errors:
index 93c3222b338debfddd36ca10743b1b49d0a6940d..eea7ba40fcae66b474ed62003b16d38e410ded0d 100644 (file)
@@ -9,7 +9,7 @@ import os
 
 from repoman.errors import COPYRIGHT_ERROR, LICENSE_ERROR, CVS_HEADER_ERROR, \
        LEADING_SPACES_ERROR, READONLY_ASSIGNMENT_ERROR, TRAILING_WHITESPACE_ERROR, \
-       MISSING_QUOTES_ERROR, NESTED_DIE_ERROR
+       MISSING_QUOTES_ERROR, NESTED_DIE_ERROR, REDUNDANT_CD_S_ERROR
 
 
 class ContentCheckException(Exception):
@@ -243,3 +243,24 @@ class EbuildUselessDodoc(ContentCheck):
                                errors.append((num + 1, "Useless dodoc '%s'" % \
                                        (match.group(2), ) + " on line: %d"))
                return errors
+
+class EbuildUselessCdS(ContentCheck):
+       """Check for redundant cd ${S} statements"""
+       repoman_check_name = 'ebuild.minorsyn'
+       method_re = re.compile(r'^\s*src_(compile|install|test)\s*\(\)')
+       cds_re = re.compile(r'^\s*cd\s+"\$(\{S\}|S)"\s')
+
+       def __init__(self, contents):
+               ContentCheck.__init__(self, contents)
+
+       def Run(self):
+               errors = []
+               check_next_line = False
+               for num, line in enumerate(self.contents):
+                       if check_next_line:
+                               check_next_line = False
+                               if self.cds_re.match(line):
+                                       errors.append((num + 1, REDUNDANT_CD_S_ERROR))
+                       elif self.method_re.match(line):
+                               check_next_line = True
+               return errors
index 8378ed4d8ca16a7cf276ecc1ee0cb862cdc6bb91..3b3b3c179ff368a7a3fdb295826e245743a7f807 100644 (file)
@@ -11,3 +11,4 @@ TRAILING_WHITESPACE_ERROR = 'Trailing whitespace error on line: %d'
 READONLY_ASSIGNMENT_ERROR = 'Ebuild contains assignment to read-only variable on line: %d'
 MISSING_QUOTES_ERROR = 'Unquoted Variable on line: %d'
 NESTED_DIE_ERROR = 'Ebuild calls die in a subshell'
+REDUNDANT_CD_S_ERROR = 'Ebuild has redundant cd ${S} statement on line: %d'