Commit 972d6fa6 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Support exclusion of x?x?x?hdpi resources.

A downstream project wants to exclude hdpi and higher density resources,
so I figured I'd land support here to reduce rebase burden.

Change-Id: I780b09703f822f455912ac9a119acb3dd56112bb
Reviewed-on: https://chromium-review.googlesource.com/1234221Reviewed-by: default avataragrieve <agrieve@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592928}
parent 644fd776
...@@ -33,9 +33,10 @@ template("system_webview_apk_tmpl") { ...@@ -33,9 +33,10 @@ template("system_webview_apk_tmpl") {
} }
aapt_locale_whitelist = locales aapt_locale_whitelist = locales
# Whitelist rationale in https://crbug.com/691733. resource_blacklist_regex = "[/-]xxxhdpi[/-]"
exclude_xxxhdpi = true
xxxhdpi_whitelist = [ # Exception rationale in https://crbug.com/691733.
resource_blacklist_exceptions = [
"*shadow*", # Combination of gradient & transparency cause pixelation. "*shadow*", # Combination of gradient & transparency cause pixelation.
"*.9.*", # Most nine-patches contain shadows. "*.9.*", # Most nine-patches contain shadows.
] ]
......
...@@ -117,14 +117,14 @@ def _ParseArgs(args): ...@@ -117,14 +117,14 @@ def _ParseArgs(args):
'be stripped out. List may include a combination of Android locales ' 'be stripped out. List may include a combination of Android locales '
'or Chrome locales.') 'or Chrome locales.')
input_opts.add_argument('--exclude-xxxhdpi', action='store_true', input_opts.add_argument('--resource-blacklist-regex', default='',
help='Do not include xxxhdpi drawables.') help='Do not include matching drawables.')
input_opts.add_argument( input_opts.add_argument(
'--xxxhdpi-whitelist', '--resource-blacklist-exceptions',
default='[]', default='[]',
help='GN list of globs that say which xxxhdpi images to include even ' help='GN list of globs that say which blacklisted images to include even '
'when --exclude-xxxhdpi is set.') 'when --resource-blacklist-regex is set.')
input_opts.add_argument('--png-to-webp', action='store_true', input_opts.add_argument('--png-to-webp', action='store_true',
help='Convert png files to webp format.') help='Convert png files to webp format.')
...@@ -166,7 +166,8 @@ def _ParseArgs(args): ...@@ -166,7 +166,8 @@ def _ParseArgs(args):
resource_utils.HandleCommonOptions(options) resource_utils.HandleCommonOptions(options)
options.locale_whitelist = build_utils.ParseGnList(options.locale_whitelist) options.locale_whitelist = build_utils.ParseGnList(options.locale_whitelist)
options.xxxhdpi_whitelist = build_utils.ParseGnList(options.xxxhdpi_whitelist) options.resource_blacklist_exceptions = build_utils.ParseGnList(
options.resource_blacklist_exceptions)
if options.check_resources_pkg_id is not None: if options.check_resources_pkg_id is not None:
if options.check_resources_pkg_id < 0: if options.check_resources_pkg_id < 0:
...@@ -414,28 +415,29 @@ def _ResourceNameFromPath(path): ...@@ -414,28 +415,29 @@ def _ResourceNameFromPath(path):
return os.path.splitext(os.path.basename(path))[0] return os.path.splitext(os.path.basename(path))[0]
def _CreateKeepPredicate(resource_dirs, exclude_xxxhdpi, xxxhdpi_whitelist): def _CreateKeepPredicate(resource_dirs, resource_blacklist_regex,
resource_blacklist_exceptions):
"""Return a predicate lambda to determine which resource files to keep.""" """Return a predicate lambda to determine which resource files to keep."""
if not exclude_xxxhdpi: if resource_blacklist_regex == '':
# Do not extract dotfiles (e.g. ".gitkeep"). aapt ignores them anyways. # Do not extract dotfiles (e.g. ".gitkeep"). aapt ignores them anyways.
return lambda path: os.path.basename(path)[0] != '.' return lambda path: os.path.basename(path)[0] != '.'
# Returns False only for xxxhdpi non-mipmap, non-whitelisted drawables. # Returns False only for non-filtered, non-mipmap, non-whitelisted drawables.
naive_predicate = lambda path: ( naive_predicate = lambda path: (
not re.search(r'[/-]xxxhdpi[/-]', path) or not re.search(resource_blacklist_regex, path) or
re.search(r'[/-]mipmap[/-]', path) or re.search(r'[/-]mipmap[/-]', path) or
build_utils.MatchesGlob(path, xxxhdpi_whitelist)) build_utils.MatchesGlob(path, resource_blacklist_exceptions))
# Build a set of all non-xxxhdpi drawables to ensure that we never exclude any # Build a set of all non-filtered drawables to ensure that we never exclude
# xxxhdpi drawable that does not exist in other densities. # any drawable that does not exist in non-filtered densities.
non_xxxhdpi_drawables = set() non_filtered_drawables = set()
for resource_dir in resource_dirs: for resource_dir in resource_dirs:
for path in _IterFiles(resource_dir): for path in _IterFiles(resource_dir):
if re.search(r'[/-]drawable[/-]', path) and naive_predicate(path): if re.search(r'[/-]drawable[/-]', path) and naive_predicate(path):
non_xxxhdpi_drawables.add(_ResourceNameFromPath(path)) non_filtered_drawables.add(_ResourceNameFromPath(path))
return lambda path: (naive_predicate(path) or return lambda path: (naive_predicate(path) or
_ResourceNameFromPath(path) not in non_xxxhdpi_drawables) _ResourceNameFromPath(path) not in non_filtered_drawables)
def _ConvertToWebP(webp_binary, png_files): def _ConvertToWebP(webp_binary, png_files):
...@@ -520,7 +522,8 @@ def _PackageApk(options, dep_subdirs, temp_dir, gen_dir, r_txt_path): ...@@ -520,7 +522,8 @@ def _PackageApk(options, dep_subdirs, temp_dir, gen_dir, r_txt_path):
renamed_paths.update(_DuplicateZhResources(dep_subdirs)) renamed_paths.update(_DuplicateZhResources(dep_subdirs))
keep_predicate = _CreateKeepPredicate( keep_predicate = _CreateKeepPredicate(
dep_subdirs, options.exclude_xxxhdpi, options.xxxhdpi_whitelist) dep_subdirs, options.resource_blacklist_regex,
options.resource_blacklist_exceptions)
png_paths = [] png_paths = []
for directory in dep_subdirs: for directory in dep_subdirs:
for f in _IterFiles(directory): for f in _IterFiles(directory):
...@@ -644,8 +647,8 @@ def main(args): ...@@ -644,8 +647,8 @@ def main(args):
# of them does not change what gets written to the depsfile. # of them does not change what gets written to the depsfile.
input_strings = options.extra_res_packages + [ input_strings = options.extra_res_packages + [
options.shared_resources, options.shared_resources,
options.exclude_xxxhdpi, options.resource_blacklist_regex,
options.xxxhdpi_whitelist, options.resource_blacklist_exceptions,
str(options.debuggable), str(options.debuggable),
str(options.png_to_webp), str(options.png_to_webp),
str(options.support_zh_hk), str(options.support_zh_hk),
......
...@@ -1708,9 +1708,9 @@ if (enable_java_templates) { ...@@ -1708,9 +1708,9 @@ if (enable_java_templates) {
# Restrict compiled locale-dependent resources to a specific whitelist. # Restrict compiled locale-dependent resources to a specific whitelist.
# NOTE: This is a list of Chromium locale names, not Android ones. # NOTE: This is a list of Chromium locale names, not Android ones.
# #
# exclude_xxxhdpi: (optional) # resource_blacklist_regex: (optional)
# #
# xxxhdpi_whitelist: (optional) # resource_blacklist_exceptions: (optional)
# #
# no_xml_namespaces: (optional) # no_xml_namespaces: (optional)
# #
...@@ -1941,10 +1941,11 @@ if (enable_java_templates) { ...@@ -1941,10 +1941,11 @@ if (enable_java_templates) {
rebase_path(_webp_binary, root_build_dir), rebase_path(_webp_binary, root_build_dir),
] ]
} }
if (defined(invoker.exclude_xxxhdpi) && invoker.exclude_xxxhdpi) { if (defined(invoker.resource_blacklist_regex)) {
args += [ "--exclude-xxxhdpi" ] args +=
if (defined(invoker.xxxhdpi_whitelist)) { [ "--resource-blacklist-regex=${invoker.resource_blacklist_regex}" ]
args += [ "--xxxhdpi-whitelist=${invoker.xxxhdpi_whitelist}" ] if (defined(invoker.resource_blacklist_exceptions)) {
args += [ "--resource-blacklist-exceptions=${invoker.resource_blacklist_exceptions}" ]
} }
} }
......
...@@ -1883,10 +1883,11 @@ if (enable_java_templates) { ...@@ -1883,10 +1883,11 @@ if (enable_java_templates) {
# linker does relocation unpacking, so we can enable it unconditionally. # linker does relocation unpacking, so we can enable it unconditionally.
# aapt_locale_whitelist: If set, all locales not in this list will be # aapt_locale_whitelist: If set, all locales not in this list will be
# stripped from resources.arsc. # stripped from resources.arsc.
# exclude_xxxhdpi: Causes all drawable-xxxhdpi images to be excluded # resource_blacklist_regex: Causes all drawable images matching the regex to
# (mipmaps are still included). # be excluded (mipmaps are still included).
# xxxhdpi_whitelist: A list of globs used when exclude_xxxhdpi=true. Files # resource_blacklist_exceptions: A list of globs used when
# that match this whitelist will still be included. # resource_blacklist_regex is set. Files that match this whitelist will
# still be included.
# shared_resources: True if this is a runtime shared library APK, like # shared_resources: True if this is a runtime shared library APK, like
# the system_webview_apk target. Ensures that its resources can be # the system_webview_apk target. Ensures that its resources can be
# used by the loading application process. # used by the loading application process.
...@@ -2153,9 +2154,9 @@ if (enable_java_templates) { ...@@ -2153,9 +2154,9 @@ if (enable_java_templates) {
"shared_resources", "shared_resources",
"support_zh_hk", "support_zh_hk",
"aapt_locale_whitelist", "aapt_locale_whitelist",
"exclude_xxxhdpi", "resource_blacklist_regex",
"resource_blacklist_exceptions",
"png_to_webp", "png_to_webp",
"xxxhdpi_whitelist",
"no_xml_namespaces", "no_xml_namespaces",
]) ])
android_manifest = _android_manifest android_manifest = _android_manifest
...@@ -2215,9 +2216,9 @@ if (enable_java_templates) { ...@@ -2215,9 +2216,9 @@ if (enable_java_templates) {
[ [
"support_zh_hk", "support_zh_hk",
"aapt_locale_whitelist", "aapt_locale_whitelist",
"exclude_xxxhdpi", "resource_blacklist_regex",
"resource_blacklist_exceptions",
"png_to_webp", "png_to_webp",
"xxxhdpi_whitelist",
"no_xml_namespaces", "no_xml_namespaces",
]) ])
android_manifest = _android_manifest android_manifest = _android_manifest
...@@ -2882,7 +2883,6 @@ if (enable_java_templates) { ...@@ -2882,7 +2883,6 @@ if (enable_java_templates) {
"emma_never_instrument", "emma_never_instrument",
"enable_chromium_linker_tests", "enable_chromium_linker_tests",
"enable_multidex", "enable_multidex",
"exclude_xxxhdpi",
"final_apk_path", "final_apk_path",
"firebase_app_id", "firebase_app_id",
"generate_buildconfig_java", "generate_buildconfig_java",
...@@ -2908,6 +2908,8 @@ if (enable_java_templates) { ...@@ -2908,6 +2908,8 @@ if (enable_java_templates) {
"proguard_enabled", "proguard_enabled",
"proguard_jar_path", "proguard_jar_path",
"requires_sdk_api_level_23", "requires_sdk_api_level_23",
"resource_blacklist_regex",
"resource_blacklist_exceptions",
"secondary_abi_loadable_modules", "secondary_abi_loadable_modules",
"secondary_abi_shared_libraries", "secondary_abi_shared_libraries",
"secondary_native_lib_placeholders", "secondary_native_lib_placeholders",
...@@ -2922,7 +2924,6 @@ if (enable_java_templates) { ...@@ -2922,7 +2924,6 @@ if (enable_java_templates) {
"version_code", "version_code",
"version_name", "version_name",
"write_asset_list", "write_asset_list",
"xxxhdpi_whitelist",
]) ])
is_bundle_module = false is_bundle_module = false
if (defined(invoker.apk_name)) { if (defined(invoker.apk_name)) {
...@@ -2985,7 +2986,6 @@ if (enable_java_templates) { ...@@ -2985,7 +2986,6 @@ if (enable_java_templates) {
"emma_never_instrument", "emma_never_instrument",
"enable_chromium_linker_tests", "enable_chromium_linker_tests",
"enable_multidex", "enable_multidex",
"exclude_xxxhdpi",
"firebase_app_id", "firebase_app_id",
"input_jars_paths", "input_jars_paths",
"is_base_module", "is_base_module",
...@@ -3004,6 +3004,8 @@ if (enable_java_templates) { ...@@ -3004,6 +3004,8 @@ if (enable_java_templates) {
"proguard_enabled", "proguard_enabled",
"proguard_jar_path", "proguard_jar_path",
"requires_sdk_api_level_23", "requires_sdk_api_level_23",
"resource_blacklist_regex",
"resource_blacklist_exceptions",
"secondary_abi_loadable_modules", "secondary_abi_loadable_modules",
"secondary_abi_shared_libraries", "secondary_abi_shared_libraries",
"secondary_native_lib_placeholders", "secondary_native_lib_placeholders",
...@@ -3018,7 +3020,6 @@ if (enable_java_templates) { ...@@ -3018,7 +3020,6 @@ if (enable_java_templates) {
"version_code", "version_code",
"version_name", "version_name",
"write_asset_list", "write_asset_list",
"xxxhdpi_whitelist",
]) ])
is_bundle_module = true is_bundle_module = true
generate_buildconfig_java = _is_base_module generate_buildconfig_java = _is_base_module
......
...@@ -95,19 +95,20 @@ template("chrome_public_common_apk_or_module_tmpl") { ...@@ -95,19 +95,20 @@ template("chrome_public_common_apk_or_module_tmpl") {
target(_target_type, target_name) { target(_target_type, target_name) {
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*")
exclude_xxxhdpi = true
# Use zh-TW strings for zh-HK (https://crbug.com/780847). resource_blacklist_regex = "[/-]xxxhdpi[/-]"
support_zh_hk = true
# Whitelist rationale in https://crbug.com/691733. # Exception rationale in https://crbug.com/691733.
xxxhdpi_whitelist = [ resource_blacklist_exceptions = [
"*shadow*", # Combination of gradient & transparency cause pixelation. "*shadow*", # Combination of gradient & transparency cause pixelation.
"*.9.*", # Most nine-patches contain shadows. "*.9.*", # Most nine-patches contain shadows.
"*ic_file_download_white*", # Bottom edge seems misaligned. "*ic_file_download_white*", # Bottom edge seems misaligned.
"*ic_lock.*", # Bottom edge seems misaligned. "*ic_lock.*", # Bottom edge seems misaligned.
] ]
# Use zh-TW strings for zh-HK (https://crbug.com/780847).
support_zh_hk = true
if (defined(shared_libraries) && shared_libraries != []) { if (defined(shared_libraries) && shared_libraries != []) {
_native_lib_file = _native_lib_file =
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_out_dir) rebase_path("$root_gen_dir/CHROME_VERSION.json", root_out_dir)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment