Ticket #74: shell.py.diff

File shell.py.diff, 2.9 KB (added by rochg, 5 years ago)
  • buildbot/steps/shell.py

    old new  
    247247    descriptionDone = ["configure"] 
    248248    command = ["./configure"] 
    249249 
    250 class Compile(ShellCommand): 
     250class WarningCountingShellCommand(ShellCommand): 
     251    warnCount = 0 
     252 
     253    def __init__(self, workdir, 
     254                 description=None, descriptionDone=None, 
     255                 command=None, 
     256                 **kwargs): 
     257        # See if we've been given a regular expression to use to match 
     258        # warngins. If not, use a default that assumes any line with "warning" 
     259        # present is a warning. This may lead to false positives in some cases. 
     260        if kwargs.has_key('warningPattern'): 
     261            warningPattern = kwargs['warningPattern'] 
     262            del kwargs['warningPattern'] 
     263        else: 
     264            warningPattern = '.*warning[: ].*' 
     265 
     266        # Now compile a regular expression from whichever warning pattern we're 
     267        # using 
     268        if "" != warningPattern: 
     269            self.warningRegExp = re.compile(warningPattern) 
     270        else: 
     271            self.warningRegExp = None 
     272 
     273        # And upcall to let the base class do its work 
     274        ShellCommand.__init__(self, workdir, 
     275                              description, descriptionDone, 
     276                              command, 
     277                              **kwargs) 
     278 
     279    def createSummary(self, log): 
     280        self.warnCount = 0 
     281 
     282        # Check if each line in the output from this command matched out 
     283        # warnings regular expressions. If did, bump the warnings count and 
     284        # add the line to the collection of lines with warnings 
     285        if None != self.warningRegExp: 
     286            warnings = [] 
     287            for line in log.getText().split("\n"): 
     288                if self.warningRegExp.match(line): 
     289                    warnings.append(line) 
     290                    self.warnCount += 1 
     291 
     292            # If there were any warnings, make the log if lines with warngins 
     293            # available 
     294            if self.warnCount: 
     295                self.addCompleteLog("warnings", "".join(warnings)) 
     296 
     297    def evaluateCommand(self, cmd): 
     298        if cmd.rc != 0: 
     299            return FAILURE 
     300        if self.warnCount: 
     301            return WARNINGS 
     302        return SUCCESS 
     303 
     304 
     305class Compile(WarningCountingShellCommand): 
    251306 
    252307    name = "compile" 
    253308    haltOnFailure = 1 
     
    260315    # traversed (assuming 'make' is being used) 
    261316 
    262317    def createSummary(self, cmd): 
    263         # TODO: grep for the characteristic GCC warning/error lines and 
     318        # TODO: grep for the characteristic GCC error lines and 
    264319        # assemble them into a pair of buffers 
     320        WarningCountingShellCommand.createSummary(self, cmd) 
    265321        pass 
    266322 
    267 class Test(ShellCommand): 
     323class Test(WarningCountingShellCommand): 
    268324 
    269325    name = "test" 
    270326    warnOnFailure = 1