Index: infra/bots/recipe_modules/flavor/android_flavor.py |
diff --git a/infra/bots/recipe_modules/skia/android_flavor.py b/infra/bots/recipe_modules/flavor/android_flavor.py |
similarity index 76% |
rename from infra/bots/recipe_modules/skia/android_flavor.py |
rename to infra/bots/recipe_modules/flavor/android_flavor.py |
index 442604e74e97419eb836af7152067fb04febc3f5..35e0b35b0b877c50262e62262419467ad1e7b27f 100644 |
--- a/infra/bots/recipe_modules/skia/android_flavor.py |
+++ b/infra/bots/recipe_modules/flavor/android_flavor.py |
@@ -6,7 +6,6 @@ |
# pylint: disable=W0201 |
-import android_devices |
import copy |
import default_flavor |
@@ -21,9 +20,9 @@ class _ADBWrapper(object): |
out on our bots. This wrapper ensures that we set a custom ADB path before |
attempting to use the module. |
""" |
- def __init__(self, adb_api, path_to_adb, serial_args, android_flavor): |
- self._adb = adb_api |
- self._adb.set_adb_path(path_to_adb) |
+ def __init__(self, m, path_to_adb, serial_args, android_flavor): |
+ self.m = m |
+ self.m.adb.set_adb_path(path_to_adb) |
self._has_root = False # This is set in install(). |
self._serial_args = serial_args |
self._wait_count = 0 |
@@ -35,8 +34,8 @@ class _ADBWrapper(object): |
cmd = [ |
self._android_flavor.android_bin.join('adb_wait_for_device') |
] + self._serial_args |
- self._android_flavor._skia_api.run( |
- self._android_flavor._skia_api.m.step, |
+ self.m.run( |
+ self.m.step, |
name='wait for device (%d)' % self._wait_count, |
cmd=cmd, |
env=self._android_flavor._default_env, |
@@ -45,8 +44,8 @@ class _ADBWrapper(object): |
cmd = [ |
self._android_flavor.android_bin.join('adb_wait_for_charge'), |
] + self._serial_args |
- self._android_flavor._skia_api.run( |
- self._android_flavor._skia_api.m.step, |
+ self.m.run( |
+ self.m.step, |
name='wait for charge (%d)' % self._wait_count, |
cmd=cmd, |
env=self._android_flavor._default_env, |
@@ -59,30 +58,30 @@ class _ADBWrapper(object): |
def __call__(self, *args, **kwargs): |
self.maybe_wait_for_device() |
- return self._android_flavor._skia_api.run(self._adb, *args, **kwargs) |
+ return self.m.run(self.m.adb, *args, **kwargs) |
class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
- def __init__(self, skia_api): |
- super(AndroidFlavorUtils, self).__init__(skia_api) |
- self.device = self._skia_api.builder_spec['device_cfg'] |
- self.android_bin = self._skia_api.skia_dir.join( |
+ def __init__(self, m): |
+ super(AndroidFlavorUtils, self).__init__(m) |
+ self.device = self.m.vars.builder_spec['device_cfg'] |
+ self.android_bin = self.m.vars.skia_dir.join( |
'platform_tools', 'android', 'bin') |
- self._android_sdk_root = self._skia_api.slave_dir.join( |
+ self._android_sdk_root = self.m.vars.slave_dir.join( |
'android_sdk', 'android-sdk') |
self.serial = None |
self.serial_args = [] |
try: |
- path_to_adb = self._skia_api.m.step( |
+ path_to_adb = self.m.step( |
'which adb', |
cmd=['which', 'adb'], |
- stdout=self._skia_api.m.raw_io.output(), |
+ stdout=self.m.raw_io.output(), |
infra_step=True).stdout.rstrip() |
- except self._skia_api.m.step.StepFailure: |
- path_to_adb = self._skia_api.m.path.join(self._android_sdk_root, |
+ except self.m.step.StepFailure: |
+ path_to_adb = self.m.path.join(self._android_sdk_root, |
'platform-tools', 'adb') |
self._adb = _ADBWrapper( |
- self._skia_api.m.adb, path_to_adb, self.serial_args, self) |
+ self.m, path_to_adb, self.serial_args, self) |
self._default_env = {'ANDROID_SDK_ROOT': self._android_sdk_root, |
'ANDROID_HOME': self._android_sdk_root, |
'SKIA_ANDROID_VERBOSE_SETUP': 1} |
@@ -95,30 +94,30 @@ class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
'--logcat', |
'-d', self.device, |
] + self.serial_args + [ |
- '-t', self._skia_api.configuration, |
+ '-t', self.m.vars.configuration, |
] |
env = dict(env or {}) |
env.update(self._default_env) |
- return self._skia_api.run(self._skia_api.m.step, name=name, cmd=args + cmd, |
+ return self.m.run(self.m.step, name=name, cmd=args + cmd, |
env=env, **kwargs) |
def compile(self, target): |
"""Build the given target.""" |
env = dict(self._default_env) |
- ccache = self._skia_api.ccache() |
+ ccache = self.m.run.ccache() |
if ccache: |
env['ANDROID_MAKE_CCACHE'] = ccache |
cmd = [self.android_bin.join('android_ninja'), target, '-d', self.device] |
- if 'Clang' in self._skia_api.builder_name: |
+ if 'Clang' in self.m.vars.builder_name: |
cmd.append('--clang') |
- if 'GCC' in self._skia_api.builder_name: |
+ if 'GCC' in self.m.vars.builder_name: |
cmd.append('--gcc') |
- if 'Vulkan' in self._skia_api.builder_name: |
+ if 'Vulkan' in self.m.vars.builder_name: |
cmd.append('--vulkan') |
- self._skia_api.run(self._skia_api.m.step, 'build %s' % target, cmd=cmd, |
- env=env, cwd=self._skia_api.m.path['checkout']) |
+ self.m.run(self.m.step, 'build %s' % target, cmd=cmd, |
+ env=env, cwd=self.m.path['checkout']) |
def device_path_join(self, *args): |
"""Like os.path.join(), but for paths on a connected Android device.""" |
@@ -128,17 +127,17 @@ class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
"""Like os.path.exists(), but for paths on a connected device.""" |
exists_str = 'FILE_EXISTS' |
return exists_str in self._adb( |
- name='exists %s' % self._skia_api.m.path.basename(path), |
+ name='exists %s' % self.m.path.basename(path), |
serial=self.serial, |
cmd=['shell', 'if', '[', '-e', path, '];', |
'then', 'echo', exists_str + ';', 'fi'], |
- stdout=self._skia_api.m.raw_io.output(), |
+ stdout=self.m.raw_io.output(), |
infra_step=True |
).stdout |
def _remove_device_dir(self, path): |
"""Remove the directory on the device.""" |
- self._adb(name='rmdir %s' % self._skia_api.m.path.basename(path), |
+ self._adb(name='rmdir %s' % self.m.path.basename(path), |
serial=self.serial, |
cmd=['shell', 'rm', '-r', path], |
infra_step=True) |
@@ -148,16 +147,16 @@ class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
def _create_device_dir(self, path): |
"""Create the directory on the device.""" |
- self._adb(name='mkdir %s' % self._skia_api.m.path.basename(path), |
+ self._adb(name='mkdir %s' % self.m.path.basename(path), |
serial=self.serial, |
cmd=['shell', 'mkdir', '-p', path], |
infra_step=True) |
def copy_directory_contents_to_device(self, host_dir, device_dir): |
"""Like shutil.copytree(), but for copying to a connected device.""" |
- self._skia_api.run( |
- self._skia_api.m.step, |
- name='push %s' % self._skia_api.m.path.basename(host_dir), |
+ self.m.run( |
+ self.m.step, |
+ name='push %s' % self.m.path.basename(host_dir), |
cmd=[ |
self.android_bin.join('adb_push_if_needed'), '--verbose', |
] + self.serial_args + [ |
@@ -168,9 +167,9 @@ class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
def copy_directory_contents_to_host(self, device_dir, host_dir): |
"""Like shutil.copytree(), but for copying from a connected device.""" |
- self._skia_api.run( |
- self._skia_api.m.step, |
- name='pull %s' % self._skia_api.m.path.basename(device_dir), |
+ self.m.run( |
+ self.m.step, |
+ name='pull %s' % self.m.path.basename(device_dir), |
cmd=[ |
self.android_bin.join('adb_pull_if_needed'), '--verbose', |
] + self.serial_args + [ |
@@ -181,7 +180,7 @@ class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
def copy_file_to_device(self, host_path, device_path): |
"""Like shutil.copyfile, but for copying to a connected device.""" |
- self._adb(name='push %s' % self._skia_api.m.path.basename(host_path), |
+ self._adb(name='push %s' % self.m.path.basename(host_path), |
serial=self.serial, |
cmd=['push', host_path, device_path], |
infra_step=True) |
@@ -194,7 +193,7 @@ class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
def has_root(self): |
"""Determine if we have root access on this device.""" |
# Special case: GalaxyS3 hangs on `adb root`. Don't bother. |
- if 'GalaxyS3' in self._skia_api.builder_name: |
+ if 'GalaxyS3' in self.m.vars.builder_name: |
return False |
# Determine if we have root access. |
@@ -203,16 +202,16 @@ class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
output = self._adb(name='adb root', |
serial=self.serial, |
cmd=['root'], |
- stdout=self._skia_api.m.raw_io.output(), |
+ stdout=self.m.raw_io.output(), |
infra_step=True).stdout.rstrip() |
if ('restarting adbd as root' in output or |
'adbd is already running as root' in output): |
has_root = True |
- except self._skia_api.m.step.StepFailure: # pragma: nocover |
+ except self.m.step.StepFailure: # pragma: nocover |
pass |
# Wait for the device to reconnect. |
- self._skia_api.run( |
- self._skia_api.m.step, |
+ self.m.run( |
+ self.m.step, |
name='wait', |
cmd=['sleep', '10'], |
infra_step=True) |
@@ -221,8 +220,24 @@ class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
def install(self): |
"""Run device-specific installation steps.""" |
+ device_scratch_dir = self._adb( |
+ name='get EXTERNAL_STORAGE dir', |
+ serial=self.serial, |
+ cmd=['shell', 'echo', '$EXTERNAL_STORAGE'], |
+ stdout=self.m.raw_io.output(), |
+ infra_step=True, |
+ ).stdout.rstrip() |
+ prefix = self.device_path_join(device_scratch_dir, 'skiabot', 'skia_') |
+ self.device_dirs = default_flavor.DeviceDirs( |
+ dm_dir=prefix + 'dm', |
+ perf_data_dir=prefix + 'perf', |
+ resource_dir=prefix + 'resources', |
+ images_dir=prefix + 'images', |
+ skp_dir=prefix + 'skp/skps', |
+ tmp_dir=prefix + 'tmp_dir') |
+ |
self._has_root = self.has_root() |
- self._skia_api.run(self._skia_api.m.step, |
+ self.m.run(self.m.step, |
name='kill skia', |
cmd=[ |
self.android_bin.join('android_kill_skia'), |
@@ -257,7 +272,7 @@ class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
def cleanup_steps(self): |
"""Run any device-specific cleanup steps.""" |
- if self._skia_api.do_test_steps or self._skia_api.do_perf_steps: |
+ if self.m.vars.do_test_steps or self.m.vars.do_perf_steps: |
self._adb(name='final battery stats', |
serial=self.serial, |
cmd=['shell', 'dumpsys', 'batteryproperties'], |
@@ -266,8 +281,8 @@ class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
serial=self.serial, |
cmd=['reboot'], |
infra_step=True) |
- self._skia_api.run( |
- self._skia_api.m.step, |
+ self.m.run( |
+ self.m.step, |
name='wait for reboot', |
cmd=['sleep', '10'], |
infra_step=True) |
@@ -281,36 +296,17 @@ class AndroidFlavorUtils(default_flavor.DefaultFlavorUtils): |
def read_file_on_device(self, path, *args, **kwargs): |
"""Read the given file.""" |
- return self._adb(name='read %s' % self._skia_api.m.path.basename(path), |
+ return self._adb(name='read %s' % self.m.path.basename(path), |
serial=self.serial, |
cmd=['shell', 'cat', path], |
- stdout=self._skia_api.m.raw_io.output(), |
+ stdout=self.m.raw_io.output(), |
infra_step=True).stdout.rstrip() |
def remove_file_on_device(self, path, *args, **kwargs): |
"""Delete the given file.""" |
- return self._adb(name='rm %s' % self._skia_api.m.path.basename(path), |
+ return self._adb(name='rm %s' % self.m.path.basename(path), |
serial=self.serial, |
cmd=['shell', 'rm', '-f', path], |
infra_step=True, |
*args, |
**kwargs) |
- |
- def get_device_dirs(self): |
- """ Set the directories which will be used by the build steps.""" |
- device_scratch_dir = self._adb( |
- name='get EXTERNAL_STORAGE dir', |
- serial=self.serial, |
- cmd=['shell', 'echo', '$EXTERNAL_STORAGE'], |
- stdout=self._skia_api.m.raw_io.output(), |
- infra_step=True, |
- ).stdout.rstrip() |
- prefix = self.device_path_join(device_scratch_dir, 'skiabot', 'skia_') |
- return default_flavor.DeviceDirs( |
- dm_dir=prefix + 'dm', |
- perf_data_dir=prefix + 'perf', |
- resource_dir=prefix + 'resources', |
- images_dir=prefix + 'images', |
- skp_dir=prefix + 'skp/skps', |
- tmp_dir=prefix + 'tmp_dir') |
- |