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