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
8import default_flavor
9import gn_flavor
10
11# Infra step failures interact really annoyingly with swarming retries.
12kInfraStep = False
13
14class iOSFlavorUtils(gn_flavor.GNFlavorUtils):
15
16  def install(self):
17    self.device_dirs = default_flavor.DeviceDirs(
18        dm_dir='dm',
19        perf_data_dir='perf',
20        resource_dir='resources',
21        images_dir='images',
22        skp_dir='skps',
23        svg_dir='svgs',
24        tmp_dir='tmp')
25
26  def step(self, name, cmd, env=None, **kwargs):
27    app = self.m.vars.skia_out.join(self.m.vars.configuration, cmd[0])
28
29    self._py('package ' + name,
30             self.m.vars.skia_dir.join('gn', 'package_ios.py'),
31             args=[str(app)])
32    self._run(name,
33              ['ios-deploy', '-b', '%s.app' % app,
34               '-I', '--args', ' '.join(map(str, cmd[1:]))])
35
36  def _run_ios_script(self, script, first, *rest):
37    full = self.m.vars.skia_dir.join('platform_tools/ios/bin/ios_' + script)
38    self.m.run(self.m.step,
39               name = '%s %s' % (script, first),
40               cmd = [full, first] + list(rest),
41               infra_step=kInfraStep)
42
43  def copy_file_to_device(self, host, device):
44    self._run_ios_script('push_file', host, device)
45
46  def copy_directory_contents_to_device(self, host, device):
47    self._run_ios_script('push_if_needed', host, device)
48
49  def copy_directory_contents_to_host(self, device, host):
50    self._run_ios_script('pull_if_needed', device, host)
51
52  def remove_file_on_device(self, path):  # pragma: nocover
53    self._run_ios_script('rm', path)
54
55  def create_clean_device_dir(self, path):
56    self._run_ios_script('rm',    path)
57    self._run_ios_script('mkdir', path)
58
59  def read_file_on_device(self, path):  # pragma: nocover
60    full = self.m.vars.skia_dir.join('platform_tools/ios/bin/ios_cat_file')
61    rc = self.m.run(self.m.step,
62                    name = 'cat_file %s' % path,
63                    cmd = [full, path],
64                    stdout=self.m.raw_io.output(),
65                    infra_step=kInfraStep)
66    return rc.stdout.rstrip() if rc.stdout else rc.stdout
67