[Buildbot-commits] buildbot/buildbot/steps shell.py,1.7,1.8

Brian Warner warner at users.sourceforge.net
Sun Dec 23 07:17:03 UTC 2007


Update of /cvsroot/buildbot/buildbot/buildbot/steps
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv4392/buildbot/steps

Modified Files:
	shell.py 
Log Message:
[project @ make Compile and Test count warnings, by regexp. Closes #74.]

Original author: warner at lothar.com
Date: 2007-12-23 07:12:34+00:00

Index: shell.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/steps/shell.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- shell.py	15 Dec 2007 01:02:04 -0000	1.7
+++ shell.py	23 Dec 2007 07:17:01 -0000	1.8
@@ -262,7 +262,70 @@
     descriptionDone = ["configure"]
     command = ["./configure"]
 
-class Compile(ShellCommand):
+class WarningCountingShellCommand(ShellCommand):
+    warnCount = 0
+    warningPattern = '.*warning[: ].*'
+
+    def __init__(self, **kwargs):
+        # See if we've been given a regular expression to use to match
+        # warnings. If not, use a default that assumes any line with "warning"
+        # present is a warning. This may lead to false positives in some cases.
+        wp = None
+        if kwargs.has_key('warningPattern'):
+            wp = kwargs['warningPattern']
+            del kwargs['warningPattern']
+            self.warningPattern = wp
+
+        # And upcall to let the base class do its work
+        ShellCommand.__init__(self, **kwargs)
+
+        if wp:
+            self.addFactoryArguments(warningPattern=wp)
+
+    def createSummary(self, log):
+        self.warnCount = 0
+
+        # Now compile a regular expression from whichever warning pattern we're
+        # using
+        if not self.warningPattern:
+            return
+
+        wre = self.warningPattern
+        if isinstance(wre, str):
+            wre = re.compile(wre)
+
+        # Check if each line in the output from this command matched our
+        # warnings regular expressions. If did, bump the warnings count and
+        # add the line to the collection of lines with warnings
+        warnings = []
+        # TODO: use log.readlines(), except we need to decide about stdout vs
+        # stderr
+        for line in log.getText().split("\n"):
+            if wre.match(line):
+                warnings.append(line)
+                self.warnCount += 1
+
+        # If there were any warnings, make the log if lines with warnings
+        # available
+        if self.warnCount:
+            self.addCompleteLog("warnings", "\n".join(warnings) + "\n")
+
+        try:
+            old_count = self.getProperty("warnings-count")
+        except KeyError:
+            old_count = 0
+        self.setProperty("warnings-count", old_count + self.warnCount)
+
+
+    def evaluateCommand(self, cmd):
+        if cmd.rc != 0:
+            return FAILURE
+        if self.warnCount:
+            return WARNINGS
+        return SUCCESS
+
+
+class Compile(WarningCountingShellCommand):
 
     name = "compile"
     haltOnFailure = 1
@@ -275,11 +338,12 @@
     # traversed (assuming 'make' is being used)
 
     def createSummary(self, cmd):
-        # TODO: grep for the characteristic GCC warning/error lines and
+        # TODO: grep for the characteristic GCC error lines and
         # assemble them into a pair of buffers
+        WarningCountingShellCommand.createSummary(self, cmd)
         pass
 
-class Test(ShellCommand):
+class Test(WarningCountingShellCommand):
 
     name = "test"
     warnOnFailure = 1





More information about the Commits mailing list