Commit 8843ff4c authored by agrieve's avatar agrieve Committed by Commit Bot

Android: Add exclude_xxxhdpi GN parameter to android_apk()

Plan to enable the flag in chrome_apk_tmpl in a follow-up.

BUG=691733

Review-Url: https://codereview.chromium.org/2948083003
Cr-Commit-Position: refs/heads/master@{#481619}
parent 63ddedc4
...@@ -135,9 +135,14 @@ def _ParseArgs(args): ...@@ -135,9 +135,14 @@ def _ParseArgs(args):
help='GN list of languages to include. All other language ' help='GN list of languages to include. All other language '
'configs will be stripped out. List may include ' 'configs will be stripped out. List may include '
'a combination of Android locales or Chrome locales.') 'a combination of Android locales or Chrome locales.')
parser.add_option('--apk-path', parser.add_option('--apk-path',
help='Path to output (partial) apk.') help='Path to output (partial) apk.')
parser.add_option('--exclude-xxxhdpi', action='store_true',
help='Do not include xxxhdpi drawables.')
parser.add_option('--xxxhdpi-whitelist',
default='[]',
help='GN list of globs that say which xxxhdpi images to '
'include even when --exclude-xxxhdpi is set.')
options, positional_args = parser.parse_args(args) options, positional_args = parser.parse_args(args)
...@@ -154,6 +159,7 @@ def _ParseArgs(args): ...@@ -154,6 +159,7 @@ def _ParseArgs(args):
options.resource_zips = build_utils.ParseGnList(options.resource_zips) options.resource_zips = build_utils.ParseGnList(options.resource_zips)
options.language_splits = build_utils.ParseGnList(options.language_splits) options.language_splits = build_utils.ParseGnList(options.language_splits)
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)
return options return options
...@@ -208,7 +214,7 @@ def PackageArgsForExtractedZip(d): ...@@ -208,7 +214,7 @@ def PackageArgsForExtractedZip(d):
""" """
subdirs = [os.path.join(d, s) for s in os.listdir(d)] subdirs = [os.path.join(d, s) for s in os.listdir(d)]
subdirs = [s for s in subdirs if os.path.isdir(s)] subdirs = [s for s in subdirs if os.path.isdir(s)]
is_multi = '0' in [os.path.basename(s) for s in subdirs] is_multi = any(os.path.basename(s).isdigit() for s in subdirs)
if is_multi: if is_multi:
res_dirs = sorted(subdirs, key=lambda p : int(os.path.basename(p))) res_dirs = sorted(subdirs, key=lambda p : int(os.path.basename(p)))
else: else:
...@@ -302,16 +308,46 @@ def _ConstructMostAaptArgs(options): ...@@ -302,16 +308,46 @@ def _ConstructMostAaptArgs(options):
return package_command return package_command
def _ResourceNameFromPath(path):
return os.path.splitext(os.path.basename(path))[0]
def _CreateExtractPredicate(dep_zips, exclude_xxxhdpi, xxxhdpi_whitelist):
if not exclude_xxxhdpi:
# 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.
naive_predicate = lambda path: (
not re.search(r'[/-]xxxhdpi[/-]', path) or
re.search(r'[/-]mipmap[/-]', path) or
build_utils.MatchesGlob(path, xxxhdpi_whitelist))
# 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()
for resource_zip_path in dep_zips:
with zipfile.ZipFile(resource_zip_path) as zip_file:
for path in zip_file.namelist():
if re.search(r'[/-]drawable[/-]', path) and naive_predicate(path):
non_xxxhdpi_drawables.add(_ResourceNameFromPath(path))
return lambda path: (naive_predicate(path) or
_ResourceNameFromPath(path) not in non_xxxhdpi_drawables)
def _OnStaleMd5(package_command, options): def _OnStaleMd5(package_command, options):
with build_utils.TempDir() as temp_dir: with build_utils.TempDir() as temp_dir:
if options.resource_zips: if options.resource_zips:
dep_zips = options.resource_zips dep_zips = options.resource_zips
extract_predicate = _CreateExtractPredicate(
dep_zips, options.exclude_xxxhdpi, options.xxxhdpi_whitelist)
for z in dep_zips: for z in dep_zips:
subdir = os.path.join(temp_dir, os.path.basename(z)) subdir = os.path.join(temp_dir, os.path.basename(z))
if os.path.exists(subdir): if os.path.exists(subdir):
raise Exception('Resource zip name conflict: ' + os.path.basename(z)) raise Exception('Resource zip name conflict: ' + os.path.basename(z))
build_utils.ExtractAll(z, path=subdir) if build_utils.ExtractAll(z, path=subdir, predicate=extract_predicate):
package_command += PackageArgsForExtractedZip(subdir) package_command += PackageArgsForExtractedZip(subdir)
build_utils.CheckOutput( build_utils.CheckOutput(
package_command, print_stdout=False, print_stderr=False) package_command, print_stdout=False, print_stderr=False)
......
...@@ -1710,6 +1710,12 @@ if (enable_java_templates) { ...@@ -1710,6 +1710,12 @@ if (enable_java_templates) {
invoker.extensions_to_not_compress, invoker.extensions_to_not_compress,
] ]
} }
if (defined(invoker.exclude_xxxhdpi) && invoker.exclude_xxxhdpi) {
args += [ "--exclude-xxxhdpi" ]
if (defined(invoker.xxxhdpi_whitelist)) {
args += [ "--xxxhdpi-whitelist=${invoker.xxxhdpi_whitelist}" ]
}
}
} }
} }
...@@ -1720,7 +1726,9 @@ if (enable_java_templates) { ...@@ -1720,7 +1726,9 @@ if (enable_java_templates) {
"aapt_locale_whitelist", "aapt_locale_whitelist",
"alternative_android_sdk_jar", "alternative_android_sdk_jar",
"android_aapt_path", "android_aapt_path",
"exclude_xxxhdpi",
"extensions_to_not_compress", "extensions_to_not_compress",
"xxxhdpi_whitelist",
]) ])
deps = _deps deps = _deps
android_manifest = _android_manifest android_manifest = _android_manifest
...@@ -1769,7 +1777,9 @@ if (enable_java_templates) { ...@@ -1769,7 +1777,9 @@ if (enable_java_templates) {
"aapt_locale_whitelist", "aapt_locale_whitelist",
"alternative_android_sdk_jar", "alternative_android_sdk_jar",
"android_aapt_path", "android_aapt_path",
"exclude_xxxhdpi",
"extensions_to_not_compress", "extensions_to_not_compress",
"xxxhdpi_whitelist",
]) ])
deps = deps =
_incremental_deps + [ ":$_generate_incremental_manifest_target_name" ] _incremental_deps + [ ":$_generate_incremental_manifest_target_name" ]
......
...@@ -1525,6 +1525,10 @@ if (enable_java_templates) { ...@@ -1525,6 +1525,10 @@ if (enable_java_templates) {
# never_incremental: If true, |incremental_apk_by_default| will be ignored. # never_incremental: If true, |incremental_apk_by_default| will be ignored.
# 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
# (mipmaps are still included).
# xxxhdpi_whitelist: A list of globs used when exclude_xxxhdpi=true. Files
# that match this whitelist will still be included.
# #
# Example # Example
# android_apk("foo_apk") { # android_apk("foo_apk") {
...@@ -2169,6 +2173,7 @@ if (enable_java_templates) { ...@@ -2169,6 +2173,7 @@ if (enable_java_templates) {
"android_aapt_path", "android_aapt_path",
"app_as_shared_lib", "app_as_shared_lib",
"deps", "deps",
"exclude_xxxhdpi",
"extensions_to_not_compress", "extensions_to_not_compress",
"language_splits", "language_splits",
"public_deps", "public_deps",
...@@ -2176,6 +2181,7 @@ if (enable_java_templates) { ...@@ -2176,6 +2181,7 @@ if (enable_java_templates) {
"shared_resources", "shared_resources",
"uncompress_shared_libraries", "uncompress_shared_libraries",
"write_asset_list", "write_asset_list",
"xxxhdpi_whitelist",
]) ])
if (!defined(deps)) { if (!defined(deps)) {
deps = [] deps = []
......
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