1 # Copyright 2017 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 # Disable warning about setting self.device_dirs in install(); we need to. 6 # pylint: disable=W0201 7 8 import default_flavor 9 import gn_flavor 10 import os 11 12 class iOSFlavorUtils(gn_flavor.GNFlavorUtils): 13 14 def install(self): 15 # Set up the device 16 self.m.run(self.m.step, 'setup_device', cmd=['ios.py'], infra_step=True) 17 18 # Install the app. 19 for app_name in ['dm', 'nanobench']: 20 app_package = self.m.vars.skia_out.join(self.m.vars.configuration, 21 '%s.app' % app_name) 22 23 def uninstall_app(attempt): 24 # If app ID changes, upgrade will fail, so try uninstalling. 25 self.m.run(self.m.step, 26 'uninstall_' + app_name, 27 cmd=['ideviceinstaller', '-U', 'com.google.%s' % app_name], 28 infra_step=True, 29 # App may not be installed. 30 abort_on_failure=False, fail_build_on_failure=False) 31 32 num_attempts = 2 33 self.m.run.with_retry(self.m.step, 'install_' + app_name, num_attempts, 34 cmd=['ideviceinstaller', '-i', app_package], 35 between_attempts_fn=uninstall_app, 36 infra_step=True) 37 38 self.device_dirs = default_flavor.DeviceDirs( 39 dm_dir='dm', 40 perf_data_dir='perf', 41 resource_dir='resources', 42 images_dir='images', 43 skp_dir='skps', 44 svg_dir='svgs', 45 tmp_dir='tmp') 46 47 def step(self, name, cmd, env=None, **kwargs): 48 bundle_id = 'com.google.%s' % cmd[0] 49 self.m.run(self.m.step, name, 50 cmd=['idevice-app-runner', '-s', bundle_id, '--args'] + 51 map(str, cmd[1:])) 52 53 def _run_ios_script(self, script, first, *rest): 54 full = self.m.vars.skia_dir.join('platform_tools/ios/bin/ios_' + script) 55 self.m.run(self.m.step, 56 name = '%s %s' % (script, first), 57 cmd = [full, first] + list(rest), 58 infra_step=True) 59 60 def copy_file_to_device(self, host, device): 61 self._run_ios_script('push_file', host, device) 62 63 def copy_directory_contents_to_device(self, host, device): 64 self._run_ios_script('push_if_needed', host, device) 65 66 def copy_directory_contents_to_host(self, device, host): 67 self._run_ios_script('pull_if_needed', device, host) 68 69 def remove_file_on_device(self, path): 70 self._run_ios_script('rm', path) 71 72 def create_clean_device_dir(self, path): 73 self._run_ios_script('rm', path) 74 self._run_ios_script('mkdir', path) 75 76 def read_file_on_device(self, path, **kwargs): 77 full = self.m.vars.skia_dir.join('platform_tools/ios/bin/ios_cat_file') 78 rv = self.m.run(self.m.step, 79 name = 'cat_file %s' % path, 80 cmd = [full, path], 81 stdout=self.m.raw_io.output(), 82 infra_step=True, 83 **kwargs) 84 return rv.stdout.rstrip() if rv and rv.stdout else None 85