Chromium Code Reviews| 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 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 import itertools | 29 import itertools |
| 30 import optparse | 30 import optparse |
| 31 import os | 31 import os |
| 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 |
|
jbudorick
2016/06/22 14:52:52
nit: get rid of this
agrieve
2016/06/22 15:39:23
Done.
| |
| 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', 'java_binary', '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): |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 # Don't allow java libraries to cross through assets/resources. | 174 # Don't allow java libraries to cross through assets/resources. |
| 175 if target_type in _RESOURCE_TYPES: | 175 if target_type in _RESOURCE_TYPES: |
| 176 ret = [p for p in ret if GetDepConfig(p)['type'] in _RESOURCE_TYPES] | 176 ret = [p for p in ret if GetDepConfig(p)['type'] in _RESOURCE_TYPES] |
| 177 return ret | 177 return ret |
| 178 | 178 |
| 179 | 179 |
| 180 def _AsInterfaceJar(jar_path): | 180 def _AsInterfaceJar(jar_path): |
| 181 return jar_path[:-3] + 'interface.jar' | 181 return jar_path[:-3] + 'interface.jar' |
| 182 | 182 |
| 183 | 183 |
| 184 def _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files): | |
| 185 ret = [] | |
| 186 for path in runtime_deps_files: | |
| 187 with open(path) as f: | |
| 188 for line in f: | |
| 189 line = line.rstrip() | |
| 190 if not line.endswith('.so'): | |
| 191 continue | |
| 192 ret.append(os.path.normpath(line)) | |
| 193 ret.reverse() | |
| 194 return ret | |
| 195 | |
| 196 | |
| 184 def main(argv): | 197 def main(argv): |
| 185 parser = optparse.OptionParser() | 198 parser = optparse.OptionParser() |
| 186 build_utils.AddDepfileOption(parser) | 199 build_utils.AddDepfileOption(parser) |
| 187 parser.add_option('--build-config', help='Path to build_config output.') | 200 parser.add_option('--build-config', help='Path to build_config output.') |
| 188 parser.add_option( | 201 parser.add_option( |
| 189 '--type', | 202 '--type', |
| 190 help='Type of this target (e.g. android_library).') | 203 help='Type of this target (e.g. android_library).') |
| 191 parser.add_option( | 204 parser.add_option( |
| 192 '--possible-deps-configs', | 205 '--possible-deps-configs', |
| 193 help='List of paths for dependency\'s build_config files. Some ' | 206 help='List of paths for dependency\'s build_config files. Some ' |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 221 help='Whether this library supports running on the Android platform.') | 234 help='Whether this library supports running on the Android platform.') |
| 222 parser.add_option('--requires-android', action='store_true', | 235 parser.add_option('--requires-android', action='store_true', |
| 223 help='Whether this library requires running on the Android platform.') | 236 help='Whether this library requires running on the Android platform.') |
| 224 parser.add_option('--bypass-platform-checks', action='store_true', | 237 parser.add_option('--bypass-platform-checks', action='store_true', |
| 225 help='Bypass checks for support/require Android platform.') | 238 help='Bypass checks for support/require Android platform.') |
| 226 | 239 |
| 227 # android library options | 240 # android library options |
| 228 parser.add_option('--dex-path', help='Path to target\'s dex output.') | 241 parser.add_option('--dex-path', help='Path to target\'s dex output.') |
| 229 | 242 |
| 230 # native library options | 243 # native library options |
| 231 parser.add_option('--native-libs', help='List of top-level native libs.') | 244 parser.add_option('--shared-libraries-runtime-deps', |
| 232 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.') | 245 help='Path to file containing runtime deps for shared ' |
| 246 'libraries.') | |
| 233 | 247 |
| 234 # apk options | 248 # apk options |
| 235 parser.add_option('--apk-path', help='Path to the target\'s apk output.') | 249 parser.add_option('--apk-path', help='Path to the target\'s apk output.') |
| 236 parser.add_option('--incremental-apk-path', | 250 parser.add_option('--incremental-apk-path', |
| 237 help="Path to the target's incremental apk output.") | 251 help="Path to the target's incremental apk output.") |
| 238 parser.add_option('--incremental-install-script-path', | 252 parser.add_option('--incremental-install-script-path', |
| 239 help="Path to the target's generated incremental install " | 253 help="Path to the target's generated incremental install " |
| 240 "script.") | 254 "script.") |
| 241 | 255 |
| 242 parser.add_option('--tested-apk-config', | 256 parser.add_option('--tested-apk-config', |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 261 'android_resources': ['build_config', 'resources_zip'], | 275 'android_resources': ['build_config', 'resources_zip'], |
| 262 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'], | 276 'android_apk': ['build_config', 'jar_path', 'dex_path', 'resources_zip'], |
| 263 'deps_dex': ['build_config', 'dex_path'], | 277 'deps_dex': ['build_config', 'dex_path'], |
| 264 'resource_rewriter': ['build_config'], | 278 'resource_rewriter': ['build_config'], |
| 265 'group': ['build_config'], | 279 'group': ['build_config'], |
| 266 } | 280 } |
| 267 required_options = required_options_map.get(options.type) | 281 required_options = required_options_map.get(options.type) |
| 268 if not required_options: | 282 if not required_options: |
| 269 raise Exception('Unknown type: <%s>' % options.type) | 283 raise Exception('Unknown type: <%s>' % options.type) |
| 270 | 284 |
| 271 if options.native_libs: | |
| 272 required_options.append('readelf_path') | |
| 273 | |
| 274 build_utils.CheckOptions(options, parser, required_options) | 285 build_utils.CheckOptions(options, parser, required_options) |
| 275 | 286 |
| 276 if options.type == 'java_library': | 287 if options.type == 'java_library': |
| 277 if options.supports_android and not options.dex_path: | 288 if options.supports_android and not options.dex_path: |
| 278 raise Exception('java_library that supports Android requires a dex path.') | 289 raise Exception('java_library that supports Android requires a dex path.') |
| 279 | 290 |
| 280 if options.requires_android and not options.supports_android: | 291 if options.requires_android and not options.supports_android: |
| 281 raise Exception( | 292 raise Exception( |
| 282 '--supports-android is required when using --requires-android') | 293 '--supports-android is required when using --requires-android') |
| 283 | 294 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 'dependency_jars': dependency_jars, | 536 'dependency_jars': dependency_jars, |
| 526 'all_interface_jars': all_interface_jars, | 537 'all_interface_jars': all_interface_jars, |
| 527 } | 538 } |
| 528 manifest = AndroidManifest(options.android_manifest) | 539 manifest = AndroidManifest(options.android_manifest) |
| 529 deps_info['package_name'] = manifest.GetPackageName() | 540 deps_info['package_name'] = manifest.GetPackageName() |
| 530 if not options.tested_apk_config and manifest.GetInstrumentation(): | 541 if not options.tested_apk_config and manifest.GetInstrumentation(): |
| 531 # This must then have instrumentation only for itself. | 542 # This must then have instrumentation only for itself. |
| 532 manifest.CheckInstrumentation(manifest.GetPackageName()) | 543 manifest.CheckInstrumentation(manifest.GetPackageName()) |
| 533 | 544 |
| 534 library_paths = [] | 545 library_paths = [] |
| 535 java_libraries_list_holder = [None] | 546 java_libraries_list = None |
| 536 libraries = build_utils.ParseGypList(options.native_libs or '[]') | 547 runtime_deps_files = build_utils.ParseGypList( |
| 537 if libraries: | 548 options.shared_libraries_runtime_deps or '[]') |
| 538 def recompute_ordered_libraries(): | 549 if runtime_deps_files: |
| 539 libraries_dir = os.path.dirname(libraries[0]) | 550 library_paths = _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files) |
| 540 write_ordered_libraries.SetReadelfPath(options.readelf_path) | 551 # Create a java literal array with the "base" library names: |
|
jbudorick
2016/06/22 14:20:48
Do we no longer need to do the library ordering lo
agrieve
2016/06/22 14:33:59
It seems GN is consistent in ordering the files in
jbudorick
2016/06/22 14:52:51
sgtm
| |
| 541 write_ordered_libraries.SetLibraryDirs([libraries_dir]) | 552 # e.g. libfoo.so -> foo |
| 542 all_deps = ( | 553 java_libraries_list = ('{%s}' % ','.join( |
| 543 write_ordered_libraries.GetSortedTransitiveDependenciesForBinaries( | 554 ['"%s"' % s[3:-3] for s in library_paths])) |
| 544 libraries)) | |
| 545 # Create a java literal array with the "base" library names: | |
| 546 # e.g. libfoo.so -> foo | |
| 547 java_libraries_list_holder[0] = ('{%s}' % ','.join( | |
| 548 ['"%s"' % s[3:-3] for s in all_deps])) | |
| 549 library_paths.extend( | |
| 550 write_ordered_libraries.FullLibraryPath(x) for x in all_deps) | |
| 551 | 555 |
| 552 # This step takes about 600ms on a z620 for chrome_apk, so it's worth | 556 all_inputs.extend(runtime_deps_files) |
| 553 # caching. | |
| 554 md5_check.CallAndRecordIfStale( | |
| 555 recompute_ordered_libraries, | |
| 556 record_path=options.build_config + '.nativelibs.md5.stamp', | |
| 557 input_paths=libraries, | |
| 558 output_paths=[options.build_config]) | |
| 559 if not library_paths: | |
| 560 prev_config = build_utils.ReadJson(options.build_config) | |
| 561 java_libraries_list_holder[0] = ( | |
| 562 prev_config['native']['java_libraries_list']) | |
| 563 library_paths.extend(prev_config['native']['libraries']) | |
| 564 | |
| 565 all_inputs.extend(library_paths) | |
| 566 config['native'] = { | 557 config['native'] = { |
| 567 'libraries': library_paths, | 558 'libraries': library_paths, |
| 568 'java_libraries_list': java_libraries_list_holder[0], | 559 'java_libraries_list': java_libraries_list, |
| 569 } | 560 } |
| 570 config['assets'], config['uncompressed_assets'] = ( | 561 config['assets'], config['uncompressed_assets'] = ( |
| 571 _MergeAssets(deps.All('android_assets'))) | 562 _MergeAssets(deps.All('android_assets'))) |
| 572 | 563 |
| 573 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 564 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
| 574 | 565 |
| 575 if options.depfile: | 566 if options.depfile: |
| 576 build_utils.WriteDepfile(options.depfile, all_inputs) | 567 build_utils.WriteDepfile(options.depfile, all_inputs) |
| 577 | 568 |
| 578 | 569 |
| 579 if __name__ == '__main__': | 570 if __name__ == '__main__': |
| 580 sys.exit(main(sys.argv[1:])) | 571 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |