Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: build/android/adb_install_apk.py

Issue 1200543002: [Android] Add support for installing split apks with adb_install_apk. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/android/pylib/sdk/aapt.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Utility script to install APKs from the command line quickly.""" 7 """Utility script to install APKs from the command line quickly."""
8 8
9 import argparse 9 import argparse
10 import glob
10 import logging 11 import logging
11 import os 12 import os
12 import sys 13 import sys
13 14
14 from pylib import constants 15 from pylib import constants
15 from pylib.device import device_blacklist 16 from pylib.device import device_blacklist
16 from pylib.device import device_errors 17 from pylib.device import device_errors
17 from pylib.device import device_utils 18 from pylib.device import device_utils
19 from pylib.utils import apk_helper
18 from pylib.utils import run_tests_helper 20 from pylib.utils import run_tests_helper
19 21
20 22
21 def main(): 23 def main():
22 parser = argparse.ArgumentParser() 24 parser = argparse.ArgumentParser()
23 25
24 apk_group = parser.add_mutually_exclusive_group(required=True) 26 apk_group = parser.add_mutually_exclusive_group(required=True)
25 apk_group.add_argument('--apk', dest='apk_name', 27 apk_group.add_argument('--apk', dest='apk_name',
26 help='DEPRECATED The name of the apk containing the' 28 help='DEPRECATED The name of the apk containing the'
27 ' application (with the .apk extension).') 29 ' application (with the .apk extension).')
28 apk_group.add_argument('apk_path', nargs='?', 30 apk_group.add_argument('apk_path', nargs='?',
29 help='The path to the APK to install.') 31 help='The path to the APK to install.')
30 32
31 # TODO(jbudorick): Remove once no clients pass --apk_package 33 # TODO(jbudorick): Remove once no clients pass --apk_package
32 parser.add_argument('--apk_package', help='DEPRECATED unused') 34 parser.add_argument('--apk_package', help='DEPRECATED unused')
35 parser.add_argument('--split',
36 action='append',
37 dest='splits',
38 help='A glob matching the apk splits. '
39 'Can be specified multiple times.')
33 parser.add_argument('--keep_data', 40 parser.add_argument('--keep_data',
34 action='store_true', 41 action='store_true',
35 default=False, 42 default=False,
36 help='Keep the package data when installing ' 43 help='Keep the package data when installing '
37 'the application.') 44 'the application.')
38 parser.add_argument('--debug', action='store_const', const='Debug', 45 parser.add_argument('--debug', action='store_const', const='Debug',
39 dest='build_type', 46 dest='build_type',
40 default=os.environ.get('BUILDTYPE', 'Debug'), 47 default=os.environ.get('BUILDTYPE', 'Debug'),
41 help='If set, run test suites under out/Debug. ' 48 help='If set, run test suites under out/Debug. '
42 'Default is env var BUILDTYPE or Debug') 49 'Default is env var BUILDTYPE or Debug')
(...skipping 12 matching lines...) Expand all
55 constants.SetBuildType(args.build_type) 62 constants.SetBuildType(args.build_type)
56 63
57 apk = args.apk_path or args.apk_name 64 apk = args.apk_path or args.apk_name
58 if not apk.endswith('.apk'): 65 if not apk.endswith('.apk'):
59 apk += '.apk' 66 apk += '.apk'
60 if not os.path.exists(apk): 67 if not os.path.exists(apk):
61 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) 68 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk)
62 if not os.path.exists(apk): 69 if not os.path.exists(apk):
63 parser.error('%s not found.' % apk) 70 parser.error('%s not found.' % apk)
64 71
72 if args.splits:
73 splits = []
74 base_apk_package = apk_helper.ApkHelper(apk).GetPackageName()
75 for split_pattern in args.splits:
76 if not split_pattern.endswith('.apk'):
jbudorick 2015/07/01 20:55:11 What's with this? Why are we modifying a user's gl
mikecase (-- gone --) 2015/07/01 22:14:57 Removed adding .apk to the end of the glob and ins
jbudorick 2015/07/01 22:18:56 This is going to sound somewhat get-off-my-lawn-is
77 split_pattern += '.apk'
78 apks = glob.glob(split_pattern)
79 if not apks:
80 apks = glob.glob(os.path.join(constants.GetOutDirectory(),
81 'apks', split_pattern))
jbudorick 2015/07/01 20:55:11 nit: indentation is off. This implies that 'apks'
mikecase (-- gone --) 2015/07/01 22:14:57 Fixed.
82 if not apks:
83 logging.warning('No apks matched for %s.' % split_pattern)
84 for f in apks:
85 helper = apk_helper.ApkHelper(f)
86 if (helper.GetPackageName() == base_apk_package
87 and helper.GetSplitName() is not None):
jbudorick 2015/07/01 20:55:11 nit: and helper.GetSplitName() ?
mikecase (-- gone --) 2015/07/01 22:14:57 Done
88 splits.append(f)
89
65 devices = device_utils.DeviceUtils.HealthyDevices() 90 devices = device_utils.DeviceUtils.HealthyDevices()
66 91
67 if args.device: 92 if args.device:
68 devices = [d for d in devices if d == args.device] 93 devices = [d for d in devices if d == args.device]
69 if not devices: 94 if not devices:
70 raise device_errors.DeviceUnreachableError(args.device) 95 raise device_errors.DeviceUnreachableError(args.device)
71 elif not devices: 96 elif not devices:
72 raise device_errors.NoDevicesError() 97 raise device_errors.NoDevicesError()
73 98
74 def blacklisting_install(device): 99 def blacklisting_install(device):
75 try: 100 try:
76 device.Install(apk, reinstall=args.keep_data) 101 if args.splits:
102 device.InstallSplitApk(apk, splits, reinstall=args.keep_data)
103 else:
104 device.Install(apk, reinstall=args.keep_data)
77 except device_errors.CommandFailedError: 105 except device_errors.CommandFailedError:
78 logging.exception('Failed to install %s', args.apk) 106 logging.exception('Failed to install %s', args.apk)
79 device_blacklist.ExtendBlacklist([str(device)]) 107 device_blacklist.ExtendBlacklist([str(device)])
80 logging.warning('Blacklisting %s', str(device)) 108 logging.warning('Blacklisting %s', str(device))
81 except device_errors.CommandTimeoutError: 109 except device_errors.CommandTimeoutError:
82 logging.exception('Timed out while installing %s', args.apk) 110 logging.exception('Timed out while installing %s', args.apk)
83 device_blacklist.ExtendBlacklist([str(device)]) 111 device_blacklist.ExtendBlacklist([str(device)])
84 logging.warning('Blacklisting %s', str(device)) 112 logging.warning('Blacklisting %s', str(device))
85 113
86 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) 114 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install)
87 115
88 116
89 if __name__ == '__main__': 117 if __name__ == '__main__':
90 sys.exit(main()) 118 sys.exit(main())
91 119
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/sdk/aapt.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698