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