Chromium Code Reviews| Index: build/android/gyp/apk_install.py |
| diff --git a/build/android/gyp/apk_install.py b/build/android/gyp/apk_install.py |
| index 8cd1a604fe671b53e9e0ea736b0bec6b85637a10..71afcbec3af3211f9b8a6a7fc67ee779b58ec377 100755 |
| --- a/build/android/gyp/apk_install.py |
| +++ b/build/android/gyp/apk_install.py |
| @@ -10,6 +10,7 @@ |
| import optparse |
| import os |
| +import re |
| import subprocess |
| import sys |
| @@ -20,6 +21,38 @@ BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') |
| sys.path.append(BUILD_ANDROID_DIR) |
| from pylib import android_commands |
| +from pylib.utils import apk_helper |
|
Yaron
2013/04/22 22:02:40
This isn't in the gyp deps but I assume you ignore
cjhopman
2013/04/24 00:16:27
Yeah, it's just infeasible to specify all the impo
|
| + |
| + |
| +def GetMetadata(apk_package): |
| + """Gets the metadata on the device for the apk_package apk.""" |
| + adb = android_commands.AndroidCommands() |
| + output = adb.RunShellCommand('ls -l /data/app/') |
| + # Matches lines like: |
| + # -rw-r--r-- system system 7376582 2013-04-19 16:34 org.chromium.chrome.testshell-1.apk |
|
Yaron
2013/04/22 22:02:40
I see a bunch of -1 and -2 apks on my local device
cjhopman
2013/04/24 00:16:27
My understanding is that there can only be one. On
|
| + apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk.*' % apk_package, s) |
|
Yaron
2013/04/22 22:02:40
Maybe end with "$"? You don't want to pick up misc
cjhopman
2013/04/24 00:16:27
Done.
|
| + matches = filter(apk_matcher, output) |
| + return matches[0] if matches else None |
| + |
| + |
| +def HasInstallMetadataChanged(apk_package, metadata_path): |
| + """Checks if the metadata on the device for apk_package has changed.""" |
| + if not os.path.exists(metadata_path): |
| + return True |
| + |
| + with open(metadata_path, 'r') as expected_file: |
| + return expected_file.read() != GetMetadata(apk_package) |
| + |
| + |
| +def RecordInstallMetadata(apk_package, metadata_path): |
| + """Records the metadata from the device for apk_package.""" |
| + metadata = GetMetadata(apk_package) |
| + if not metadata: |
| + raise 'APK install failed unexpectedly.' |
| + |
| + with open(metadata_path, 'w') as outfile: |
| + outfile.write(metadata) |
| + |
| def main(argv): |
| parser = optparse.OptionParser() |
| @@ -39,17 +72,28 @@ def main(argv): |
| 'install', '-r', |
| options.apk_path] |
| + serial_number = android_commands.AndroidCommands().Adb().GetSerialNumber() |
| + apk_package = apk_helper.GetPackageName(options.apk_path) |
| + |
| + metadata_path = '%s.%s.device.time.stamp' % (options.apk_path, serial_number) |
| + |
| + # If the APK on the device does not match the one that was last installed by |
| + # the build, then the APK has to be installed (regardless of the md5 record). |
| + force_install = HasInstallMetadataChanged(apk_package, metadata_path) |
| + |
| def Install(): |
| - build_utils.CheckCallDie(install_cmd) |
| - build_utils.Touch(options.install_record) |
| + build_utils.CheckCallDie(install_cmd) |
| + RecordInstallMetadata(apk_package, metadata_path) |
| + build_utils.Touch(options.install_record) |
| + |
| - serial_number = android_commands.AndroidCommands().Adb().GetSerialNumber() |
| record_path = '%s.%s.md5.stamp' % (options.apk_path, serial_number) |
| md5_check.CallAndRecordIfStale( |
| Install, |
| record_path=record_path, |
| input_paths=[options.apk_path], |
| - input_strings=install_cmd) |
| + input_strings=install_cmd, |
| + force=force_install) |
| if options.stamp: |
| build_utils.Touch(options.stamp) |