| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 for path in runtime_deps_files: | 202 for path in runtime_deps_files: |
| 203 with open(path) as f: | 203 with open(path) as f: |
| 204 for line in f: | 204 for line in f: |
| 205 line = line.rstrip() | 205 line = line.rstrip() |
| 206 if not line.endswith('.so'): | 206 if not line.endswith('.so'): |
| 207 continue | 207 continue |
| 208 ret.append(os.path.normpath(line)) | 208 ret.append(os.path.normpath(line)) |
| 209 ret.reverse() | 209 ret.reverse() |
| 210 return ret | 210 return ret |
| 211 | 211 |
| 212 |
| 212 def _CreateJavaLibrariesList(library_paths): | 213 def _CreateJavaLibrariesList(library_paths): |
| 213 """ Create a java literal array with the "base" library names: | 214 """Returns a java literal array with the "base" library names: |
| 214 e.g. libfoo.so -> foo | 215 e.g. libfoo.so -> foo |
| 215 """ | 216 """ |
| 216 return ('{%s}' % ','.join(['"%s"' % s[3:-3] for s in library_paths])) | 217 return ('{%s}' % ','.join(['"%s"' % s[3:-3] for s in library_paths])) |
| 217 | 218 |
| 219 |
| 220 def _CreateJavaAssetList(assets): |
| 221 """Returns a java literal array from a list of assets in the form src:dst.""" |
| 222 return '{%s}' % ','.join(sorted(['"%s"' % a.split(':')[1] for a in assets])) |
| 223 |
| 224 |
| 218 def main(argv): | 225 def main(argv): |
| 219 parser = optparse.OptionParser() | 226 parser = optparse.OptionParser() |
| 220 build_utils.AddDepfileOption(parser) | 227 build_utils.AddDepfileOption(parser) |
| 221 parser.add_option('--build-config', help='Path to build_config output.') | 228 parser.add_option('--build-config', help='Path to build_config output.') |
| 222 parser.add_option( | 229 parser.add_option( |
| 223 '--type', | 230 '--type', |
| 224 help='Type of this target (e.g. android_library).') | 231 help='Type of this target (e.g. android_library).') |
| 225 parser.add_option( | 232 parser.add_option( |
| 226 '--deps-configs', | 233 '--deps-configs', |
| 227 help='List of paths for dependency\'s build_config files. ') | 234 help='List of paths for dependency\'s build_config files. ') |
| 228 | 235 |
| 229 # android_resources options | 236 # android_resources options |
| 230 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') | 237 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') |
| 231 parser.add_option('--resources-zip', help='Path to target\'s resources zip.') | 238 parser.add_option('--resources-zip', help='Path to target\'s resources zip.') |
| 232 parser.add_option('--r-text', help='Path to target\'s R.txt file.') | 239 parser.add_option('--r-text', help='Path to target\'s R.txt file.') |
| 233 parser.add_option('--package-name', | 240 parser.add_option('--package-name', |
| 234 help='Java package name for these resources.') | 241 help='Java package name for these resources.') |
| 235 parser.add_option('--android-manifest', help='Path to android manifest.') | 242 parser.add_option('--android-manifest', help='Path to android manifest.') |
| 236 parser.add_option('--is-locale-resource', action='store_true', | |
| 237 help='Whether it is locale resource.') | |
| 238 parser.add_option('--resource-dirs', action='append', default=[], | 243 parser.add_option('--resource-dirs', action='append', default=[], |
| 239 help='GYP-list of resource dirs') | 244 help='GYP-list of resource dirs') |
| 240 | 245 |
| 241 # android_assets options | 246 # android_assets options |
| 242 parser.add_option('--asset-sources', help='List of asset sources.') | 247 parser.add_option('--asset-sources', help='List of asset sources.') |
| 243 parser.add_option('--asset-renaming-sources', | 248 parser.add_option('--asset-renaming-sources', |
| 244 help='List of asset sources with custom destinations.') | 249 help='List of asset sources with custom destinations.') |
| 245 parser.add_option('--asset-renaming-destinations', | 250 parser.add_option('--asset-renaming-destinations', |
| 246 help='List of asset custom destinations.') | 251 help='List of asset custom destinations.') |
| 247 parser.add_option('--disable-asset-compression', action='store_true', | 252 parser.add_option('--disable-asset-compression', action='store_true', |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 | 288 |
| 284 parser.add_option('--tested-apk-config', | 289 parser.add_option('--tested-apk-config', |
| 285 help='Path to the build config of the tested apk (for an instrumentation ' | 290 help='Path to the build config of the tested apk (for an instrumentation ' |
| 286 'test apk).') | 291 'test apk).') |
| 287 parser.add_option('--proguard-enabled', action='store_true', | 292 parser.add_option('--proguard-enabled', action='store_true', |
| 288 help='Whether proguard is enabled for this apk.') | 293 help='Whether proguard is enabled for this apk.') |
| 289 parser.add_option('--proguard-configs', | 294 parser.add_option('--proguard-configs', |
| 290 help='GYP-list of proguard flag files to use in final apk.') | 295 help='GYP-list of proguard flag files to use in final apk.') |
| 291 parser.add_option('--proguard-info', | 296 parser.add_option('--proguard-info', |
| 292 help='Path to the proguard .info output for this apk.') | 297 help='Path to the proguard .info output for this apk.') |
| 293 parser.add_option('--has-alternative-locale-resource', action='store_true', | |
| 294 help='Whether there is alternative-locale-resource in direct deps') | |
| 295 parser.add_option('--fail', | 298 parser.add_option('--fail', |
| 296 help='GYP-list of error message lines to fail with.') | 299 help='GYP-list of error message lines to fail with.') |
| 297 | 300 |
| 298 options, args = parser.parse_args(argv) | 301 options, args = parser.parse_args(argv) |
| 299 | 302 |
| 300 if args: | 303 if args: |
| 301 parser.error('No positional arguments should be given.') | 304 parser.error('No positional arguments should be given.') |
| 302 if options.fail: | 305 if options.fail: |
| 303 parser.error('\n'.join(build_utils.ParseGnList(options.fail))) | 306 parser.error('\n'.join(build_utils.ParseGnList(options.fail))) |
| 304 | 307 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 332 raise Exception( | 335 raise Exception( |
| 333 '--supports-android is required when using --requires-android') | 336 '--supports-android is required when using --requires-android') |
| 334 | 337 |
| 335 direct_deps_config_paths = build_utils.ParseGnList(options.deps_configs) | 338 direct_deps_config_paths = build_utils.ParseGnList(options.deps_configs) |
| 336 direct_deps_config_paths = _FilterDepsPaths(direct_deps_config_paths, | 339 direct_deps_config_paths = _FilterDepsPaths(direct_deps_config_paths, |
| 337 options.type) | 340 options.type) |
| 338 | 341 |
| 339 deps = Deps(direct_deps_config_paths) | 342 deps = Deps(direct_deps_config_paths) |
| 340 all_inputs = deps.AllConfigPaths() | 343 all_inputs = deps.AllConfigPaths() |
| 341 | 344 |
| 342 # Remove other locale resources if there is alternative_locale_resource in | |
| 343 # direct deps. | |
| 344 if options.has_alternative_locale_resource: | |
| 345 alternative = [r['path'] for r in deps.Direct('android_resources') | |
| 346 if r.get('is_locale_resource')] | |
| 347 # We can only have one locale resources in direct deps. | |
| 348 if len(alternative) != 1: | |
| 349 raise Exception('The number of locale resource in direct deps is wrong %d' | |
| 350 % len(alternative)) | |
| 351 unwanted = [r['path'] for r in deps.All('android_resources') | |
| 352 if r.get('is_locale_resource') and r['path'] not in alternative] | |
| 353 for p in unwanted: | |
| 354 deps.RemoveNonDirectDep(p) | |
| 355 | |
| 356 | |
| 357 direct_library_deps = deps.Direct('java_library') | 345 direct_library_deps = deps.Direct('java_library') |
| 358 all_library_deps = deps.All('java_library') | 346 all_library_deps = deps.All('java_library') |
| 359 | 347 |
| 360 all_resources_deps = deps.All('android_resources') | 348 all_resources_deps = deps.All('android_resources') |
| 361 # Resources should be ordered with the highest-level dependency first so that | 349 # Resources should be ordered with the highest-level dependency first so that |
| 362 # overrides are done correctly. | 350 # overrides are done correctly. |
| 363 all_resources_deps.reverse() | 351 all_resources_deps.reverse() |
| 364 | 352 |
| 365 if options.type == 'android_apk' and options.tested_apk_config: | 353 if options.type == 'android_apk' and options.tested_apk_config: |
| 366 tested_apk_deps = Deps([options.tested_apk_config]) | 354 tested_apk_deps = Deps([options.tested_apk_config]) |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 deps_info['resources_zip'] = options.resources_zip | 466 deps_info['resources_zip'] = options.resources_zip |
| 479 if options.srcjar: | 467 if options.srcjar: |
| 480 deps_info['srcjar'] = options.srcjar | 468 deps_info['srcjar'] = options.srcjar |
| 481 if options.android_manifest: | 469 if options.android_manifest: |
| 482 manifest = AndroidManifest(options.android_manifest) | 470 manifest = AndroidManifest(options.android_manifest) |
| 483 deps_info['package_name'] = manifest.GetPackageName() | 471 deps_info['package_name'] = manifest.GetPackageName() |
| 484 if options.package_name: | 472 if options.package_name: |
| 485 deps_info['package_name'] = options.package_name | 473 deps_info['package_name'] = options.package_name |
| 486 if options.r_text: | 474 if options.r_text: |
| 487 deps_info['r_text'] = options.r_text | 475 deps_info['r_text'] = options.r_text |
| 488 if options.is_locale_resource: | |
| 489 deps_info['is_locale_resource'] = True | |
| 490 | 476 |
| 491 deps_info['resources_dirs'] = [] | 477 deps_info['resources_dirs'] = [] |
| 492 if options.resource_dirs: | 478 if options.resource_dirs: |
| 493 for gyp_list in options.resource_dirs: | 479 for gyp_list in options.resource_dirs: |
| 494 deps_info['resources_dirs'].extend(build_utils.ParseGnList(gyp_list)) | 480 deps_info['resources_dirs'].extend(build_utils.ParseGnList(gyp_list)) |
| 495 | 481 |
| 496 if options.supports_android and options.type in ('android_apk', | 482 if options.supports_android and options.type in ('android_apk', |
| 497 'java_library'): | 483 'java_library'): |
| 498 # Lint all resources that are not already linted by a dependent library. | 484 # Lint all resources that are not already linted by a dependent library. |
| 499 owned_resource_dirs = set() | 485 owned_resource_dirs = set() |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 | 637 |
| 652 all_inputs.extend(runtime_deps_files) | 638 all_inputs.extend(runtime_deps_files) |
| 653 config['native'] = { | 639 config['native'] = { |
| 654 'libraries': library_paths, | 640 'libraries': library_paths, |
| 655 'secondary_abi_libraries': secondary_abi_library_paths, | 641 'secondary_abi_libraries': secondary_abi_library_paths, |
| 656 'java_libraries_list': java_libraries_list, | 642 'java_libraries_list': java_libraries_list, |
| 657 'secondary_abi_java_libraries_list': secondary_abi_java_libraries_list, | 643 'secondary_abi_java_libraries_list': secondary_abi_java_libraries_list, |
| 658 } | 644 } |
| 659 config['assets'], config['uncompressed_assets'] = ( | 645 config['assets'], config['uncompressed_assets'] = ( |
| 660 _MergeAssets(deps.All('android_assets'))) | 646 _MergeAssets(deps.All('android_assets'))) |
| 647 config['compressed_assets_java_list'] = ( |
| 648 _CreateJavaAssetList(config['assets'])) |
| 649 config['uncompressed_assets_java_list'] = ( |
| 650 _CreateJavaAssetList(config['uncompressed_assets'])) |
| 661 | 651 |
| 662 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 652 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
| 663 | 653 |
| 664 if options.depfile: | 654 if options.depfile: |
| 665 build_utils.WriteDepfile(options.depfile, options.build_config, all_inputs) | 655 build_utils.WriteDepfile(options.depfile, options.build_config, all_inputs) |
| 666 | 656 |
| 667 | 657 |
| 668 if __name__ == '__main__': | 658 if __name__ == '__main__': |
| 669 sys.exit(main(sys.argv[1:])) | 659 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |