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

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: Addressed jbudorick's comment. Users now pass in glob to match splits. Created 5 years, 6 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
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
21 def main(): 22 def main():
22 parser = argparse.ArgumentParser() 23 parser = argparse.ArgumentParser()
23 24
24 apk_group = parser.add_mutually_exclusive_group(required=True) 25 apk_group = parser.add_mutually_exclusive_group(required=True)
25 apk_group.add_argument('--apk', dest='apk_name', 26 apk_group.add_argument('--apk', dest='apk_name',
26 help='DEPRECATED The name of the apk containing the' 27 help='DEPRECATED The name of the apk containing the'
27 ' application (with the .apk extension).') 28 ' application (with the .apk extension).')
28 apk_group.add_argument('apk_path', nargs='?', 29 apk_group.add_argument('apk_path', nargs='?',
29 help='The path to the APK to install.') 30 help='The path to the APK to install.')
30 31
31 # TODO(jbudorick): Remove once no clients pass --apk_package 32 # TODO(jbudorick): Remove once no clients pass --apk_package
32 parser.add_argument('--apk_package', help='DEPRECATED unused') 33 parser.add_argument('--apk_package', help='DEPRECATED unused')
34 parser.add_argument('--splits',
35 nargs='*',
jbudorick 2015/06/29 15:49:01 I'm not sure how well this combines with the apk_p
mikecase (-- gone --) 2015/06/29 20:06:21 Changed this argument back to use action='append'
36 help='A list of globs for the apk splits.')
33 parser.add_argument('--keep_data', 37 parser.add_argument('--keep_data',
34 action='store_true', 38 action='store_true',
35 default=False, 39 default=False,
36 help='Keep the package data when installing ' 40 help='Keep the package data when installing '
37 'the application.') 41 'the application.')
38 parser.add_argument('--debug', action='store_const', const='Debug', 42 parser.add_argument('--debug', action='store_const', const='Debug',
39 dest='build_type', 43 dest='build_type',
40 default=os.environ.get('BUILDTYPE', 'Debug'), 44 default=os.environ.get('BUILDTYPE', 'Debug'),
41 help='If set, run test suites under out/Debug. ' 45 help='If set, run test suites under out/Debug. '
42 'Default is env var BUILDTYPE or Debug') 46 'Default is env var BUILDTYPE or Debug')
(...skipping 12 matching lines...) Expand all
55 constants.SetBuildType(args.build_type) 59 constants.SetBuildType(args.build_type)
56 60
57 apk = args.apk_path or args.apk_name 61 apk = args.apk_path or args.apk_name
58 if not apk.endswith('.apk'): 62 if not apk.endswith('.apk'):
59 apk += '.apk' 63 apk += '.apk'
60 if not os.path.exists(apk): 64 if not os.path.exists(apk):
61 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk) 65 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk)
62 if not os.path.exists(apk): 66 if not os.path.exists(apk):
63 parser.error('%s not found.' % apk) 67 parser.error('%s not found.' % apk)
64 68
69 if args.splits:
jbudorick 2015/06/26 23:26:59 Is there any way we can detect which apk of a list
agrieve 2015/06/26 23:53:03 It'll be the only one without a split="foo" attrib
mikecase (-- gone --) 2015/06/27 00:21:22 If you're going to pass in a glob like Chrome*.apk
jbudorick 2015/06/29 15:49:01 Hmm, right.
70 splits = []
71 base_apk_package = apk_helper.ApkHelper(apk).GetPackageName()
72 for split_pattern in args.splits:
73 if not split_pattern.endswith('.apk'):
74 split_pattern += '.apk'
75 apks = glob.glob(split_pattern)
76 if not apks:
77 apks = glob.glob(os.path.join(constants.GetOutDirectory(),
78 'apks', split_pattern))
79 if not apks:
80 logging.warning('No apks matched for %s.' % split_pattern)
81 for f in apks:
82 helper = apk_helper.ApkHelper(f)
83 if (helper.GetPackageName() == base_apk_package
84 and helper.GetSplitName() is not None):
85 splits.append(f)
86
65 devices = device_utils.DeviceUtils.HealthyDevices() 87 devices = device_utils.DeviceUtils.HealthyDevices()
66 88
67 if args.device: 89 if args.device:
68 devices = [d for d in devices if d == args.device] 90 devices = [d for d in devices if d == args.device]
69 if not devices: 91 if not devices:
70 raise device_errors.DeviceUnreachableError(args.device) 92 raise device_errors.DeviceUnreachableError(args.device)
71 elif not devices: 93 elif not devices:
72 raise device_errors.NoDevicesError() 94 raise device_errors.NoDevicesError()
73 95
74 def blacklisting_install(device): 96 def blacklisting_install(device):
75 try: 97 try:
76 device.Install(apk, reinstall=args.keep_data) 98 if args.splits:
99 device.InstallSplitApk(apk, splits, reinstall=args.keep_data)
100 else:
101 device.Install(apk, reinstall=args.keep_data)
77 except device_errors.CommandFailedError: 102 except device_errors.CommandFailedError:
78 logging.exception('Failed to install %s', args.apk) 103 logging.exception('Failed to install %s', args.apk)
79 device_blacklist.ExtendBlacklist([str(device)]) 104 device_blacklist.ExtendBlacklist([str(device)])
80 logging.warning('Blacklisting %s', str(device)) 105 logging.warning('Blacklisting %s', str(device))
81 except device_errors.CommandTimeoutError: 106 except device_errors.CommandTimeoutError:
82 logging.exception('Timed out while installing %s', args.apk) 107 logging.exception('Timed out while installing %s', args.apk)
83 device_blacklist.ExtendBlacklist([str(device)]) 108 device_blacklist.ExtendBlacklist([str(device)])
84 logging.warning('Blacklisting %s', str(device)) 109 logging.warning('Blacklisting %s', str(device))
85 110
86 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install) 111 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install)
87 112
88 113
89 if __name__ == '__main__': 114 if __name__ == '__main__':
90 sys.exit(main()) 115 sys.exit(main())
91 116
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/utils/apk_helper.py » ('j') | build/android/pylib/utils/apk_helper.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698