| 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 18 matching lines...) Expand all Loading... |
| 29 a. inputs/deps ensure that the action runs whenever one of the files changes | 29 a. inputs/deps ensure that the action runs whenever one of the files changes |
| 30 b. the files are added to the action's depfile | 30 b. the files are added to the action's depfile |
| 31 """ | 31 """ |
| 32 | 32 |
| 33 import optparse | 33 import optparse |
| 34 import os | 34 import os |
| 35 import sys | 35 import sys |
| 36 | 36 |
| 37 from util import build_utils | 37 from util import build_utils |
| 38 | 38 |
| 39 import write_ordered_libraries |
| 40 |
| 41 |
| 39 dep_config_cache = {} | 42 dep_config_cache = {} |
| 40 def GetDepConfig(path): | 43 def GetDepConfig(path): |
| 41 if not path in dep_config_cache: | 44 if not path in dep_config_cache: |
| 42 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] | 45 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] |
| 43 return dep_config_cache[path] | 46 return dep_config_cache[path] |
| 44 | 47 |
| 45 | 48 |
| 46 def DepsOfType(wanted_type, configs): | 49 def DepsOfType(wanted_type, configs): |
| 47 return [c for c in configs if c['type'] == wanted_type] | 50 return [c for c in configs if c['type'] == wanted_type] |
| 48 | 51 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 67 'files are handled differently based on the type of this target.') | 70 'files are handled differently based on the type of this target.') |
| 68 | 71 |
| 69 # android_resources/apk options | 72 # android_resources/apk options |
| 70 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') | 73 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') |
| 71 parser.add_option('--resources-zip', help='Path to target\'s resources zip.') | 74 parser.add_option('--resources-zip', help='Path to target\'s resources zip.') |
| 72 | 75 |
| 73 # android_library/apk options | 76 # android_library/apk options |
| 74 parser.add_option('--jar-path', help='Path to target\'s jar output.') | 77 parser.add_option('--jar-path', help='Path to target\'s jar output.') |
| 75 parser.add_option('--dex-path', help='Path to target\'s dex output.') | 78 parser.add_option('--dex-path', help='Path to target\'s dex output.') |
| 76 | 79 |
| 80 # apk native library options |
| 81 parser.add_option('--native-libs', help='List of top-level native libs.') |
| 82 parser.add_option('--readelf-path', help='Path to toolchain\'s readelf.') |
| 83 |
| 77 options, args = parser.parse_args(argv) | 84 options, args = parser.parse_args(argv) |
| 78 | 85 |
| 79 if args: | 86 if args: |
| 80 parser.error('No positional arguments should be given.') | 87 parser.error('No positional arguments should be given.') |
| 81 | 88 |
| 82 | 89 |
| 83 if not options.type in [ | 90 if not options.type in [ |
| 84 'android_library', 'android_resources', 'android_apk']: | 91 'android_library', 'android_resources', 'android_apk']: |
| 85 raise Exception('Unknown type: <%s>' % options.type) | 92 raise Exception('Unknown type: <%s>' % options.type) |
| 86 | 93 |
| 87 | 94 |
| 88 required_options = ['build_config'] + { | 95 required_options = ['build_config'] + { |
| 89 'android_library': ['jar_path', 'dex_path'], | 96 'android_library': ['jar_path', 'dex_path'], |
| 90 'android_resources': ['resources_zip'], | 97 'android_resources': ['resources_zip'], |
| 91 'android_apk': ['jar_path', 'dex_path', 'resources_zip'] | 98 'android_apk': ['jar_path', 'dex_path', 'resources_zip'] |
| 92 }[options.type] | 99 }[options.type] |
| 93 | 100 |
| 101 if options.native_libs: |
| 102 required_options += ['readelf_path'] |
| 103 |
| 94 build_utils.CheckOptions(options, parser, required_options) | 104 build_utils.CheckOptions(options, parser, required_options) |
| 95 | 105 |
| 96 possible_deps_config_paths = build_utils.ParseGypList( | 106 possible_deps_config_paths = build_utils.ParseGypList( |
| 97 options.possible_deps_configs) | 107 options.possible_deps_configs) |
| 98 | 108 |
| 99 | 109 |
| 100 | |
| 101 | |
| 102 allow_unknown_deps = options.type == 'android_apk' | 110 allow_unknown_deps = options.type == 'android_apk' |
| 103 unknown_deps = [ | 111 unknown_deps = [ |
| 104 c for c in possible_deps_config_paths if not os.path.exists(c)] | 112 c for c in possible_deps_config_paths if not os.path.exists(c)] |
| 105 if unknown_deps and not allow_unknown_deps: | 113 if unknown_deps and not allow_unknown_deps: |
| 106 raise Exception('Unknown deps: ' + unknown_deps) | 114 raise Exception('Unknown deps: ' + unknown_deps) |
| 107 | 115 |
| 108 direct_deps_config_paths = [ | 116 direct_deps_config_paths = [ |
| 109 c for c in possible_deps_config_paths if not c in unknown_deps] | 117 c for c in possible_deps_config_paths if not c in unknown_deps] |
| 110 all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths) | 118 all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths) |
| 111 | 119 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 config['resources']['dependency_zips'] = [ | 158 config['resources']['dependency_zips'] = [ |
| 151 c['resources_zip'] for c in all_resources_deps] | 159 c['resources_zip'] for c in all_resources_deps] |
| 152 | 160 |
| 153 if options.type == 'android_apk': | 161 if options.type == 'android_apk': |
| 154 config['apk_dex'] = {} | 162 config['apk_dex'] = {} |
| 155 dex_config = config['apk_dex'] | 163 dex_config = config['apk_dex'] |
| 156 # TODO(cjhopman): proguard version | 164 # TODO(cjhopman): proguard version |
| 157 dex_deps_files = [c['dex_path'] for c in all_library_deps] | 165 dex_deps_files = [c['dex_path'] for c in all_library_deps] |
| 158 dex_config['dependency_dex_files'] = dex_deps_files | 166 dex_config['dependency_dex_files'] = dex_deps_files |
| 159 | 167 |
| 168 library_paths = [] |
| 169 java_libraries_list = [] |
| 170 if options.native_libs: |
| 171 libraries = build_utils.ParseGypList(options.native_libs) |
| 172 libraries_dir = os.path.dirname(libraries[0]) |
| 173 write_ordered_libraries.SetReadelfPath(options.readelf_path) |
| 174 write_ordered_libraries.SetLibraryDirs([libraries_dir]) |
| 175 all_native_library_deps = ( |
| 176 write_ordered_libraries.GetSortedTransitiveDependenciesForBinaries( |
| 177 libraries)) |
| 178 java_libraries_list = '{%s}' % ','.join( |
| 179 ['"%s"' % s for s in all_native_library_deps]) |
| 180 library_paths = map( |
| 181 write_ordered_libraries.FullLibraryPath, all_native_library_deps) |
| 182 |
| 183 config['native'] = { |
| 184 'libraries': library_paths, |
| 185 'java_libraries_list': java_libraries_list |
| 186 } |
| 187 |
| 160 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 188 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
| 161 | 189 |
| 162 if options.depfile: | 190 if options.depfile: |
| 163 build_utils.WriteDepfile( | 191 build_utils.WriteDepfile( |
| 164 options.depfile, | 192 options.depfile, |
| 165 all_deps_config_paths + build_utils.GetPythonDependencies()) | 193 all_deps_config_paths + build_utils.GetPythonDependencies()) |
| 166 | 194 |
| 167 | 195 |
| 168 if __name__ == '__main__': | 196 if __name__ == '__main__': |
| 169 sys.exit(main(sys.argv[1:])) | 197 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |