Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be | 
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. | 
| 4 | 4 | 
| 5 """ Skia-specific subclass of BuildStep """ | 5 """ Skia-specific subclass of BuildStep """ | 
| 6 | 6 | 
| 7 | 7 | 
| 8 from buildbot.status.logfile import STDOUT | 8 from buildbot.status.logfile import STDOUT | 
| 9 from master.log_parser import retcode_command | 9 from master.log_parser import retcode_command | 
| 10 import re | 10 import re | 
| 11 | 11 | 
| 12 | 12 | 
| 13 class SkiaBuildStep(retcode_command.ReturnCodeCommand): | 13 class SkiaBuildStep(retcode_command.ReturnCodeCommand): | 
| 14 """ BuildStep wrapper for Skia. Allows us to define properties of BuildSteps | 14 """ BuildStep wrapper for Skia. Allows us to define properties of BuildSteps | 
| 15 to be used by ShouldDoStep. This is necessary because the properties referred | 15 to be used by ShouldDoStep. This is necessary because the properties referred | 
| 16 to by BuildStep.getProperty() are scoped for the entire duration of the build. | 16 to by BuildStep.getProperty() are scoped for the entire duration of the build. | 
| 17 """ | 17 """ | 
| 18 def __init__(self, is_upload_step=False, is_rebaseline_step=False, | 18 def __init__(self, is_upload_step=False, is_rebaseline_step=False, | 
| 19 get_props_from_stdout=None, exception_on_failure=False, | 19 get_links_from_stdout=None, get_props_from_stdout=None, | 
| 20 **kwargs): | 20 exception_on_failure=False, **kwargs): | 
| 21 """ Instantiates a new SkiaBuildStep. | 21 """ Instantiates a new SkiaBuildStep. | 
| 22 | 22 | 
| 23 is_upload_step: boolean indicating whether this step should be skipped when | 23 is_upload_step: boolean indicating whether this step should be skipped when | 
| 24 the buildbot is not performing uploads. | 24 the buildbot is not performing uploads. | 
| 25 is_rebaseline_step: boolean indicating whether this step is required for | 25 is_rebaseline_step: boolean indicating whether this step is required for | 
| 26 rebaseline-only builds. | 26 rebaseline-only builds. | 
| 27 get_links_from_stdout: optional dictionary. Keys are strings indicating | |
| 28 link text to set based on the output of this step. Values are | |
| 29 strings containing regular expressions for parsing the linked URL from | |
| 30 the output of the step. | |
| 27 get_props_from_stdout: optional dictionary. Keys are strings indicating | 31 get_props_from_stdout: optional dictionary. Keys are strings indicating | 
| 28 build properties to set based on the output of this step. Values are | 32 build properties to set based on the output of this step. Values are | 
| 29 strings containing regular expressions for parsing the property from | 33 strings containing regular expressions for parsing the property from | 
| 30 the output of the step. | 34 the output of the step. | 
| 31 exception_on_failure: boolean indicating whether to raise an exception if | 35 exception_on_failure: boolean indicating whether to raise an exception if | 
| 32 this step fails. This causes the step to go purple instead of red, and | 36 this step fails. This causes the step to go purple instead of red, and | 
| 33 causes the build to stop. Should be used if the build step's failure is | 37 causes the build to stop. Should be used if the build step's failure is | 
| 34 typically transient or results from an infrastructure failure rather | 38 typically transient or results from an infrastructure failure rather | 
| 35 than a code change. | 39 than a code change. | 
| 36 """ | 40 """ | 
| 37 self._is_upload_step = is_upload_step | 41 self._is_upload_step = is_upload_step | 
| 38 self._is_rebaseline_step = is_rebaseline_step | 42 self._is_rebaseline_step = is_rebaseline_step | 
| 43 self._get_links_from_stdout = get_links_from_stdout | |
| 39 self._get_props_from_stdout = get_props_from_stdout | 44 self._get_props_from_stdout = get_props_from_stdout | 
| 40 self._exception_on_failure = exception_on_failure | 45 self._exception_on_failure = exception_on_failure | 
| 41 | 46 | 
| 42 # self._changed_props will be a dictionary containing the build properties | 47 # self._changed_props will be a dictionary containing the build properties | 
| 43 # which were updated by this BuildStep. Those properties will be displayed | 48 # which were updated by this BuildStep. Those properties will be displayed | 
| 44 # in the label for this step. | 49 # in the label for this step. | 
| 45 self._changed_props = None | 50 self._changed_props = None | 
| 46 | 51 | 
| 47 retcode_command.ReturnCodeCommand.__init__(self, **kwargs) | 52 retcode_command.ReturnCodeCommand.__init__(self, **kwargs) | 
| 48 self.name = ''.join(self.description) | 53 self.name = ''.join(self.description) | 
| 49 | 54 | 
| 50 def IsUploadStep(self): | 55 def IsUploadStep(self): | 
| 51 return self._is_upload_step | 56 return self._is_upload_step | 
| 52 | 57 | 
| 53 def IsRebaselineStep(self): | 58 def IsRebaselineStep(self): | 
| 54 return self._is_rebaseline_step | 59 return self._is_rebaseline_step | 
| 55 | 60 | 
| 56 def commandComplete(self, cmd): | 61 def commandComplete(self, cmd): | 
| 57 """ Override of BuildStep's commandComplete method which allows us to parse | 62 """ Override of BuildStep's commandComplete method which allows us to parse | 
| 58 build properties from the output of this step. """ | 63 build properties from the output of this step. """ | 
| 59 | 64 | 
| 60 # We make a best effort to parse the properties out of stdout, whether | 65 if self._get_props_from_stdout or self._get_links_from_stdout: | 
| 61 # the command succeeded or failed. If the command succeeded, we | |
| 62 # definitely expect the property to be found in stdout--if not, raise | |
| 63 # an exception. | |
| 64 if self._get_props_from_stdout: | |
| 65 log = cmd.logs['stdio'] | 66 log = cmd.logs['stdio'] | 
| 66 stdout = ''.join(log.getChunks([STDOUT], onlyText=True)) | 67 stdout = ''.join(log.getChunks([STDOUT], onlyText=True)) | 
| 
 
