Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 1 | # Copyright 2016 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 | |
| 6 | # pylint: disable=W0201 |
| 7 | |
| 8 | |
| 9 | from recipe_engine import recipe_api |
| 10 | |
| 11 | from . import default_flavor |
Ravi Mistry | d8ebf69 | 2017-02-17 11:28:36 -0500 | [diff] [blame] | 12 | from . import flutter_flavor |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 13 | from . import gn_android_flavor |
Kevin Lubick | 261ea19 | 2017-04-05 07:32:45 -0400 | [diff] [blame] | 14 | from . import gn_chromebook_flavor |
Kevin Lubick | dcd2a90 | 2017-03-08 14:01:01 -0500 | [diff] [blame] | 15 | from . import gn_chromecast_flavor |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 16 | from . import gn_flavor |
Mike Klein | 20f0078 | 2017-02-02 18:55:03 -0500 | [diff] [blame] | 17 | from . import ios_flavor |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 18 | from . import pdfium_flavor |
| 19 | from . import valgrind_flavor |
| 20 | |
| 21 | |
| 22 | TEST_EXPECTED_SKP_VERSION = '42' |
| 23 | TEST_EXPECTED_SVG_VERSION = '42' |
| 24 | TEST_EXPECTED_SK_IMAGE_VERSION = '42' |
| 25 | |
| 26 | VERSION_FILE_SK_IMAGE = 'SK_IMAGE_VERSION' |
| 27 | VERSION_FILE_SKP = 'SKP_VERSION' |
| 28 | VERSION_FILE_SVG = 'SVG_VERSION' |
| 29 | |
| 30 | VERSION_NONE = -1 |
| 31 | |
| 32 | def is_android(builder_cfg): |
| 33 | return 'Android' in builder_cfg.get('extra_config', '') |
| 34 | |
Kevin Lubick | dcd2a90 | 2017-03-08 14:01:01 -0500 | [diff] [blame] | 35 | def is_chromecast(builder_cfg): |
Kevin Lubick | 291547d | 2017-03-21 09:25:34 -0400 | [diff] [blame] | 36 | return ('Chromecast' in builder_cfg.get('extra_config', '') or |
| 37 | 'Chromecast' in builder_cfg.get('os', '')) |
Kevin Lubick | dcd2a90 | 2017-03-08 14:01:01 -0500 | [diff] [blame] | 38 | |
Kevin Lubick | 261ea19 | 2017-04-05 07:32:45 -0400 | [diff] [blame] | 39 | def is_chromebook(builder_cfg): |
| 40 | return ('Chromebook' in builder_cfg.get('extra_config', '') or |
| 41 | 'Chromebook' in builder_cfg.get('os', '')) |
| 42 | |
Ravi Mistry | d8ebf69 | 2017-02-17 11:28:36 -0500 | [diff] [blame] | 43 | def is_flutter(builder_cfg): |
| 44 | return 'Flutter' in builder_cfg.get('extra_config', '') |
| 45 | |
Mike Klein | 20f0078 | 2017-02-02 18:55:03 -0500 | [diff] [blame] | 46 | def is_ios(builder_cfg): |
Stephan Altmueller | babb101 | 2017-04-05 11:45:52 -0400 | [diff] [blame] | 47 | return ('iOS' in builder_cfg.get('extra_config', '') or |
| 48 | 'iOS' == builder_cfg.get('os', '')) |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 49 | |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 50 | def is_pdfium(builder_cfg): |
| 51 | return 'PDFium' in builder_cfg.get('extra_config', '') |
| 52 | |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 53 | def is_valgrind(builder_cfg): |
| 54 | return 'Valgrind' in builder_cfg.get('extra_config', '') |
| 55 | |
| 56 | |
| 57 | class SkiaFlavorApi(recipe_api.RecipeApi): |
| 58 | def get_flavor(self, builder_cfg): |
| 59 | """Return a flavor utils object specific to the given builder.""" |
Ravi Mistry | d8ebf69 | 2017-02-17 11:28:36 -0500 | [diff] [blame] | 60 | if is_flutter(builder_cfg): |
Eric Boren | 43b9c6b | 2017-04-06 07:53:30 -0400 | [diff] [blame^] | 61 | return flutter_flavor.FlutterFlavorUtils(self) |
Kevin Lubick | dcd2a90 | 2017-03-08 14:01:01 -0500 | [diff] [blame] | 62 | if is_chromecast(builder_cfg): |
Eric Boren | 43b9c6b | 2017-04-06 07:53:30 -0400 | [diff] [blame^] | 63 | return gn_chromecast_flavor.GNChromecastFlavorUtils(self) |
Kevin Lubick | 261ea19 | 2017-04-05 07:32:45 -0400 | [diff] [blame] | 64 | if is_chromebook(builder_cfg): |
Eric Boren | 43b9c6b | 2017-04-06 07:53:30 -0400 | [diff] [blame^] | 65 | return gn_chromebook_flavor.GNChromebookFlavorUtils(self) |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 66 | if is_android(builder_cfg): |
Eric Boren | 43b9c6b | 2017-04-06 07:53:30 -0400 | [diff] [blame^] | 67 | return gn_android_flavor.GNAndroidFlavorUtils(self) |
Mike Klein | 20f0078 | 2017-02-02 18:55:03 -0500 | [diff] [blame] | 68 | elif is_ios(builder_cfg): |
Eric Boren | 43b9c6b | 2017-04-06 07:53:30 -0400 | [diff] [blame^] | 69 | return ios_flavor.iOSFlavorUtils(self) |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 70 | elif is_pdfium(builder_cfg): |
Eric Boren | 43b9c6b | 2017-04-06 07:53:30 -0400 | [diff] [blame^] | 71 | return pdfium_flavor.PDFiumFlavorUtils(self) |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 72 | elif is_valgrind(builder_cfg): |
Eric Boren | 43b9c6b | 2017-04-06 07:53:30 -0400 | [diff] [blame^] | 73 | return valgrind_flavor.ValgrindFlavorUtils(self) |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 74 | else: |
Eric Boren | 43b9c6b | 2017-04-06 07:53:30 -0400 | [diff] [blame^] | 75 | return gn_flavor.GNFlavorUtils(self) |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 76 | |
| 77 | def setup(self): |
| 78 | self._f = self.get_flavor(self.m.vars.builder_cfg) |
| 79 | |
| 80 | def step(self, name, cmd, **kwargs): |
| 81 | return self._f.step(name, cmd, **kwargs) |
| 82 | |
Eric Boren | 53262d0 | 2017-03-20 15:40:12 -0400 | [diff] [blame] | 83 | def compile(self, target): |
| 84 | return self._f.compile(target) |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 85 | |
| 86 | def copy_extra_build_products(self, swarming_out_dir): |
| 87 | return self._f.copy_extra_build_products(swarming_out_dir) |
| 88 | |
| 89 | @property |
| 90 | def out_dir(self): |
| 91 | return self._f.out_dir |
| 92 | |
| 93 | def device_path_join(self, *args): |
| 94 | return self._f.device_path_join(*args) |
| 95 | |
| 96 | def copy_directory_contents_to_device(self, host_dir, device_dir): |
| 97 | return self._f.copy_directory_contents_to_device(host_dir, device_dir) |
| 98 | |
| 99 | def copy_directory_contents_to_host(self, device_dir, host_dir): |
| 100 | return self._f.copy_directory_contents_to_host(device_dir, host_dir) |
| 101 | |
| 102 | def copy_file_to_device(self, host_path, device_path): |
| 103 | return self._f.copy_file_to_device(host_path, device_path) |
| 104 | |
| 105 | def create_clean_host_dir(self, path): |
| 106 | return self._f.create_clean_host_dir(path) |
| 107 | |
| 108 | def create_clean_device_dir(self, path): |
| 109 | return self._f.create_clean_device_dir(path) |
| 110 | |
| 111 | def read_file_on_device(self, path): |
| 112 | return self._f.read_file_on_device(path) |
| 113 | |
| 114 | def remove_file_on_device(self, path): |
| 115 | return self._f.remove_file_on_device(path) |
| 116 | |
| 117 | def install_everything(self): |
| 118 | self.install(skps=True, images=True, svgs=True, resources=True) |
| 119 | |
| 120 | def install(self, skps=False, images=False, svgs=False, resources=False): |
| 121 | self._f.install() |
| 122 | self.device_dirs = self._f.device_dirs |
| 123 | |
| 124 | # TODO(borenet): Only copy files which have changed. |
| 125 | if resources: |
| 126 | self.copy_directory_contents_to_device( |
| 127 | self.m.vars.resource_dir, |
| 128 | self.device_dirs.resource_dir) |
| 129 | |
| 130 | if skps: |
| 131 | self._copy_skps() |
| 132 | if images: |
| 133 | self._copy_images() |
| 134 | if svgs: |
| 135 | self._copy_svgs() |
| 136 | |
| 137 | def cleanup_steps(self): |
| 138 | return self._f.cleanup_steps() |
| 139 | |
| 140 | def _copy_dir(self, host_version, version_file, tmp_dir, |
| 141 | host_path, device_path, test_expected_version, |
| 142 | test_actual_version): |
| 143 | actual_version_file = self.m.path.join(tmp_dir, version_file) |
| 144 | # Copy to device. |
| 145 | device_version_file = self.device_path_join( |
| 146 | self.device_dirs.tmp_dir, version_file) |
| 147 | if str(actual_version_file) != str(device_version_file): |
| 148 | try: |
| 149 | device_version = self.read_file_on_device(device_version_file) |
Mike Klein | 2098008 | 2017-02-02 13:45:15 -0500 | [diff] [blame] | 150 | except self.m.step.StepFailure: # pragma: nocover |
| 151 | device_version = VERSION_NONE # pragma: nocover |
Eric Boren | 7e97dc0 | 2017-02-02 09:02:37 -0500 | [diff] [blame] | 152 | if device_version != host_version: |
| 153 | self.remove_file_on_device(device_version_file) |
| 154 | self.create_clean_device_dir(device_path) |
| 155 | self.copy_directory_contents_to_device( |
| 156 | host_path, device_path) |
| 157 | |
| 158 | # Copy the new version file. |
| 159 | self.copy_file_to_device(actual_version_file, device_version_file) |
| 160 | |
| 161 | def _copy_images(self): |
| 162 | """Download and copy test images if needed.""" |
| 163 | version_file = self.m.vars.infrabots_dir.join( |
| 164 | 'assets', 'skimage', 'VERSION') |
| 165 | test_data = self.m.properties.get( |
| 166 | 'test_downloaded_sk_image_version', TEST_EXPECTED_SK_IMAGE_VERSION) |
| 167 | version = self.m.run.readfile( |
| 168 | version_file, |
| 169 | name='Get downloaded skimage VERSION', |
| 170 | test_data=test_data).rstrip() |
| 171 | self.m.run.writefile( |
| 172 | self.m.path.join(self.m.vars.tmp_dir, VERSION_FILE_SK_IMAGE), |
| 173 | version) |
| 174 | self._copy_dir( |
| 175 | version, |
| 176 | VERSION_FILE_SK_IMAGE, |
| 177 | self.m.vars.tmp_dir, |
| 178 | self.m.vars.images_dir, |
| 179 | self.device_dirs.images_dir, |
| 180 | test_expected_version=self.m.properties.get( |
| 181 | 'test_downloaded_sk_image_version', |
| 182 | TEST_EXPECTED_SK_IMAGE_VERSION), |
| 183 | test_actual_version=self.m.properties.get( |
| 184 | 'test_downloaded_sk_image_version', |
| 185 | TEST_EXPECTED_SK_IMAGE_VERSION)) |
| 186 | return version |
| 187 | |
| 188 | def _copy_skps(self): |
| 189 | """Download and copy the SKPs if needed.""" |
| 190 | version_file = self.m.vars.infrabots_dir.join( |
| 191 | 'assets', 'skp', 'VERSION') |
| 192 | test_data = self.m.properties.get( |
| 193 | 'test_downloaded_skp_version', TEST_EXPECTED_SKP_VERSION) |
| 194 | version = self.m.run.readfile( |
| 195 | version_file, |
| 196 | name='Get downloaded SKP VERSION', |
| 197 | test_data=test_data).rstrip() |
| 198 | self.m.run.writefile( |
| 199 | self.m.path.join(self.m.vars.tmp_dir, VERSION_FILE_SKP), |
| 200 | version) |
| 201 | self._copy_dir( |
| 202 | version, |
| 203 | VERSION_FILE_SKP, |
| 204 | self.m.vars.tmp_dir, |
| 205 | self.m.vars.local_skp_dir, |
| 206 | self.device_dirs.skp_dir, |
| 207 | test_expected_version=self.m.properties.get( |
| 208 | 'test_downloaded_skp_version', TEST_EXPECTED_SKP_VERSION), |
| 209 | test_actual_version=self.m.properties.get( |
| 210 | 'test_downloaded_skp_version', TEST_EXPECTED_SKP_VERSION)) |
| 211 | return version |
| 212 | |
| 213 | def _copy_svgs(self): |
| 214 | """Download and copy the SVGs if needed.""" |
| 215 | version_file = self.m.vars.infrabots_dir.join( |
| 216 | 'assets', 'svg', 'VERSION') |
| 217 | test_data = self.m.properties.get( |
| 218 | 'test_downloaded_svg_version', TEST_EXPECTED_SVG_VERSION) |
| 219 | version = self.m.run.readfile( |
| 220 | version_file, |
| 221 | name='Get downloaded SVG VERSION', |
| 222 | test_data=test_data).rstrip() |
| 223 | self.m.run.writefile( |
| 224 | self.m.path.join(self.m.vars.tmp_dir, VERSION_FILE_SVG), |
| 225 | version) |
| 226 | self._copy_dir( |
| 227 | version, |
| 228 | VERSION_FILE_SVG, |
| 229 | self.m.vars.tmp_dir, |
| 230 | self.m.vars.local_svg_dir, |
| 231 | self.device_dirs.svg_dir, |
| 232 | test_expected_version=self.m.properties.get( |
| 233 | 'test_downloaded_svg_version', TEST_EXPECTED_SVG_VERSION), |
| 234 | test_actual_version=self.m.properties.get( |
| 235 | 'test_downloaded_svg_version', TEST_EXPECTED_SVG_VERSION)) |
| 236 | return version |