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 device = device_utils.DeviceUtils(args.device, default_retries=0) |
| 51 else: |
| 52 devices = device_utils.DeviceUtils.HealthyDevices(default_retries=0) |
| 53 if not devices: |
| 54 raise device_errors.NoDevicesError() |
| 55 elif len(devices) > 1: |
| 56 raise Exception('More than one device available.\n' |
| 57 'Use --device=SERIAL to select a device.') |
| 58 device = devices[0] |
| 59 |
| 60 apk_package = apk_helper.ApkHelper(args.apk_path).GetPackageName() |
| 61 device_incremental_dir = '/data/local/tmp/incremental-app-%s' % apk_package |
| 62 |
| 63 if args.uninstall: |
| 64 logging.info('Uninstalling .apk') |
| 65 device.Uninstall(apk_package) |
| 66 logging.info('Removing side-loaded files') |
| 67 device.RunShellCommand(['rm', '-rf', device_incremental_dir], |
| 68 check_return=True) |
| 69 return |
| 70 |
| 71 # Install .apk(s) if any of them have changed. |
| 72 logging.info('Installing .apk') |
| 73 if args.splits: |
| 74 splits = [] |
| 75 for split_glob in args.splits: |
| 76 splits.extend((f for f in glob.glob(split_glob))) |
| 77 device.InstallSplitApk(args.apk_path, splits, reinstall=True) |
| 78 else: |
| 79 device.Install(args.apk_path, reinstall=True) |
| 80 |
| 81 # Push .so files to the device (if they have changed). |
| 82 if args.lib_dir: |
| 83 logging.info('Pushing libraries') |
| 84 device_lib_dir = posixpath.join(device_incremental_dir, 'lib') |
| 85 device.PushChangedFiles([(args.lib_dir, device_lib_dir)], |
| 86 delete_device_stale=True) |
| 87 |
| 88 |
| 89 if __name__ == '__main__': |
| 90 sys.exit(main()) |
| 91 |
OLD | NEW |