OLD | NEW |
| (Empty) |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 """ Skia-specific subclass of BuildStep """ | |
6 | |
7 | |
8 from buildbot.status.logfile import STDOUT | |
9 from master.log_parser import retcode_command | |
10 import re | |
11 | |
12 | |
13 class SkiaBuildStep(retcode_command.ReturnCodeCommand): | |
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 | |
16 to by BuildStep.getProperty() are scoped for the entire duration of the build. | |
17 """ | |
18 def __init__(self, is_upload_step=False, is_rebaseline_step=False, | |
19 get_props_from_stdout=None, exception_on_failure=False, | |
20 **kwargs): | |
21 """ Instantiates a new SkiaBuildStep. | |
22 | |
23 is_upload_step: boolean indicating whether this step should be skipped when | |
24 the buildbot is not performing uploads. | |
25 is_rebaseline_step: boolean indicating whether this step is required for | |
26 rebaseline-only builds. | |
27 get_props_from_stdout: optional dictionary. Keys are strings indicating | |
28 build properties to set based on the output of this step. Values are | |
29 strings containing regular expressions for parsing the property from | |
30 the output of the step. | |
31 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 | |
33 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 | |
35 than a code change. | |
36 """ | |
37 self._is_upload_step = is_upload_step | |
38 self._is_rebaseline_step = is_rebaseline_step | |
39 self._get_props_from_stdout = get_props_from_stdout | |
40 self._exception_on_failure = exception_on_failure | |
41 | |
42 # self._changed_props will be a dictionary containing the build properties | |
43 # which were updated by this BuildStep. Those properties will be displayed | |
44 # in the label for this step. | |
45 self._changed_props = None | |
46 | |
47 retcode_command.ReturnCodeCommand.__init__(self, **kwargs) | |
48 self.name = ''.join(self.description) | |
49 | |
50 def IsUploadStep(self): | |
51 return self._is_upload_step | |
52 | |
53 def IsRebaselineStep(self): | |
54 return self._is_rebaseline_step | |
55 | |
56 def commandComplete(self, cmd): | |
57 """ Override of BuildStep's commandComplete method which allows us to parse | |
58 build properties from the output of this step. """ | |
59 | |
60 # We make a best effort to parse the properties out of stdout, whether | |
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 stdout = ''.join(log.getChunks([STDOUT], onlyText=True)) | |
67 self._changed_props = {} | |
68 for prop, regex in self._get_props_from_stdout.iteritems(): | |
69 matches = re.search(regex, stdout) | |
70 if not matches: | |
71 if cmd.rc == 0: | |
72 raise Exception('Unable to parse %s from stdout.' % prop) | |
73 continue | |
74 groups = matches.groups() | |
75 if len(groups) != 1: | |
76 if cmd.rc == 0: | |
77 raise Exception('Multiple matches for "%s"' % regex) | |
78 continue | |
79 prop_value = groups[0] | |
80 self.setProperty(prop, prop_value, ''.join(self.description)) | |
81 self._changed_props[prop] = prop_value | |
82 | |
83 if (cmd.rc not in (0, retcode_command.ReturnCodeCommand.RETCODE_WARNINGS) | |
84 and self._exception_on_failure): | |
85 raise Exception('Command marked exception_on_failure failed.') | |
86 retcode_command.ReturnCodeCommand.commandComplete(self, cmd) | |
87 | |
88 def getText(self, cmd, results): | |
89 """ Override of BuildStep's getText method which appends any changed build | |
90 properties to the description of the BuildStep. """ | |
91 text = self.description | |
92 if self._changed_props: | |
93 text.extend(['%s: %s' % ( | |
94 key, self._changed_props.get(key)) for key in self._changed_props]) | |
95 return text | |
96 | |
97 | |
98 def _HasProperty(step, prop): | |
99 """ Helper used by ShouldDoStep. Determine whether the given BuildStep has | |
100 the requested property. | |
101 | |
102 step: an instance of BuildStep | |
103 prop: string, the property to test | |
104 """ | |
105 try: | |
106 step.getProperty(prop) | |
107 return True | |
108 # pylint: disable=W0702 | |
109 except: | |
110 return False | |
111 | |
112 | |
113 def ShouldDoStep(step): | |
114 """ At build time, use build properties to determine whether or not a step | |
115 should be run or skipped. | |
116 | |
117 step: an instance of BuildStep which we may or may not run. | |
118 """ | |
119 print step.build.getProperties() | |
120 if not isinstance(step, SkiaBuildStep): | |
121 return True | |
122 | |
123 # 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 | |
125 # the "force_upload" property was set. | |
126 if step.IsUploadStep() and \ | |
127 not _HasProperty(step, 'scheduler') and \ | |
128 not _HasProperty(step, 'force_upload'): | |
129 return False | |
130 | |
131 # Unless we have determined otherwise, run the step. | |
132 return True | |
OLD | NEW |