2017-02-02 23:55:03 +00:00
|
|
|
# Copyright 2017 The Chromium Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2017-02-03 18:31:05 +00:00
|
|
|
# Disable warning about setting self.device_dirs in install(); we need to.
|
|
|
|
# pylint: disable=W0201
|
|
|
|
|
2017-02-02 23:55:03 +00:00
|
|
|
|
2018-05-24 13:14:18 +00:00
|
|
|
from . import default
|
|
|
|
|
|
|
|
|
|
|
|
"""iOS flavor, used for running code on iOS."""
|
|
|
|
|
|
|
|
|
|
|
|
class iOSFlavor(default.DefaultFlavor):
|
2018-05-18 11:36:55 +00:00
|
|
|
def __init__(self, m):
|
2018-05-24 13:14:18 +00:00
|
|
|
super(iOSFlavor, self).__init__(m)
|
|
|
|
self.device_dirs = default.DeviceDirs(
|
2018-05-18 11:36:55 +00:00
|
|
|
bin_dir='[unused]',
|
|
|
|
dm_dir='dm',
|
|
|
|
perf_data_dir='perf',
|
|
|
|
resource_dir='resources',
|
|
|
|
images_dir='images',
|
2018-07-19 17:27:49 +00:00
|
|
|
lotties_dir='lotties',
|
2018-05-18 11:36:55 +00:00
|
|
|
skp_dir='skps',
|
|
|
|
svg_dir='svgs',
|
|
|
|
tmp_dir='tmp')
|
2017-02-02 23:55:03 +00:00
|
|
|
|
2017-02-03 18:31:05 +00:00
|
|
|
def install(self):
|
2017-04-25 15:38:38 +00:00
|
|
|
# Set up the device
|
|
|
|
self.m.run(self.m.step, 'setup_device', cmd=['ios.py'], infra_step=True)
|
|
|
|
|
|
|
|
# Install the app.
|
|
|
|
for app_name in ['dm', 'nanobench']:
|
2018-06-01 14:08:53 +00:00
|
|
|
app_package = self.host_dirs.bin_dir.join('%s.app' % app_name)
|
2018-01-03 21:12:57 +00:00
|
|
|
|
2018-01-04 16:29:15 +00:00
|
|
|
def uninstall_app(attempt):
|
|
|
|
# If app ID changes, upgrade will fail, so try uninstalling.
|
|
|
|
self.m.run(self.m.step,
|
|
|
|
'uninstall_' + app_name,
|
|
|
|
cmd=['ideviceinstaller', '-U', 'com.google.%s' % app_name],
|
|
|
|
infra_step=True,
|
|
|
|
# App may not be installed.
|
|
|
|
abort_on_failure=False, fail_build_on_failure=False)
|
|
|
|
|
|
|
|
num_attempts = 2
|
|
|
|
self.m.run.with_retry(self.m.step, 'install_' + app_name, num_attempts,
|
|
|
|
cmd=['ideviceinstaller', '-i', app_package],
|
|
|
|
between_attempts_fn=uninstall_app,
|
|
|
|
infra_step=True)
|
2017-04-25 15:38:38 +00:00
|
|
|
|
2017-02-02 23:55:03 +00:00
|
|
|
def step(self, name, cmd, env=None, **kwargs):
|
2017-04-25 15:38:38 +00:00
|
|
|
bundle_id = 'com.google.%s' % cmd[0]
|
|
|
|
self.m.run(self.m.step, name,
|
2017-05-19 20:29:05 +00:00
|
|
|
cmd=['idevice-app-runner', '-s', bundle_id, '--args'] +
|
2017-04-25 15:38:38 +00:00
|
|
|
map(str, cmd[1:]))
|
2017-02-02 23:55:03 +00:00
|
|
|
|
|
|
|
def _run_ios_script(self, script, first, *rest):
|
2018-05-18 11:36:55 +00:00
|
|
|
full = self.m.path['start_dir'].join(
|
|
|
|
'skia', 'platform_tools', 'ios', 'bin', 'ios_' + script)
|
2017-02-02 23:55:03 +00:00
|
|
|
self.m.run(self.m.step,
|
|
|
|
name = '%s %s' % (script, first),
|
|
|
|
cmd = [full, first] + list(rest),
|
2017-04-25 15:38:38 +00:00
|
|
|
infra_step=True)
|
2017-02-02 23:55:03 +00:00
|
|
|
|
|
|
|
def copy_file_to_device(self, host, device):
|
|
|
|
self._run_ios_script('push_file', host, device)
|
|
|
|
|
|
|
|
def copy_directory_contents_to_device(self, host, device):
|
|
|
|
self._run_ios_script('push_if_needed', host, device)
|
|
|
|
|
|
|
|
def copy_directory_contents_to_host(self, device, host):
|
|
|
|
self._run_ios_script('pull_if_needed', device, host)
|
|
|
|
|
2017-04-19 17:36:00 +00:00
|
|
|
def remove_file_on_device(self, path):
|
2017-02-02 23:55:03 +00:00
|
|
|
self._run_ios_script('rm', path)
|
|
|
|
|
|
|
|
def create_clean_device_dir(self, path):
|
|
|
|
self._run_ios_script('rm', path)
|
|
|
|
self._run_ios_script('mkdir', path)
|
|
|
|
|
2017-04-24 19:59:55 +00:00
|
|
|
def read_file_on_device(self, path, **kwargs):
|
2018-05-18 11:36:55 +00:00
|
|
|
full = self.m.path['start_dir'].join(
|
|
|
|
'skia', 'platform_tools', 'ios', 'bin', 'ios_cat_file')
|
2017-04-24 19:59:55 +00:00
|
|
|
rv = self.m.run(self.m.step,
|
2017-02-02 23:55:03 +00:00
|
|
|
name = 'cat_file %s' % path,
|
|
|
|
cmd = [full, path],
|
|
|
|
stdout=self.m.raw_io.output(),
|
2017-04-25 15:38:38 +00:00
|
|
|
infra_step=True,
|
2017-04-24 19:59:55 +00:00
|
|
|
**kwargs)
|
|
|
|
return rv.stdout.rstrip() if rv and rv.stdout else None
|