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

Side by Side Diff: build/android/gyp/apkbuilder.py

Issue 1828523002: Support packaging secondary abi native libraries in APK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | build/config/android/config.gni » ('j') | build/config/android/config.gni » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2015 The Chromium Authors. All rights reserved. 3 # Copyright (c) 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 """Adds the code parts to a resource APK.""" 7 """Adds the code parts to a resource APK."""
8 8
9 import argparse 9 import argparse
10 import itertools 10 import itertools
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 parser.add_argument('--output-apk', 43 parser.add_argument('--output-apk',
44 help='Path to the output file', 44 help='Path to the output file',
45 required=True) 45 required=True)
46 parser.add_argument('--dex-file', 46 parser.add_argument('--dex-file',
47 help='Path to the classes.dex to use') 47 help='Path to the classes.dex to use')
48 parser.add_argument('--native-libs', 48 parser.add_argument('--native-libs',
49 action='append', 49 action='append',
50 help='GYP-list of native libraries to include. ' 50 help='GYP-list of native libraries to include. '
51 'Can be specified multiple times.', 51 'Can be specified multiple times.',
52 default=[]) 52 default=[])
53 parser.add_argument('--secondary-native-libs',
54 action='append',
55 help='The libraries for secondary android-abi. '
agrieve 2016/03/23 18:11:19 You should say that this is a GYP-list
michaelbai 2016/03/23 18:55:33 Done.
56 'Can be specified multiple times.',
57 default=[])
53 parser.add_argument('--android-abi', 58 parser.add_argument('--android-abi',
54 help='Android architecture to use for native libraries') 59 help='Android architecture to use for native libraries')
60 parser.add_argument('--secondary-android-abi',
61 help='The secondary Android architecture to use for'
62 'secondary native libraries')
55 parser.add_argument('--native-lib-placeholders', 63 parser.add_argument('--native-lib-placeholders',
56 help='GYP-list of native library placeholders to add.', 64 help='GYP-list of native library placeholders to add.',
57 default='[]') 65 default='[]')
58 parser.add_argument('--emma-device-jar', 66 parser.add_argument('--emma-device-jar',
59 help='Path to emma_device.jar to include.') 67 help='Path to emma_device.jar to include.')
60 parser.add_argument('--uncompress-shared-libraries', 68 parser.add_argument('--uncompress-shared-libraries',
61 action='store_true', 69 action='store_true',
62 help='Uncompress shared libraries') 70 help='Uncompress shared libraries')
63 options = parser.parse_args(args) 71 options = parser.parse_args(args)
64 options.assets = build_utils.ParseGypList(options.assets) 72 options.assets = build_utils.ParseGypList(options.assets)
65 options.uncompressed_assets = build_utils.ParseGypList( 73 options.uncompressed_assets = build_utils.ParseGypList(
66 options.uncompressed_assets) 74 options.uncompressed_assets)
67 options.native_lib_placeholders = build_utils.ParseGypList( 75 options.native_lib_placeholders = build_utils.ParseGypList(
68 options.native_lib_placeholders) 76 options.native_lib_placeholders)
69 all_libs = [] 77 all_libs = []
70 for gyp_list in options.native_libs: 78 for gyp_list in options.native_libs:
71 all_libs.extend(build_utils.ParseGypList(gyp_list)) 79 all_libs.extend(build_utils.ParseGypList(gyp_list))
72 options.native_libs = all_libs 80 options.native_libs = all_libs
81 secondary_libs = []
82 for gyp_list in options.secondary_native_libs:
83 secondary_libs.extend(build_utils.ParseGypList(gyp_list))
84 options.secondary_native_libs = secondary_libs
85
73 86
74 if not options.android_abi and (options.native_libs or 87 if not options.android_abi and (options.native_libs or
75 options.native_lib_placeholders): 88 options.native_lib_placeholders):
76 raise Exception('Must specify --android-abi with --native-libs') 89 raise Exception('Must specify --android-abi with --native-libs')
90 if not options.secondary_android_abi and options.secondary_native_libs:
91 raise Exception('Must specify --secondary-android-abi with'
92 ' --secondary-native-libs')
77 return options 93 return options
78 94
79 95
80 def _SplitAssetPath(path): 96 def _SplitAssetPath(path):
81 """Returns (src, dest) given an asset path in the form src[:dest].""" 97 """Returns (src, dest) given an asset path in the form src[:dest]."""
82 path_parts = path.split(':') 98 path_parts = path.split(':')
83 src_path = path_parts[0] 99 src_path = path_parts[0]
84 if len(path_parts) > 1: 100 if len(path_parts) > 1:
85 dest_path = path_parts[1] 101 dest_path = path_parts[1]
86 else: 102 else:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 build_utils.AddToZipHermetic(apk, apk_path, src_path=src_path, 152 build_utils.AddToZipHermetic(apk, apk_path, src_path=src_path,
137 compress=compress) 153 compress=compress)
138 154
139 155
140 def _CreateAssetsList(path_tuples): 156 def _CreateAssetsList(path_tuples):
141 """Returns a newline-separated list of asset paths for the given paths.""" 157 """Returns a newline-separated list of asset paths for the given paths."""
142 dests = sorted(t[1] for t in path_tuples) 158 dests = sorted(t[1] for t in path_tuples)
143 return '\n'.join(dests) + '\n' 159 return '\n'.join(dests) + '\n'
144 160
145 161
162 def _AddNativeLibraries(out_apk, native_libs, android_abi, uncompress):
163 """Add native libraries to APK."""
164 for path in native_libs:
165 basename = os.path.basename(path)
166 apk_path = 'lib/%s/%s' % (android_abi, basename)
167
168 compress = None
169 if (uncompress and os.path.splitext(basename)[1] == '.so'):
170 compress = False
171
172 build_utils.AddToZipHermetic(out_apk,
173 apk_path,
174 src_path=path,
175 compress=compress)
176
177
146 def main(args): 178 def main(args):
147 args = build_utils.ExpandFileArgs(args) 179 args = build_utils.ExpandFileArgs(args)
148 options = _ParseArgs(args) 180 options = _ParseArgs(args)
149 181
150 native_libs = sorted(options.native_libs) 182 native_libs = sorted(options.native_libs)
151 183
152 input_paths = [options.resource_apk, __file__] + native_libs 184 input_paths = [options.resource_apk, __file__] + native_libs
185
186 secondary_native_libs = []
187 if options.secondary_native_libs:
188 secondary_native_libs = sorted(options.secondary_native_libs)
189 input_paths += secondary_native_libs
190
153 if options.dex_file: 191 if options.dex_file:
154 input_paths.append(options.dex_file) 192 input_paths.append(options.dex_file)
155 193
156 if options.emma_device_jar: 194 if options.emma_device_jar:
157 input_paths.append(options.emma_device_jar) 195 input_paths.append(options.emma_device_jar)
158 196
159 input_strings = [options.android_abi, 197 input_strings = [options.android_abi,
160 options.native_lib_placeholders, 198 options.native_lib_placeholders,
161 options.uncompress_shared_libraries] 199 options.uncompress_shared_libraries]
162 200
201 if options.secondary_android_abi:
202 input_strings.append(options.secondary_android_abi)
203
163 _assets = _ExpandPaths(options.assets) 204 _assets = _ExpandPaths(options.assets)
164 _uncompressed_assets = _ExpandPaths(options.uncompressed_assets) 205 _uncompressed_assets = _ExpandPaths(options.uncompressed_assets)
165 206
166 for src_path, dest_path in itertools.chain(_assets, _uncompressed_assets): 207 for src_path, dest_path in itertools.chain(_assets, _uncompressed_assets):
167 input_paths.append(src_path) 208 input_paths.append(src_path)
168 input_strings.append(dest_path) 209 input_strings.append(dest_path)
169 210
170 def on_stale_md5(): 211 def on_stale_md5():
171 tmp_apk = options.output_apk + '.tmp' 212 tmp_apk = options.output_apk + '.tmp'
172 try: 213 try:
(...skipping 28 matching lines...) Expand all
201 # 3. Dex files 242 # 3. Dex files
202 if options.dex_file and options.dex_file.endswith('.zip'): 243 if options.dex_file and options.dex_file.endswith('.zip'):
203 with zipfile.ZipFile(options.dex_file, 'r') as dex_zip: 244 with zipfile.ZipFile(options.dex_file, 'r') as dex_zip:
204 for dex in (d for d in dex_zip.namelist() if d.endswith('.dex')): 245 for dex in (d for d in dex_zip.namelist() if d.endswith('.dex')):
205 build_utils.AddToZipHermetic(out_apk, dex, data=dex_zip.read(dex)) 246 build_utils.AddToZipHermetic(out_apk, dex, data=dex_zip.read(dex))
206 elif options.dex_file: 247 elif options.dex_file:
207 build_utils.AddToZipHermetic(out_apk, 'classes.dex', 248 build_utils.AddToZipHermetic(out_apk, 'classes.dex',
208 src_path=options.dex_file) 249 src_path=options.dex_file)
209 250
210 # 4. Native libraries. 251 # 4. Native libraries.
211 for path in native_libs: 252 _AddNativeLibraries(out_apk,
212 basename = os.path.basename(path) 253 native_libs,
213 apk_path = 'lib/%s/%s' % (options.android_abi, basename) 254 options.android_abi,
255 options.uncompress_shared_libraries)
214 256
215 compress = None 257 if options.secondary_android_abi:
216 if (options.uncompress_shared_libraries and 258 _AddNativeLibraries(out_apk,
217 os.path.splitext(basename)[1] == '.so'): 259 secondary_native_libs,
218 compress = False 260 options.secondary_android_abi,
219 261 options.uncompress_shared_libraries)
220 build_utils.AddToZipHermetic(out_apk,
221 apk_path,
222 src_path=path,
223 compress=compress)
224 262
225 for name in sorted(options.native_lib_placeholders): 263 for name in sorted(options.native_lib_placeholders):
226 # Empty libs files are ignored by md5check, but rezip requires them 264 # Empty libs files are ignored by md5check, but rezip requires them
227 # to be empty in order to identify them as placeholders. 265 # to be empty in order to identify them as placeholders.
228 apk_path = 'lib/%s/%s' % (options.android_abi, name) 266 apk_path = 'lib/%s/%s' % (options.android_abi, name)
229 build_utils.AddToZipHermetic(out_apk, apk_path, data='') 267 build_utils.AddToZipHermetic(out_apk, apk_path, data='')
230 268
231 # 5. Resources 269 # 5. Resources
232 for info in resource_infos[1:]: 270 for info in resource_infos[1:]:
233 copy_resource(info) 271 copy_resource(info)
(...skipping 25 matching lines...) Expand all
259 build_utils.CallAndWriteDepfileIfStale( 297 build_utils.CallAndWriteDepfileIfStale(
260 on_stale_md5, 298 on_stale_md5,
261 options, 299 options,
262 input_paths=input_paths, 300 input_paths=input_paths,
263 input_strings=input_strings, 301 input_strings=input_strings,
264 output_paths=[options.output_apk]) 302 output_paths=[options.output_apk])
265 303
266 304
267 if __name__ == '__main__': 305 if __name__ == '__main__':
268 main(sys.argv[1:]) 306 main(sys.argv[1:])
OLDNEW
« no previous file with comments | « no previous file | build/config/android/config.gni » ('j') | build/config/android/config.gni » ('J')

Powered by Google App Engine
This is Rietveld 408576698