Commit be117a44 authored by Eric Stevenson's avatar Eric Stevenson Committed by Commit Bot

Android: Support package_resources post-processing.

This CL adds support for android_apk targets to post-process a resource
packaged APK.

Bug: 695304
Change-Id: Ic3b58f48fdfdf4e87ebf45546b2ef12369390aaf
Reviewed-on: https://chromium-review.googlesource.com/558427Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Eric Stevenson <estevenson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487554}
parent 5beb8e39
......@@ -271,7 +271,7 @@ def AddToZipHermetic(zip_file, zip_path, src_path=None, data=None,
zip_path: Destination path within the zip file.
src_path: Path of the source file. Mutually exclusive with |data|.
data: File data as a string.
compress: Whether to enable compression. Default is take from ZipFile
compress: Whether to enable compression. Default is taken from ZipFile
constructor.
"""
assert (src_path is None) != (data is None), (
......@@ -303,13 +303,15 @@ def AddToZipHermetic(zip_file, zip_path, src_path=None, data=None,
zip_file.writestr(zipinfo, data, compress_type)
def DoZip(inputs, output, base_dir=None):
def DoZip(inputs, output, base_dir=None, compress_fn=None):
"""Creates a zip file from a list of files.
Args:
inputs: A list of paths to zip, or a list of (zip_path, fs_path) tuples.
output: Destination .zip file.
base_dir: Prefix to strip from inputs.
compress_fn: Applied to each input to determine whether or not to compress.
By default, items will be |zipfile.ZIP_STORED|.
"""
input_tuples = []
for tup in inputs:
......@@ -321,16 +323,17 @@ def DoZip(inputs, output, base_dir=None):
input_tuples.sort(key=lambda tup: tup[0])
with zipfile.ZipFile(output, 'w') as outfile:
for zip_path, fs_path in input_tuples:
AddToZipHermetic(outfile, zip_path, src_path=fs_path)
compress = compress_fn(zip_path) if compress_fn else None
AddToZipHermetic(outfile, zip_path, src_path=fs_path, compress=compress)
def ZipDir(output, base_dir):
def ZipDir(output, base_dir, compress_fn=None):
"""Creates a zip file from a directory."""
inputs = []
for root, _, files in os.walk(base_dir):
for f in files:
inputs.append(os.path.join(root, f))
DoZip(inputs, output, base_dir)
DoZip(inputs, output, base_dir, compress_fn=compress_fn)
def MatchesGlob(path, filters):
......
......@@ -1631,7 +1631,18 @@ if (enable_java_templates) {
}
template("package_resources_helper") {
action(target_name) {
_resource_packaged_apk_path = invoker.resource_packaged_apk_path
_package_resources_target = target_name
_post_process = defined(invoker.post_process_package_resources_script) &&
defined(invoker.post_process_package_resources_args)
if (_post_process) {
_package_resources_target = "${_package_resources_target}__intermediate"
_post_processed_resource_packaged_apk_path = _resource_packaged_apk_path
_resource_packaged_apk_path =
"${_resource_packaged_apk_path}__intermediate.ap_"
}
action(_package_resources_target) {
deps = invoker.deps
script = "//build/android/gyp/package_resources.py"
......@@ -1643,7 +1654,7 @@ if (enable_java_templates) {
inputs += [ _resources_zip ]
}
outputs = [
invoker.resource_packaged_apk_path,
_resource_packaged_apk_path,
]
if (defined(invoker.android_aapt_path)) {
......@@ -1674,7 +1685,7 @@ if (enable_java_templates) {
"--version-name",
_version_name,
"--apk-path",
rebase_path(invoker.resource_packaged_apk_path, root_build_dir),
rebase_path(_resource_packaged_apk_path, root_build_dir),
]
if (defined(_resources_zip)) {
......@@ -1727,6 +1738,32 @@ if (enable_java_templates) {
}
}
}
if (_post_process) {
action(target_name) {
depfile = "${target_gen_dir}/${target_name}.d"
script = invoker.post_process_package_resources_script
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--apk-path",
rebase_path(_resource_packaged_apk_path, root_build_dir),
"--output",
rebase_path(_post_processed_resource_packaged_apk_path,
root_build_dir),
]
args += invoker.post_process_package_resources_args
inputs = [
_resource_packaged_apk_path,
]
outputs = [
_post_processed_resource_packaged_apk_path,
]
deps = [
":${_package_resources_target}",
]
}
}
}
_package_resources_target_name = "${target_name}__package_resources"
......@@ -1739,6 +1776,8 @@ if (enable_java_templates) {
"png_to_webp",
"exclude_xxxhdpi",
"extensions_to_not_compress",
"post_process_package_resources_args",
"post_process_package_resources_script",
"xxxhdpi_whitelist",
])
deps = _deps
......@@ -1791,6 +1830,8 @@ if (enable_java_templates) {
"png_to_webp",
"exclude_xxxhdpi",
"extensions_to_not_compress",
"post_process_package_resources_args",
"post_process_package_resources_script",
"xxxhdpi_whitelist",
])
deps =
......
......@@ -2269,6 +2269,8 @@ if (enable_java_templates) {
"exclude_xxxhdpi",
"extensions_to_not_compress",
"language_splits",
"post_process_package_resources_args",
"post_process_package_resources_script",
"public_deps",
"secondary_native_libs",
"shared_resources",
......
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