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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 def DepsOfType(wanted_type, configs): | 84 def DepsOfType(wanted_type, configs): |
85 return [c for c in configs if c['type'] == wanted_type] | 85 return [c for c in configs if c['type'] == wanted_type] |
86 | 86 |
87 | 87 |
88 def GetAllDepsConfigsInOrder(deps_config_paths): | 88 def GetAllDepsConfigsInOrder(deps_config_paths): |
89 def GetDeps(path): | 89 def GetDeps(path): |
90 return set(GetDepConfig(path)['deps_configs']) | 90 return set(GetDepConfig(path)['deps_configs']) |
91 return build_utils.GetSortedTransitiveDependencies(deps_config_paths, GetDeps) | 91 return build_utils.GetSortedTransitiveDependencies(deps_config_paths, GetDeps) |
92 | 92 |
93 | 93 |
94 def ResolveGroups(configs): | |
95 while True: | |
96 groups = DepsOfType('group', configs) | |
97 if not groups: | |
98 return configs | |
99 for config in groups: | |
100 index = configs.index(config) | |
101 expanded_configs = [GetDepConfig(p) for p in config['deps_configs']] | |
102 configs[index:index + 1] = expanded_configs | |
103 | |
104 | |
105 class Deps(object): | 94 class Deps(object): |
106 def __init__(self, direct_deps_config_paths): | 95 def __init__(self, direct_deps_config_paths): |
107 self.all_deps_config_paths = GetAllDepsConfigsInOrder( | 96 self.all_deps_config_paths = GetAllDepsConfigsInOrder( |
108 direct_deps_config_paths) | 97 direct_deps_config_paths) |
109 self.direct_deps_configs = ResolveGroups( | 98 self.direct_deps_configs = [ |
110 [GetDepConfig(p) for p in direct_deps_config_paths]) | 99 GetDepConfig(p) for p in direct_deps_config_paths] |
111 self.all_deps_configs = [ | 100 self.all_deps_configs = [ |
112 GetDepConfig(p) for p in self.all_deps_config_paths] | 101 GetDepConfig(p) for p in self.all_deps_config_paths] |
113 self.direct_deps_config_paths = direct_deps_config_paths | 102 self.direct_deps_config_paths = direct_deps_config_paths |
114 | 103 |
115 def All(self, wanted_type=None): | 104 def All(self, wanted_type=None): |
116 if type is None: | 105 if type is None: |
117 return self.all_deps_configs | 106 return self.all_deps_configs |
118 return DepsOfType(wanted_type, self.all_deps_configs) | 107 return DepsOfType(wanted_type, self.all_deps_configs) |
119 | 108 |
120 def Direct(self, wanted_type=None): | 109 def Direct(self, wanted_type=None): |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 | 156 |
168 def create_list(asset_map): | 157 def create_list(asset_map): |
169 ret = ['%s:%s' % (src, dest) for dest, src in asset_map.iteritems()] | 158 ret = ['%s:%s' % (src, dest) for dest, src in asset_map.iteritems()] |
170 # Sort to ensure deterministic ordering. | 159 # Sort to ensure deterministic ordering. |
171 ret.sort() | 160 ret.sort() |
172 return ret | 161 return ret |
173 | 162 |
174 return create_list(compressed), create_list(uncompressed) | 163 return create_list(compressed), create_list(uncompressed) |
175 | 164 |
176 | 165 |
177 def _FilterUnwantedDepsPaths(dep_paths, target_type): | 166 def _ResolveGroups(configs): |
167 """Returns a list of configs with all groups inlined.""" | |
168 ret = list(configs) | |
169 while True: | |
170 groups = DepsOfType('group', ret) | |
171 if not groups: | |
172 return ret | |
173 for config in groups: | |
174 index = ret.index(config) | |
175 expanded_configs = [GetDepConfig(p) for p in config['deps_configs']] | |
176 ret[index:index + 1] = expanded_configs | |
177 | |
178 | |
179 def _FilterDepsPaths(dep_paths, target_type): | |
180 """Resolves all groups and trims dependency branches that we never want. | |
181 | |
182 E.g. When a resource or asset depends on an apk target, the intent is to | |
183 include the .apk as a resource/asset, not to have the apk's classpath added. | |
Ian Wen
2016/07/14 17:14:53
This makes so much sense! Thanks for the comment!
| |
184 """ | |
185 configs = [GetDepConfig(p) for p in dep_paths] | |
186 configs = _ResolveGroups(configs) | |
178 # Don't allow root targets to be considered as a dep. | 187 # Don't allow root targets to be considered as a dep. |
179 ret = [p for p in dep_paths if GetDepConfig(p)['type'] not in _ROOT_TYPES] | 188 configs = [c for c in configs if c['type'] not in _ROOT_TYPES] |
180 | 189 |
181 # Don't allow java libraries to cross through assets/resources. | 190 # Don't allow java libraries to cross through assets/resources. |
182 if target_type in _RESOURCE_TYPES: | 191 if target_type in _RESOURCE_TYPES: |
183 ret = [p for p in ret if GetDepConfig(p)['type'] in _RESOURCE_TYPES] | 192 configs = [c for c in configs if c['type'] in _RESOURCE_TYPES] |
184 return ret | 193 return [c['path'] for c in configs] |
185 | 194 |
186 | 195 |
187 def _AsInterfaceJar(jar_path): | 196 def _AsInterfaceJar(jar_path): |
188 return jar_path[:-3] + 'interface.jar' | 197 return jar_path[:-3] + 'interface.jar' |
189 | 198 |
190 | 199 |
191 def _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files): | 200 def _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files): |
192 ret = [] | 201 ret = [] |
193 for path in runtime_deps_files: | 202 for path in runtime_deps_files: |
194 with open(path) as f: | 203 with open(path) as f: |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 | 309 |
301 if options.type == 'java_library': | 310 if options.type == 'java_library': |
302 if options.supports_android and not options.dex_path: | 311 if options.supports_android and not options.dex_path: |
303 raise Exception('java_library that supports Android requires a dex path.') | 312 raise Exception('java_library that supports Android requires a dex path.') |
304 | 313 |
305 if options.requires_android and not options.supports_android: | 314 if options.requires_android and not options.supports_android: |
306 raise Exception( | 315 raise Exception( |
307 '--supports-android is required when using --requires-android') | 316 '--supports-android is required when using --requires-android') |
308 | 317 |
309 direct_deps_config_paths = build_utils.ParseGypList(options.deps_configs) | 318 direct_deps_config_paths = build_utils.ParseGypList(options.deps_configs) |
310 direct_deps_config_paths = _FilterUnwantedDepsPaths(direct_deps_config_paths, | 319 direct_deps_config_paths = _FilterDepsPaths(direct_deps_config_paths, |
311 options.type) | 320 options.type) |
312 | 321 |
313 deps = Deps(direct_deps_config_paths) | 322 deps = Deps(direct_deps_config_paths) |
314 all_inputs = deps.AllConfigPaths() + build_utils.GetPythonDependencies() | 323 all_inputs = deps.AllConfigPaths() + build_utils.GetPythonDependencies() |
315 | 324 |
316 # Remove other locale resources if there is alternative_locale_resource in | 325 # Remove other locale resources if there is alternative_locale_resource in |
317 # direct deps. | 326 # direct deps. |
318 if options.has_alternative_locale_resource: | 327 if options.has_alternative_locale_resource: |
319 alternative = [r['path'] for r in deps.Direct('android_resources') | 328 alternative = [r['path'] for r in deps.Direct('android_resources') |
320 if r.get('is_locale_resource')] | 329 if r.get('is_locale_resource')] |
321 # We can only have one locale resources in direct deps. | 330 # We can only have one locale resources in direct deps. |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 _MergeAssets(deps.All('android_assets'))) | 599 _MergeAssets(deps.All('android_assets'))) |
591 | 600 |
592 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 601 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
593 | 602 |
594 if options.depfile: | 603 if options.depfile: |
595 build_utils.WriteDepfile(options.depfile, all_inputs) | 604 build_utils.WriteDepfile(options.depfile, all_inputs) |
596 | 605 |
597 | 606 |
598 if __name__ == '__main__': | 607 if __name__ == '__main__': |
599 sys.exit(main(sys.argv[1:])) | 608 sys.exit(main(sys.argv[1:])) |
OLD | NEW |