Commit ea0f96c8 authored by Mohamed Heikal's avatar Mohamed Heikal Committed by Commit Bot

Merges process and package resources script

process_resources.py and package_resources.py are currently both required to
create the final apk. They currently communicate using zipfiles. This ends up
having 3-4 zips/unzips during the final build of the same apk in order to
perform modifications. This merger allows all the required processing to be
done before apk creation with no need for zipping. It also simplifies the
process_resources.py script to separate the code that runs during library
builds vs apk builds.

Bug: 782316
Change-Id: I958c1d107d593b0932275d3c4452c2c51c499b55
Reviewed-on: https://chromium-review.googlesource.com/791152
Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519850}
parent 3159570e
...@@ -32,7 +32,7 @@ public class LocaleUtils { ...@@ -32,7 +32,7 @@ public class LocaleUtils {
static { static {
// A variation of this mapping also exists in: // A variation of this mapping also exists in:
// build/android/gyp/package_resources.py // build/android/gyp/process_resources.py
HashMap<String, String> mapForChromium = new HashMap<>(); HashMap<String, String> mapForChromium = new HashMap<>();
mapForChromium.put("iw", "he"); // Hebrew mapForChromium.put("iw", "he"); // Hebrew
mapForChromium.put("ji", "yi"); // Yiddish mapForChromium.put("ji", "yi"); // Yiddish
......
This diff is collapsed.
This diff is collapsed.
...@@ -1383,7 +1383,19 @@ if (enable_java_templates) { ...@@ -1383,7 +1383,19 @@ if (enable_java_templates) {
# Runs process_resources.py # Runs process_resources.py
template("process_resources") { template("process_resources") {
action(target_name) { _process_resources_target_name = target_name
if (defined(invoker.output)) {
_post_process = defined(invoker.post_process_script)
_packaged_resources_path = invoker.output
if (_post_process) {
_process_resources_target_name = "${target_name}__intermediate"
_packaged_resources_path =
get_path_info(_packaged_resources_path, "dir") + "/" +
get_path_info(_packaged_resources_path, "name") +
".intermediate.ap_"
}
}
action(_process_resources_target_name) {
set_sources_assignment_filter([]) set_sources_assignment_filter([])
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
...@@ -1426,6 +1438,7 @@ if (enable_java_templates) { ...@@ -1426,6 +1438,7 @@ if (enable_java_templates) {
} }
inputs = [ inputs = [
android_default_aapt_path,
invoker.build_config, invoker.build_config,
invoker.android_manifest, invoker.android_manifest,
_android_aapt_path, _android_aapt_path,
...@@ -1445,26 +1458,46 @@ if (enable_java_templates) { ...@@ -1445,26 +1458,46 @@ if (enable_java_templates) {
rebase_path(_android_aapt_path, root_build_dir), rebase_path(_android_aapt_path, root_build_dir),
"--android-manifest", "--android-manifest",
rebase_path(invoker.android_manifest, root_build_dir), rebase_path(invoker.android_manifest, root_build_dir),
"--resource-dirs=$_rebased_all_resource_dirs",
"--dependencies-res-zips=@FileArg($_rebased_build_config:resources:dependency_zips)", "--dependencies-res-zips=@FileArg($_rebased_build_config:resources:dependency_zips)",
"--extra-res-packages=@FileArg($_rebased_build_config:resources:extra_package_names)", "--extra-res-packages=@FileArg($_rebased_build_config:resources:extra_package_names)",
"--extra-r-text-files=@FileArg($_rebased_build_config:resources:extra_r_text_files)", "--extra-r-text-files=@FileArg($_rebased_build_config:resources:extra_r_text_files)",
] ]
if (defined(invoker.zip_path)) { if (_rebased_all_resource_dirs != []) {
outputs += [ invoker.zip_path ] args += [ "--resource-dirs=$_rebased_all_resource_dirs" ]
}
if (defined(invoker.version_code)) {
args += [ args += [
"--resource-zip-out", "--version-code",
rebase_path(invoker.zip_path, root_build_dir), invoker.version_code,
]
}
if (defined(invoker.version_name)) {
args += [
"--version-name",
invoker.version_name,
]
}
if (defined(_packaged_resources_path)) {
outputs += [ _packaged_resources_path ]
args += [
"--apk-path",
rebase_path(_packaged_resources_path, root_build_dir),
] ]
} }
if (defined(invoker.all_resources_zip_path)) { # Useful to have android:debuggable in the manifest even for Release
_all_resources_zip = invoker.all_resources_zip_path # builds. Just omit it for officai
outputs += [ _all_resources_zip ] if (debuggable_apks) {
args += [ "--debuggable" ]
}
if (defined(invoker.zip_path)) {
outputs += [ invoker.zip_path ]
args += [ args += [
"--all-resources-zip-out", "--resource-zip-out",
rebase_path(_all_resources_zip, root_build_dir), rebase_path(invoker.zip_path, root_build_dir),
] ]
} }
...@@ -1517,11 +1550,6 @@ if (enable_java_templates) { ...@@ -1517,11 +1550,6 @@ if (enable_java_templates) {
args += [ "--app-as-shared-lib" ] args += [ "--app-as-shared-lib" ]
} }
if (defined(invoker.include_all_resources) &&
invoker.include_all_resources) {
args += [ "--include-all-resources" ]
}
if (defined(invoker.proguard_file)) { if (defined(invoker.proguard_file)) {
outputs += [ invoker.proguard_file ] outputs += [ invoker.proguard_file ]
args += [ args += [
...@@ -1538,112 +1566,6 @@ if (enable_java_templates) { ...@@ -1538,112 +1566,6 @@ if (enable_java_templates) {
] ]
} }
if (defined(invoker.support_zh_hk) && invoker.support_zh_hk) {
args += [ "--support-zh-hk" ]
}
if (defined(invoker.args)) {
args += invoker.args
}
}
}
# Runs aapt to create an .ap_ file, which is a zip file containing
# compiled xml and a resources.arsc file.
#
# Required Variables:
# output: Path to .ap_ to create.
# android_manifest: The AndroidManifest.xml for the apk.
# version_code: The verison code to use.
# version_name: The verison name to use.
# Optional Variables:
# aapt_locale_whitelist: If set, all locales not in this list will be
# stripped from resources.arsc.
# alternative_android_sdk_jar: An alternative android sdk jar.
# app_as_shared_lib: Enables --app-as-shared-lib.
# exclude_xxxhdpi: Causes all drawable-xxxhdpi images to be excluded
# (mipmaps are still included).
# png_to_webp: If true, pngs (with the exception of 9-patch) are
# converted to webp.
# post_process_script: Script to call to post-process the .ap_.
# resources_zip: Resource .zip file created by process_resources to package.
# shared_resources: Enables --shared-lib.
# density_splits: A list of densities to create apk splits for.
# language_splits: A list of language codes to create apk splits for.
# xxxhdpi_whitelist: A list of globs used when exclude_xxxhdpi=true. Files
# that match this whitelist will still be included.
template("package_resources") {
_post_process = defined(invoker.post_process_script)
_package_resources_target_name = target_name
_packaged_resources_path = invoker.output
if (_post_process) {
_package_resources_target_name = "${target_name}__intermediate"
_packaged_resources_path =
get_path_info(_packaged_resources_path, "dir") + "/" +
get_path_info(_packaged_resources_path, "name") + ".intermediate.ap_"
}
action(_package_resources_target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
"visibility",
])
script = "//build/android/gyp/package_resources.py"
depfile = "${target_gen_dir}/${target_name}.d"
outputs = [
_packaged_resources_path,
]
_android_sdk_jar = android_sdk_jar
if (defined(invoker.alternative_android_sdk_jar)) {
_android_sdk_jar = invoker.alternative_android_sdk_jar
}
inputs = [
android_default_aapt_path,
_android_sdk_jar,
invoker.android_manifest,
]
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--android-sdk-jar",
rebase_path(_android_sdk_jar, root_build_dir),
"--aapt-path",
rebase_path(android_default_aapt_path, root_build_dir),
"--android-manifest",
rebase_path(invoker.android_manifest, root_build_dir),
"--version-code",
invoker.version_code,
"--version-name",
invoker.version_name,
"--apk-path",
rebase_path(_packaged_resources_path, root_build_dir),
]
# Useful to have android:debuggable in the manifest even for Release
# builds. Just omit it for officai
if (debuggable_apks) {
args += [ "--debuggable" ]
}
if (defined(invoker.resources_zip)) {
inputs += [ invoker.resources_zip ]
args += [
"--resource-zips",
rebase_path(invoker.resources_zip, root_build_dir),
]
}
if (defined(invoker.shared_resources) && invoker.shared_resources) {
args += [ "--shared-resources" ]
}
if (defined(invoker.app_as_shared_lib) && invoker.app_as_shared_lib) {
args += [ "--app-as-shared-lib" ]
}
if (defined(invoker.density_splits) && invoker.density_splits != []) { if (defined(invoker.density_splits) && invoker.density_splits != []) {
args += [ "--create-density-splits" ] args += [ "--create-density-splits" ]
foreach(_density, invoker.density_splits) { foreach(_density, invoker.density_splits) {
...@@ -1675,12 +1597,17 @@ if (enable_java_templates) { ...@@ -1675,12 +1597,17 @@ if (enable_java_templates) {
args += [ "--xxxhdpi-whitelist=${invoker.xxxhdpi_whitelist}" ] args += [ "--xxxhdpi-whitelist=${invoker.xxxhdpi_whitelist}" ]
} }
} }
if (defined(invoker.support_zh_hk) && invoker.support_zh_hk) { if (defined(invoker.support_zh_hk) && invoker.support_zh_hk) {
args += [ "--support-zh-hk" ] args += [ "--support-zh-hk" ]
} }
if (defined(invoker.args)) {
args += invoker.args
}
} }
if (_post_process) { if (defined(_packaged_resources_path) && _post_process) {
action(target_name) { action(target_name) {
depfile = "${target_gen_dir}/${target_name}.d" depfile = "${target_gen_dir}/${target_name}.d"
script = invoker.post_process_script script = invoker.post_process_script
...@@ -1699,7 +1626,7 @@ if (enable_java_templates) { ...@@ -1699,7 +1626,7 @@ if (enable_java_templates) {
invoker.output, invoker.output,
] ]
public_deps = [ public_deps = [
":${_package_resources_target_name}", ":${_process_resources_target_name}",
] ]
} }
} }
......
...@@ -1740,8 +1740,6 @@ if (enable_java_templates) { ...@@ -1740,8 +1740,6 @@ if (enable_java_templates) {
# (optional). # (optional).
# apk_under_test: For an instrumentation test apk, this is the target of the # apk_under_test: For an instrumentation test apk, this is the target of the
# tested apk. # tested apk.
# include_all_resources - If true include all resource IDs in all generated
# R.java files.
# testonly: Marks this target as "test-only". # testonly: Marks this target as "test-only".
# write_asset_list: Adds an extra file to the assets, which contains a list of # write_asset_list: Adds an extra file to the assets, which contains a list of
# all other asset files. # all other asset files.
...@@ -1794,7 +1792,6 @@ if (enable_java_templates) { ...@@ -1794,7 +1792,6 @@ if (enable_java_templates) {
# JUnit tests use resource zip files. These must not be put in gen/ # JUnit tests use resource zip files. These must not be put in gen/
# directory or they will not be available to tester bots. # directory or they will not be available to tester bots.
_all_resources_zip_path = "$_base_path.resources.all.zip"
_jar_path = "$_base_path.jar" _jar_path = "$_base_path.jar"
_lib_dex_path = "$_base_path.dex.jar" _lib_dex_path = "$_base_path.dex.jar"
_rebased_lib_dex_path = rebase_path(_lib_dex_path, root_build_dir) _rebased_lib_dex_path = rebase_path(_lib_dex_path, root_build_dir)
...@@ -2113,19 +2110,29 @@ if (enable_java_templates) { ...@@ -2113,19 +2110,29 @@ if (enable_java_templates) {
[ [
"alternative_android_sdk_jar", "alternative_android_sdk_jar",
"app_as_shared_lib", "app_as_shared_lib",
"include_all_resources",
"shared_resources", "shared_resources",
"support_zh_hk", "support_zh_hk",
"aapt_locale_whitelist",
"exclude_xxxhdpi",
"png_to_webp",
"xxxhdpi_whitelist",
]) ])
android_manifest = _android_manifest
version_code = _version_code
version_name = _version_name
if (defined(invoker.post_process_package_resources_script)) {
post_process_script = invoker.post_process_package_resources_script
}
srcjar_path = "${target_gen_dir}/${target_name}.srcjar" srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
r_text_out_path = "${target_gen_dir}/${target_name}_R.txt" r_text_out_path = "${target_gen_dir}/${target_name}_R.txt"
android_manifest = _android_manifest
all_resources_zip_path = _all_resources_zip_path
generate_constant_ids = true generate_constant_ids = true
proguard_file = _generated_proguard_config proguard_file = _generated_proguard_config
if (_enable_multidex) { if (_enable_multidex) {
proguard_file_main_dex = _generated_proguard_main_dex_config proguard_file_main_dex = _generated_proguard_main_dex_config
} }
output = _packaged_resources_path
density_splits = _density_splits
language_splits = _language_splits
build_config = _build_config build_config = _build_config
deps = _deps + [ deps = _deps + [
...@@ -2134,34 +2141,6 @@ if (enable_java_templates) { ...@@ -2134,34 +2141,6 @@ if (enable_java_templates) {
] ]
} }
_srcjar_deps += [ ":$_process_resources_target" ] _srcjar_deps += [ ":$_process_resources_target" ]
_package_resources_target = "${target_name}__package_resources"
package_resources(_package_resources_target) {
forward_variables_from(invoker,
[
"aapt_locale_whitelist",
"alternative_android_sdk_jar",
"app_as_shared_lib",
"exclude_xxxhdpi",
"png_to_webp",
"shared_resources",
"support_zh_hk",
"xxxhdpi_whitelist",
])
deps = _deps + [
":$_android_manifest_target",
":$_process_resources_target",
]
android_manifest = _android_manifest
version_code = _version_code
version_name = _version_name
if (defined(invoker.post_process_package_resources_script)) {
post_process_script = invoker.post_process_package_resources_script
}
resources_zip = _all_resources_zip_path
output = _packaged_resources_path
density_splits = _density_splits
language_splits = _language_splits
}
if (_native_libs_deps != []) { if (_native_libs_deps != []) {
_enable_chromium_linker_tests = false _enable_chromium_linker_tests = false
...@@ -2520,7 +2499,7 @@ if (enable_java_templates) { ...@@ -2520,7 +2499,7 @@ if (enable_java_templates) {
incremental_deps = _deps + [ incremental_deps = _deps + [
":$_android_manifest_target", ":$_android_manifest_target",
":$_build_config_target", ":$_build_config_target",
":$_package_resources_target", ":$_process_resources_target",
] ]
# This target generates the input file _all_resources_zip_path. # This target generates the input file _all_resources_zip_path.
...@@ -2528,7 +2507,7 @@ if (enable_java_templates) { ...@@ -2528,7 +2507,7 @@ if (enable_java_templates) {
":$_android_manifest_target", ":$_android_manifest_target",
":$_build_config_target", ":$_build_config_target",
":$_final_dex_target_name", ":$_final_dex_target_name",
":$_package_resources_target", ":$_process_resources_target",
] ]
if ((_native_libs_deps != [] || if ((_native_libs_deps != [] ||
...@@ -2570,7 +2549,7 @@ if (enable_java_templates) { ...@@ -2570,7 +2549,7 @@ if (enable_java_templates) {
] ]
} }
package_resources("${_apk_rule}__process_resources") { process_resources("${_apk_rule}__process_resources") {
deps = [ deps = [
":${_apk_rule}__generate_manifest", ":${_apk_rule}__generate_manifest",
] ]
......
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