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

Side by Side Diff: build/android/adb_install_apk.py

Issue 2392643003: Removes files from //build that we don't need (Closed)
Patch Set: Created 4 years, 2 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 | « build/android/adb_gdb_mojo_shell ('k') | build/android/adb_kill_android_webview_shell » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Utility script to install APKs from the command line quickly."""
8
9 import argparse
10 import glob
11 import logging
12 import os
13 import sys
14
15 from pylib import constants
16 from pylib.device import device_blacklist
17 from pylib.device import device_errors
18 from pylib.device import device_utils
19 from pylib.utils import apk_helper
20 from pylib.utils import run_tests_helper
21
22
23 def main():
24 parser = argparse.ArgumentParser()
25
26 apk_group = parser.add_mutually_exclusive_group(required=True)
27 apk_group.add_argument('--apk', dest='apk_name',
28 help='DEPRECATED The name of the apk containing the'
29 ' application (with the .apk extension).')
30 apk_group.add_argument('apk_path', nargs='?',
31 help='The path to the APK to install.')
32
33 # TODO(jbudorick): Remove once no clients pass --apk_package
34 parser.add_argument('--apk_package', help='DEPRECATED unused')
35 parser.add_argument('--split',
36 action='append',
37 dest='splits',
38 help='A glob matching the apk splits. '
39 'Can be specified multiple times.')
40 parser.add_argument('--keep_data',
41 action='store_true',
42 default=False,
43 help='Keep the package data when installing '
44 'the application.')
45 parser.add_argument('--debug', action='store_const', const='Debug',
46 dest='build_type',
47 default=os.environ.get('BUILDTYPE', 'Debug'),
48 help='If set, run test suites under out/Debug. '
49 'Default is env var BUILDTYPE or Debug')
50 parser.add_argument('--release', action='store_const', const='Release',
51 dest='build_type',
52 help='If set, run test suites under out/Release. '
53 'Default is env var BUILDTYPE or Debug.')
54 parser.add_argument('-d', '--device', dest='device',
55 help='Target device for apk to install on.')
56 parser.add_argument('-v', '--verbose', action='count',
57 help='Enable verbose logging.')
58
59 args = parser.parse_args()
60
61 run_tests_helper.SetLogLevel(args.verbose)
62 constants.SetBuildType(args.build_type)
63
64 apk = args.apk_path or args.apk_name
65 if not apk.endswith('.apk'):
66 apk += '.apk'
67 if not os.path.exists(apk):
68 apk = os.path.join(constants.GetOutDirectory(), 'apks', apk)
69 if not os.path.exists(apk):
70 parser.error('%s not found.' % apk)
71
72 if args.splits:
73 splits = []
74 base_apk_package = apk_helper.ApkHelper(apk).GetPackageName()
75 for split_glob in args.splits:
76 apks = [f for f in glob.glob(split_glob) if f.endswith('.apk')]
77 if not apks:
78 logging.warning('No apks matched for %s.' % split_glob)
79 for f in apks:
80 helper = apk_helper.ApkHelper(f)
81 if (helper.GetPackageName() == base_apk_package
82 and helper.GetSplitName()):
83 splits.append(f)
84
85 devices = device_utils.DeviceUtils.HealthyDevices()
86
87 if args.device:
88 devices = [d for d in devices if d == args.device]
89 if not devices:
90 raise device_errors.DeviceUnreachableError(args.device)
91 elif not devices:
92 raise device_errors.NoDevicesError()
93
94 def blacklisting_install(device):
95 try:
96 if args.splits:
97 device.InstallSplitApk(apk, splits, reinstall=args.keep_data)
98 else:
99 device.Install(apk, reinstall=args.keep_data)
100 except device_errors.CommandFailedError:
101 logging.exception('Failed to install %s', args.apk_name)
102 device_blacklist.ExtendBlacklist([str(device)])
103 logging.warning('Blacklisting %s', str(device))
104 except device_errors.CommandTimeoutError:
105 logging.exception('Timed out while installing %s', args.apk_name)
106 device_blacklist.ExtendBlacklist([str(device)])
107 logging.warning('Blacklisting %s', str(device))
108
109 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_install)
110
111
112 if __name__ == '__main__':
113 sys.exit(main())
114
OLDNEW
« no previous file with comments | « build/android/adb_gdb_mojo_shell ('k') | build/android/adb_kill_android_webview_shell » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698