Make the EbuildQuote check filter out matches that appear to be an argument
authorZac Medico <zmedico@gentoo.org>
Fri, 14 Nov 2008 21:57:14 +0000 (21:57 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 14 Nov 2008 21:57:14 +0000 (21:57 -0000)
to a message command. For example: false || ewarn "foo $WORKDIR/bar baz"
Thanks to Diego 'Flameeyes' Pettenò <flameeyes@g.o> for reporting this
issue (currently triggered by ruby-prof-0.7.0.ebuild).

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

pym/repoman/checks.py

index dd81d87162641cdceb791d07283f08850e7e588d..c9415b759b2936786beff1b38679f92f46fb94bc 100644 (file)
@@ -83,8 +83,11 @@ class EbuildQuote(LineCheck):
        """Ensure ebuilds have valid quoting around things like D,FILESDIR, etc..."""
 
        repoman_check_name = 'ebuild.minorsyn'
-       _ignored_commands = ["echo", "local", "export"]
-       _ignored_commands += ["eerror", "einfo", "elog", "eqawarn", "ewarn"]
+       _message_commands = ["die", "echo", "eerror",
+               "einfo", "elog", "eqawarn", "ewarn"]
+       _message_re = re.compile(r'\s(' + "|".join(_message_commands) + \
+               r')\s+"[^"]*"\s*$')
+       _ignored_commands = ["local", "export"] + _message_commands
        ignore_line = re.compile(r'(^$)|(^\s*#.*)|(^\s*\w+=.*)' + \
                r'|(^\s*(' + "|".join(_ignored_commands) + r')\s+)')
        var_names = ["D", "DISTDIR", "FILESDIR", "S", "T", "ROOT", "WORKDIR"]
@@ -125,6 +128,15 @@ class EbuildQuote(LineCheck):
                        if self.var_reference.search(group) is None:
                                continue
 
+                       # Filter matches that appear to be an
+                       # argument to a message command.
+                       # For example: false || ewarn "foo $WORKDIR/bar baz"
+                       message_match = self._message_re.search(line)
+                       if message_match is not None and \
+                               message_match.start() < pos and \
+                               message_match.end() > pos:
+                               break
+
                        # This is an attempt to avoid false positives without getting
                        # too complex, while possibly allowing some (hopefully
                        # unlikely) violations to slip through. We just assume