• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
9from . import default
10
11
12"""iOS flavor, used for running code on iOS."""
13
14
15class iOSFlavor(default.DefaultFlavor):
16  def __init__(self, m):
17    super(iOSFlavor, self).__init__(m)
18    self.device_dirs = default.DeviceDirs(
19        bin_dir='[unused]',
20        dm_dir='dm',
21        perf_data_dir='perf',
22        resource_dir='resources',
23        images_dir='images',
24        lotties_dir='lotties',
25        skp_dir='skps',
26        svg_dir='svgs',
27        mskp_dir='mskp',
28        tmp_dir='tmp')
29
30  def install(self):
31    # Set up the device
32    self.m.run(self.m.step, 'setup_device', cmd=['ios.py'], infra_step=True)
33
34    # Install the app.
35    for app_name in ['dm', 'nanobench']:
36      app_package = self.host_dirs.bin_dir.join('%s.app' % app_name)
37
38      def uninstall_app(attempt):
39        # If app ID changes, upgrade will fail, so try uninstalling.
40        self.m.run(self.m.step,
41                   'uninstall_' + app_name,
42                   cmd=['ideviceinstaller', '-U', 'com.google.%s' % app_name],
43                   infra_step=True,
44                   # App may not be installed.
45                   abort_on_failure=False, fail_build_on_failure=False)
46
47      num_attempts = 2
48      self.m.run.with_retry(self.m.step, 'install_' + app_name, num_attempts,
49                            cmd=['ideviceinstaller', '-i', app_package],
50                            between_attempts_fn=uninstall_app,
51                            infra_step=True)
52
53  def step(self, name, cmd, env=None, **kwargs):
54    bundle_id = 'com.google.%s' % cmd[0]
55    self.m.run(self.m.step, name,
56               cmd=['idevice-app-runner', '-s', bundle_id, '--args'] +
57                    map(str, cmd[1:]))
58
59  def _run_ios_script(self, script, first, *rest):
60    full = self.m.path['start_dir'].join(
61        'skia', 'platform_tools', 'ios', 'bin', 'ios_' + script)
62    self.m.run(self.m.step,
63               name = '%s %s' % (script, first),
64               cmd = [full, first] + list(rest),
65               infra_step=True)
66
67  def copy_file_to_device(self, host, device):
68    self._run_ios_script('push_file', host, device)
69
70  def copy_directory_contents_to_device(self, host, device):
71    self._run_ios_script('push_if_needed', host, device)
72
73  def copy_directory_contents_to_host(self, device, host):
74    self._run_ios_script('pull_if_needed', device, host)
75
76  def remove_file_on_device(self, path):
77    self._run_ios_script('rm', path)
78
79  def create_clean_device_dir(self, path):
80    self._run_ios_script('rm',    path)
81    self._run_ios_script('mkdir', path)
82
83  def read_file_on_device(self, path, **kwargs):
84    full = self.m.path['start_dir'].join(
85        'skia', 'platform_tools', 'ios', 'bin', 'ios_cat_file')
86    rv = self.m.run(self.m.step,
87                    name = 'cat_file %s' % path,
88                    cmd = [full, path],
89                    stdout=self.m.raw_io.output(),
90                    infra_step=True,
91                    **kwargs)
92    return rv.stdout.rstrip() if rv and rv.stdout else None
93