Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 """Install *_incremental.apk targets as well as their dependent files.""" | |
| 8 | |
| 9 import argparse | |
| 10 import glob | |
| 11 import logging | |
| 12 import os | |
| 13 import posixpath | |
| 14 import sys | |
| 15 | |
| 16 from pylib import constants | |
| 17 from pylib.device import device_errors | |
| 18 from pylib.device import device_utils | |
| 19 from pylib.utils import apk_helper | |
| 20 | |
| 21 | |
| 22 def main(): | |
| 23 logging.basicConfig(level=logging.INFO, | |
| 24 format='%(asctime)s %(message)s') | |
| 25 parser = argparse.ArgumentParser() | |
| 26 | |
| 27 parser.add_argument('apk_path', | |
| 28 help='The path to the APK to install.') | |
| 29 parser.add_argument('--split', | |
| 30 action='append', | |
| 31 dest='splits', | |
| 32 help='A glob matching the apk splits. ' | |
| 33 'Can be specified multiple times.') | |
| 34 parser.add_argument('--lib-dir', | |
| 35 help='Path to native libraries directory.') | |
| 36 parser.add_argument('-d', '--device', dest='device', | |
| 37 help='Target device for apk to install on.') | |
| 38 parser.add_argument('--uninstall', | |
| 39 action='store_true', | |
| 40 default=False, | |
| 41 help='Remove the app and all side-loaded files.') | |
| 42 | |
| 43 args = parser.parse_args() | |
| 44 | |
| 45 constants.SetBuildType('Debug') | |
| 46 | |
| 47 if args.device: | |
| 48 # Retries are annoying when commands fail for legitimate reasons. Might want | |
| 49 # to enable them if this is ever used on bots though. | |
| 50 devices = [device_utils.DeviceUtils(args.device, default_retries=0)] | |
| 51 if not devices: | |
| 52 raise device_errors.DeviceUnreachableError(args.device) | |
|
jbudorick
2015/08/27 00:37:37
As written, this block will never be executed.
agrieve
2015/08/27 03:19:59
Done.
| |
| 53 else: | |
| 54 devices = device_utils.DeviceUtils.HealthyDevices(default_retries=0) | |
| 55 if not devices: | |
| 56 raise device_errors.NoDevicesError() | |
| 57 elif len(devices) > 1: | |
| 58 raise Exception('More than one device available.\n' | |
| 59 'Use --device=SERIAL to select a device.') | |
| 60 device = devices[0] | |
| 61 | |
| 62 apk_package = apk_helper.ApkHelper(args.apk_path).GetPackageName() | |
| 63 device_incremental_dir = '/data/local/tmp/incremental-app-%s' % apk_package | |
| 64 | |
| 65 if args.uninstall: | |
| 66 logging.info('Uninstalling .apk') | |
| 67 device.Uninstall(apk_package) | |
| 68 logging.info('Removing side-loaded files') | |
| 69 device.RunShellCommand(['rm', '-rf', device_incremental_dir], | |
| 70 check_return=True) | |
| 71 return | |
| 72 | |
| 73 # Install .apk(s) if any of them have changed.apk | |
|
jbudorick
2015/08/27 00:37:37
"changed.apk" ?
agrieve
2015/08/27 03:19:59
Done.
| |
| 74 logging.info('Installing .apk') | |
| 75 if args.splits: | |
| 76 splits = [] | |
| 77 for split_glob in args.splits: | |
| 78 splits.extend((f for f in glob.glob(split_glob))) | |
| 79 device.InstallSplitApk(args.apk_path, splits, reinstall=True) | |
| 80 else: | |
| 81 device.Install(args.apk_path, reinstall=True) | |
| 82 | |
| 83 # Push .so files to the device (if they have changed). | |
| 84 if args.lib_dir: | |
| 85 logging.info('Pushing libraries') | |
| 86 device_lib_dir = posixpath.join(device_incremental_dir, 'lib') | |
| 87 device.PushChangedFiles([(args.lib_dir, device_lib_dir)], | |
| 88 delete_device_stale=True) | |
| 89 | |
| 90 | |
| 91 if __name__ == '__main__': | |
| 92 sys.exit(main()) | |
| 93 | |
| OLD | NEW |