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") {
}
aapt_locale_whitelist = locales
# Whitelist rationale in https://crbug.com/691733.
exclude_xxxhdpi = true
xxxhdpi_whitelist = [
resource_blacklist_regex = "[/-]xxxhdpi[/-]"
# Exception rationale in https://crbug.com/691733.
resource_blacklist_exceptions = [
"*shadow*", # Combination of gradient & transparency cause pixelation.
"*.9.*", # Most nine-patches contain shadows.
]
......
......@@ -117,14 +117,14 @@ def _ParseArgs(args):
'be stripped out. List may include a combination of Android locales '
'or Chrome locales.')
input_opts.add_argument('--exclude-xxxhdpi', action='store_true',
help='Do not include xxxhdpi drawables.')
input_opts.add_argument('--resource-blacklist-regex', default='',
help='Do not include matching drawables.')
input_opts.add_argument(
'--xxxhdpi-whitelist',
'--resource-blacklist-exceptions',
default='[]',
help='GN list of globs that say which xxxhdpi images to include even '
'when --exclude-xxxhdpi is set.')
help='GN list of globs that say which blacklisted images to include even '
'when --resource-blacklist-regex is set.')
input_opts.add_argument('--png-to-webp', action='store_true',
help='Convert png files to webp format.')
......@@ -166,7 +166,8 @@ def _ParseArgs(args):
resource_utils.HandleCommonOptions(options)
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 < 0:
......@@ -414,28 +415,29 @@ def _ResourceNameFromPath(path):
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."""
if not exclude_xxxhdpi:
if resource_blacklist_regex == '':
# Do not extract dotfiles (e.g. ".gitkeep"). aapt ignores them anyways.
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: (
not re.search(r'[/-]xxxhdpi[/-]', path) or
not re.search(resource_blacklist_regex, 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
# xxxhdpi drawable that does not exist in other densities.
non_xxxhdpi_drawables = set()
# Build a set of all non-filtered drawables to ensure that we never exclude
# any drawable that does not exist in non-filtered densities.
non_filtered_drawables = set()
for resource_dir in resource_dirs:
for path in _IterFiles(resource_dir):
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
_ResourceNameFromPath(path) not in non_xxxhdpi_drawables)
_ResourceNameFromPath(path) not in non_filtered_drawables)
def _ConvertToWebP(webp_binary, png_files):
......@@ -520,7 +522,8 @@ def _PackageApk(options, dep_subdirs, temp_dir, gen_dir, r_txt_path):
renamed_paths.update(_DuplicateZhResources(dep_subdirs))
keep_predicate = _CreateKeepPredicate(
dep_subdirs, options.exclude_xxxhdpi, options.xxxhdpi_whitelist)
dep_subdirs, options.resource_blacklist_regex,
options.resource_blacklist_exceptions)
png_paths = []
for directory in dep_subdirs:
for f in _IterFiles(directory):
......@@ -644,8 +647,8 @@ def main(args):
# of them does not change what gets written to the depsfile.
input_strings = options.extra_res_packages + [
options.shared_resources,
options.exclude_xxxhdpi,
options.xxxhdpi_whitelist,
options.resource_blacklist_regex,
options.resource_blacklist_exceptions,
str(options.debuggable),
str(options.png_to_webp),
str(options.support_zh_hk),
......
......@@ -1708,9 +1708,9 @@ if (enable_java_templates) {
# Restrict compiled locale-dependent resources to a specific whitelist.
# 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)
#
......@@ -1941,10 +1941,11 @@ if (enable_java_templates) {
rebase_path(_webp_binary, root_build_dir),
]
}
if (defined(invoker.exclude_xxxhdpi) && invoker.exclude_xxxhdpi) {
args += [ "--exclude-xxxhdpi" ]
if (defined(invoker.xxxhdpi_whitelist)) {
args += [ "--xxxhdpi-whitelist=${invoker.xxxhdpi_whitelist}" ]
if (defined(invoker.resource_blacklist_regex)) {
args +=
[ "--resource-blacklist-regex=${invoker.resource_blacklist_regex}" ]
if (defined(invoker.resource_blacklist_exceptions)) {
args += [ "--resource-blacklist-exceptions=${invoker.resource_blacklist_exceptions}" ]
}
}
......
......@@ -1883,10 +1883,11 @@ if (enable_java_templates) {
# linker does relocation unpacking, so we can enable it unconditionally.
# aapt_locale_whitelist: If set, all locales not in this list will be
# stripped from resources.arsc.
# exclude_xxxhdpi: Causes all drawable-xxxhdpi images to be excluded
# (mipmaps are still included).
# xxxhdpi_whitelist: A list of globs used when exclude_xxxhdpi=true. Files
# that match this whitelist will still be included.
# resource_blacklist_regex: Causes all drawable images matching the regex to
# be excluded (mipmaps are still included).
# resource_blacklist_exceptions: A list of globs used when
# 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
# the system_webview_apk target. Ensures that its resources can be
# used by the loading application process.
......@@ -2153,9 +2154,9 @@ if (enable_java_templates) {
"shared_resources",
"support_zh_hk",
"aapt_locale_whitelist",
"exclude_xxxhdpi",
"resource_blacklist_regex",
"resource_blacklist_exceptions",
"png_to_webp",
"xxxhdpi_whitelist",
"no_xml_namespaces",
])
android_manifest = _android_manifest
......@@ -2215,9 +2216,9 @@ if (enable_java_templates) {
[
"support_zh_hk",
"aapt_locale_whitelist",
"exclude_xxxhdpi",
"resource_blacklist_regex",
"resource_blacklist_exceptions",
"png_to_webp",
"xxxhdpi_whitelist",
"no_xml_namespaces",
])
android_manifest = _android_manifest
......@@ -2882,7 +2883,6 @@ if (enable_java_templates) {
"emma_never_instrument",
"enable_chromium_linker_tests",
"enable_multidex",
"exclude_xxxhdpi",
"final_apk_path",
"firebase_app_id",
"generate_buildconfig_java",
......@@ -2908,6 +2908,8 @@ if (enable_java_templates) {
"proguard_enabled",
"proguard_jar_path",
"requires_sdk_api_level_23",
"resource_blacklist_regex",
"resource_blacklist_exceptions",
"secondary_abi_loadable_modules",
"secondary_abi_shared_libraries",
"secondary_native_lib_placeholders",
......@@ -2922,7 +2924,6 @@ if (enable_java_templates) {
"version_code",
"version_name",
"write_asset_list",
"xxxhdpi_whitelist",
])
is_bundle_module = false
if (defined(invoker.apk_name)) {
......@@ -2985,7 +2986,6 @@ if (enable_java_templates) {
"emma_never_instrument",
"enable_chromium_linker_tests",
"enable_multidex",
"exclude_xxxhdpi",
"firebase_app_id",
"input_jars_paths",
"is_base_module",
......@@ -3004,6 +3004,8 @@ if (enable_java_templates) {
"proguard_enabled",
"proguard_jar_path",
"requires_sdk_api_level_23",
"resource_blacklist_regex",
"resource_blacklist_exceptions",
"secondary_abi_loadable_modules",
"secondary_abi_shared_libraries",
"secondary_native_lib_placeholders",
......@@ -3018,7 +3020,6 @@ if (enable_java_templates) {
"version_code",
"version_name",
"write_asset_list",
"xxxhdpi_whitelist",
])
is_bundle_module = true
generate_buildconfig_java = _is_base_module
......
......@@ -95,19 +95,20 @@ template("chrome_public_common_apk_or_module_tmpl") {
target(_target_type, target_name) {
forward_variables_from(invoker, "*")
exclude_xxxhdpi = true
# Use zh-TW strings for zh-HK (https://crbug.com/780847).
support_zh_hk = true
resource_blacklist_regex = "[/-]xxxhdpi[/-]"
# Whitelist rationale in https://crbug.com/691733.
xxxhdpi_whitelist = [
# Exception rationale in https://crbug.com/691733.
resource_blacklist_exceptions = [
"*shadow*", # Combination of gradient & transparency cause pixelation.
"*.9.*", # Most nine-patches contain shadows.
"*ic_file_download_white*", # 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 != []) {
_native_lib_file =
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