OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 26 matching lines...) Expand all Loading... |
319 # overrides are done correctly. | 335 # overrides are done correctly. |
320 all_resources_deps.reverse() | 336 all_resources_deps.reverse() |
321 | 337 |
322 if options.type == 'android_apk' and options.tested_apk_config: | 338 if options.type == 'android_apk' and options.tested_apk_config: |
323 tested_apk_deps = Deps([options.tested_apk_config]) | 339 tested_apk_deps = Deps([options.tested_apk_config]) |
324 tested_apk_resources_deps = tested_apk_deps.All('android_resources') | 340 tested_apk_resources_deps = tested_apk_deps.All('android_resources') |
325 all_resources_deps = [ | 341 all_resources_deps = [ |
326 d for d in all_resources_deps if not d in tested_apk_resources_deps] | 342 d for d in all_resources_deps if not d in tested_apk_resources_deps] |
327 | 343 |
328 # Initialize some common config. | 344 # Initialize some common config. |
| 345 # Any value that needs to be queryable by dependents must go within deps_info. |
329 config = { | 346 config = { |
330 'deps_info': { | 347 'deps_info': { |
331 'name': os.path.basename(options.build_config), | 348 'name': os.path.basename(options.build_config), |
332 'path': options.build_config, | 349 'path': options.build_config, |
333 'type': options.type, | 350 'type': options.type, |
334 'deps_configs': direct_deps_config_paths | 351 'deps_configs': direct_deps_config_paths |
335 } | 352 }, |
| 353 # Info needed only by generate_gradle.py. |
| 354 'gradle': {} |
336 } | 355 } |
337 deps_info = config['deps_info'] | 356 deps_info = config['deps_info'] |
| 357 gradle = config['gradle'] |
| 358 |
| 359 # Required for generating gradle files. |
| 360 if options.type == 'java_library': |
| 361 deps_info['is_prebuilt'] = is_java_prebuilt |
| 362 |
| 363 if options.android_manifest: |
| 364 gradle['android_manifest'] = options.android_manifest |
| 365 if options.type in ('java_binary', 'java_library', 'android_apk'): |
| 366 if options.java_sources_file: |
| 367 gradle['java_sources_file'] = options.java_sources_file |
| 368 gradle['dependent_prebuilt_jars'] = deps.PrebuiltJarPaths() |
| 369 gradle['dependent_projects'] = ( |
| 370 [c['path'] for c in direct_library_deps if not c['is_prebuilt']]) |
| 371 |
338 | 372 |
339 if (options.type in ('java_binary', 'java_library') and | 373 if (options.type in ('java_binary', 'java_library') and |
340 not options.bypass_platform_checks): | 374 not options.bypass_platform_checks): |
341 deps_info['requires_android'] = options.requires_android | 375 deps_info['requires_android'] = options.requires_android |
342 deps_info['supports_android'] = options.supports_android | 376 deps_info['supports_android'] = options.supports_android |
343 | 377 |
344 deps_require_android = (all_resources_deps + | 378 deps_require_android = (all_resources_deps + |
345 [d['name'] for d in all_library_deps if d['requires_android']]) | 379 [d['name'] for d in all_library_deps if d['requires_android']]) |
346 deps_not_support_android = ( | 380 deps_not_support_android = ( |
347 [d['name'] for d in all_library_deps if not d['supports_android']]) | 381 [d['name'] for d in all_library_deps if not d['supports_android']]) |
(...skipping 13 matching lines...) Expand all Loading... |
361 deps_info['dex_path'] = options.dex_path | 395 deps_info['dex_path'] = options.dex_path |
362 if options.type == 'android_apk': | 396 if options.type == 'android_apk': |
363 deps_info['apk_path'] = options.apk_path | 397 deps_info['apk_path'] = options.apk_path |
364 deps_info['incremental_apk_path'] = options.incremental_apk_path | 398 deps_info['incremental_apk_path'] = options.incremental_apk_path |
365 deps_info['incremental_install_script_path'] = ( | 399 deps_info['incremental_install_script_path'] = ( |
366 options.incremental_install_script_path) | 400 options.incremental_install_script_path) |
367 | 401 |
368 # Classpath values filled in below (after applying tested_apk_config). | 402 # Classpath values filled in below (after applying tested_apk_config). |
369 config['javac'] = {} | 403 config['javac'] = {} |
370 | 404 |
| 405 |
371 if options.type in ('java_binary', 'java_library'): | 406 if options.type in ('java_binary', 'java_library'): |
372 # Only resources might have srcjars (normal srcjar targets are listed in | 407 # Only resources might have srcjars (normal srcjar targets are listed in |
373 # srcjar_deps). A resource's srcjar contains the R.java file for those | 408 # srcjar_deps). A resource's srcjar contains the R.java file for those |
374 # resources, and (like Android's default build system) we allow a library to | 409 # resources, and (like Android's default build system) we allow a library to |
375 # refer to the resources in any of its dependents. | 410 # refer to the resources in any of its dependents. |
376 config['javac']['srcjars'] = [ | 411 config['javac']['srcjars'] = [ |
377 c['srcjar'] for c in all_resources_deps if 'srcjar' in c] | 412 c['srcjar'] for c in all_resources_deps if 'srcjar' in c] |
378 | 413 |
379 # Used to strip out R.class for android_prebuilt()s. | 414 # Used to strip out R.class for android_prebuilt()s. |
380 if options.type == 'java_library': | 415 if options.type == 'java_library': |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 _MergeAssets(deps.All('android_assets'))) | 586 _MergeAssets(deps.All('android_assets'))) |
552 | 587 |
553 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 588 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
554 | 589 |
555 if options.depfile: | 590 if options.depfile: |
556 build_utils.WriteDepfile(options.depfile, all_inputs) | 591 build_utils.WriteDepfile(options.depfile, all_inputs) |
557 | 592 |
558 | 593 |
559 if __name__ == '__main__': | 594 if __name__ == '__main__': |
560 sys.exit(main(sys.argv[1:])) | 595 sys.exit(main(sys.argv[1:])) |
OLD | NEW |