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

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

Issue 2615753004: Android: Stop including unsupport locales in resources.arsc (Closed)
Patch Set: Make monochrome include all locales Created 3 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
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 # pylint: disable=C0301 7 # pylint: disable=C0301
8 """Package resources into an apk. 8 """Package resources into an apk.
9 9
10 See https://android.googlesource.com/platform/tools/base/+/master/legacy/ant-tas ks/src/main/java/com/android/ant/AaptExecTask.java 10 See https://android.googlesource.com/platform/tools/base/+/master/legacy/ant-tas ks/src/main/java/com/android/ant/AaptExecTask.java
11 and 11 and
12 https://android.googlesource.com/platform/sdk/+/master/files/ant/build.xml 12 https://android.googlesource.com/platform/sdk/+/master/files/ant/build.xml
13 """ 13 """
14 # pylint: enable=C0301 14 # pylint: enable=C0301
15 15
16 import optparse 16 import optparse
17 import os 17 import os
18 import re 18 import re
19 import shutil 19 import shutil
20 import sys 20 import sys
21 import zipfile 21 import zipfile
22 22
23 from util import build_utils 23 from util import build_utils
24 24
25 25
26 # A variation of this lists also exists in:
27 # //base/android/java/src/org/chromium/base/LocaleUtils.java
28 _CHROME_TO_ANDROID_LOCALE_MAP = {
29 'en-GB': 'en-rGB',
30 'en-US': 'en-rUS',
31 'es-419': 'es-rUS',
32 'fin': 'tl',
33 'he': 'iw',
34 'id': 'in',
35 'pt-PT': 'pt-rPT',
36 'pt-BR': 'pt-rBR',
37 'yi': 'ji',
38 'zh-CN': 'zh-rCN',
39 'zh-TW': 'zh-rTW',
40 }
41
26 # List is generated from the chrome_apk.apk_intermediates.ap_ via: 42 # List is generated from the chrome_apk.apk_intermediates.ap_ via:
27 # unzip -l $FILE_AP_ | cut -c31- | grep res/draw | cut -d'/' -f 2 | sort \ 43 # unzip -l $FILE_AP_ | cut -c31- | grep res/draw | cut -d'/' -f 2 | sort \
28 # | uniq | grep -- -tvdpi- | cut -c10- 44 # | uniq | grep -- -tvdpi- | cut -c10-
29 # and then manually sorted. 45 # and then manually sorted.
30 # Note that we can't just do a cross-product of dimentions because the filenames 46 # Note that we can't just do a cross-product of dimentions because the filenames
31 # become too big and aapt fails to create the files. 47 # become too big and aapt fails to create the files.
32 # This leaves all default drawables (mdpi) in the main apk. Android gets upset 48 # This leaves all default drawables (mdpi) in the main apk. Android gets upset
33 # though if any drawables are missing from the default drawables/ directory. 49 # though if any drawables are missing from the default drawables/ directory.
34 DENSITY_SPLITS = { 50 DENSITY_SPLITS = {
35 'hdpi': ( 51 'hdpi': (
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 parser.add_option('--asset-dir', 122 parser.add_option('--asset-dir',
107 help='directories containing assets to be packaged') 123 help='directories containing assets to be packaged')
108 parser.add_option('--no-compress', help='disables compression for the ' 124 parser.add_option('--no-compress', help='disables compression for the '
109 'given comma separated list of extensions') 125 'given comma separated list of extensions')
110 parser.add_option( 126 parser.add_option(
111 '--create-density-splits', 127 '--create-density-splits',
112 action='store_true', 128 action='store_true',
113 help='Enables density splits') 129 help='Enables density splits')
114 parser.add_option('--language-splits', 130 parser.add_option('--language-splits',
115 default='[]', 131 default='[]',
116 help='GYP list of languages to create splits for') 132 help='GN list of languages to create splits for')
133 parser.add_option('--locale-whitelist',
134 default='[]',
135 help='GN list of languages to include. All other language '
136 'configs will be stripped out. List may include '
137 'a combination of Android locales or Chrome locales.')
117 138
118 parser.add_option('--apk-path', 139 parser.add_option('--apk-path',
119 help='Path to output (partial) apk.') 140 help='Path to output (partial) apk.')
120 141
121 options, positional_args = parser.parse_args(args) 142 options, positional_args = parser.parse_args(args)
122 143
123 if positional_args: 144 if positional_args:
124 parser.error('No positional arguments should be given.') 145 parser.error('No positional arguments should be given.')
125 146
126 # Check that required options have been provided. 147 # Check that required options have been provided.
127 required_options = ('android_sdk_jar', 'aapt_path', 'configuration_name', 148 required_options = ('android_sdk_jar', 'aapt_path', 'configuration_name',
128 'android_manifest', 'version_code', 'version_name', 149 'android_manifest', 'version_code', 'version_name',
129 'apk_path') 150 'apk_path')
130 151
131 build_utils.CheckOptions(options, parser, required=required_options) 152 build_utils.CheckOptions(options, parser, required=required_options)
132 153
133 options.resource_zips = build_utils.ParseGnList(options.resource_zips) 154 options.resource_zips = build_utils.ParseGnList(options.resource_zips)
134 options.language_splits = build_utils.ParseGnList(options.language_splits) 155 options.language_splits = build_utils.ParseGnList(options.language_splits)
156 options.locale_whitelist = build_utils.ParseGnList(options.locale_whitelist)
135 return options 157 return options
136 158
137 159
160 def _ToAaptLocales(locale_whitelist):
161 """Converts the list of Chrome locales to aapt config locales."""
162 ret = set()
163 for locale in locale_whitelist:
164 locale = _CHROME_TO_ANDROID_LOCALE_MAP.get(locale, locale)
165 if locale is None or ('-' in locale and '-r' not in locale):
166 raise Exception('_CHROME_TO_ANDROID_LOCALE_MAP needs updating.'
167 ' Found: %s' % locale)
168 ret.add(locale)
169 # Always keep non-regional fall-backs.
170 language = locale.split('-')[0]
171 ret.add(language)
172
173 return sorted(ret)
174
175
138 def MoveImagesToNonMdpiFolders(res_root): 176 def MoveImagesToNonMdpiFolders(res_root):
139 """Move images from drawable-*-mdpi-* folders to drawable-* folders. 177 """Move images from drawable-*-mdpi-* folders to drawable-* folders.
140 178
141 Why? http://crbug.com/289843 179 Why? http://crbug.com/289843
142 """ 180 """
143 for src_dir_name in os.listdir(res_root): 181 for src_dir_name in os.listdir(res_root):
144 src_components = src_dir_name.split('-') 182 src_components = src_dir_name.split('-')
145 if src_components[0] != 'drawable' or 'mdpi' not in src_components: 183 if src_components[0] != 'drawable' or 'mdpi' not in src_components:
146 continue 184 continue
147 src_dir = os.path.join(res_root, src_dir_name) 185 src_dir = os.path.join(res_root, src_dir_name)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 for config in DENSITY_SPLITS.itervalues(): 288 for config in DENSITY_SPLITS.itervalues():
251 package_command.extend(('--split', ','.join(config))) 289 package_command.extend(('--split', ','.join(config)))
252 290
253 if options.language_splits: 291 if options.language_splits:
254 for lang in options.language_splits: 292 for lang in options.language_splits:
255 package_command.extend(('--split', lang)) 293 package_command.extend(('--split', lang))
256 294
257 if 'Debug' in options.configuration_name: 295 if 'Debug' in options.configuration_name:
258 package_command += ['--debug-mode'] 296 package_command += ['--debug-mode']
259 297
298 if options.locale_whitelist:
299 aapt_locales = _ToAaptLocales(options.locale_whitelist)
300 package_command += ['-c', ','.join(aapt_locales)]
301
260 return package_command 302 return package_command
261 303
262 304
263 def _OnStaleMd5(package_command, options): 305 def _OnStaleMd5(package_command, options):
264 with build_utils.TempDir() as temp_dir: 306 with build_utils.TempDir() as temp_dir:
265 if options.resource_zips: 307 if options.resource_zips:
266 dep_zips = options.resource_zips 308 dep_zips = options.resource_zips
267 for z in dep_zips: 309 for z in dep_zips:
268 subdir = os.path.join(temp_dir, os.path.basename(z)) 310 subdir = os.path.join(temp_dir, os.path.basename(z))
269 if os.path.exists(subdir): 311 if os.path.exists(subdir):
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 build_utils.CallAndWriteDepfileIfStale( 358 build_utils.CallAndWriteDepfileIfStale(
317 lambda: _OnStaleMd5(package_command, options), 359 lambda: _OnStaleMd5(package_command, options),
318 options, 360 options,
319 input_paths=input_paths, 361 input_paths=input_paths,
320 input_strings=input_strings, 362 input_strings=input_strings,
321 output_paths=output_paths) 363 output_paths=output_paths)
322 364
323 365
324 if __name__ == '__main__': 366 if __name__ == '__main__':
325 main(sys.argv[1:]) 367 main(sys.argv[1:])
OLDNEW
« no previous file with comments | « base/android/java/src/org/chromium/base/LocaleUtils.java ('k') | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698