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

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

Issue 2127013002: 🎣 Reland of Make Android .build_configs aware of prebuilts and java sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix GN not knowing the list of inputs in javac and emma rules Created 4 years, 5 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 | « build/android/gyp/javac.py ('k') | 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 def AllConfigPaths(self): 125 def AllConfigPaths(self):
126 return self.all_deps_config_paths 126 return self.all_deps_config_paths
127 127
128 def RemoveNonDirectDep(self, path): 128 def RemoveNonDirectDep(self, path):
129 if path in self.direct_deps_config_paths: 129 if path in self.direct_deps_config_paths:
130 raise Exception('Cannot remove direct dep.') 130 raise Exception('Cannot remove direct dep.')
131 self.all_deps_config_paths.remove(path) 131 self.all_deps_config_paths.remove(path)
132 self.all_deps_configs.remove(GetDepConfig(path)) 132 self.all_deps_configs.remove(GetDepConfig(path))
133 133
134 def PrebuiltJarPaths(self):
135 ret = []
136 for config in self.Direct('java_library'):
137 if config['is_prebuilt']:
138 ret.append(config['jar_path'])
139 ret.extend(Deps(config['deps_configs']).PrebuiltJarPaths())
140 return ret
141
142
134 def _MergeAssets(all_assets): 143 def _MergeAssets(all_assets):
135 """Merges all assets from the given deps. 144 """Merges all assets from the given deps.
136 145
137 Returns: 146 Returns:
138 A tuple of lists: (compressed, uncompressed) 147 A tuple of lists: (compressed, uncompressed)
139 Each tuple entry is a list of "srcPath:zipPath". srcPath is the path of the 148 Each tuple entry is a list of "srcPath:zipPath". srcPath is the path of the
140 asset to add, and zipPath is the location within the zip (excluding assets/ 149 asset to add, and zipPath is the location within the zip (excluding assets/
141 prefix) 150 prefix)
142 """ 151 """
143 compressed = {} 152 compressed = {}
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 parser.add_option('--asset-sources', help='List of asset sources.') 228 parser.add_option('--asset-sources', help='List of asset sources.')
220 parser.add_option('--asset-renaming-sources', 229 parser.add_option('--asset-renaming-sources',
221 help='List of asset sources with custom destinations.') 230 help='List of asset sources with custom destinations.')
222 parser.add_option('--asset-renaming-destinations', 231 parser.add_option('--asset-renaming-destinations',
223 help='List of asset custom destinations.') 232 help='List of asset custom destinations.')
224 parser.add_option('--disable-asset-compression', action='store_true', 233 parser.add_option('--disable-asset-compression', action='store_true',
225 help='Whether to disable asset compression.') 234 help='Whether to disable asset compression.')
226 235
227 # java library options 236 # java library options
228 parser.add_option('--jar-path', help='Path to target\'s jar output.') 237 parser.add_option('--jar-path', help='Path to target\'s jar output.')
238 parser.add_option('--java-sources-file', help='Path to .sources file')
229 parser.add_option('--supports-android', action='store_true', 239 parser.add_option('--supports-android', action='store_true',
230 help='Whether this library supports running on the Android platform.') 240 help='Whether this library supports running on the Android platform.')
231 parser.add_option('--requires-android', action='store_true', 241 parser.add_option('--requires-android', action='store_true',
232 help='Whether this library requires running on the Android platform.') 242 help='Whether this library requires running on the Android platform.')
233 parser.add_option('--bypass-platform-checks', action='store_true', 243 parser.add_option('--bypass-platform-checks', action='store_true',
234 help='Bypass checks for support/require Android platform.') 244 help='Bypass checks for support/require Android platform.')
235 245
236 # android library options 246 # android library options
237 parser.add_option('--dex-path', help='Path to target\'s dex output.') 247 parser.add_option('--dex-path', help='Path to target\'s dex output.')
238 248
(...skipping 21 matching lines...) Expand all
260 help='Whether there is alternative-locale-resource in direct deps') 270 help='Whether there is alternative-locale-resource in direct deps')
261 271
262 options, args = parser.parse_args(argv) 272 options, args = parser.parse_args(argv)
263 273
264 if args: 274 if args:
265 parser.error('No positional arguments should be given.') 275 parser.error('No positional arguments should be given.')
266 276
267 required_options_map = { 277 required_options_map = {
268 'java_binary': ['build_config', 'jar_path'], 278 'java_binary': ['build_config', 'jar_path'],
269 'java_library': ['build_config', 'jar_path'], 279 'java_library': ['build_config', 'jar_path'],
280 'java_prebuilt': ['build_config', 'jar_path'],
270 'android_assets': ['build_config'], 281 'android_assets': ['build_config'],
271 'android_resources': ['build_config', 'resources_zip'], 282 'android_resources': ['build_config', 'resources_zip'],
272 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'], 283 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'],
273 'deps_dex': ['build_config', 'dex_path'], 284 'deps_dex': ['build_config', 'dex_path'],
274 'resource_rewriter': ['build_config'], 285 'resource_rewriter': ['build_config'],
275 'group': ['build_config'], 286 'group': ['build_config'],
276 } 287 }
277 required_options = required_options_map.get(options.type) 288 required_options = required_options_map.get(options.type)
278 if not required_options: 289 if not required_options:
279 raise Exception('Unknown type: <%s>' % options.type) 290 raise Exception('Unknown type: <%s>' % options.type)
280 291
281 build_utils.CheckOptions(options, parser, required_options) 292 build_utils.CheckOptions(options, parser, required_options)
282 293
294 # Java prebuilts are the same as libraries except for in gradle files.
295 is_java_prebuilt = options.type == 'java_prebuilt'
296 if is_java_prebuilt:
297 options.type = 'java_library'
298
283 if options.type == 'java_library': 299 if options.type == 'java_library':
284 if options.supports_android and not options.dex_path: 300 if options.supports_android and not options.dex_path:
285 raise Exception('java_library that supports Android requires a dex path.') 301 raise Exception('java_library that supports Android requires a dex path.')
286 302
287 if options.requires_android and not options.supports_android: 303 if options.requires_android and not options.supports_android:
288 raise Exception( 304 raise Exception(
289 '--supports-android is required when using --requires-android') 305 '--supports-android is required when using --requires-android')
290 306
291 direct_deps_config_paths = build_utils.ParseGypList(options.deps_configs) 307 direct_deps_config_paths = build_utils.ParseGypList(options.deps_configs)
292 direct_deps_config_paths = _FilterUnwantedDepsPaths(direct_deps_config_paths, 308 direct_deps_config_paths = _FilterUnwantedDepsPaths(direct_deps_config_paths,
(...skipping 25 matching lines...) Expand all
318 # overrides are done correctly. 334 # overrides are done correctly.
319 all_resources_deps.reverse() 335 all_resources_deps.reverse()
320 336
321 if options.type == 'android_apk' and options.tested_apk_config: 337 if options.type == 'android_apk' and options.tested_apk_config:
322 tested_apk_deps = Deps([options.tested_apk_config]) 338 tested_apk_deps = Deps([options.tested_apk_config])
323 tested_apk_resources_deps = tested_apk_deps.All('android_resources') 339 tested_apk_resources_deps = tested_apk_deps.All('android_resources')
324 all_resources_deps = [ 340 all_resources_deps = [
325 d for d in all_resources_deps if not d in tested_apk_resources_deps] 341 d for d in all_resources_deps if not d in tested_apk_resources_deps]
326 342
327 # Initialize some common config. 343 # Initialize some common config.
344 # Any value that needs to be queryable by dependents must go within deps_info.
328 config = { 345 config = {
329 'deps_info': { 346 'deps_info': {
330 'name': os.path.basename(options.build_config), 347 'name': os.path.basename(options.build_config),
331 'path': options.build_config, 348 'path': options.build_config,
332 'type': options.type, 349 'type': options.type,
333 'deps_configs': direct_deps_config_paths 350 'deps_configs': direct_deps_config_paths
334 } 351 },
352 # Info needed only by generate_gradle.py.
353 'gradle': {}
335 } 354 }
336 deps_info = config['deps_info'] 355 deps_info = config['deps_info']
356 gradle = config['gradle']
357
358 # Required for generating gradle files.
359 if options.type == 'java_library':
360 deps_info['is_prebuilt'] = is_java_prebuilt
361
362 if options.android_manifest:
363 gradle['android_manifest'] = options.android_manifest
364 if options.type in ('java_binary', 'java_library', 'android_apk'):
365 if options.java_sources_file:
366 gradle['java_sources_file'] = options.java_sources_file
367 gradle['dependent_prebuilt_jars'] = deps.PrebuiltJarPaths()
368 gradle['dependent_projects'] = (
369 [c['path'] for c in direct_library_deps if not c['is_prebuilt']])
370
337 371
338 if (options.type in ('java_binary', 'java_library') and 372 if (options.type in ('java_binary', 'java_library') and
339 not options.bypass_platform_checks): 373 not options.bypass_platform_checks):
340 deps_info['requires_android'] = options.requires_android 374 deps_info['requires_android'] = options.requires_android
341 deps_info['supports_android'] = options.supports_android 375 deps_info['supports_android'] = options.supports_android
342 376
343 deps_require_android = (all_resources_deps + 377 deps_require_android = (all_resources_deps +
344 [d['name'] for d in all_library_deps if d['requires_android']]) 378 [d['name'] for d in all_library_deps if d['requires_android']])
345 deps_not_support_android = ( 379 deps_not_support_android = (
346 [d['name'] for d in all_library_deps if not d['supports_android']]) 380 [d['name'] for d in all_library_deps if not d['supports_android']])
(...skipping 13 matching lines...) Expand all
360 deps_info['dex_path'] = options.dex_path 394 deps_info['dex_path'] = options.dex_path
361 if options.type == 'android_apk': 395 if options.type == 'android_apk':
362 deps_info['apk_path'] = options.apk_path 396 deps_info['apk_path'] = options.apk_path
363 deps_info['incremental_apk_path'] = options.incremental_apk_path 397 deps_info['incremental_apk_path'] = options.incremental_apk_path
364 deps_info['incremental_install_script_path'] = ( 398 deps_info['incremental_install_script_path'] = (
365 options.incremental_install_script_path) 399 options.incremental_install_script_path)
366 400
367 # Classpath values filled in below (after applying tested_apk_config). 401 # Classpath values filled in below (after applying tested_apk_config).
368 config['javac'] = {} 402 config['javac'] = {}
369 403
404
370 if options.type in ('java_binary', 'java_library'): 405 if options.type in ('java_binary', 'java_library'):
371 # Only resources might have srcjars (normal srcjar targets are listed in 406 # Only resources might have srcjars (normal srcjar targets are listed in
372 # srcjar_deps). A resource's srcjar contains the R.java file for those 407 # srcjar_deps). A resource's srcjar contains the R.java file for those
373 # resources, and (like Android's default build system) we allow a library to 408 # resources, and (like Android's default build system) we allow a library to
374 # refer to the resources in any of its dependents. 409 # refer to the resources in any of its dependents.
375 config['javac']['srcjars'] = [ 410 config['javac']['srcjars'] = [
376 c['srcjar'] for c in all_resources_deps if 'srcjar' in c] 411 c['srcjar'] for c in all_resources_deps if 'srcjar' in c]
377 412
378 # Used to strip out R.class for android_prebuilt()s. 413 # Used to strip out R.class for android_prebuilt()s.
379 if options.type == 'java_library': 414 if options.type == 'java_library':
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 _MergeAssets(deps.All('android_assets'))) 577 _MergeAssets(deps.All('android_assets')))
543 578
544 build_utils.WriteJson(config, options.build_config, only_if_changed=True) 579 build_utils.WriteJson(config, options.build_config, only_if_changed=True)
545 580
546 if options.depfile: 581 if options.depfile:
547 build_utils.WriteDepfile(options.depfile, all_inputs) 582 build_utils.WriteDepfile(options.depfile, all_inputs)
548 583
549 584
550 if __name__ == '__main__': 585 if __name__ == '__main__':
551 sys.exit(main(sys.argv[1:])) 586 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « build/android/gyp/javac.py ('k') | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698