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 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 ret = list(configs) | |
| 168 while True: | |
| 169 groups = DepsOfType('group', ret) | |
| 170 if not groups: | |
| 171 return ret | |
| 172 for config in groups: | |
| 173 index = ret.index(config) | |
| 174 expanded_configs = [GetDepConfig(p) for p in config['deps_configs']] | |
| 175 ret[index:index + 1] = expanded_configs | |
|
Ian Wen
2016/07/14 04:04:55
IIUC, this removes "group" from "deps_config" of a
agrieve
2016/07/14 13:22:02
Exactly. Certainly seems deserving of a comment, d
| |
| 176 | |
| 177 | |
| 178 def _FilterDepsPaths(dep_paths, target_type): | |
| 179 configs = [GetDepConfig(p) for p in dep_paths] | |
| 180 configs = _ResolveGroups(configs) | |
| 178 # Don't allow root targets to be considered as a dep. | 181 # 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] | 182 configs = [c for c in configs if c['type'] not in _ROOT_TYPES] |
| 180 | 183 |
| 181 # Don't allow java libraries to cross through assets/resources. | 184 # Don't allow java libraries to cross through assets/resources. |
| 182 if target_type in _RESOURCE_TYPES: | 185 if target_type in _RESOURCE_TYPES: |
| 183 ret = [p for p in ret if GetDepConfig(p)['type'] in _RESOURCE_TYPES] | 186 configs = [c for c in configs if c['type'] in _RESOURCE_TYPES] |
|
Ian Wen
2016/07/14 04:04:55
Sorry I have a million questions... :P
Doesn't th
agrieve
2016/07/14 13:22:02
Added a comment to this function as well. That is
| |
| 184 return ret | 187 return [c['path'] for c in configs] |
| 185 | 188 |
| 186 | 189 |
| 187 def _AsInterfaceJar(jar_path): | 190 def _AsInterfaceJar(jar_path): |
| 188 return jar_path[:-3] + 'interface.jar' | 191 return jar_path[:-3] + 'interface.jar' |
| 189 | 192 |
| 190 | 193 |
| 191 def _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files): | 194 def _ExtractSharedLibsFromRuntimeDeps(runtime_deps_files): |
| 192 ret = [] | 195 ret = [] |
| 193 for path in runtime_deps_files: | 196 for path in runtime_deps_files: |
| 194 with open(path) as f: | 197 with open(path) as f: |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 | 301 |
| 299 if options.type == 'java_library': | 302 if options.type == 'java_library': |
| 300 if options.supports_android and not options.dex_path: | 303 if options.supports_android and not options.dex_path: |
| 301 raise Exception('java_library that supports Android requires a dex path.') | 304 raise Exception('java_library that supports Android requires a dex path.') |
| 302 | 305 |
| 303 if options.requires_android and not options.supports_android: | 306 if options.requires_android and not options.supports_android: |
| 304 raise Exception( | 307 raise Exception( |
| 305 '--supports-android is required when using --requires-android') | 308 '--supports-android is required when using --requires-android') |
| 306 | 309 |
| 307 direct_deps_config_paths = build_utils.ParseGypList(options.deps_configs) | 310 direct_deps_config_paths = build_utils.ParseGypList(options.deps_configs) |
| 308 direct_deps_config_paths = _FilterUnwantedDepsPaths(direct_deps_config_paths, | 311 direct_deps_config_paths = _FilterDepsPaths(direct_deps_config_paths, |
| 309 options.type) | 312 options.type) |
| 310 | 313 |
| 311 deps = Deps(direct_deps_config_paths) | 314 deps = Deps(direct_deps_config_paths) |
| 312 all_inputs = deps.AllConfigPaths() + build_utils.GetPythonDependencies() | 315 all_inputs = deps.AllConfigPaths() + build_utils.GetPythonDependencies() |
| 313 | 316 |
| 314 # Remove other locale resources if there is alternative_locale_resource in | 317 # Remove other locale resources if there is alternative_locale_resource in |
| 315 # direct deps. | 318 # direct deps. |
| 316 if options.has_alternative_locale_resource: | 319 if options.has_alternative_locale_resource: |
| 317 alternative = [r['path'] for r in deps.Direct('android_resources') | 320 alternative = [r['path'] for r in deps.Direct('android_resources') |
| 318 if r.get('is_locale_resource')] | 321 if r.get('is_locale_resource')] |
| 319 # We can only have one locale resources in direct deps. | 322 # We can only have one locale resources in direct deps. |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 _MergeAssets(deps.All('android_assets'))) | 580 _MergeAssets(deps.All('android_assets'))) |
| 578 | 581 |
| 579 build_utils.WriteJson(config, options.build_config, only_if_changed=True) | 582 build_utils.WriteJson(config, options.build_config, only_if_changed=True) |
| 580 | 583 |
| 581 if options.depfile: | 584 if options.depfile: |
| 582 build_utils.WriteDepfile(options.depfile, all_inputs) | 585 build_utils.WriteDepfile(options.depfile, all_inputs) |
| 583 | 586 |
| 584 | 587 |
| 585 if __name__ == '__main__': | 588 if __name__ == '__main__': |
| 586 sys.exit(main(sys.argv[1:])) | 589 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |