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

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

Issue 1498593003: GN(android): Distinguish java_binary from java_library in build_config (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@build_config_barriers
Patch Set: Created 5 years 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/internal_rules.gni » ('j') | no next file with comments »
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 2014 The Chromium Authors. All rights reserved. 3 # Copyright 2014 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 """Writes a build_config file. 7 """Writes a build_config file.
8 8
9 The build_config file for a target is a json file containing information about 9 The build_config file for a target is a json file containing information about
10 how to build that target based on the target's dependencies. This includes 10 how to build that target based on the target's dependencies. This includes
(...skipping 21 matching lines...) Expand all
32 import sys 32 import sys
33 import xml.dom.minidom 33 import xml.dom.minidom
34 34
35 from util import build_utils 35 from util import build_utils
36 from util import md5_check 36 from util import md5_check
37 37
38 import write_ordered_libraries 38 import write_ordered_libraries
39 39
40 40
41 # Types that should never be used as a dependency of another build config. 41 # Types that should never be used as a dependency of another build config.
42 _ROOT_TYPES = ('android_apk', 'deps_dex', 'resource_rewriter') 42 _ROOT_TYPES = ('android_apk', 'deps_dex', 'java_binary', 'resource_rewriter')
43 # Types that should not allow code deps to pass through. 43 # Types that should not allow code deps to pass through.
44 _RESOURCE_TYPES = ('android_assets', 'android_resources') 44 _RESOURCE_TYPES = ('android_assets', 'android_resources')
45 45
46 46
47 class AndroidManifest(object): 47 class AndroidManifest(object):
48 def __init__(self, path): 48 def __init__(self, path):
49 self.path = path 49 self.path = path
50 dom = xml.dom.minidom.parse(path) 50 dom = xml.dom.minidom.parse(path)
51 manifests = dom.getElementsByTagName('manifest') 51 manifests = dom.getElementsByTagName('manifest')
52 assert len(manifests) == 1 52 assert len(manifests) == 1
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 help='Whether proguard is enabled for this apk.') 216 help='Whether proguard is enabled for this apk.')
217 parser.add_option('--proguard-info', 217 parser.add_option('--proguard-info',
218 help='Path to the proguard .info output for this apk.') 218 help='Path to the proguard .info output for this apk.')
219 219
220 options, args = parser.parse_args(argv) 220 options, args = parser.parse_args(argv)
221 221
222 if args: 222 if args:
223 parser.error('No positional arguments should be given.') 223 parser.error('No positional arguments should be given.')
224 224
225 required_options_map = { 225 required_options_map = {
226 'java_binary': ['build_config', 'jar_path'],
226 'java_library': ['build_config', 'jar_path'], 227 'java_library': ['build_config', 'jar_path'],
227 'android_assets': ['build_config'], 228 'android_assets': ['build_config'],
228 'android_resources': ['build_config', 'resources_zip'], 229 'android_resources': ['build_config', 'resources_zip'],
229 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'], 230 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'],
230 'deps_dex': ['build_config', 'dex_path'], 231 'deps_dex': ['build_config', 'dex_path'],
231 'resource_rewriter': ['build_config'] 232 'resource_rewriter': ['build_config']
232 } 233 }
233 required_options = required_options_map.get(options.type) 234 required_options = required_options_map.get(options.type)
234 if not required_options: 235 if not required_options:
235 raise Exception('Unknown type: <%s>' % options.type) 236 raise Exception('Unknown type: <%s>' % options.type)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 config = { 284 config = {
284 'deps_info': { 285 'deps_info': {
285 'name': os.path.basename(options.build_config), 286 'name': os.path.basename(options.build_config),
286 'path': options.build_config, 287 'path': options.build_config,
287 'type': options.type, 288 'type': options.type,
288 'deps_configs': direct_deps_config_paths 289 'deps_configs': direct_deps_config_paths
289 } 290 }
290 } 291 }
291 deps_info = config['deps_info'] 292 deps_info = config['deps_info']
292 293
293 if (options.type == 'java_library' and not options.bypass_platform_checks): 294 if (options.type in ('java_binary', 'java_library') and
295 not options.bypass_platform_checks):
294 deps_info['requires_android'] = options.requires_android 296 deps_info['requires_android'] = options.requires_android
295 deps_info['supports_android'] = options.supports_android 297 deps_info['supports_android'] = options.supports_android
296 298
297 deps_require_android = (all_resources_deps + 299 deps_require_android = (all_resources_deps +
298 [d['name'] for d in all_library_deps if d['requires_android']]) 300 [d['name'] for d in all_library_deps if d['requires_android']])
299 deps_not_support_android = ( 301 deps_not_support_android = (
300 [d['name'] for d in all_library_deps if not d['supports_android']]) 302 [d['name'] for d in all_library_deps if not d['supports_android']])
301 303
302 if deps_require_android and not options.requires_android: 304 if deps_require_android and not options.requires_android:
303 raise Exception('Some deps require building for the Android platform: ' + 305 raise Exception('Some deps require building for the Android platform: ' +
304 str(deps_require_android)) 306 str(deps_require_android))
305 307
306 if deps_not_support_android and options.supports_android: 308 if deps_not_support_android and options.supports_android:
307 raise Exception('Not all deps support the Android platform: ' + 309 raise Exception('Not all deps support the Android platform: ' +
308 str(deps_not_support_android)) 310 str(deps_not_support_android))
309 311
310 if options.type in ('java_library', 'android_apk'): 312 if options.type in ('java_binary', 'java_library', 'android_apk'):
311 javac_classpath = [c['jar_path'] for c in direct_library_deps] 313 javac_classpath = [c['jar_path'] for c in direct_library_deps]
312 java_full_classpath = [c['jar_path'] for c in all_library_deps] 314 java_full_classpath = [c['jar_path'] for c in all_library_deps]
313 deps_info['resources_deps'] = [c['path'] for c in all_resources_deps] 315 deps_info['resources_deps'] = [c['path'] for c in all_resources_deps]
314 deps_info['jar_path'] = options.jar_path 316 deps_info['jar_path'] = options.jar_path
315 if options.type == 'android_apk' or options.supports_android: 317 if options.type == 'android_apk' or options.supports_android:
316 deps_info['dex_path'] = options.dex_path 318 deps_info['dex_path'] = options.dex_path
317 if options.type == 'android_apk': 319 if options.type == 'android_apk':
318 deps_info['apk_path'] = options.apk_path 320 deps_info['apk_path'] = options.apk_path
319 config['javac'] = { 321 config['javac'] = {
320 'classpath': javac_classpath, 322 'classpath': javac_classpath,
321 } 323 }
322 config['java'] = { 324 config['java'] = {
323 'full_classpath': java_full_classpath 325 'full_classpath': java_full_classpath
324 } 326 }
325 327
326 if options.type == 'java_library': 328 if options.type in ('java_binary', 'java_library'):
327 # Only resources might have srcjars (normal srcjar targets are listed in 329 # Only resources might have srcjars (normal srcjar targets are listed in
328 # srcjar_deps). A resource's srcjar contains the R.java file for those 330 # srcjar_deps). A resource's srcjar contains the R.java file for those
329 # resources, and (like Android's default build system) we allow a library to 331 # resources, and (like Android's default build system) we allow a library to
330 # refer to the resources in any of its dependents. 332 # refer to the resources in any of its dependents.
331 config['javac']['srcjars'] = [ 333 config['javac']['srcjars'] = [
332 c['srcjar'] for c in direct_resources_deps if 'srcjar' in c] 334 c['srcjar'] for c in direct_resources_deps if 'srcjar' in c]
333 335
334 if options.type == 'android_apk': 336 if options.type == 'android_apk':
335 # Apks will get their resources srcjar explicitly passed to the java step. 337 # Apks will get their resources srcjar explicitly passed to the java step.
336 config['javac']['srcjars'] = [] 338 config['javac']['srcjars'] = []
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 build_utils.WriteJson(config, options.build_config, only_if_changed=True) 472 build_utils.WriteJson(config, options.build_config, only_if_changed=True)
471 473
472 if options.depfile: 474 if options.depfile:
473 build_utils.WriteDepfile( 475 build_utils.WriteDepfile(
474 options.depfile, 476 options.depfile,
475 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) 477 deps.AllConfigPaths() + build_utils.GetPythonDependencies())
476 478
477 479
478 if __name__ == '__main__': 480 if __name__ == '__main__':
479 sys.exit(main(sys.argv[1:])) 481 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698