Commit 697c9ab8 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Android: Compile .proto and .arsc resources at the same time

Saves a couple of seconds of build time for base bundle modules,
and simplifies the GN logic for resources.

Also fixes chrome_apk using unoptimized arsc file when lemon is
enabled (broken by 2e296d82).

Simplifies temp file usage in compile_resources.py by having all
outputs go to the staging directory.

Removes cruft:
 * Unused --no-compress flag
 * Unnecessary "Touch()" of R.txt

Bug: 950233
Change-Id: Ida77380e8038002435ec3d320105d9feaa3c2136
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1568568
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarTibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653275}
parent 83a8ff8f
This diff is collapsed.
......@@ -127,11 +127,10 @@ def main(args):
action='append',
help='Same as --assets, except disables compression.')
parser.add_argument(
'--resource-apk',
dest='resource_apks',
'--in-res-info-path',
required=True,
action='append',
help='An .ap_ file built using aapt')
help='Paths to .ap_.info files')
options = parser.parse_args(args)
......@@ -143,7 +142,7 @@ def main(args):
jar_inputs = _FindJarInputs(set(options.jar_files))
pak_inputs = _PakInfoPathsForAssets(options.assets +
options.uncompressed_assets)
res_inputs = [p + '.info' for p in options.resource_apks]
res_inputs = options.in_res_info_path
# Don't bother re-running if no .info files have changed (saves ~250ms).
md5_check.CallAndRecordIfStale(
......
......@@ -599,11 +599,21 @@ class _ResourceBuildContext(object):
# A location to place aapt-generated files.
self.gen_dir = os.path.join(self.temp_dir, 'gen')
os.mkdir(self.gen_dir)
# Location of the generated R.txt file.
self.r_txt_path = os.path.join(self.gen_dir, 'R.txt')
# A location to place generated R.java files.
self.srcjar_dir = os.path.join(self.temp_dir, 'java')
os.mkdir(self.srcjar_dir)
# Temporary file locacations.
self.r_txt_path = os.path.join(self.gen_dir, 'R.txt')
self.srcjar_path = os.path.join(self.temp_dir, 'R.srcjar')
self.info_path = os.path.join(self.temp_dir, 'size.info')
self.stable_ids_path = os.path.join(self.temp_dir, 'in_ids.txt')
self.emit_ids_path = os.path.join(self.temp_dir, 'out_ids.txt')
self.proguard_path = os.path.join(self.temp_dir, 'keeps.flags')
self.proguard_main_dex_path = os.path.join(self.temp_dir, 'maindex.flags')
self.arsc_path = os.path.join(self.temp_dir, 'out.ap_')
self.proto_path = os.path.join(self.temp_dir, 'out.proto.ap_')
self.optimized_arsc_path = os.path.join(self.temp_dir, 'out.opt.ap_')
self.optimized_proto_path = os.path.join(self.temp_dir, 'out.opt.proto.ap_')
def Close(self):
"""Close the context and destroy all temporary files."""
......
......@@ -924,6 +924,7 @@ def main(argv):
parser.add_option('--final-dex-path',
help='Path to final input classes.dex (or classes.zip) to '
'use in final apk.')
parser.add_option('--res-size-info', help='Path to .ap_.info')
parser.add_option('--apk-proto-resources',
help='Path to resources compiled in protocol buffer format '
' for this apk.')
......@@ -962,7 +963,7 @@ def main(argv):
'android_apk': ['build_config', 'dex_path', 'final_dex_path'] + \
jar_path_options,
'android_app_bundle_module': ['build_config', 'dex_path',
'final_dex_path'] + jar_path_options,
'final_dex_path', 'res_size_info'] + jar_path_options,
'android_assets': ['build_config'],
'android_resources': ['build_config', 'resources_zip'],
'dist_aar': ['build_config'],
......@@ -1277,6 +1278,8 @@ def main(argv):
if options.type == 'android_apk' and options.tested_apk_config:
config['resources']['arsc_package_name'] = (
tested_apk_config['package_name'])
if options.res_size_info:
config['resources']['size_info'] = options.res_size_info
if is_apk_or_module_target:
deps_dex_files = [c['dex_path'] for c in all_library_deps]
......
This diff is collapsed.
......@@ -2070,7 +2070,10 @@ if (enable_java_templates) {
_is_bundle_module =
defined(invoker.is_bundle_module) && invoker.is_bundle_module
_is_base_module = defined(invoker.is_base_module) && invoker.is_base_module
if (_is_bundle_module) {
_is_base_module =
defined(invoker.is_base_module) && invoker.is_base_module
}
_enable_multidex =
!defined(invoker.enable_multidex) || invoker.enable_multidex
......@@ -2084,34 +2087,36 @@ if (enable_java_templates) {
if (!_is_bundle_module) {
_final_rtxt_path = "${_final_apk_path}.R.txt"
}
_res_size_info_path = "$target_out_dir/$target_name.ap_.info"
_final_apk_path_no_ext_list =
process_file_template([ _final_apk_path ],
"{{source_dir}}/{{source_name_part}}")
_final_apk_path_no_ext = _final_apk_path_no_ext_list[0]
assert(_final_apk_path_no_ext != "") # Mark as used.
_optimize_resources =
defined(invoker.optimize_resources) && invoker.optimize_resources
# Non-base bundle modules create only proto resources.
if (!_is_bundle_module || _is_base_module) {
_packaged_resources_path = "$target_out_dir/$target_name.ap_"
_arsc_resources_path = "$target_out_dir/$target_name.ap_"
}
if (_is_bundle_module) {
# Path to the intermediate proto-format resources zip file.
_proto_resources_path = "$target_gen_dir/$target_name.proto.ap_"
_proto_resources_path = "$target_out_dir/$target_name.proto.ap_"
if (_optimize_resources) {
_optimized_proto_resources_path =
"$target_out_dir/$target_name.optimized.proto.ap_"
}
} else {
# resource_sizes.py needs to be able to find the unpacked resources.arsc
# file based on apk name to compute normatlized size.
_resource_sizes_arsc_path =
"$root_out_dir/arsc/" +
rebase_path(_final_apk_path_no_ext, root_build_dir) + ".ap_"
}
_optimize_resources =
defined(invoker.optimize_resources) && invoker.optimize_resources
if (_optimize_resources) {
_optimized_resources_path = "$target_out_dir/$_template_name.optimized."
if (_is_bundle_module) {
_optimized_resources_path += ".proto.ap_"
} else {
_optimized_resources_path += ".ap_"
if (_optimize_resources) {
_optimized_arsc_resources_path =
"$target_out_dir/$target_name.optimized.ap_"
}
}
......@@ -2358,6 +2363,7 @@ if (enable_java_templates) {
srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
r_text_out_path = _compile_resources_rtxt_out
emit_ids_out_path = _compile_resources_emit_ids_out
size_info_path = _res_size_info_path
proguard_file = _generated_proguard_config
if (_enable_main_dex_list) {
proguard_file_main_dex = _generated_proguard_main_dex_config
......@@ -2382,28 +2388,37 @@ if (enable_java_templates) {
assert(!defined(resource_ids_provider_dep))
resource_ids_provider_dep = invoker.apk_under_test
deps += [ "${invoker.apk_under_test}__compile_resources" ]
include_resource =
get_label_info(invoker.apk_under_test, "target_out_dir") + "/" +
get_label_info(invoker.apk_under_test, "name") + ".ap_"
_link_against = invoker.apk_under_test
}
if (_is_bundle_module) {
proto_format = true
output = _proto_resources_path
proto_output = _proto_resources_path
if (_optimize_resources) {
optimized_proto_output = _optimized_proto_resources_path
}
if (defined(invoker.base_module_target)) {
deps += [ "${invoker.base_module_target}__compile_arsc_resources" ]
include_resource =
get_label_info(invoker.base_module_target, "target_out_dir") +
"/" + get_label_info(invoker.base_module_target, "name") + ".ap_"
_link_against = invoker.base_module_target
}
} else {
output = _packaged_resources_path
} else if (_optimize_resources) {
optimized_arsc_output = _optimized_arsc_resources_path
}
if (_optimize_resources) {
optimized_resources_path = _optimized_resources_path
if (defined(_link_against)) {
deps += [ "${_link_against}__compile_resources" ]
include_resource = get_label_info(_link_against, "target_out_dir") +
"/" + get_label_info(_link_against, "name") + ".ap_"
}
# Bundle modules have to reference resources from the base module.
if (!_is_bundle_module || _is_base_module) {
arsc_output = _arsc_resources_path
}
if (defined(invoker.shared_resources_whitelist_target)) {
......@@ -2422,7 +2437,7 @@ if (enable_java_templates) {
# resource_sizes.py doesn't care if it gets the optimized .arsc.
sources = [
_packaged_resources_path,
_arsc_resources_path,
]
outputs = [
_resource_sizes_arsc_path,
......@@ -2453,38 +2468,6 @@ if (enable_java_templates) {
_final_deps += [ ":$_copy_rtxt_target" ]
}
if (_is_base_module && _is_bundle_module) {
# Bundle modules have to reference resources from the base module.
# However, to compile the bundle module's resources we have to give it an
# arsc resource to link against (aapt2 fails with proto resources). Thus,
# add an arsc resource compilation step to make the bundle module's link
# step work.
compile_resources("${_template_name}__compile_arsc_resources") {
forward_variables_from(invoker,
[
"support_zh_hk",
"aapt_locale_whitelist",
"resource_blacklist_regex",
"resource_blacklist_exceptions",
"png_to_webp",
"no_xml_namespaces",
])
android_manifest = _android_manifest
version_code = _version_code
version_name = _version_name
proto_format = false
output = _packaged_resources_path
build_config = _build_config
deps = _deps + [
":$_merge_manifest_target",
":$_build_config_target",
_android_sdk_dep,
]
}
}
_srcjar_deps += [ ":$_compile_resources_target" ]
if (_native_libs_deps != [] || _secondary_abi_native_libs_deps != []) {
......@@ -2642,6 +2625,7 @@ if (enable_java_templates) {
])
if (_is_bundle_module) {
type = "android_app_bundle_module"
res_size_info_path = _res_size_info_path
} else {
type = "android_apk"
}
......@@ -2817,7 +2801,7 @@ if (enable_java_templates) {
create_size_info_files(_size_info_target) {
name = "${invoker.name}.apk"
build_config = _build_config
packaged_resources_path = _packaged_resources_path
res_size_info_path = _res_size_info_path
deps = _deps + [
":$_build_config_target",
":$_compile_resources_target",
......@@ -2852,9 +2836,12 @@ if (enable_java_templates) {
"write_asset_list",
"uncompress_dex",
])
packaged_resources_path = _packaged_resources_path
if (_optimize_resources) {
optimized_resources_path = _optimized_resources_path
packaged_resources_path = _arsc_resources_path
if (_optimize_resources && _is_bundle_module) {
optimized_resources_path = _optimized_proto_resources_path
} else if (_optimize_resources) {
optimized_resources_path = _optimized_arsc_resources_path
}
apk_path = _final_apk_path
......
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