Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: infra/bots/recipe_modules/flavor/gn_android_flavor.py

Issue 2320153002: GN: Android perf/tests (Closed)
Patch Set: eric Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: infra/bots/recipe_modules/flavor/gn_android_flavor.py
diff --git a/infra/bots/recipe_modules/flavor/gn_android_flavor.py b/infra/bots/recipe_modules/flavor/gn_android_flavor.py
index 4cbaab38a6e10cfc6b1e1a89d863749a6db5d0e1..2142f10eabf62fa4922583c2a855d54b44177cd8 100644
--- a/infra/bots/recipe_modules/flavor/gn_android_flavor.py
+++ b/infra/bots/recipe_modules/flavor/gn_android_flavor.py
@@ -3,16 +3,37 @@
# found in the LICENSE file.
import default_flavor
+import subprocess
"""GN Android flavor utils, used for building Skia for Android with GN."""
class GNAndroidFlavorUtils(default_flavor.DefaultFlavorUtils):
+ def __init__(self, m):
+ super(GNAndroidFlavorUtils, self).__init__(m)
+ self._ever_ran_adb = False
+
+ prefix = '/data/local/tmp/'
+ self.device_dirs = default_flavor.DeviceDirs(
+ dm_dir = prefix + 'dm_out',
+ perf_data_dir = prefix + 'perf',
+ resource_dir = prefix + 'resources',
+ images_dir = prefix + 'images',
+ skp_dir = prefix + 'skps',
+ svg_dir = prefix + 'svgs',
+ tmp_dir = prefix + 'tmp')
+
def supported(self):
return 'GN_Android' == self.m.vars.builder_cfg.get('extra_config', '')
- def _run(self, title, cmd):
- path = self.m.vars.default_env['PATH']
- self.m.vars.default_env = {'PATH': path}
- self.m.run(self.m.step, title, cmd=cmd, cwd=self.m.vars.skia_dir, env={})
+ def _run(self, title, *cmd, **kwargs):
+ self.m.vars.default_env = {k: v for (k,v)
+ in self.m.vars.default_env.iteritems()
+ if k in ['PATH']}
+ return self.m.run(self.m.step, title, cmd=list(cmd),
+ cwd=self.m.vars.skia_dir, env={}, **kwargs)
+
+ def _adb(self, title, *cmd, **kwargs):
+ self._ever_ran_adb = True
+ return self._run(title, 'adb', *cmd, **kwargs)
def compile(self, unused_target, **kwargs):
compiler = self.m.vars.builder_cfg.get('compiler')
@@ -31,6 +52,80 @@ class GNAndroidFlavorUtils(default_flavor.DefaultFlavorUtils):
'target_cpu': quote(target_arch),
}.iteritems()))
- self._run('fetch-gn', [self.m.vars.skia_dir.join('bin', 'fetch-gn')])
- self._run('gn gen', ['gn', 'gen', self.out_dir, '--args=' + gn_args])
- self._run('ninja', ['ninja', '-C', self.out_dir])
+ self._run('fetch-gn', self.m.vars.skia_dir.join('bin', 'fetch-gn'))
+ self._run('gn gen', 'gn', 'gen', self.out_dir, '--args=' + gn_args)
+ self._run('ninja', 'ninja', '-C', self.out_dir)
+
+ def install(self):
+ self._adb('reboot', 'reboot')
+ self._adb('wait for device', 'wait-for-usb-device')
+ self._adb('TEMPORARY clear /data/local/tmp',
+ 'shell', 'rm', '-rf', '/data/local/tmp/*')
+ self._adb('mkdir /data/local/tmp/resources',
+ 'shell', 'mkdir', '-p', '/data/local/tmp/resources')
+
+ def cleanup_steps(self):
+ if self._ever_ran_adb:
+ self._adb('TEMPORARY clear /data/local/tmp',
+ 'shell', 'rm', '-rf', '/data/local/tmp/*')
+ self._adb('TEMPORARY reboot', 'reboot')
+ self._adb('kill adb server', 'kill-server')
+
+ def step(self, name, cmd, env=None, **kwargs):
+ app = self.m.vars.skia_out.join(self.m.vars.configuration, cmd[0])
+ self._adb('push %s' % cmd[0],
+ 'push', app, '/data/local/tmp')
+
+ sh = '%s.sh' % cmd[0]
+ self.m.run.writefile(self.m.vars.tmp_dir.join(sh),
+ 'set -x; /data/local/tmp/%s; echo $? >/data/local/tmp/rc' %
+ subprocess.list2cmdline(map(str, cmd)))
+ self._adb('push %s' % sh,
+ 'push', self.m.vars.tmp_dir.join(sh), '/data/local/tmp')
+
+ self._adb('clear log', 'logcat', '-c')
+ self._adb(cmd[0], 'shell', 'sh', '/data/local/tmp/' + sh)
+ self._adb('dump log ', 'logcat', '-d')
+
+ self.m.python.inline('check %s rc' % cmd[0], """
+ import subprocess
+ import sys
+ sys.exit(int(subprocess.check_output(['adb', 'shell', 'cat',
+ '/data/local/tmp/rc'])))
+ """)
+
+ def copy_file_to_device(self, host, device):
+ self._adb('push %s %s' % (host, device), 'push', host, device)
+
+ def copy_directory_contents_to_device(self, host, device):
+ # Copy the tree, avoiding hidden directories and resolving symlinks.
+ self.m.python.inline('push %s/* %s' % (host, device), """
+ import os
+ import subprocess
+ import sys
+ host = sys.argv[1]
+ device = sys.argv[2]
+ for d, _, fs in os.walk(host):
+ p = os.path.relpath(d, host)
+ if p != '.' and p.startswith('.'):
+ continue
+ for f in fs:
+ print os.path.join(p,f)
+ subprocess.check_call(['adb', 'push',
+ os.path.realpath(os.path.join(host, p, f)),
+ os.path.join(device, p, f)])
+ """, args=[host, device], cwd=self.m.vars.skia_dir)
+
+ def copy_directory_contents_to_host(self, device, host):
+ self._adb('pull %s %s' % (device, host), 'pull', device, host)
+
+ def read_file_on_device(self, path):
+ return self._adb('read %s' % path,
+ 'shell', 'cat', path, stdout=self.m.raw_io.output()).stdout
+
+ def remove_file_on_device(self, path):
+ self._adb('rm %s' % path, 'shell', 'rm', '-f', path)
+
+ def create_clean_device_dir(self, path):
+ self._adb('rm %s' % path, 'shell', 'rm', '-rf', path)
+ self._adb('mkdir %s' % path, 'shell', 'mkdir', '-p', path)

Powered by Google App Engine
This is Rietveld 408576698