OLD | NEW |
| (Empty) |
1 # Copyright 2015 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 import copy | |
7 import default_flavor | |
8 | |
9 | |
10 """iOS flavor utils, used for building for and running tests on iOS.""" | |
11 | |
12 | |
13 class iOSFlavorUtils(default_flavor.DefaultFlavorUtils): | |
14 def __init__(self, skia_api): | |
15 super(iOSFlavorUtils, self).__init__(skia_api) | |
16 self.default_env = {} | |
17 self.default_env['XCODEBUILD'] = ( | |
18 self._skia_api.slave_dir.join('xcodebuild')) | |
19 self.ios_bin = self._skia_api.skia_dir.join( | |
20 'platform_tools', 'ios', 'bin') | |
21 | |
22 def step(self, name, cmd, **kwargs): | |
23 args = [self.ios_bin.join('ios_run_skia')] | |
24 env = {} | |
25 env.update(kwargs.pop('env', {})) | |
26 env.update(self.default_env) | |
27 # Convert 'dm' and 'nanobench' from positional arguments | |
28 # to flags, which is what iOSShell expects to select which | |
29 # one is being run. | |
30 cmd = ["--" + c if c in ['dm', 'nanobench'] else c | |
31 for c in cmd] | |
32 return self._skia_api.run(self._skia_api.m.step, name=name, cmd=args + cmd, | |
33 env=env, | |
34 **kwargs) | |
35 | |
36 def compile(self, target): | |
37 """Build the given target.""" | |
38 cmd = [self.ios_bin.join('ios_ninja')] | |
39 self._skia_api.run(self._skia_api.m.step, 'build iOSShell', cmd=cmd, | |
40 cwd=self._skia_api.m.path['checkout']) | |
41 | |
42 def device_path_join(self, *args): | |
43 """Like os.path.join(), but for paths on a connected iOS device.""" | |
44 return '/'.join(args) | |
45 | |
46 def device_path_exists(self, path): | |
47 """Like os.path.exists(), but for paths on a connected device.""" | |
48 return self._skia_api.run( | |
49 self._skia_api.m.step, | |
50 'exists %s' % path, | |
51 cmd=[self.ios_bin.join('ios_path_exists'), path], | |
52 env=self.default_env, | |
53 infra_step=True, | |
54 ) # pragma: no cover | |
55 | |
56 def _remove_device_dir(self, path): | |
57 """Remove the directory on the device.""" | |
58 return self._skia_api.run( | |
59 self._skia_api.m.step, | |
60 'rmdir %s' % path, | |
61 cmd=[self.ios_bin.join('ios_rm'), path], | |
62 env=self.default_env, | |
63 infra_step=True, | |
64 ) | |
65 | |
66 def _create_device_dir(self, path): | |
67 """Create the directory on the device.""" | |
68 return self._skia_api.run( | |
69 self._skia_api.m.step, | |
70 'mkdir %s' % path, | |
71 cmd=[self.ios_bin.join('ios_mkdir'), path], | |
72 env=self.default_env, | |
73 infra_step=True, | |
74 ) | |
75 | |
76 def copy_directory_contents_to_device(self, host_dir, device_dir): | |
77 """Like shutil.copytree(), but for copying to a connected device.""" | |
78 return self._skia_api.run( | |
79 self._skia_api.m.step, | |
80 name='push %s to %s' % (self._skia_api.m.path.basename(host_dir), | |
81 self._skia_api.m.path.basename(device_dir)), | |
82 cmd=[self.ios_bin.join('ios_push_if_needed'), | |
83 host_dir, device_dir], | |
84 env=self.default_env, | |
85 infra_step=True, | |
86 ) | |
87 | |
88 def copy_directory_contents_to_host(self, device_dir, host_dir): | |
89 """Like shutil.copytree(), but for copying from a connected device.""" | |
90 self._skia_api.run( | |
91 self._skia_api.m.step, | |
92 name='pull %s' % self._skia_api.m.path.basename(device_dir), | |
93 cmd=[self.ios_bin.join('ios_pull_if_needed'), | |
94 device_dir, host_dir], | |
95 env=self.default_env, | |
96 infra_step=True, | |
97 ) | |
98 | |
99 def copy_file_to_device(self, host_path, device_path): | |
100 """Like shutil.copyfile, but for copying to a connected device.""" | |
101 self._skia_api.run( | |
102 self._skia_api.m.step, | |
103 name='push %s' % host_path, | |
104 cmd=[self.ios_bin.join('ios_push_file'), host_path, device_path], | |
105 env=self.default_env, | |
106 infra_step=True, | |
107 ) # pragma: no cover | |
108 | |
109 def copy_extra_build_products(self, swarming_out_dir): | |
110 xcode_dir = self._skia_api.m.path.join( | |
111 'xcodebuild', '%s-iphoneos' % self._skia_api.configuration) | |
112 self._skia_api.copy_build_products( | |
113 self._skia_api.skia_dir.join(xcode_dir), | |
114 swarming_out_dir.join(xcode_dir)) | |
115 | |
116 def create_clean_device_dir(self, path): | |
117 """Like shutil.rmtree() + os.makedirs(), but on a connected device.""" | |
118 self._remove_device_dir(path) | |
119 self._create_device_dir(path) | |
120 | |
121 def install(self): | |
122 """Run device-specific installation steps.""" | |
123 self._skia_api.run( | |
124 self._skia_api.m.step, | |
125 name='install iOSShell', | |
126 cmd=[self.ios_bin.join('ios_install')], | |
127 env=self.default_env, | |
128 infra_step=True) | |
129 | |
130 def cleanup_steps(self): | |
131 """Run any device-specific cleanup steps.""" | |
132 if self._skia_api.do_test_steps or self._skia_api.do_perf_steps: | |
133 self._skia_api.run( | |
134 self._skia_api.m.step, | |
135 name='reboot', | |
136 cmd=[self.ios_bin.join('ios_restart')], | |
137 env=self.default_env, | |
138 infra_step=True) | |
139 self._skia_api.run( | |
140 self._skia_api.m.step, | |
141 name='wait for reboot', | |
142 cmd=['sleep', '20'], | |
143 env=self.default_env, | |
144 infra_step=True) | |
145 | |
146 def read_file_on_device(self, path): | |
147 """Read the given file.""" | |
148 ret = self._skia_api.run( | |
149 self._skia_api.m.step, | |
150 name='read %s' % self._skia_api.m.path.basename(path), | |
151 cmd=[self.ios_bin.join('ios_cat_file'), path], | |
152 env=self.default_env, | |
153 stdout=self._skia_api.m.raw_io.output(), | |
154 infra_step=True) | |
155 return ret.stdout.rstrip() if ret.stdout else ret.stdout | |
156 | |
157 def remove_file_on_device(self, path): | |
158 """Remove the file on the device.""" | |
159 return self._skia_api.run( | |
160 self._skia_api.m.step, | |
161 'rm %s' % path, | |
162 cmd=[self.ios_bin.join('ios_rm'), path], | |
163 env=self.default_env, | |
164 infra_step=True, | |
165 ) | |
166 | |
167 def get_device_dirs(self): | |
168 """ Set the directories which will be used by the build steps.""" | |
169 prefix = self.device_path_join('skiabot', 'skia_') | |
170 return default_flavor.DeviceDirs( | |
171 dm_dir=prefix + 'dm', | |
172 perf_data_dir=prefix + 'perf', | |
173 resource_dir=prefix + 'resources', | |
174 images_dir=prefix + 'images', | |
175 skp_dir=prefix + 'skp/skps', | |
176 tmp_dir=prefix + 'tmp_dir') | |
OLD | NEW |