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

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

Issue 1338813003: GN: Side-load dex files as well as native code in incremental installs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix pylint warnings Created 5 years, 3 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2015 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 """Install *_incremental.apk targets as well as their dependent files."""
8
9 import argparse
10 import glob
11 import logging
12 import posixpath
13 import sys
14 import time
15
16 from devil.android import apk_helper
17 from devil.android import device_utils
18 from devil.android import device_errors
19 from devil.utils import reraiser_thread
20 from pylib import constants
21 from pylib.utils import run_tests_helper
22
23
24 def main():
25 start_time = time.time()
26 parser = argparse.ArgumentParser()
27 parser.add_argument('apk_path',
28 help='The path to the APK to install.')
29 parser.add_argument('--split',
30 action='append',
31 dest='splits',
32 help='A glob matching the apk splits. '
33 'Can be specified multiple times.')
34 parser.add_argument('--lib-dir',
35 help='Path to native libraries directory.')
36 parser.add_argument('-d', '--device', dest='device',
37 help='Target device for apk to install on.')
38 parser.add_argument('--uninstall',
39 action='store_true',
40 default=False,
41 help='Remove the app and all side-loaded files.')
42 parser.add_argument('--output-directory',
43 help='Path to the root build directory.')
44 parser.add_argument('--no-threading',
45 action='store_true',
46 default=False,
47 help='Do not install and push concurrently')
48 parser.add_argument('-v',
49 '--verbose',
50 dest='verbose_count',
51 default=0,
52 action='count',
53 help='Verbose level (multiple times for more)')
54
55 args = parser.parse_args()
56
57 logging.basicConfig(format='%(asctime)s (%(thread)d) %(message)s')
58 run_tests_helper.SetLogLevel(args.verbose_count)
59 constants.SetBuildType('Debug')
60 if args.output_directory:
61 constants.SetOutputDirectory(args.output_directory)
62
63 if args.device:
64 # Retries are annoying when commands fail for legitimate reasons. Might want
65 # to enable them if this is ever used on bots though.
66 device = device_utils.DeviceUtils(args.device, default_retries=0)
67 else:
68 devices = device_utils.DeviceUtils.HealthyDevices(default_retries=0)
69 if not devices:
70 raise device_errors.NoDevicesError()
71 elif len(devices) == 1:
72 device = devices[0]
73 else:
74 all_devices = device_utils.DeviceUtils.parallel(devices)
75 msg = ('More than one device available.\n'
76 'Use --device=SERIAL to select a device.\n'
77 'Available devices:\n')
78 descriptions = all_devices.pMap(lambda d: d.build_description).pGet(None)
79 for d, desc in zip(devices, descriptions):
80 msg += ' %s (%s)\n' % (d, desc)
81 raise Exception(msg)
82
83 apk_package = apk_helper.ApkHelper(args.apk_path).GetPackageName()
84 device_incremental_dir = '/data/local/tmp/incremental-app-%s' % apk_package
85
86 if args.uninstall:
87 logging.info('Uninstalling .apk')
88 device.Uninstall(apk_package)
89 logging.info('Removing side-loaded files')
90 device.RunShellCommand(['rm', '-rf', device_incremental_dir],
91 check_return=True)
92 return
93
94 # Install .apk(s) if any of them have changed.
95 def do_install():
96 if args.splits:
97 splits = []
98 for split_glob in args.splits:
99 splits.extend((f for f in glob.glob(split_glob)))
100 device.InstallSplitApk(args.apk_path, splits, reinstall=True,
101 allow_cached_props=True)
102 else:
103 device.Install(args.apk_path, reinstall=True)
104 logging.info('Finished installing .apk')
105
106 # Push .so files to the device (if they have changed).
107 def do_push_libs():
108 if args.lib_dir:
109 device_lib_dir = posixpath.join(device_incremental_dir, 'lib')
110 device.PushChangedFiles([(args.lib_dir, device_lib_dir)],
111 delete_device_stale=True)
112 logging.info('Finished pushing native libs')
113
114 # Concurrency here speeds things up quite a bit, but DeviceUtils hasn't
115 # been designed for multi-threading. Enabling only because this is a
116 # developer-only tool.
117 if args.no_threading:
118 do_install()
119 do_push_libs()
120 else:
121 reraiser_thread.RunAsync((do_install, do_push_libs))
122 logging.info('Took %s seconds', round(time.time() - start_time, 1))
123
124
125 if __name__ == '__main__':
126 sys.exit(main())
127
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698