Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # 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
| |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """This module wraps Android's split-select tool.""" | |
| 6 # pylint: disable=unused-argument | |
| 7 | |
| 8 import os | |
| 9 | |
| 10 from pylib import cmd_helper | |
| 11 from pylib import constants | |
| 12 from pylib.device import decorators | |
| 13 from pylib.device import device_errors | |
| 14 from pylib.utils import timeout_retry | |
| 15 | |
| 16 _SPLIT_SELECT_PATH = os.path.join(constants.ANDROID_SDK_TOOLS, 'split-select') | |
| 17 _DEFAULT_TIMEOUT = 30 | |
| 18 _DEFAULT_RETRIES = 2 | |
| 19 | |
| 20 @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
| |
| 21 def _RunSplitSelectCmd(args, timeout=None, retries=None, | |
| 22 check_error=True): | |
| 23 """Runs a split-select command. | |
| 24 | |
| 25 Args: | |
| 26 args: A list of arguments for split-select. | |
| 27 timeout: Timeout in seconds. | |
| 28 retries: Number of retries. | |
| 29 check_error: Check that the command doesn't return an error message. | |
| 30 | |
| 31 Returns: | |
| 32 The output of the command. | |
| 33 """ | |
| 34 cmd = [_SPLIT_SELECT_PATH] + args | |
| 35 status, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( | |
| 36 cmd, timeout_retry.CurrentTimeoutThread().GetRemainingTime()) | |
| 37 if status != 0: | |
| 38 raise Exception('Failed running command %s' % str(cmd)) | |
| 39 if check_error and output.startswith('error:'): | |
| 40 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
| |
| 41 return output | |
| 42 | |
| 43 def _SplitConfig(device): | |
| 44 """Returns a config specifying which APK splits are required by the device. | |
| 45 | |
| 46 Args: | |
| 47 device: A DeviceUtils object. | |
| 48 """ | |
| 49 return ('%s-r%s-%s:%s' % | |
| 50 (device.langauge_setting, | |
| 51 device.country_setting, | |
| 52 device.screen_density, | |
| 53 device.product_cpu_abi)) | |
| 54 | |
| 55 def SelectSplits(device, base_apk, split_apks, | |
| 56 timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): | |
| 57 """Determines which APK splits the device requires. | |
| 58 | |
| 59 Args: | |
| 60 device: A DeviceUtils object. | |
| 61 base_apk: The path of the base APK. | |
| 62 split_apks: A list of paths of APK splits. | |
| 63 timeout: Timeout in seconds. | |
| 64 retries: Number of retries. | |
| 65 | |
| 66 Returns: | |
| 67 The list of APK splits that the device requires. | |
| 68 """ | |
| 69 config = _SplitConfig(device) | |
| 70 args = ['--target', config, '--base', base_apk] | |
| 71 for split in split_apks: | |
| 72 args.extend(['--split', split]) | |
| 73 return _RunSplitSelectCmd(args, timeout=timeout, retries=retries).splitlines() | |
| OLD | NEW |