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

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: 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 RemoveNoneDirectDep(self, path):
agrieve 2015/12/30 15:22:15 nit: RemoveNoneDirectDep -> RemoveNonDirectDep
michaelbai 2015/12/30 19:29:48 Done.
120 if path in self.direct_deps_config_paths:
121 raise Exception('Can not remove direct dep')
agrieve 2015/12/30 15:22:15 nit: Can not -> Cannot (although assert() might be
michaelbai 2015/12/30 19:29:48 Done.
122 self.all_deps_config_paths.remove(path)
123 self.all_deps_configs = [
agrieve 2015/12/30 15:22:15 nit: GetDepConfig() caches, so you can just do:
michaelbai 2015/12/30 19:29:48 Done.
124 GetDepConfig(p) for p in self.all_deps_config_paths]
118 125
119 def _MergeAssets(all_assets): 126 def _MergeAssets(all_assets):
120 """Merges all assets from the given deps. 127 """Merges all assets from the given deps.
121 128
122 Returns: 129 Returns:
123 A tuple of lists: (compressed, uncompressed) 130 A tuple of lists: (compressed, uncompressed)
124 Each tuple entry is a list of "srcPath:zipPath". srcPath is the path of the 131 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/ 132 asset to add, and zipPath is the location within the zip (excluding assets/
126 prefix) 133 prefix)
127 """ 134 """
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 'dependencies may not write build_config files. Missing build_config ' 180 'dependencies may not write build_config files. Missing build_config '
174 'files are handled differently based on the type of this target.') 181 'files are handled differently based on the type of this target.')
175 182
176 # android_resources options 183 # android_resources options
177 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.') 184 parser.add_option('--srcjar', help='Path to target\'s resources srcjar.')
178 parser.add_option('--resources-zip', help='Path to target\'s resources zip.') 185 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.') 186 parser.add_option('--r-text', help='Path to target\'s R.txt file.')
180 parser.add_option('--package-name', 187 parser.add_option('--package-name',
181 help='Java package name for these resources.') 188 help='Java package name for these resources.')
182 parser.add_option('--android-manifest', help='Path to android manifest.') 189 parser.add_option('--android-manifest', help='Path to android manifest.')
190 parser.add_option('--is-locale-resource', action='store_true',
191 help='Whether it is locale resource.')
183 192
184 # android_assets options 193 # android_assets options
185 parser.add_option('--asset-sources', help='List of asset sources.') 194 parser.add_option('--asset-sources', help='List of asset sources.')
186 parser.add_option('--asset-renaming-sources', 195 parser.add_option('--asset-renaming-sources',
187 help='List of asset sources with custom destinations.') 196 help='List of asset sources with custom destinations.')
188 parser.add_option('--asset-renaming-destinations', 197 parser.add_option('--asset-renaming-destinations',
189 help='List of asset custom destinations.') 198 help='List of asset custom destinations.')
190 parser.add_option('--disable-asset-compression', action='store_true', 199 parser.add_option('--disable-asset-compression', action='store_true',
191 help='Whether to disable asset compression.') 200 help='Whether to disable asset compression.')
192 201
(...skipping 16 matching lines...) Expand all
209 # apk options 218 # apk options
210 parser.add_option('--apk-path', help='Path to the target\'s apk output.') 219 parser.add_option('--apk-path', help='Path to the target\'s apk output.')
211 220
212 parser.add_option('--tested-apk-config', 221 parser.add_option('--tested-apk-config',
213 help='Path to the build config of the tested apk (for an instrumentation ' 222 help='Path to the build config of the tested apk (for an instrumentation '
214 'test apk).') 223 'test apk).')
215 parser.add_option('--proguard-enabled', action='store_true', 224 parser.add_option('--proguard-enabled', action='store_true',
216 help='Whether proguard is enabled for this apk.') 225 help='Whether proguard is enabled for this apk.')
217 parser.add_option('--proguard-info', 226 parser.add_option('--proguard-info',
218 help='Path to the proguard .info output for this apk.') 227 help='Path to the proguard .info output for this apk.')
228 parser.add_option('--has-alternative-locale-resource', action='store_true',
229 help='Whether there is alternative-locale-resource in direct deps')
219 230
220 options, args = parser.parse_args(argv) 231 options, args = parser.parse_args(argv)
221 232
222 if args: 233 if args:
223 parser.error('No positional arguments should be given.') 234 parser.error('No positional arguments should be given.')
224 235
225 required_options_map = { 236 required_options_map = {
226 'java_binary': ['build_config', 'jar_path'], 237 'java_binary': ['build_config', 'jar_path'],
227 'java_library': ['build_config', 'jar_path'], 238 'java_library': ['build_config', 'jar_path'],
228 'android_assets': ['build_config'], 239 'android_assets': ['build_config'],
(...skipping 29 matching lines...) Expand all
258 if unknown_deps and not allow_unknown_deps: 269 if unknown_deps and not allow_unknown_deps:
259 raise Exception('Unknown deps: ' + str(unknown_deps)) 270 raise Exception('Unknown deps: ' + str(unknown_deps))
260 271
261 direct_deps_config_paths = [ 272 direct_deps_config_paths = [
262 c for c in possible_deps_config_paths if not c in unknown_deps] 273 c for c in possible_deps_config_paths if not c in unknown_deps]
263 direct_deps_config_paths = _FilterUnwantedDepsPaths(direct_deps_config_paths, 274 direct_deps_config_paths = _FilterUnwantedDepsPaths(direct_deps_config_paths,
264 options.type) 275 options.type)
265 276
266 deps = Deps(direct_deps_config_paths) 277 deps = Deps(direct_deps_config_paths)
267 278
279 # Remove other locale resources if there is alternative_locale_resource in
280 # direct deps.
281 if options.has_alternative_locale_resource:
282 alternative = [ r['path'] for r in deps.Direct('android_resources')
agrieve 2015/12/30 15:22:15 nit: whitespace is off here. should be: - No spac
michaelbai 2015/12/30 19:29:48 Done.
283 if r.get('is_locale_resource') ]
284 # We can only have one locale resources in direct deps.
285 if len(alternative) != 1:
286 raise Exception('The number of locale resource in direct deps is wrong %d'
287 % len(alternative))
288 unwanted = [ r['path'] for r in deps.All('android_resources')
agrieve 2015/12/30 15:22:14 same here
michaelbai 2015/12/30 19:29:48 Done.
289 if r.get('is_locale_resource') and r['path'] not in alternative ]
290 for p in unwanted:
291 deps.RemoveNoneDirectDep(p)
292
293
268 direct_library_deps = deps.Direct('java_library') 294 direct_library_deps = deps.Direct('java_library')
269 all_library_deps = deps.All('java_library') 295 all_library_deps = deps.All('java_library')
270 296
271 direct_resources_deps = deps.Direct('android_resources') 297 direct_resources_deps = deps.Direct('android_resources')
272 all_resources_deps = deps.All('android_resources') 298 all_resources_deps = deps.All('android_resources')
273 # Resources should be ordered with the highest-level dependency first so that 299 # Resources should be ordered with the highest-level dependency first so that
274 # overrides are done correctly. 300 # overrides are done correctly.
275 all_resources_deps.reverse() 301 all_resources_deps.reverse()
276 302
277 if options.type == 'android_apk' and options.tested_apk_config: 303 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 381 deps_info['resources_zip'] = options.resources_zip
356 if options.srcjar: 382 if options.srcjar:
357 deps_info['srcjar'] = options.srcjar 383 deps_info['srcjar'] = options.srcjar
358 if options.android_manifest: 384 if options.android_manifest:
359 manifest = AndroidManifest(options.android_manifest) 385 manifest = AndroidManifest(options.android_manifest)
360 deps_info['package_name'] = manifest.GetPackageName() 386 deps_info['package_name'] = manifest.GetPackageName()
361 if options.package_name: 387 if options.package_name:
362 deps_info['package_name'] = options.package_name 388 deps_info['package_name'] = options.package_name
363 if options.r_text: 389 if options.r_text:
364 deps_info['r_text'] = options.r_text 390 deps_info['r_text'] = options.r_text
391 if options.is_locale_resource:
392 deps_info['is_locale_resource'] = True
365 393
366 if options.type in ('android_resources','android_apk', 'resource_rewriter'): 394 if options.type in ('android_resources','android_apk', 'resource_rewriter'):
367 config['resources'] = {} 395 config['resources'] = {}
368 config['resources']['dependency_zips'] = [ 396 config['resources']['dependency_zips'] = [
369 c['resources_zip'] for c in all_resources_deps] 397 c['resources_zip'] for c in all_resources_deps]
370 config['resources']['extra_package_names'] = [] 398 config['resources']['extra_package_names'] = []
371 config['resources']['extra_r_text_files'] = [] 399 config['resources']['extra_r_text_files'] = []
372 400
373 if options.type == 'android_apk' or options.type == 'resource_rewriter': 401 if options.type == 'android_apk' or options.type == 'resource_rewriter':
374 config['resources']['extra_package_names'] = [ 402 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) 506 build_utils.WriteJson(config, options.build_config, only_if_changed=True)
479 507
480 if options.depfile: 508 if options.depfile:
481 build_utils.WriteDepfile( 509 build_utils.WriteDepfile(
482 options.depfile, 510 options.depfile,
483 deps.AllConfigPaths() + build_utils.GetPythonDependencies()) 511 deps.AllConfigPaths() + build_utils.GetPythonDependencies())
484 512
485 513
486 if __name__ == '__main__': 514 if __name__ == '__main__':
487 sys.exit(main(sys.argv[1:])) 515 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