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 subprocess | 13 import subprocess |
14 import sys | 14 import sys |
15 | 15 |
16 from util import build_utils | 16 from util import build_utils |
17 from util import md5_check | 17 from util import md5_check |
18 | 18 |
19 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') | 19 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') |
20 sys.path.append(BUILD_ANDROID_DIR) | 20 sys.path.append(BUILD_ANDROID_DIR) |
21 | 21 |
22 from pylib import android_commands | 22 from pylib import android_commands |
23 | 23 |
24 def main(argv): | 24 def main(argv): |
25 parser = optparse.OptionParser() | 25 parser = optparse.OptionParser() |
26 parser.add_option('--android-sdk-tools', | 26 parser.add_option('--android-sdk-tools', |
27 help='Path to Android SDK tools.') | 27 help='Path to Android SDK tools.') |
28 parser.add_option('--apk-path', | 28 parser.add_option('--apk-path', |
29 help='Path to .apk to install.') | 29 help='Path to .apk to install.') |
| 30 parser.add_option('--install-record', |
| 31 help='Path to install record (touched only when APK is installed).') |
30 parser.add_option('--stamp', | 32 parser.add_option('--stamp', |
31 help='Path to touch on success.') | 33 help='Path to touch on success.') |
32 options, _ = parser.parse_args() | 34 options, _ = parser.parse_args() |
33 | 35 |
34 # TODO(cjhopman): Should this install to all devices/be configurable? | 36 # TODO(cjhopman): Should this install to all devices/be configurable? |
35 install_cmd = [ | 37 install_cmd = [ |
36 os.path.join(options.android_sdk_tools, 'adb'), | 38 os.path.join(options.android_sdk_tools, 'adb'), |
37 'install', '-r', | 39 'install', '-r', |
38 options.apk_path] | 40 options.apk_path] |
39 | 41 |
| 42 def Install(): |
| 43 build_utils.CheckCallDie(install_cmd) |
| 44 build_utils.Touch(options.install_record) |
| 45 |
40 serial_number = android_commands.AndroidCommands().Adb().GetSerialNumber() | 46 serial_number = android_commands.AndroidCommands().Adb().GetSerialNumber() |
41 record_path = '%s.%s.md5.stamp' % (options.apk_path, serial_number) | 47 record_path = '%s.%s.md5.stamp' % (options.apk_path, serial_number) |
42 md5_check.CallAndRecordIfStale( | 48 md5_check.CallAndRecordIfStale( |
43 lambda: build_utils.CheckCallDie(install_cmd), | 49 Install, |
44 record_path=record_path, | 50 record_path=record_path, |
45 input_paths=[options.apk_path], | 51 input_paths=[options.apk_path], |
46 input_strings=install_cmd) | 52 input_strings=install_cmd) |
47 | 53 |
48 if options.stamp: | 54 if options.stamp: |
49 build_utils.Touch(options.stamp) | 55 build_utils.Touch(options.stamp) |
50 | 56 |
51 | 57 |
52 if __name__ == '__main__': | 58 if __name__ == '__main__': |
53 sys.exit(main(sys.argv)) | 59 sys.exit(main(sys.argv)) |
OLD | NEW |