| OLD | NEW |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 """ Utilities for generic build steps. """ | 5 """ Utilities for generic build steps. """ |
| 6 | 6 |
| 7 import errno | 7 import errno |
| 8 import os | 8 import os |
| 9 import shutil | 9 import shutil |
| 10 import sys | 10 import sys |
| 11 | 11 |
| 12 from utils import file_utils | 12 from utils import file_utils |
| 13 from utils import shell_utils | 13 from utils import shell_utils |
| 14 | 14 |
| 15 | 15 |
| 16 class DeviceDirs(object): | 16 class DeviceDirs(object): |
| 17 def __init__(self, perf_data_dir, gm_actual_dir, gm_expected_dir, | 17 def __init__(self, perf_data_dir, gm_actual_dir, gm_expected_dir, |
| 18 resource_dir, skimage_in_dir, skimage_expected_dir, | 18 resource_dir, skimage_in_dir, skimage_expected_dir, |
| 19 skimage_out_dir, skp_dir, skp_perf_dir, | 19 skimage_out_dir, skp_dir, skp_perf_dir, skp_out_dir, tmp_dir): |
| 20 playback_actual_images_dir, playback_actual_summaries_dir, | |
| 21 playback_expected_summaries_dir, tmp_dir): | |
| 22 self._perf_data_dir = perf_data_dir | 20 self._perf_data_dir = perf_data_dir |
| 23 self._gm_actual_dir = gm_actual_dir | 21 self._gm_actual_dir = gm_actual_dir |
| 24 self._gm_expected_dir = gm_expected_dir | 22 self._gm_expected_dir = gm_expected_dir |
| 25 self._resource_dir = resource_dir | 23 self._resource_dir = resource_dir |
| 26 self._skimage_in_dir = skimage_in_dir | 24 self._skimage_in_dir = skimage_in_dir |
| 27 self._skimage_expected_dir = skimage_expected_dir | 25 self._skimage_expected_dir = skimage_expected_dir |
| 28 self._skimage_out_dir = skimage_out_dir | 26 self._skimage_out_dir = skimage_out_dir |
| 29 self._skp_dir = skp_dir | 27 self._skp_dir = skp_dir |
| 30 self._skp_perf_dir = skp_perf_dir | 28 self._skp_perf_dir = skp_perf_dir |
| 31 self._playback_actual_images_dir = playback_actual_images_dir | 29 self._skp_out_dir = skp_out_dir |
| 32 self._playback_actual_summaries_dir = playback_actual_summaries_dir | |
| 33 self._playback_expected_summaries_dir = playback_expected_summaries_dir | |
| 34 self._tmp_dir = tmp_dir | 30 self._tmp_dir = tmp_dir |
| 35 | 31 |
| 36 def GMActualDir(self): | 32 def GMActualDir(self): |
| 37 """Holds images and JSON summary written out by the 'gm' tool.""" | 33 return self._gm_actual_dir |
| 38 return self._gm_actual_dir | |
| 39 | 34 |
| 40 def GMExpectedDir(self): | 35 def GMExpectedDir(self): |
| 41 """Holds expectations JSON summary read by the 'gm' tool.""" | |
| 42 return self._gm_expected_dir | 36 return self._gm_expected_dir |
| 43 | 37 |
| 44 def PerfDir(self): | 38 def PerfDir(self): |
| 45 return self._perf_data_dir | 39 return self._perf_data_dir |
| 46 | 40 |
| 47 def PlaybackActualImagesDir(self): | |
| 48 """Holds image files written out by the 'render_pictures' tool.""" | |
| 49 return self._playback_actual_images_dir | |
| 50 | |
| 51 def PlaybackActualSummariesDir(self): | |
| 52 """Holds actual-result JSON summaries written by 'render_pictures' tool.""" | |
| 53 return self._playback_actual_summaries_dir | |
| 54 | |
| 55 def PlaybackExpectedSummariesDir(self): | |
| 56 """Holds expected-result JSON summaries read by 'render_pictures' tool.""" | |
| 57 return self._playback_expected_summaries_dir | |
| 58 | |
| 59 def ResourceDir(self): | 41 def ResourceDir(self): |
| 60 return self._resource_dir | 42 return self._resource_dir |
| 61 | 43 |
| 62 def SKImageInDir(self): | 44 def SKImageInDir(self): |
| 63 return self._skimage_in_dir | 45 return self._skimage_in_dir |
| 64 | 46 |
| 65 def SKImageExpectedDir(self): | 47 def SKImageExpectedDir(self): |
| 66 return self._skimage_expected_dir | 48 return self._skimage_expected_dir |
| 67 | 49 |
| 68 def SKImageOutDir(self): | 50 def SKImageOutDir(self): |
| 69 return self._skimage_out_dir | 51 return self._skimage_out_dir |
| 70 | 52 |
| 71 def SKPDir(self): | 53 def SKPDir(self): |
| 72 """Holds SKP files that are consumed by RenderSKPs and BenchPictures.""" | |
| 73 return self._skp_dir | 54 return self._skp_dir |
| 74 | 55 |
| 75 def SKPPerfDir(self): | 56 def SKPPerfDir(self): |
| 76 return self._skp_perf_dir | 57 return self._skp_perf_dir |
| 77 | 58 |
| 59 def SKPOutDir(self): |
| 60 return self._skp_out_dir |
| 61 |
| 78 def TmpDir(self): | 62 def TmpDir(self): |
| 79 return self._tmp_dir | 63 return self._tmp_dir |
| 80 | 64 |
| 81 | 65 |
| 82 class DefaultBuildStepUtils: | 66 class DefaultBuildStepUtils: |
| 83 """ Utilities to be used by subclasses of BuildStep. | 67 """ Utilities to be used by subclasses of BuildStep. |
| 84 | 68 |
| 85 The methods in this class define how certain high-level functions should work. | 69 The methods in this class define how certain high-level functions should work. |
| 86 Each build step flavor should correspond to a subclass of BuildStepUtils which | 70 Each build step flavor should correspond to a subclass of BuildStepUtils which |
| 87 may override any of these functions as appropriate for that flavor. | 71 may override any of these functions as appropriate for that flavor. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 115 """ Read the contents of a file on the associated device. Subclasses should | 99 """ Read the contents of a file on the associated device. Subclasses should |
| 116 override this method with one appropriate for reading the contents of a file | 100 override this method with one appropriate for reading the contents of a file |
| 117 on the device side. """ | 101 on the device side. """ |
| 118 with open(filepath) as f: | 102 with open(filepath) as f: |
| 119 return f.read() | 103 return f.read() |
| 120 | 104 |
| 121 def CopyDirectoryContentsToDevice(self, host_dir, device_dir): | 105 def CopyDirectoryContentsToDevice(self, host_dir, device_dir): |
| 122 """ Copy the contents of a host-side directory to a clean directory on the | 106 """ Copy the contents of a host-side directory to a clean directory on the |
| 123 device side. Subclasses should override this method with one appropriate for | 107 device side. Subclasses should override this method with one appropriate for |
| 124 copying the contents of a host-side directory to a clean device-side | 108 copying the contents of a host-side directory to a clean device-side |
| 125 directory. | 109 directory.""" |
| 126 | |
| 127 TODO(epoger): Clarify the description a bit: this method does not expect | |
| 128 device_dir to be an empty directory before it is called. Implementations | |
| 129 of this method for other device types create an empty directory at | |
| 130 device_dir as the first step. | |
| 131 """ | |
| 132 # For "normal" builders who don't have an attached device, we expect | 110 # For "normal" builders who don't have an attached device, we expect |
| 133 # host_dir and device_dir to be the same. | 111 # host_dir and device_dir to be the same. |
| 134 if host_dir != device_dir: | 112 if host_dir != device_dir: |
| 135 raise ValueError('For builders who do not have attached devices, copying ' | 113 raise ValueError('For builders who do not have attached devices, copying ' |
| 136 'from host to device is undefined and only allowed if ' | 114 'from host to device is undefined and only allowed if ' |
| 137 'host_dir and device_dir are the same.') | 115 'host_dir and device_dir are the same.') |
| 138 | 116 |
| 139 def CopyDirectoryContentsToHost(self, device_dir, host_dir): | 117 def CopyDirectoryContentsToHost(self, device_dir, host_dir): |
| 140 """ Copy the contents of a device-side directory to a clean directory on the | 118 """ Copy the contents of a device-side directory to a clean directory on the |
| 141 host side. Subclasses should override this method with one appropriate for | 119 host side. Subclasses should override this method with one appropriate for |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 make_cmd = 'make' | 203 make_cmd = 'make' |
| 226 if os.name == 'nt': | 204 if os.name == 'nt': |
| 227 make_cmd = 'make.bat' | 205 make_cmd = 'make.bat' |
| 228 shell_utils.run([make_cmd, 'clean']) | 206 shell_utils.run([make_cmd, 'clean']) |
| 229 | 207 |
| 230 def PreRun(self): | 208 def PreRun(self): |
| 231 """ Preprocessing step to run before the BuildStep itself. """ | 209 """ Preprocessing step to run before the BuildStep itself. """ |
| 232 pass | 210 pass |
| 233 | 211 |
| 234 def GetDeviceDirs(self): | 212 def GetDeviceDirs(self): |
| 235 """ Set the directories which will be used by the BuildStep. | 213 """ Set the directories which will be used by the BuildStep. """ |
| 236 | |
| 237 In the case of DefaultBuildStepUtils, host_dirs and device_dirs are the | |
| 238 same, which is why CopyDirectoryContentsToDevice() is a no-op. | |
| 239 """ | |
| 240 return DeviceDirs( | 214 return DeviceDirs( |
| 241 perf_data_dir=self._step.perf_data_dir, | 215 perf_data_dir=self._step.perf_data_dir, |
| 242 # TODO(epoger): Instead, set gm_actual_dir to self._step._gm_actual_dir | 216 # TODO(epoger): Instead, set gm_actual_dir to self._step._gm_actual_dir |
| 243 # and remove os.path.join() with self._builder_name in postrender.py ? | 217 # and remove os.path.join() with self._builder_name in postrender.py ? |
| 244 # (CopyDirectoryContentsToHost fails if the paths are different when | 218 # (CopyDirectoryContentsToHost fails if the paths are different when |
| 245 # host==device, so why not just make them inherently equal?) | 219 # host==device, so why not just make them inherently equal?) |
| 246 gm_actual_dir=os.path.join(os.pardir, os.pardir, 'gm', 'actual'), | 220 gm_actual_dir=os.path.join(os.pardir, os.pardir, 'gm', 'actual'), |
| 247 gm_expected_dir=os.path.join(os.pardir, os.pardir, 'gm', 'expected'), | 221 gm_expected_dir=os.path.join(os.pardir, os.pardir, 'gm', 'expected'), |
| 248 resource_dir=self._step.resource_dir, | 222 resource_dir=self._step.resource_dir, |
| 249 skimage_in_dir=self._step.skimage_in_dir, | 223 skimage_in_dir=self._step.skimage_in_dir, |
| 250 skimage_expected_dir=self._step.skimage_expected_dir, | 224 skimage_expected_dir=self._step.skimage_expected_dir, |
| 251 skimage_out_dir=self._step.skimage_out_dir, | 225 skimage_out_dir=self._step.skimage_out_dir, |
| 252 skp_dir=self._step.skp_dir, | 226 skp_dir=self._step.skp_dir, |
| 253 skp_perf_dir=self._step.perf_data_dir, | 227 skp_perf_dir=self._step.perf_data_dir, |
| 254 playback_actual_images_dir=self._step.playback_actual_images_dir, | 228 skp_out_dir=self._step.skp_out_dir, |
| 255 playback_actual_summaries_dir=self._step.playback_actual_summaries_dir, | |
| 256 playback_expected_summaries_dir=( | |
| 257 self._step.playback_expected_summaries_dir), | |
| 258 tmp_dir=os.path.join(os.pardir, 'tmp')) | 229 tmp_dir=os.path.join(os.pardir, 'tmp')) |
| OLD | NEW |