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 |
11 import logging | 11 import logging |
12 import os | 12 import os |
13 import posixpath | 13 import posixpath |
14 import shutil | 14 import shutil |
15 import sys | 15 import sys |
| 16 import zipfile |
16 | 17 |
17 sys.path.append( | 18 sys.path.append( |
18 os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))) | 19 os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))) |
19 import devil_chromium | 20 import devil_chromium |
20 from devil.android import apk_helper | 21 from devil.android import apk_helper |
21 from devil.android import device_utils | 22 from devil.android import device_utils |
22 from devil.android import device_errors | 23 from devil.android import device_errors |
23 from devil.android.sdk import version_codes | 24 from devil.android.sdk import version_codes |
24 from devil.utils import reraiser_thread | 25 from devil.utils import reraiser_thread |
25 from pylib import constants | 26 from pylib import constants |
(...skipping 30 matching lines...) Expand all Loading... |
56 f() | 57 f() |
57 timer.Stop(log=False) | 58 timer.Stop(log=False) |
58 return timer | 59 return timer |
59 | 60 |
60 | 61 |
61 def _GetDeviceIncrementalDir(package): | 62 def _GetDeviceIncrementalDir(package): |
62 """Returns the device path to put incremental files for the given package.""" | 63 """Returns the device path to put incremental files for the given package.""" |
63 return '/data/local/tmp/incremental-app-%s' % package | 64 return '/data/local/tmp/incremental-app-%s' % package |
64 | 65 |
65 | 66 |
| 67 def _HasClasses(jar_path): |
| 68 """Returns whether the given jar contains classes.dex.""" |
| 69 with zipfile.ZipFile(jar_path) as jar: |
| 70 return 'classes.dex' in jar.namelist() |
| 71 |
| 72 |
66 def Uninstall(device, package, enable_device_cache=False): | 73 def Uninstall(device, package, enable_device_cache=False): |
67 """Uninstalls and removes all incremental files for the given package.""" | 74 """Uninstalls and removes all incremental files for the given package.""" |
68 main_timer = time_profile.TimeProfile() | 75 main_timer = time_profile.TimeProfile() |
69 device.Uninstall(package) | 76 device.Uninstall(package) |
70 if enable_device_cache: | 77 if enable_device_cache: |
71 # Uninstall is rare, so just wipe the cache in this case. | 78 # Uninstall is rare, so just wipe the cache in this case. |
72 cache_path = _DeviceCachePath(device) | 79 cache_path = _DeviceCachePath(device) |
73 if os.path.exists(cache_path): | 80 if os.path.exists(cache_path): |
74 os.unlink(cache_path) | 81 os.unlink(cache_path) |
75 device.RunShellCommand(['rm', '-rf', _GetDeviceIncrementalDir(package)], | 82 device.RunShellCommand(['rm', '-rf', _GetDeviceIncrementalDir(package)], |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 138 |
132 if dex_files: | 139 if dex_files: |
133 push_dex_timer.Start() | 140 push_dex_timer.Start() |
134 # Put all .dex files to be pushed into a temporary directory so that we | 141 # Put all .dex files to be pushed into a temporary directory so that we |
135 # can use delete_device_stale=True. | 142 # can use delete_device_stale=True. |
136 with build_utils.TempDir() as temp_dir: | 143 with build_utils.TempDir() as temp_dir: |
137 device_dex_dir = posixpath.join(device_incremental_dir, 'dex') | 144 device_dex_dir = posixpath.join(device_incremental_dir, 'dex') |
138 # Ensure no two files have the same name. | 145 # Ensure no two files have the same name. |
139 transformed_names = _TransformDexPaths(dex_files) | 146 transformed_names = _TransformDexPaths(dex_files) |
140 for src_path, dest_name in zip(dex_files, transformed_names): | 147 for src_path, dest_name in zip(dex_files, transformed_names): |
141 shutil.copy(src_path, os.path.join(temp_dir, dest_name)) | 148 # Binary targets with no extra classes create .dex.jar without a |
| 149 # classes.dex (which Android chokes on). |
| 150 if _HasClasses(src_path): |
| 151 shutil.copy(src_path, os.path.join(temp_dir, dest_name)) |
142 device.PushChangedFiles([(temp_dir, device_dex_dir)], | 152 device.PushChangedFiles([(temp_dir, device_dex_dir)], |
143 delete_device_stale=True) | 153 delete_device_stale=True) |
144 push_dex_timer.Stop(log=False) | 154 push_dex_timer.Stop(log=False) |
145 | 155 |
146 def check_selinux(): | 156 def check_selinux(): |
147 # Marshmallow has no filesystem access whatsoever. It might be possible to | 157 # Marshmallow has no filesystem access whatsoever. It might be possible to |
148 # get things working on Lollipop, but attempts so far have failed. | 158 # get things working on Lollipop, but attempts so far have failed. |
149 # http://crbug.com/558818 | 159 # http://crbug.com/558818 |
150 has_selinux = device.build_version_sdk >= version_codes.LOLLIPOP | 160 has_selinux = device.build_version_sdk >= version_codes.LOLLIPOP |
151 if has_selinux and apk.HasIsolatedProcesses(): | 161 if has_selinux and apk.HasIsolatedProcesses(): |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 Uninstall(device, apk.GetPackageName(), enable_device_cache=args.cache) | 305 Uninstall(device, apk.GetPackageName(), enable_device_cache=args.cache) |
296 else: | 306 else: |
297 Install(device, apk, split_globs=args.splits, native_libs=args.native_libs, | 307 Install(device, apk, split_globs=args.splits, native_libs=args.native_libs, |
298 dex_files=args.dex_files, enable_device_cache=args.cache, | 308 dex_files=args.dex_files, enable_device_cache=args.cache, |
299 use_concurrency=args.threading, | 309 use_concurrency=args.threading, |
300 show_proguard_warning=args.show_proguard_warning) | 310 show_proguard_warning=args.show_proguard_warning) |
301 | 311 |
302 | 312 |
303 if __name__ == '__main__': | 313 if __name__ == '__main__': |
304 sys.exit(main()) | 314 sys.exit(main()) |
OLD | NEW |