Chromium Code Reviews| Index: build/android/pylib/device/split_select_wrapper.py |
| diff --git a/build/android/pylib/device/split_select_wrapper.py b/build/android/pylib/device/split_select_wrapper.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..841dcb183dec3e8e7b14f70bb917c09dc4d005cb |
| --- /dev/null |
| +++ b/build/android/pylib/device/split_select_wrapper.py |
| @@ -0,0 +1,73 @@ |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
|
jbudorick
2015/06/19 13:20:14
I don't think this should be in build/android/pyli
|
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""This module wraps Android's split-select tool.""" |
| +# pylint: disable=unused-argument |
| + |
| +import os |
| + |
| +from pylib import cmd_helper |
| +from pylib import constants |
| +from pylib.device import decorators |
| +from pylib.device import device_errors |
| +from pylib.utils import timeout_retry |
| + |
| +_SPLIT_SELECT_PATH = os.path.join(constants.ANDROID_SDK_TOOLS, 'split-select') |
| +_DEFAULT_TIMEOUT = 30 |
| +_DEFAULT_RETRIES = 2 |
| + |
| +@decorators.WithTimeoutAndRetries |
|
jbudorick
2015/06/19 13:20:13
Why are we decorating this? It's private and there
mikecase (-- gone --)
2015/06/19 17:17:52
Didn't know this decorator was only for code run o
jbudorick
2015/06/19 17:32:13
It isn't, but it's usually for things that have a
|
| +def _RunSplitSelectCmd(args, timeout=None, retries=None, |
| + check_error=True): |
| + """Runs a split-select command. |
| + |
| + Args: |
| + args: A list of arguments for split-select. |
| + timeout: Timeout in seconds. |
| + retries: Number of retries. |
| + check_error: Check that the command doesn't return an error message. |
| + |
| + Returns: |
| + The output of the command. |
| + """ |
| + cmd = [_SPLIT_SELECT_PATH] + args |
| + status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( |
| + cmd, timeout_retry.CurrentTimeoutThread().GetRemainingTime()) |
| + if status != 0: |
| + raise Exception('Failed running command %s' % str(cmd)) |
| + if check_error and output.startswith('error:'): |
| + raise Exception('Failed command %s with output %s' % (str(cmd), output)) |
|
perezju
2015/06/19 11:15:19
so split-select might return zero-exit code but wi
mikecase (-- gone --)
2015/06/19 17:17:52
Hmm. Good catch, I was kinda copying what the adb
|
| + return output |
| + |
| +def _SplitConfig(device): |
| + """Returns a config specifying which APK splits are required by the device. |
| + |
| + Args: |
| + device: A DeviceUtils object. |
| + """ |
| + return ('%s-r%s-%s:%s' % |
| + (device.langauge_setting, |
| + device.country_setting, |
| + device.screen_density, |
| + device.product_cpu_abi)) |
| + |
| +def SelectSplits(device, base_apk, split_apks, |
| + timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): |
| + """Determines which APK splits the device requires. |
| + |
| + Args: |
| + device: A DeviceUtils object. |
| + base_apk: The path of the base APK. |
| + split_apks: A list of paths of APK splits. |
| + timeout: Timeout in seconds. |
| + retries: Number of retries. |
| + |
| + Returns: |
| + The list of APK splits that the device requires. |
| + """ |
| + config = _SplitConfig(device) |
| + args = ['--target', config, '--base', base_apk] |
| + for split in split_apks: |
| + args.extend(['--split', split]) |
| + return _RunSplitSelectCmd(args, timeout=timeout, retries=retries).splitlines() |