Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 # The locale properties here are new in sdk level 21. | |
| 29 SHELL_CONFIG_COMMAND = ('echo $(getprop persist.sys.language)-' | |
|
jbudorick
2015/05/19 18:21:59
This is kind of a dumb question, but ... what does
agrieve
2015/05/19 18:34:53
Update pydoc with example output.
| |
| 30 'r$(getprop persist.sys.country)-' | |
| 31 '$(D=$(getprop ro.sf.lcd_density);' | |
| 32 ' D=${D/120/ldpi};' | |
| 33 ' D=${D/160/mdpi};' | |
| 34 ' D=${D/240/hdpi};' | |
| 35 ' D=${D/320/xhdpi};' | |
| 36 ' D=${D/480/xxhdpi};' | |
| 37 ' D=${D/[0-9]*/tvdpi/};' | |
| 38 ' echo $D):' | |
| 39 '$(getprop ro.product.cpu.abi)') | |
| 40 return device.RunShellCommand(SHELL_CONFIG_COMMAND)[0] | |
| 41 | |
| 42 | |
| 26 def GetNewMetadata(device, apk_package): | 43 def GetNewMetadata(device, apk_package): |
| 27 """Gets the metadata on the device for the apk_package apk.""" | 44 """Gets the metadata on the device for the apk_package apk.""" |
| 28 output = device.RunShellCommand('ls -l /data/app/') | 45 output = device.RunShellCommand('ls -l /data/app/') |
| 29 # Matches lines like: | 46 # Matches lines like: |
| 30 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ | 47 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ |
| 31 # org.chromium.chrome.shell.apk | 48 # org.chromium.chrome.shell.apk |
| 32 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ | 49 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ |
| 33 # org.chromium.chrome.shell-1.apk | 50 # org.chromium.chrome.shell-1.apk |
| 34 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?(.apk)?$' % apk_package, s) | 51 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?(.apk)?$' % apk_package, s) |
| 35 matches = filter(apk_matcher, output) | 52 matches = filter(apk_matcher, output) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 55 | 72 |
| 56 | 73 |
| 57 def main(): | 74 def main(): |
| 58 parser = optparse.OptionParser() | 75 parser = optparse.OptionParser() |
| 59 parser.add_option('--apk-path', | 76 parser.add_option('--apk-path', |
| 60 help='Path to .apk to install.') | 77 help='Path to .apk to install.') |
| 61 parser.add_option('--split-apk-path', | 78 parser.add_option('--split-apk-path', |
| 62 help='Path to .apk splits (can specify multiple times, causes ' | 79 help='Path to .apk splits (can specify multiple times, causes ' |
| 63 '--install-multiple to be used.', | 80 '--install-multiple to be used.', |
| 64 action='append') | 81 action='append') |
| 82 parser.add_option('--android-sdk-tools', | |
| 83 help='Path to the Android SDK build tools folder. ' + | |
| 84 'Required when using --split-apk-path.') | |
| 65 parser.add_option('--install-record', | 85 parser.add_option('--install-record', |
| 66 help='Path to install record (touched only when APK is installed).') | 86 help='Path to install record (touched only when APK is installed).') |
| 67 parser.add_option('--build-device-configuration', | 87 parser.add_option('--build-device-configuration', |
| 68 help='Path to build device configuration.') | 88 help='Path to build device configuration.') |
| 69 parser.add_option('--stamp', | 89 parser.add_option('--stamp', |
| 70 help='Path to touch on success.') | 90 help='Path to touch on success.') |
| 71 parser.add_option('--configuration-name', | 91 parser.add_option('--configuration-name', |
| 72 help='The build CONFIGURATION_NAME') | 92 help='The build CONFIGURATION_NAME') |
| 73 options, _ = parser.parse_args() | 93 options, _ = parser.parse_args() |
| 74 | 94 |
| 75 device = build_device.GetBuildDeviceFromPath( | 95 device = build_device.GetBuildDeviceFromPath( |
| 76 options.build_device_configuration) | 96 options.build_device_configuration) |
| 77 if not device: | 97 if not device: |
| 78 return | 98 return |
| 79 | 99 |
| 80 constants.SetBuildType(options.configuration_name) | 100 constants.SetBuildType(options.configuration_name) |
| 81 | 101 |
| 82 serial_number = device.GetSerialNumber() | 102 serial_number = device.GetSerialNumber() |
| 83 apk_package = apk_helper.GetPackageName(options.apk_path) | 103 apk_package = apk_helper.GetPackageName(options.apk_path) |
| 84 | 104 |
| 85 metadata_path = '%s.%s.device.time.stamp' % (options.apk_path, serial_number) | 105 metadata_path = '%s.%s.device.time.stamp' % (options.apk_path, serial_number) |
| 86 | 106 |
| 87 # If the APK on the device does not match the one that was last installed by | 107 # 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). | 108 # the build, then the APK has to be installed (regardless of the md5 record). |
| 89 force_install = HasInstallMetadataChanged(device, apk_package, metadata_path) | 109 force_install = HasInstallMetadataChanged(device, apk_package, metadata_path) |
| 90 | 110 |
| 111 def SelectSplits(target_config, base_apk, split_apks, android_sdk_tools): | |
| 112 cmd = [os.path.join(android_sdk_tools, 'split-select'), | |
| 113 '--target', target_config, | |
| 114 '--base', base_apk, | |
| 115 ] | |
| 116 for split in split_apks: | |
| 117 cmd.extend(('--split', split)) | |
| 118 | |
| 119 # split-select outputs one path per line and a blank line at the end. | |
| 120 output = build_utils.CheckOutput(cmd) | |
| 121 return [x for x in output.split('\n') if x] | |
| 122 | |
| 91 def Install(): | 123 def Install(): |
| 92 # TODO: Filter splits using split-select. | 124 if options.split_apk_path: |
| 93 active_splits = options.split_apk_path | 125 requiredSdkVersion = constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP |
| 94 if active_splits: | 126 actualSdkVersion = device.device.build_version_sdk |
| 95 device.adb.InstallMultiple( | 127 if actualSdkVersion < requiredSdkVersion: |
| 96 [options.apk_path] + active_splits, | 128 raise Exception(('--split-apk-path requires sdk version %s. Device has ' |
| 97 reinstall=True) | 129 'version %s') % (requiredSdkVersion, actualSdkVersion)) |
| 130 device_config = RetrieveDeviceConfig(device) | |
| 131 active_splits = SelectSplits( | |
| 132 device_config, | |
| 133 options.apk_path, | |
| 134 options.split_apk_path, | |
| 135 options.android_sdk_tools) | |
| 136 | |
| 137 all_apks = [options.apk_path] + active_splits | |
| 138 apk_names = [os.path.basename(path) for path in all_apks] | |
|
jbudorick
2015/05/19 18:21:59
nit: looks like you're only using this once, so it
agrieve
2015/05/19 18:34:53
Done.
| |
| 139 print 'Installing apks:', ', '.join(apk_names) | |
| 140 device.device.adb.InstallMultiple(all_apks, reinstall=True) | |
|
jbudorick
2015/05/19 18:21:59
device.device? Is this right?
agrieve
2015/05/19 18:34:53
Sad naming :(
device is a BuildDevice
device.devi
| |
| 98 else: | 141 else: |
| 99 device.Install(options.apk_path, reinstall=True) | 142 device.Install(options.apk_path, reinstall=True) |
| 100 | 143 |
| 101 RecordInstallMetadata(device, apk_package, metadata_path) | 144 RecordInstallMetadata(device, apk_package, metadata_path) |
| 102 build_utils.Touch(options.install_record) | 145 build_utils.Touch(options.install_record) |
| 103 | 146 |
| 104 | 147 |
| 105 record_path = '%s.%s.md5.stamp' % (options.apk_path, serial_number) | 148 record_path = '%s.%s.md5.stamp' % (options.apk_path, serial_number) |
| 106 md5_check.CallAndRecordIfStale( | 149 md5_check.CallAndRecordIfStale( |
| 107 Install, | 150 Install, |
| 108 record_path=record_path, | 151 record_path=record_path, |
| 109 input_paths=[options.apk_path], | 152 input_paths=[options.apk_path], |
| 110 force=force_install) | 153 force=force_install) |
| 111 | 154 |
| 112 if options.stamp: | 155 if options.stamp: |
| 113 build_utils.Touch(options.stamp) | 156 build_utils.Touch(options.stamp) |
| 114 | 157 |
| 115 | 158 |
| 116 if __name__ == '__main__': | 159 if __name__ == '__main__': |
| 117 sys.exit(main()) | 160 sys.exit(main()) |
| OLD | NEW |