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

Side by Side Diff: build/android/gyp/apk_install.py

Issue 1141403002: Add split-select logic to apk_install.py & fix crash when --split-apk-path is used (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@uses-sdk-21
Patch Set: Created 5 years, 7 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 | no next file » | 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 2013 The Chromium Authors. All rights reserved. 3 # Copyright 2013 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 """Installs an APK. 7 """Installs an APK.
8 8
9 """ 9 """
10 10
11 import optparse 11 import optparse
12 import os 12 import os
13 import re 13 import re
14 import sys 14 import sys
15 15
16 from util import build_device 16 from util import build_device
17 from util import build_utils 17 from util import build_utils
18 from util import md5_check 18 from util import md5_check
19 19
20 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') 20 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..')
21 sys.path.append(BUILD_ANDROID_DIR) 21 sys.path.append(BUILD_ANDROID_DIR)
22 22
23 from pylib import constants 23 from pylib import constants
24 from pylib.utils import apk_helper 24 from pylib.utils import apk_helper
25 25
26 def RetrieveDeviceConfig(device):
27 """Probes the given device for its split-select config."""
28 SHELL_CONFIG_COMMAND = ('echo $(getprop persist.sys.language)-'
jbudorick 2015/05/19 15:06:59 I have questions about this that I'll ask you abou
agrieve 2015/05/19 18:34:53 Acknowledged.
29 'r$(getprop persist.sys.country)-'
30 '$(D=$(getprop ro.sf.lcd_density);'
31 ' D=${D/120/ldpi};'
32 ' D=${D/160/mdpi};'
33 ' D=${D/240/hdpi};'
34 ' D=${D/320/xhdpi};'
35 ' D=${D/480/xxhdpi};'
36 ' D=${D/[0-9]*/tvdpi/};'
37 ' echo $D):'
38 '$(getprop ro.product.cpu.abi)')
39 return device.RunShellCommand(SHELL_CONFIG_COMMAND)[0]
40
41
26 def GetNewMetadata(device, apk_package): 42 def GetNewMetadata(device, apk_package):
27 """Gets the metadata on the device for the apk_package apk.""" 43 """Gets the metadata on the device for the apk_package apk."""
28 output = device.RunShellCommand('ls -l /data/app/') 44 output = device.RunShellCommand('ls -l /data/app/')
29 # Matches lines like: 45 # Matches lines like:
30 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ 46 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \
31 # org.chromium.chrome.shell.apk 47 # org.chromium.chrome.shell.apk
32 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ 48 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \
33 # org.chromium.chrome.shell-1.apk 49 # org.chromium.chrome.shell-1.apk
34 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?(.apk)?$' % apk_package, s) 50 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?(.apk)?$' % apk_package, s)
35 matches = filter(apk_matcher, output) 51 matches = filter(apk_matcher, output)
(...skipping 19 matching lines...) Expand all
55 71
56 72
57 def main(): 73 def main():
58 parser = optparse.OptionParser() 74 parser = optparse.OptionParser()
59 parser.add_option('--apk-path', 75 parser.add_option('--apk-path',
60 help='Path to .apk to install.') 76 help='Path to .apk to install.')
61 parser.add_option('--split-apk-path', 77 parser.add_option('--split-apk-path',
62 help='Path to .apk splits (can specify multiple times, causes ' 78 help='Path to .apk splits (can specify multiple times, causes '
63 '--install-multiple to be used.', 79 '--install-multiple to be used.',
64 action='append') 80 action='append')
81 parser.add_option('--android-sdk-tools',
82 help='Path to the Android SDK build tools folder. ' +
83 'Required when using --split-apk-path.')
65 parser.add_option('--install-record', 84 parser.add_option('--install-record',
66 help='Path to install record (touched only when APK is installed).') 85 help='Path to install record (touched only when APK is installed).')
67 parser.add_option('--build-device-configuration', 86 parser.add_option('--build-device-configuration',
68 help='Path to build device configuration.') 87 help='Path to build device configuration.')
69 parser.add_option('--stamp', 88 parser.add_option('--stamp',
70 help='Path to touch on success.') 89 help='Path to touch on success.')
71 parser.add_option('--configuration-name', 90 parser.add_option('--configuration-name',
72 help='The build CONFIGURATION_NAME') 91 help='The build CONFIGURATION_NAME')
73 options, _ = parser.parse_args() 92 options, _ = parser.parse_args()
74 93
75 device = build_device.GetBuildDeviceFromPath( 94 device = build_device.GetBuildDeviceFromPath(
76 options.build_device_configuration) 95 options.build_device_configuration)
77 if not device: 96 if not device:
78 return 97 return
79 98
80 constants.SetBuildType(options.configuration_name) 99 constants.SetBuildType(options.configuration_name)
81 100
82 serial_number = device.GetSerialNumber() 101 serial_number = device.GetSerialNumber()
83 apk_package = apk_helper.GetPackageName(options.apk_path) 102 apk_package = apk_helper.GetPackageName(options.apk_path)
84 103
85 metadata_path = '%s.%s.device.time.stamp' % (options.apk_path, serial_number) 104 metadata_path = '%s.%s.device.time.stamp' % (options.apk_path, serial_number)
86 105
87 # If the APK on the device does not match the one that was last installed by 106 # If the APK on the device does not match the one that was last installed by
88 # the build, then the APK has to be installed (regardless of the md5 record). 107 # the build, then the APK has to be installed (regardless of the md5 record).
89 force_install = HasInstallMetadataChanged(device, apk_package, metadata_path) 108 force_install = HasInstallMetadataChanged(device, apk_package, metadata_path)
90 109
110 def SelectSplits(target_config, base_apk, split_apks, android_sdk_tools):
111 cmd = [os.path.join(android_sdk_tools, 'split-select'),
112 '--target', target_config,
113 '--base', base_apk,
114 ]
115 for split in split_apks:
116 cmd.extend(('--split', split))
117
118 # split-select outputs one path per line and a blank line at the end.
119 output = build_utils.CheckOutput(cmd)
120 return [x for x in output.split('\n') if x]
121
91 def Install(): 122 def Install():
92 # TODO: Filter splits using split-select. 123 if options.split_apk_path:
jbudorick 2015/05/19 15:12:48 This should check against a minimum SDK level, e.g
93 active_splits = options.split_apk_path 124 device_config = RetrieveDeviceConfig(device)
94 if active_splits: 125 active_splits = SelectSplits(device_config, options.apk_path,
jbudorick 2015/05/19 15:06:59 nit: either indent params on subsequent lines to t
agrieve 2015/05/19 18:34:52 Done.
95 device.adb.InstallMultiple( 126 options.split_apk_path, options.android_sdk_tools)
96 [options.apk_path] + active_splits, 127
97 reinstall=True) 128 all_apks = [options.apk_path] + active_splits
129 apk_names = [os.path.basename(path) for path in all_apks]
130 print('Installing apks: ' + ', '.join(apk_names))
jbudorick 2015/05/19 15:06:59 nit: We don't typically use the python3 print synt
agrieve 2015/05/19 18:34:53 Done.
131 device.device.adb.InstallMultiple(all_apks, reinstall=True)
98 else: 132 else:
99 device.Install(options.apk_path, reinstall=True) 133 device.Install(options.apk_path, reinstall=True)
100 134
101 RecordInstallMetadata(device, apk_package, metadata_path) 135 RecordInstallMetadata(device, apk_package, metadata_path)
102 build_utils.Touch(options.install_record) 136 build_utils.Touch(options.install_record)
103 137
104 138
105 record_path = '%s.%s.md5.stamp' % (options.apk_path, serial_number) 139 record_path = '%s.%s.md5.stamp' % (options.apk_path, serial_number)
106 md5_check.CallAndRecordIfStale( 140 md5_check.CallAndRecordIfStale(
107 Install, 141 Install,
108 record_path=record_path, 142 record_path=record_path,
109 input_paths=[options.apk_path], 143 input_paths=[options.apk_path],
110 force=force_install) 144 force=force_install)
111 145
112 if options.stamp: 146 if options.stamp:
113 build_utils.Touch(options.stamp) 147 build_utils.Touch(options.stamp)
114 148
115 149
116 if __name__ == '__main__': 150 if __name__ == '__main__':
117 sys.exit(main()) 151 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698