borenet
2014/06/06 12:10:34
This is probably a performance killer. Seems like
 
epoger
2014/06/09 13:33:29
I don't know how the chunks are split.  It would n
 
 | |
| 67 self._changed_props = {} | 68 self._changed_props = {} | 
| 68 for prop, regex in self._get_props_from_stdout.iteritems(): | 69 | 
| 69 matches = re.search(regex, stdout) | 70 # We make a best effort to parse the properties out of stdout, whether | 
| 70 if not matches: | 71 # the command succeeded or failed. If the command succeeded, we | 
| 71 if cmd.rc == 0: | 72 # definitely expect the property to be found in stdout--if not, raise | 
| 72 raise Exception('Unable to parse %s from stdout.' % prop) | 73 # an exception. | 
| 73 continue | 74 if self._get_props_from_stdout: | 
| 74 groups = matches.groups() | 75 for prop, regex in self._get_props_from_stdout.iteritems(): | 
| 75 if len(groups) != 1: | 76 matches = re.search(regex, stdout) | 
| 76 if cmd.rc == 0: | 77 if not matches: | 
| 77 raise Exception('Multiple matches for "%s"' % regex) | 78 if cmd.rc == 0: | 
| 78 continue | 79 raise Exception('Unable to parse %s from stdout.' % prop) | 
| 79 prop_value = groups[0] | 80 continue | 
| 80 self.setProperty(prop, prop_value, ''.join(self.description)) | 81 groups = matches.groups() | 
| 81 self._changed_props[prop] = prop_value | 82 if len(groups) != 1: | 
| 83 if cmd.rc == 0: | |
| 84 raise Exception('Multiple matches for "%s"' % regex) | |
| 85 continue | |
| 86 prop_value = groups[0] | |
| 87 self.setProperty(prop, prop_value, ''.join(self.description)) | |
| 88 self._changed_props[prop] = prop_value | |
| 89 | |
| 90 # If there might be URL links we want in stdout, look for them; | |
| 91 # their presence is optional, though, so we don't throw an exception | |
| 92 # if they are not found. | |
| 93 if self._get_links_from_stdout: | |
| 94 for name, regex in self._get_links_from_stdout.iteritems(): | |
| 95 matches = re.search(regex, stdout) | |
| 96 if matches: | |
| 97 groups = matches.groups() | |
| 98 for url in groups: | |
| 99 self.addURL(name, url) | |
| 82 | 100 | 
| 83 if (cmd.rc not in (0, retcode_command.ReturnCodeCommand.RETCODE_WARNINGS) | 101 if (cmd.rc not in (0, retcode_command.ReturnCodeCommand.RETCODE_WARNINGS) | 
| 84 and self._exception_on_failure): | 102 and self._exception_on_failure): | 
| 85 raise Exception('Command marked exception_on_failure failed.') | 103 raise Exception('Command marked exception_on_failure failed.') | 
| 86 retcode_command.ReturnCodeCommand.commandComplete(self, cmd) | 104 retcode_command.ReturnCodeCommand.commandComplete(self, cmd) | 
| 87 | 105 | 
| 88 def getText(self, cmd, results): | 106 def getText(self, cmd, results): | 
| 89 """ Override of BuildStep's getText method which appends any changed build | 107 """ Override of BuildStep's getText method which appends any changed build | 
| 90 properties to the description of the BuildStep. """ | 108 properties to the description of the BuildStep. """ | 
| 91 text = self.description | 109 text = self.description | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 # If this step uploads results (and thus overwrites the most recently uploaded | 141 # If this step uploads results (and thus overwrites the most recently uploaded | 
| 124 # results), only run it on scheduled builds (i.e. most recent revision) or if | 142 # results), only run it on scheduled builds (i.e. most recent revision) or if | 
| 125 # the "force_upload" property was set. | 143 # the "force_upload" property was set. | 
| 126 if step.IsUploadStep() and \ | 144 if step.IsUploadStep() and \ | 
| 127 not _HasProperty(step, 'scheduler') and \ | 145 not _HasProperty(step, 'scheduler') and \ | 
| 128 not _HasProperty(step, 'force_upload'): | 146 not _HasProperty(step, 'force_upload'): | 
| 129 return False | 147 return False | 
| 130 | 148 | 
| 131 # Unless we have determined otherwise, run the step. | 149 # Unless we have determined otherwise, run the step. | 
| 132 return True | 150 return True | 
| OLD | NEW |