Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ios.py
Go to the documentation of this file.
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
6from . import default
7
8
9"""iOS flavor, used for running code on iOS."""
10
11
13 def __init__(self, m, app_name):
14 super(iOSFlavor, self).__init__(m, app_name)
15 self.device_dirsdevice_dirs = default.DeviceDirs(
16 bin_dir='[unused]',
17 dm_dir='dm',
18 perf_data_dir='perf',
19 resource_dir='resources',
20 fonts_dir = 'NOT_SUPPORTED',
21 images_dir='images',
22 lotties_dir='lotties',
23 skp_dir='skps',
24 svg_dir='svgs',
25 mskp_dir='mskp',
26 tmp_dir='tmp',
27 texttraces_dir='')
28
29 @property
30 def env(self):
31 return {
32 'IOS_BUNDLE_ID': 'com.google.%s' % self.app_nameapp_name,
33 'IOS_MOUNT_POINT': self.m.vars.workdir.join('mnt_iosdevice'),
34 }
35
36 def context(self):
37 return self.m.context(env=self.env)
38
39 def _run(self, title, *cmd, **kwargs):
40 def sleep(attempt):
41 self.m.step(
42 'sleep before attempt %d' % attempt,
43 cmd=['sleep', '2']) # pragma: nocover
44
45 return self.m.run.with_retry(self.m.step, title, 3, cmd=list(cmd),
46 between_attempts_fn=sleep, **kwargs)
47
48 def install(self):
49 with self.context():
50 self._install()
51
52 def _install(self):
53 # We assume a single device is connected.
54
55 # Pair the device.
56 try:
57 self.m.run(self.m.step, 'check if device is paired',
58 cmd=['idevicepair', 'validate'],
59 infra_step=True, abort_on_failure=True,
60 fail_build_on_failure=False)
61 except self.m.step.StepFailure: # pragma: nocover
62 self._run_run('pair device', 'idevicepair', 'pair') # pragma: nocover
63
64 # Mount developer image.
65 image_info = self._run_run('list mounted image',
66 'ideviceimagemounter', '--list',
67 stdout=self.m.raw_io.output())
68 image_info_out = (
69 image_info.stdout.decode('utf-8').strip() if image_info.stdout else '')
70
71 if 'ImageSignature' not in image_info_out:
72 image_pkgs = self.m.file.glob_paths('locate ios-dev-image package',
73 self.m.path['start_dir'],
74 'ios-dev-image*',
75 test_data=['ios-dev-image-13.2'])
76 if len(image_pkgs) != 1:
77 raise Exception('glob for ios-dev-image* returned %s'
78 % image_pkgs) # pragma: nocover
79
80 image_pkg = image_pkgs[0]
81 contents = self.m.file.listdir(
82 'locate image and signature', image_pkg,
83 test_data=['DeveloperDiskImage.dmg',
84 'DeveloperDiskImage.dmg.signature'])
85 image = None
86 sig = None
87 for f in contents:
88 if str(f).endswith('.dmg'):
89 image = f
90 if str(f).endswith('.dmg.signature'):
91 sig = f
92 if not image or not sig:
93 raise Exception('%s does not contain *.dmg and *.dmg.signature' %
94 image_pkg) # pragma: nocover
95
96 self._run_run('mount developer image', 'ideviceimagemounter', image, sig)
97
98 # Install app (necessary before copying any resources to the device).
99 if self.app_nameapp_name:
100 app_package = self.host_dirs.bin_dir.join('%s.app' % self.app_nameapp_name)
101
102 def uninstall_app(attempt):
103 # If app ID changes, upgrade will fail, so try uninstalling.
104 self.m.run(self.m.step,
105 'uninstall %s' % self.app_nameapp_name,
106 cmd=['ideviceinstaller', '-U',
107 'com.google.%s' % self.app_nameapp_name],
108 infra_step=True,
109 # App may not be installed.
110 abort_on_failure=False, fail_build_on_failure=False)
111
112 num_attempts = 2
113 self.m.run.with_retry(self.m.step, 'install %s' % self.app_nameapp_name,
114 num_attempts,
115 cmd=['ideviceinstaller', '-i', app_package],
116 between_attempts_fn=uninstall_app,
117 infra_step=True)
118
119 def step(self, name, cmd, **kwargs):
120 app_name = cmd[0]
121 bundle_id = 'com.google.%s' % app_name
122 args = [bundle_id] + [str(ele) for ele in cmd[1:]]
123 success = False
124 with self.context():
125 try:
126 self.m.run(self.m.step, name, cmd=['idevicedebug', 'run'] + args)
127 success = True
128 finally:
129 if not success:
130 self.m.run(
131 self.m.step, '%s with full debug output' % name,
132 cmd=['python3', self.module.resource('ios_debug_cmd.py')] + args)
133
134 def _run_ios_script(self, script, first, *rest):
135 with self.context():
136 full = self.m.path['start_dir'].join(
137 'skia', 'platform_tools', 'ios', 'bin', 'ios_' + script)
138 self.m.run(self.m.step,
139 name = '%s %s' % (script, first),
140 cmd = [full, first] + list(rest),
141 infra_step=True)
142
143 def copy_file_to_device(self, host, device):
144 self._run_ios_script('push_file', host, device)
145
146 def copy_directory_contents_to_device(self, host, device):
147 self._run_ios_script('push_if_needed', host, device)
148
149 def copy_directory_contents_to_host(self, device, host):
150 self._run_ios_script('pull_if_needed', device, host)
151
152 def remove_file_on_device(self, path):
153 self._run_ios_script('rm', path)
154
155 def create_clean_device_dir(self, path):
156 self._run_ios_script('rm', path)
157 self._run_ios_script('mkdir', path)
158
159 def read_file_on_device(self, path, **kwargs):
160 with self.context():
161 full = self.m.path['start_dir'].join(
162 'skia', 'platform_tools', 'ios', 'bin', 'ios_cat_file')
163 rv = self.m.run(self.m.step,
164 name = 'cat_file %s' % path,
165 cmd = [full, path],
166 stdout=self.m.raw_io.output(),
167 infra_step=True,
168 **kwargs)
169 return rv.stdout.decode('utf-8').rstrip() if rv and rv.stdout else None
_run(self, title, cmd, infra_step=False, **kwargs)
Definition default.py:116
create_clean_device_dir(self, path)
Definition ios.py:155
_run(self, title, *cmd, **kwargs)
Definition ios.py:39
_run_ios_script(self, script, first, *rest)
Definition ios.py:134
read_file_on_device(self, path, **kwargs)
Definition ios.py:159
copy_file_to_device(self, host, device)
Definition ios.py:143
copy_directory_contents_to_device(self, host, device)
Definition ios.py:146
step(self, name, cmd, **kwargs)
Definition ios.py:119
copy_directory_contents_to_host(self, device, host)
Definition ios.py:149
__init__(self, m, app_name)
Definition ios.py:13
Definition __init__.py:1
Definition run.py:1