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

Unified 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: Address review nits 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/apk_install.py
diff --git a/build/android/gyp/apk_install.py b/build/android/gyp/apk_install.py
index 419dc170bb8e9066ba0d1fe9ae590808c0c797e5..bd5068e9c9068d3f3ac5bf6085dd95b472924102 100755
--- a/build/android/gyp/apk_install.py
+++ b/build/android/gyp/apk_install.py
@@ -23,6 +23,27 @@ sys.path.append(BUILD_ANDROID_DIR)
from pylib import constants
from pylib.utils import apk_helper
+def RetrieveDeviceConfig(device):
+ """Probes the given device for its split-select config.
+
+ For example: en-rUS-xhdpi:armeabi-v7a
+ Run "split-select --help" for more info about the format.
+ """
+ # The locale properties here are new in sdk level 21.
+ SHELL_CONFIG_COMMAND = ('echo $(getprop persist.sys.language)-'
jbudorick 2015/05/20 01:43:05 This would seemingly be much more readable as just
jbudorick 2015/05/20 01:44:05 I should note that this is mildly slower than what
agrieve 2015/05/20 14:33:58 Yeah, this was my original reasoning, but seems fa
agrieve 2015/05/20 14:33:58 Done.
+ 'r$(getprop persist.sys.country)-'
+ '$(D=$(getprop ro.sf.lcd_density);'
+ ' D=${D/120/ldpi};'
+ ' D=${D/160/mdpi};'
+ ' D=${D/240/hdpi};'
+ ' D=${D/320/xhdpi};'
+ ' D=${D/480/xxhdpi};'
+ ' D=${D/[0-9]*/tvdpi/};'
+ ' echo $D):'
+ '$(getprop ro.product.cpu.abi)')
+ return device.RunShellCommand(SHELL_CONFIG_COMMAND)[0]
+
+
def GetNewMetadata(device, apk_package):
"""Gets the metadata on the device for the apk_package apk."""
output = device.RunShellCommand('ls -l /data/app/')
@@ -62,6 +83,9 @@ def main():
help='Path to .apk splits (can specify multiple times, causes '
'--install-multiple to be used.',
action='append')
+ parser.add_option('--android-sdk-tools',
+ help='Path to the Android SDK build tools folder. ' +
+ 'Required when using --split-apk-path.')
parser.add_option('--install-record',
help='Path to install record (touched only when APK is installed).')
parser.add_option('--build-device-configuration',
@@ -88,13 +112,36 @@ def main():
# the build, then the APK has to be installed (regardless of the md5 record).
force_install = HasInstallMetadataChanged(device, apk_package, metadata_path)
+ def SelectSplits(target_config, base_apk, split_apks, android_sdk_tools):
+ cmd = [os.path.join(android_sdk_tools, 'split-select'),
+ '--target', target_config,
+ '--base', base_apk,
+ ]
+ for split in split_apks:
+ cmd.extend(('--split', split))
+
+ # split-select outputs one path per line and a blank line at the end.
+ output = build_utils.CheckOutput(cmd)
+ return [x for x in output.split('\n') if x]
+
def Install():
- # TODO: Filter splits using split-select.
- active_splits = options.split_apk_path
- if active_splits:
- device.adb.InstallMultiple(
- [options.apk_path] + active_splits,
- reinstall=True)
+ if options.split_apk_path:
+ requiredSdkVersion = constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP
+ actualSdkVersion = device.device.build_version_sdk
+ if actualSdkVersion < requiredSdkVersion:
+ raise Exception(('--split-apk-path requires sdk version %s. Device has '
+ 'version %s') % (requiredSdkVersion, actualSdkVersion))
+ device_config = RetrieveDeviceConfig(device)
+ active_splits = SelectSplits(
+ device_config,
+ options.apk_path,
+ options.split_apk_path,
+ options.android_sdk_tools)
+
+ all_apks = [options.apk_path] + active_splits
+ apk_names = ', '.join((os.path.basename(path) for path in all_apks))
+ print 'Installing apks:', apk_names
cjhopman 2015/05/20 01:37:28 maybe drop the print
agrieve 2015/05/20 14:33:58 Done.
+ device.device.adb.InstallMultiple(all_apks, reinstall=True)
else:
device.Install(options.apk_path, reinstall=True)
« 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