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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 if not path in dep_config_cache: | 72 if not path in dep_config_cache: |
73 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] | 73 dep_config_cache[path] = build_utils.ReadJson(path)['deps_info'] |
74 return dep_config_cache[path] | 74 return dep_config_cache[path] |
75 | 75 |
76 | 76 |
77 def DepsOfType(wanted_type, configs): | 77 def DepsOfType(wanted_type, configs): |
78 return [c for c in configs if c['type'] == wanted_type] | 78 return [c for c in configs if c['type'] == wanted_type] |
79 | 79 |
80 | 80 |
81 def GetAllDepsConfigsInOrder(deps_config_paths): | 81 def GetAllDepsConfigsInOrder(deps_config_paths): |
82 def Deps(path): | 82 def GetDeps(path): |
83 return set(GetDepConfig(path)['deps_configs']) | 83 return set(GetDepConfig(path)['deps_configs']) |
84 return build_utils.GetSortedTransitiveDependencies(deps_config_paths, Deps) | 84 return build_utils.GetSortedTransitiveDependencies(deps_config_paths, GetDeps) |
| 85 |
| 86 |
| 87 class Deps(object): |
| 88 def __init__(self, direct_deps_config_paths): |
| 89 self.all_deps_config_paths = GetAllDepsConfigsInOrder( |
| 90 direct_deps_config_paths) |
| 91 self.direct_deps_configs = [ |
| 92 GetDepConfig(p) for p in direct_deps_config_paths] |
| 93 self.all_deps_configs = [ |
| 94 GetDepConfig(p) for p in self.all_deps_config_paths] |
| 95 |
| 96 def All(self, wanted_type=None): |
| 97 if type is None: |
| 98 return self.all_deps_configs |
| 99 return DepsOfType(wanted_type, self.all_deps_configs) |
| 100 |
| 101 def Direct(self, wanted_type=None): |
| 102 if wanted_type is None: |
| 103 return self.direct_deps_configs |
| 104 return DepsOfType(wanted_type, self.direct_deps_configs) |
| 105 |
| 106 def AllConfigPaths(self): |
| 107 return self.all_deps_config_paths |
85 | 108 |
86 | 109 |
87 def main(argv): | 110 def main(argv): |
88 parser = optparse.OptionParser() | 111 parser = optparse.OptionParser() |
89 build_utils.AddDepfileOption(parser) | 112 build_utils.AddDepfileOption(parser) |
90 parser.add_option('--build-config', help='Path to build_config output.') | 113 parser.add_option('--build-config', help='Path to build_config output.') |
91 parser.add_option( | 114 parser.add_option( |
92 '--type', | 115 '--type', |
93 help='Type of this target (e.g. android_library).') | 116 help='Type of this target (e.g. android_library).') |
94 parser.add_option( | 117 parser.add_option( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 options.possible_deps_configs) | 181 options.possible_deps_configs) |
159 | 182 |
160 allow_unknown_deps = options.type == 'android_apk' | 183 allow_unknown_deps = options.type == 'android_apk' |
161 unknown_deps = [ | 184 unknown_deps = [ |
162 c for c in possible_deps_config_paths if not os.path.exists(c)] | 185 c for c in possible_deps_config_paths if not os.path.exists(c)] |
163 if unknown_deps and not allow_unknown_deps: | 186 if unknown_deps and not allow_unknown_deps: |
164 raise Exception('Unknown deps: ' + str(unknown_deps)) | 187 raise Exception('Unknown deps: ' + str(unknown_deps)) |
165 | 188 |
166 direct_deps_config_paths = [ | 189 direct_deps_config_paths = [ |
167 c for c in possible_deps_config_paths if not c in unknown_deps] | 190 c for c in possible_deps_config_paths if not c in unknown_deps] |
168 all_deps_config_paths = GetAllDepsConfigsInOrder(direct_deps_config_paths) | |
169 | 191 |
170 direct_deps_configs = [GetDepConfig(p) for p in direct_deps_config_paths] | 192 deps = Deps(direct_deps_config_paths) |
171 all_deps_configs = [GetDepConfig(p) for p in all_deps_config_paths] | 193 direct_library_deps = deps.Direct('java_library') |
| 194 all_library_deps = deps.All('java_library') |
172 | 195 |
173 direct_library_deps = DepsOfType('java_library', direct_deps_configs) | 196 direct_resources_deps = deps.Direct('android_resources') |
174 all_library_deps = DepsOfType('java_library', all_deps_configs) | 197 all_resources_deps = deps.All('android_resources') |
175 | |
176 direct_resources_deps = DepsOfType('android_resources', direct_deps_configs) | |
177 all_resources_deps = DepsOfType('android_resources', all_deps_configs) | |
178 # Resources should be ordered with the highest-level dependency first so that | 198 # Resources should be ordered with the highest-level dependency first so that |
179 # overrides are done correctly. | 199 # overrides are done correctly. |
180 all_resources_deps.reverse() | 200 all_resources_deps.reverse() |
181 | 201 |
| 202 if options.type == 'android_apk' and options.tested_apk_config: |
| 203 tested_apk_deps = Deps([options.tested_apk_config]) |
| 204 tested_apk_resources_deps = tested_apk_deps.All('android_resources') |
| 205 all_resources_deps = [ |
| 206 d for d in all_resources_deps if not d in tested_apk_resources_deps] |
| 207 |
182 # Initialize some common config. | 208 # Initialize some common config. |
183 config = { | 209 config = { |
184 'deps_info': { | 210 'deps_info': { |
185 'name': os.path.basename(options.build_config), | 211 'name': os.path.basename(options.build_config), |
186 'path': options.build_config, | 212 'path': options.build_config, |
187 'type': options.type, | 213 'type': options.type, |
188 'deps_configs': direct_deps_config_paths, | 214 'deps_configs': direct_deps_config_paths, |
189 } | 215 } |
190 } | 216 } |
191 deps_info = config['deps_info'] | 217 deps_info = config['deps_info'] |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 if options.type == 'android_apk': | 275 if options.type == 'android_apk': |
250 config['resources']['extra_package_names'] = [ | 276 config['resources']['extra_package_names'] = [ |
251 c['package_name'] for c in all_resources_deps if 'package_name' in c] | 277 c['package_name'] for c in all_resources_deps if 'package_name' in c] |
252 | 278 |
253 if options.type in ['android_apk', 'deps_dex']: | 279 if options.type in ['android_apk', 'deps_dex']: |
254 deps_dex_files = [c['dex_path'] for c in all_library_deps] | 280 deps_dex_files = [c['dex_path'] for c in all_library_deps] |
255 | 281 |
256 # An instrumentation test apk should exclude the dex files that are in the apk | 282 # An instrumentation test apk should exclude the dex files that are in the apk |
257 # under test. | 283 # under test. |
258 if options.type == 'android_apk' and options.tested_apk_config: | 284 if options.type == 'android_apk' and options.tested_apk_config: |
259 tested_apk_config_paths = GetAllDepsConfigsInOrder( | 285 tested_apk_deps = Deps([options.tested_apk_config]) |
260 [options.tested_apk_config]) | 286 tested_apk_library_deps = tested_apk_deps.All('java_library') |
261 tested_apk_configs = [GetDepConfig(p) for p in tested_apk_config_paths] | |
262 tested_apk_library_deps = DepsOfType('java_library', tested_apk_configs) | |
263 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] | 287 tested_apk_deps_dex_files = [c['dex_path'] for c in tested_apk_library_deps] |
264 deps_dex_files = [ | 288 deps_dex_files = [ |
265 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] | 289 p for p in deps_dex_files if not p in tested_apk_deps_dex_files] |
266 | 290 |
267 tested_apk_config = GetDepConfig(options.tested_apk_config) | 291 tested_apk_config = GetDepConfig(options.tested_apk_config) |
268 expected_tested_package = tested_apk_config['package_name'] | 292 expected_tested_package = tested_apk_config['package_name'] |
269 AndroidManifest(options.android_manifest).CheckInstrumentation( | 293 AndroidManifest(options.android_manifest).CheckInstrumentation( |
270 expected_tested_package) | 294 expected_tested_package) |
271 | 295 |
272 # Dependencies for the final dex file of an apk or a 'deps_dex'. | 296 # Dependencies for the final dex file of an apk or a 'deps_dex'. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 config['native'] = { | 333 config['native'] = { |
310 'libraries': library_paths, | 334 'libraries': library_paths, |
311 'java_libraries_list': java_libraries_list | 335 'java_libraries_list': java_libraries_list |
312 } | 336 } |
313 | 337 |
314 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 338 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
315 | 339 |
316 if options.depfile: | 340 if options.depfile: |
317 build_utils.WriteDepfile( | 341 build_utils.WriteDepfile( |
318 options.depfile, | 342 options.depfile, |
319 all_deps_config_paths + build_utils.GetPythonDependencies()) | 343 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) |
320 | 344 |
321 | 345 |
322 if __name__ == '__main__': | 346 if __name__ == '__main__': |
323 sys.exit(main(sys.argv[1:])) | 347 sys.exit(main(sys.argv[1:])) |
OLD | NEW |