OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 """Install *_incremental.apk targets as well as their dependent files.""" | 7 """Install *_incremental.apk targets as well as their dependent files.""" |
8 | 8 |
9 import argparse | 9 import argparse |
10 import glob | 10 import glob |
(...skipping 14 matching lines...) Expand all Loading... | |
25 from pylib import constants | 25 from pylib import constants |
26 from pylib.utils import run_tests_helper | 26 from pylib.utils import run_tests_helper |
27 from pylib.utils import time_profile | 27 from pylib.utils import time_profile |
28 | 28 |
29 prev_sys_path = list(sys.path) | 29 prev_sys_path = list(sys.path) |
30 sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, 'gyp')) | 30 sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, 'gyp')) |
31 from util import build_utils | 31 from util import build_utils |
32 sys.path = prev_sys_path | 32 sys.path = prev_sys_path |
33 | 33 |
34 | 34 |
35 def _DeviceCachePath(device): | |
36 file_name = 'device_cache_%s.json' % device.adb.GetDeviceSerial() | |
37 return os.path.join(constants.GetOutDirectory(), file_name) | |
38 | |
39 | |
35 def _TransformDexPaths(paths): | 40 def _TransformDexPaths(paths): |
36 """Given paths like ["/a/b/c", "/a/c/d"], returns ["b.c", "c.d"].""" | 41 """Given paths like ["/a/b/c", "/a/c/d"], returns ["b.c", "c.d"].""" |
37 if len(paths) == 1: | 42 if len(paths) == 1: |
38 return [os.path.basename(paths[0])] | 43 return [os.path.basename(paths[0])] |
39 | 44 |
40 prefix_len = len(os.path.commonprefix(paths)) | 45 prefix_len = len(os.path.commonprefix(paths)) |
41 return [p[prefix_len:].replace(os.sep, '.') for p in paths] | 46 return [p[prefix_len:].replace(os.sep, '.') for p in paths] |
42 | 47 |
43 | 48 |
44 def _Execute(concurrently, *funcs): | 49 def _Execute(concurrently, *funcs): |
45 """Calls all functions in |funcs| concurrently or in sequence.""" | 50 """Calls all functions in |funcs| concurrently or in sequence.""" |
46 timer = time_profile.TimeProfile() | 51 timer = time_profile.TimeProfile() |
47 if concurrently: | 52 if concurrently: |
48 reraiser_thread.RunAsync(funcs) | 53 reraiser_thread.RunAsync(funcs) |
49 else: | 54 else: |
50 for f in funcs: | 55 for f in funcs: |
51 f() | 56 f() |
52 timer.Stop(log=False) | 57 timer.Stop(log=False) |
53 return timer | 58 return timer |
54 | 59 |
55 | 60 |
56 def _GetDeviceIncrementalDir(package): | 61 def _GetDeviceIncrementalDir(package): |
57 """Returns the device path to put incremental files for the given package.""" | 62 """Returns the device path to put incremental files for the given package.""" |
58 return '/data/local/tmp/incremental-app-%s' % package | 63 return '/data/local/tmp/incremental-app-%s' % package |
59 | 64 |
60 | 65 |
61 def Uninstall(device, package): | 66 def Uninstall(device, package, enable_device_cache=False): |
62 """Uninstalls and removes all incremental files for the given package.""" | 67 """Uninstalls and removes all incremental files for the given package.""" |
63 main_timer = time_profile.TimeProfile() | 68 main_timer = time_profile.TimeProfile() |
64 device.Uninstall(package) | 69 device.Uninstall(package) |
70 if enable_device_cache: | |
71 # Uninstall is rare, so just wipe the cache in this case. | |
72 cache_path = _DeviceCachePath(device) | |
73 if os.path.exists(cache_path): | |
74 os.unlink(cache_path) | |
65 device.RunShellCommand(['rm', '-rf', _GetDeviceIncrementalDir(package)], | 75 device.RunShellCommand(['rm', '-rf', _GetDeviceIncrementalDir(package)], |
66 check_return=True) | 76 check_return=True) |
67 logging.info('Uninstall took %s seconds.', main_timer.GetDelta()) | 77 logging.info('Uninstall took %s seconds.', main_timer.GetDelta()) |
68 | 78 |
69 | 79 |
70 def Install(device, apk, split_globs=None, native_libs=None, dex_files=None, | 80 def Install(device, apk, split_globs=None, native_libs=None, dex_files=None, |
71 enable_device_cache=True, use_concurrency=True, | 81 enable_device_cache=False, use_concurrency=True, |
jbudorick
2016/02/08 16:32:46
What's the point of flipping this default?
agrieve
2016/02/08 16:35:44
test_runner.py uses this function to install incre
| |
72 show_proguard_warning=False): | 82 show_proguard_warning=False): |
73 """Installs the given incremental apk and all required supporting files. | 83 """Installs the given incremental apk and all required supporting files. |
74 | 84 |
75 Args: | 85 Args: |
76 device: A DeviceUtils instance. | 86 device: A DeviceUtils instance. |
77 apk: The path to the apk, or an ApkHelper instance. | 87 apk: The path to the apk, or an ApkHelper instance. |
78 split_globs: Glob patterns for any required apk splits (optional). | 88 split_globs: Glob patterns for any required apk splits (optional). |
79 native_libs: List of app's native libraries (optional). | 89 native_libs: List of app's native libraries (optional). |
80 dex_files: List of .dex.jar files that comprise the app's Dalvik code. | 90 dex_files: List of .dex.jar files that comprise the app's Dalvik code. |
81 enable_device_cache: Whether to enable on-device caching of checksums. | 91 enable_device_cache: Whether to enable on-device caching of checksums. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 # Marshmallow has no filesystem access whatsoever. It might be possible to | 147 # Marshmallow has no filesystem access whatsoever. It might be possible to |
138 # get things working on Lollipop, but attempts so far have failed. | 148 # get things working on Lollipop, but attempts so far have failed. |
139 # http://crbug.com/558818 | 149 # http://crbug.com/558818 |
140 has_selinux = device.build_version_sdk >= version_codes.LOLLIPOP | 150 has_selinux = device.build_version_sdk >= version_codes.LOLLIPOP |
141 if has_selinux and apk.HasIsolatedProcesses(): | 151 if has_selinux and apk.HasIsolatedProcesses(): |
142 raise Exception('Cannot use incremental installs on Android L+ without ' | 152 raise Exception('Cannot use incremental installs on Android L+ without ' |
143 'first disabling isoloated processes.\n' | 153 'first disabling isoloated processes.\n' |
144 'To do so, use GN arg:\n' | 154 'To do so, use GN arg:\n' |
145 ' disable_incremental_isolated_processes=true') | 155 ' disable_incremental_isolated_processes=true') |
146 | 156 |
147 cache_path = '%s/files-cache.json' % device_incremental_dir | 157 cache_path = _DeviceCachePath(device) |
148 def restore_cache(): | 158 def restore_cache(): |
149 if not enable_device_cache: | 159 if not enable_device_cache: |
150 logging.info('Ignoring device cache') | 160 logging.info('Ignoring device cache') |
151 return | 161 return |
152 # Delete the cached file so that any exceptions cause the next attempt | 162 if os.path.exists(cache_path): |
153 # to re-compute md5s. | 163 logging.info('Using device cache: %s', cache_path) |
154 cmd = 'P=%s;cat $P 2>/dev/null && rm $P' % cache_path | 164 with open(cache_path) as f: |
155 lines = device.RunShellCommand(cmd, check_return=False, large_output=True) | 165 device.LoadCacheData(f.read()) |
156 if lines: | 166 # Delete the cached file so that any exceptions cause it to be cleared. |
157 device.LoadCacheData(lines[0]) | 167 os.unlink(cache_path) |
158 else: | 168 else: |
159 logging.info('Device cache not found: %s', cache_path) | 169 logging.info('No device cache present: %s', cache_path) |
160 | 170 |
161 def save_cache(): | 171 def save_cache(): |
162 cache_data = device.DumpCacheData() | 172 with open(cache_path, 'w') as f: |
163 device.WriteFile(cache_path, cache_data) | 173 f.write(device.DumpCacheData()) |
174 logging.info('Wrote device cache: %s', cache_path) | |
164 | 175 |
165 # Create 2 lock files: | 176 # Create 2 lock files: |
166 # * install.lock tells the app to pause on start-up (until we release it). | 177 # * install.lock tells the app to pause on start-up (until we release it). |
167 # * firstrun.lock is used by the app to pause all secondary processes until | 178 # * firstrun.lock is used by the app to pause all secondary processes until |
168 # the primary process finishes loading the .dex / .so files. | 179 # the primary process finishes loading the .dex / .so files. |
169 def create_lock_files(): | 180 def create_lock_files(): |
170 # Creates or zeros out lock files. | 181 # Creates or zeros out lock files. |
171 cmd = ('D="%s";' | 182 cmd = ('D="%s";' |
172 'mkdir -p $D &&' | 183 'mkdir -p $D &&' |
173 'echo -n >$D/install.lock 2>$D/firstrun.lock') | 184 'echo -n >$D/install.lock 2>$D/firstrun.lock') |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 msg = ('More than one device available.\n' | 285 msg = ('More than one device available.\n' |
275 'Use --device=SERIAL to select a device.\n' | 286 'Use --device=SERIAL to select a device.\n' |
276 'Available devices:\n') | 287 'Available devices:\n') |
277 descriptions = all_devices.pMap(lambda d: d.build_description).pGet(None) | 288 descriptions = all_devices.pMap(lambda d: d.build_description).pGet(None) |
278 for d, desc in zip(devices, descriptions): | 289 for d, desc in zip(devices, descriptions): |
279 msg += ' %s (%s)\n' % (d, desc) | 290 msg += ' %s (%s)\n' % (d, desc) |
280 raise Exception(msg) | 291 raise Exception(msg) |
281 | 292 |
282 apk = apk_helper.ToHelper(args.apk_path) | 293 apk = apk_helper.ToHelper(args.apk_path) |
283 if args.uninstall: | 294 if args.uninstall: |
284 Uninstall(device, apk.GetPackageName()) | 295 Uninstall(device, apk.GetPackageName(), enable_device_cache=args.cache) |
285 else: | 296 else: |
286 Install(device, apk, split_globs=args.splits, native_libs=args.native_libs, | 297 Install(device, apk, split_globs=args.splits, native_libs=args.native_libs, |
287 dex_files=args.dex_files, enable_device_cache=args.cache, | 298 dex_files=args.dex_files, enable_device_cache=args.cache, |
288 use_concurrency=args.threading, | 299 use_concurrency=args.threading, |
289 show_proguard_warning=args.show_proguard_warning) | 300 show_proguard_warning=args.show_proguard_warning) |
290 | 301 |
291 | 302 |
292 if __name__ == '__main__': | 303 if __name__ == '__main__': |
293 sys.exit(main()) | 304 sys.exit(main()) |
OLD | NEW |