Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: build/android/gyp/write_build_config.py

Issue 1554533003: port alternative_locale_resource to GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 95
96 class Deps(object): 96 class Deps(object):
97 def __init__(self, direct_deps_config_paths): 97 def __init__(self, direct_deps_config_paths):
98 self.all_deps_config_paths = GetAllDepsConfigsInOrder( 98 self.all_deps_config_paths = GetAllDepsConfigsInOrder(
99 direct_deps_config_paths) 99 direct_deps_config_paths)
100 self.direct_deps_configs = [ 100 self.direct_deps_configs = [
101 GetDepConfig(p) for p in direct_deps_config_paths] 101 GetDepConfig(p) for p in direct_deps_config_paths]
102 self.all_deps_configs = [ 102 self.all_deps_configs = [
103 GetDepConfig(p) for p in self.all_deps_config_paths] 103 GetDepConfig(p) for p in self.all_deps_config_paths]
104 self.direct_deps_config_paths = direct_deps_config_paths
104 105
105 def All(self, wanted_type=None): 106 def All(self, wanted_type=None):
106 if type is None: 107 if type is None:
107 return self.all_deps_configs 108 return self.all_deps_configs
108 return DepsOfType(wanted_type, self.all_deps_configs) 109 return DepsOfType(wanted_type, self.all_deps_configs)
109 110
110 def Direct(self, wanted_type=None): 111 def Direct(self, wanted_type=None):
111 if wanted_type is None: 112 if wanted_type is None:
112 return self.direct_deps_configs 113 return self.direct_deps_configs
113 return DepsOfType(wanted_type, self.direct_deps_configs) 114 return DepsOfType(wanted_type, self.direct_deps_configs)
114 115
115 def AllConfigPaths(self): 116 def AllConfigPaths(self):
116 return self.all_deps_config_paths 117 return self.all_deps_config_paths
117 118
119 def RemoveNonDirectDep(self, path):
120 if path in self.direct_deps_config_paths:
121 raise Exception('Cannot remove direct dep.')
122 self.all_deps_config_paths.remove(path)
123 self.all_deps_configs.remove(GetDepConfig(path))
118 124
119 def _MergeAssets(all_assets): 125 def _MergeAssets(all_assets):
120 """Merges all assets from the given deps. 126 """Merges all assets from the given deps.
121 127
122 Returns: 128 Returns:
123 A tuple of lists: (compressed, uncompressed) 129 A tuple of lists: (compressed, uncompressed)
124 Each tuple entry is a list of "srcPath:zipPath". srcPath is the path of the 130 Each tuple entry is a list of "srcPath:zipPath". srcPath is the path of the
125 asset to add, and zipPath is the location within the zip (excluding assets/ 131 asset to add, and zipPath is the location within the zip (excluding assets/
126 prefix) 132 prefix)
127 """ 133 """
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 'dependencies may not write build_config files. Missing build_config ' 179 'dependencies may not write build_config files. Missing build_config '
174 'files are handled differently based on the type of this target.') 180 'files are handled differently based on the type of this target.')
175 181
176 # android_resources options 182 # android_resources options
177 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') 183 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
178 parser.add_option('--resources-zip', help='Path to target\'s resources zip.') 184 parser.add_option('--resources-zip', help='Path to target\'s resources zip.')
179 parser.add_option('--r-text', help='Path to target\'s R.txt file.') 185 parser.add_option('--r-text', help='Path to target\'s R.txt file.')
180 parser.add_option('--package-name', 186 parser.add_option('--package-name',
181 help='Java package name for these resources.') 187 help='Java package name for these resources.')
182 parser.add_option('--android-manifest', help='Path to android manifest.') 188 parser.add_option('--android-manifest', help='Path to android manifest.')
189 parser.add_option('--is-locale-resource', action='store_true',
190 help='Whether it is locale resource.')
183 191
184 # android_assets options 192 # android_assets options
185 parser.add_option('--asset-sources', help='List of asset sources.') 193 parser.add_option('--asset-sources', help='List of asset sources.')
186 parser.add_option('--asset-renaming-sources', 194 parser.add_option('--asset-renaming-sources',
187 help='List of asset sources with custom destinations.') 195 help='List of asset sources with custom destinations.')
188 parser.add_option('--asset-renaming-destinations', 196 parser.add_option('--asset-renaming-destinations',
189 help='List of asset custom destinations.') 197 help='List of asset custom destinations.')
190 parser.add_option('--disable-asset-compression', action='store_true', 198 parser.add_option('--disable-asset-compression', action='store_true',
191 help='Whether to disable asset compression.') 199 help='Whether to disable asset compression.')
192 200
(...skipping 16 matching lines...) Expand all
209 # apk options 217 # apk options
210 parser.add_option('--apk-path', help='Path to the target\'s apk output.') 218 parser.add_option('--apk-path', help='Path to the target\'s apk output.')
211 219
212 parser.add_option('--tested-apk-config', 220 parser.add_option('--tested-apk-config',
213 help='Path to the build config of the tested apk (for an instrumentation ' 221 help='Path to the build config of the tested apk (for an instrumentation '
214 'test apk).') 222 'test apk).')
215 parser.add_option('--proguard-enabled', action='store_true', 223 parser.add_option('--proguard-enabled', action='store_true',
216 help='Whether proguard is enabled for this apk.') 224 help='Whether proguard is enabled for this apk.')
217 parser.add_option('--proguard-info', 225 parser.add_option('--proguard-info',
218 help='Path to the proguard .info output for this apk.') 226 help='Path to the proguard .info output for this apk.')
227 parser.add_option('--has-alternative-locale-resource', action='store_true',
228 help='Whether there is alternative-locale-resource in direct deps')
219 229
220 options, args = parser.parse_args(argv) 230 options, args = parser.parse_args(argv)
221 231
222 if args: 232 if args:
223 parser.error('No positional arguments should be given.') 233 parser.error('No positional arguments should be given.')
224 234
225 required_options_map = { 235 required_options_map = {
226 'java_binary': ['build_config', 'jar_path'], 236 'java_binary': ['build_config', 'jar_path'],
227 'java_library': ['build_config', 'jar_path'], 237 'java_library': ['build_config', 'jar_path'],
228 'android_assets': ['build_config'], 238 'android_assets': ['build_config'],
(...skipping 29 matching lines...) Expand all
258 if unknown_deps and not allow_unknown_deps: 268 if unknown_deps and not allow_unknown_deps:
259 raise Exception('Unknown deps: ' + str(unknown_deps)) 269 raise Exception('Unknown deps: ' + str(unknown_deps))
260 270
261 direct_deps_config_paths = [ 271 direct_deps_config_paths = [
262 c for c in possible_deps_config_paths if not c in unknown_deps] 272 c for c in possible_deps_config_paths if not c in unknown_deps]
263 direct_deps_config_paths = _FilterUnwantedDepsPaths(direct_deps_config_paths, 273 direct_deps_config_paths = _FilterUnwantedDepsPaths(direct_deps_config_paths,
264 options.type) 274 options.type)
265 275
266 deps = Deps(direct_deps_config_paths) 276 deps = Deps(direct_deps_config_paths)
267 277
278 # Remove other locale resources if there is alternative_locale_resource in
279 # direct deps.
280 if options.has_alternative_locale_resource:
281 alternative = [r['path'] for r in deps.Direct('android_resources')
282 if r.get('is_locale_resource')]
283 # We can only have one locale resources in direct deps.
284 if len(alternative) != 1:
285 raise Exception('The number of locale resource in direct deps is wrong %d'
286 % len(alternative))
287 unwanted = [r['path'] for r in deps.All('android_resources')
288 if r.get('is_locale_resource') and r['path'] not in alternative]
289 for p in unwanted:
290 deps.RemoveNonDirectDep(p)
291
292
268 direct_library_deps = deps.Direct('java_library') 293 direct_library_deps = deps.Direct('java_library')
269 all_library_deps = deps.All('java_library') 294 all_library_deps = deps.All('java_library')
270 295
271 direct_resources_deps = deps.Direct('android_resources') 296 direct_resources_deps = deps.Direct('android_resources')
272 all_resources_deps = deps.All('android_resources') 297 all_resources_deps = deps.All('android_resources')
273 # Resources should be ordered with the highest-level dependency first so that 298 # Resources should be ordered with the highest-level dependency first so that
274 # overrides are done correctly. 299 # overrides are done correctly.
275 all_resources_deps.reverse() 300 all_resources_deps.reverse()
276 301
277 if options.type == 'android_apk' and options.tested_apk_config: 302 if options.type == 'android_apk' and options.tested_apk_config:
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 deps_info['resources_zip'] = options.resources_zip 380 deps_info['resources_zip'] = options.resources_zip
356 if options.srcjar: 381 if options.srcjar:
357 deps_info['srcjar'] = options.srcjar 382 deps_info['srcjar'] = options.srcjar
358 if options.android_manifest: 383 if options.android_manifest:
359 manifest = AndroidManifest(options.android_manifest) 384 manifest = AndroidManifest(options.android_manifest)
360 deps_info['package_name'] = manifest.GetPackageName() 385 deps_info['package_name'] = manifest.GetPackageName()
361 if options.package_name: 386 if options.package_name:
362 deps_info['package_name'] = options.package_name 387 deps_info['package_name'] = options.package_name
363 if options.r_text: 388 if options.r_text:
364 deps_info['r_text'] = options.r_text 389 deps_info['r_text'] = options.r_text
390 if options.is_locale_resource:
391 deps_info['is_locale_resource'] = True
365 392
366 if options.type in ('android_resources','android_apk', 'resource_rewriter'): 393 if options.type in ('android_resources','android_apk', 'resource_rewriter'):
367 config['resources'] = {} 394 config['resources'] = {}
368 config['resources']['dependency_zips'] = [ 395 config['resources']['dependency_zips'] = [
369 c['resources_zip'] for c in all_resources_deps] 396 c['resources_zip'] for c in all_resources_deps]
370 config['resources']['extra_package_names'] = [] 397 config['resources']['extra_package_names'] = []
371 config['resources']['extra_r_text_files'] = [] 398 config['resources']['extra_r_text_files'] = []
372 399
373 if options.type == 'android_apk' or options.type == 'resource_rewriter': 400 if options.type == 'android_apk' or options.type == 'resource_rewriter':
374 config['resources']['extra_package_names'] = [ 401 config['resources']['extra_package_names'] = [
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 build_utils.WriteJson(config, options.build_config, only_if_changed=True) 505 build_utils.WriteJson(config, options.build_config, only_if_changed=True)
479 506
480 if options.depfile: 507 if options.depfile:
481 build_utils.WriteDepfile( 508 build_utils.WriteDepfile(
482 options.depfile, 509 options.depfile,
483 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) 510 deps.AllConfigPaths() + build_utils.GetPythonDependencies())
484 511
485 512
486 if __name__ == '__main__': 513 if __name__ == '__main__':
487 sys.exit(main(sys.argv[1:])) 514 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698