blob: 9d64a329f54d624f589edfe906576e6b983741ba [file] [log] [blame]
Eric Boren7e97dc02017-02-02 09:02:37 -05001# 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
9from recipe_engine import recipe_api
10
11from . import default_flavor
Ravi Mistryd8ebf692017-02-17 11:28:36 -050012from . import flutter_flavor
Eric Boren7e97dc02017-02-02 09:02:37 -050013from . import gn_android_flavor
Kevin Lubick261ea192017-04-05 07:32:45 -040014from . import gn_chromebook_flavor
Kevin Lubickdcd2a902017-03-08 14:01:01 -050015from . import gn_chromecast_flavor
Eric Boren7e97dc02017-02-02 09:02:37 -050016from . import gn_flavor
Mike Klein20f00782017-02-02 18:55:03 -050017from . import ios_flavor
Eric Boren7e97dc02017-02-02 09:02:37 -050018from . import pdfium_flavor
19from . import valgrind_flavor
20
21
22TEST_EXPECTED_SKP_VERSION = '42'
23TEST_EXPECTED_SVG_VERSION = '42'
24TEST_EXPECTED_SK_IMAGE_VERSION = '42'
25
26VERSION_FILE_SK_IMAGE = 'SK_IMAGE_VERSION'
27VERSION_FILE_SKP = 'SKP_VERSION'
28VERSION_FILE_SVG = 'SVG_VERSION'
29
30VERSION_NONE = -1
31
32def is_android(builder_cfg):
33 return 'Android' in builder_cfg.get('extra_config', '')
34
Kevin Lubickdcd2a902017-03-08 14:01:01 -050035def is_chromecast(builder_cfg):
Kevin Lubick291547d2017-03-21 09:25:34 -040036 return ('Chromecast' in builder_cfg.get('extra_config', '') or
37 'Chromecast' in builder_cfg.get('os', ''))
Kevin Lubickdcd2a902017-03-08 14:01:01 -050038
Kevin Lubick261ea192017-04-05 07:32:45 -040039def is_chromebook(builder_cfg):
40 return ('Chromebook' in builder_cfg.get('extra_config', '') or
41 'Chromebook' in builder_cfg.get('os', ''))
42
Ravi Mistryd8ebf692017-02-17 11:28:36 -050043def is_flutter(builder_cfg):
44 return 'Flutter' in builder_cfg.get('extra_config', '')
45
Mike Klein20f00782017-02-02 18:55:03 -050046def is_ios(builder_cfg):
Stephan Altmuellerbabb1012017-04-05 11:45:52 -040047 return ('iOS' in builder_cfg.get('extra_config', '') or
48 'iOS' == builder_cfg.get('os', ''))
Eric Boren7e97dc02017-02-02 09:02:37 -050049
Eric Boren7e97dc02017-02-02 09:02:37 -050050def is_pdfium(builder_cfg):
51 return 'PDFium' in builder_cfg.get('extra_config', '')
52
Eric Boren7e97dc02017-02-02 09:02:37 -050053def is_valgrind(builder_cfg):
54 return 'Valgrind' in builder_cfg.get('extra_config', '')
55
56
57class SkiaFlavorApi(recipe_api.RecipeApi):
58 def get_flavor(self, builder_cfg):
59 """Return a flavor utils object specific to the given builder."""
Ravi Mistryd8ebf692017-02-17 11:28:36 -050060 if is_flutter(builder_cfg):
Eric Boren43b9c6b2017-04-06 07:53:30 -040061 return flutter_flavor.FlutterFlavorUtils(self)
Kevin Lubickdcd2a902017-03-08 14:01:01 -050062 if is_chromecast(builder_cfg):
Eric Boren43b9c6b2017-04-06 07:53:30 -040063 return gn_chromecast_flavor.GNChromecastFlavorUtils(self)
Kevin Lubick261ea192017-04-05 07:32:45 -040064 if is_chromebook(builder_cfg):
Eric Boren43b9c6b2017-04-06 07:53:30 -040065 return gn_chromebook_flavor.GNChromebookFlavorUtils(self)
Eric Boren7e97dc02017-02-02 09:02:37 -050066 if is_android(builder_cfg):
Eric Boren43b9c6b2017-04-06 07:53:30 -040067 return gn_android_flavor.GNAndroidFlavorUtils(self)
Mike Klein20f00782017-02-02 18:55:03 -050068 elif is_ios(builder_cfg):
Eric Boren43b9c6b2017-04-06 07:53:30 -040069 return ios_flavor.iOSFlavorUtils(self)
Eric Boren7e97dc02017-02-02 09:02:37 -050070 elif is_pdfium(builder_cfg):
Eric Boren43b9c6b2017-04-06 07:53:30 -040071 return pdfium_flavor.PDFiumFlavorUtils(self)
Eric Boren7e97dc02017-02-02 09:02:37 -050072 elif is_valgrind(builder_cfg):
Eric Boren43b9c6b2017-04-06 07:53:30 -040073 return valgrind_flavor.ValgrindFlavorUtils(self)
Eric Boren7e97dc02017-02-02 09:02:37 -050074 else:
Eric Boren43b9c6b2017-04-06 07:53:30 -040075 return gn_flavor.GNFlavorUtils(self)
Eric Boren7e97dc02017-02-02 09:02:37 -050076
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 Boren53262d02017-03-20 15:40:12 -040083 def compile(self, target):
84 return self._f.compile(target)
Eric Boren7e97dc02017-02-02 09:02:37 -050085
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 Klein20980082017-02-02 13:45:15 -0500150 except self.m.step.StepFailure: # pragma: nocover
151 device_version = VERSION_NONE # pragma: nocover
Eric Boren7e97dc02017-02-02 09:02:37 -0500152 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