Reland "Trichrome Proguard: Fix locale pak selection."

This is a reland of beea44ce6c50b4cac0ee949401b3731a1ecb0737

Fixed the package name of the generated file being incorrect for Webview in
chrome_public_apk_tmpl.gni.

Original change's description:
> Trichrome Proguard: Fix locale pak selection.
>
> This CL moves the arrays of locale pak files out of BuildConfig.java
> into a new file, LocaleConfig.java.
>
> This file is generated with a unique package which allows Chrome
> and Webview to have different versions in Trichrome.
>
> Bug: 960025
> Change-Id: I906d0c7e6c1540bfaa5f89e7bd9adbd9f97c8262
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1610255
> Commit-Queue: Eric Stevenson <estevenson@chromium.org>
> Reviewed-by: David Trainor <dtrainor@chromium.org>
> Reviewed-by: Richard Coles <torne@chromium.org>
> Reviewed-by: Andrew Grieve <agrieve@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#662209}

TBR: dtrainor@chromium.org, torne@chromium.org
Bug: 960025
Change-Id: Id8ffe2e02c461ccff1b23d5328972c893415f05b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1625375
Commit-Queue: Eric Stevenson <estevenson@chromium.org>
Auto-Submit: Eric Stevenson <estevenson@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#662324}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 8209b4f7d3b506efadc655f8b5776eb5d15e413f
This commit is contained in:
Eric Stevenson 2019-05-22 19:54:40 +00:00 коммит произвёл Commit Bot
Родитель 2b6c9e9be1
Коммит 79ef19832f
4 изменённых файлов: 84 добавлений и 48 удалений

Просмотреть файл

@ -931,14 +931,6 @@ def main(argv):
'--resource-ids-provider',
help='Path to the .build_config for the APK that this static library '
'target uses to generate stable resource IDs.')
parser.add_option(
'--compressed-locales-provider',
help='Path to the .build_config that contains the compressed locales '
'Java list for this static library target.')
parser.add_option(
'--uncompressed-locales-provider',
help='Path to the .build_config that contains the uncompressed locales '
'Java list for this static library target.')
parser.add_option('--tested-apk-config',
help='Path to the build config of the tested apk (for an instrumentation '
@ -1722,27 +1714,11 @@ def main(argv):
config['assets'], config['uncompressed_assets'], locale_paks = (
_MergeAssets(deps.All('android_assets')))
if options.compressed_locales_provider:
dep_config = GetDepConfig(options.compressed_locales_provider)
if dep_config['type'] == 'android_app_bundle':
dep_config = GetDepConfig(dep_config['base_module_config'])
deps_info['compressed_locales_java_list'] = dep_config[
'compressed_locales_java_list']
else:
deps_info[
'compressed_locales_java_list'] = _CreateJavaLocaleListFromAssets(
config['assets'], locale_paks)
if options.uncompressed_locales_provider:
dep_config = GetDepConfig(options.uncompressed_locales_provider)
if dep_config['type'] == 'android_app_bundle':
dep_config = GetDepConfig(dep_config['base_module_config'])
deps_info['uncompressed_locales_java_list'] = dep_config[
'uncompressed_locales_java_list']
else:
deps_info[
'uncompressed_locales_java_list'] = _CreateJavaLocaleListFromAssets(
config['uncompressed_assets'], locale_paks)
deps_info['compressed_locales_java_list'] = _CreateJavaLocaleListFromAssets(
config['assets'], locale_paks)
deps_info[
'uncompressed_locales_java_list'] = _CreateJavaLocaleListFromAssets(
config['uncompressed_assets'], locale_paks)
config['extra_android_manifests'] = filter(None, (
d.get('android_manifest') for d in all_resources_deps))

Просмотреть файл

@ -0,0 +1,27 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package PACKAGE;
/**
* Locale configuration. Generated on a per-target basis.
*/
public class LocaleConfig {
// Sorted list of locales that have a compressed .pak within assets.
// Stored as an array because AssetManager.list() is slow.
#if defined(COMPRESSED_LOCALE_LIST)
public static final String[] COMPRESSED_LOCALES = COMPRESSED_LOCALE_LIST;
#else
public static final String[] COMPRESSED_LOCALES = {};
#endif
// Sorted list of locales that have an uncompressed .pak within assets.
// Stored as an array because AssetManager.list() is slow.
#if defined(UNCOMPRESSED_LOCALE_LIST)
public static final String[] UNCOMPRESSED_LOCALES = UNCOMPRESSED_LOCALE_LIST;
#else
public static final String[] UNCOMPRESSED_LOCALES = {};
#endif
}

Просмотреть файл

@ -487,12 +487,6 @@ template("write_build_config") {
if (_target.is_resource_ids_provider) {
args += [ "--resource-ids-provider=$_config" ]
}
if (_target.is_compressed_locales_provider) {
args += [ "--compressed-locales-provider=$_config" ]
}
if (_target.is_uncompressed_locales_provider) {
args += [ "--uncompressed-locales-provider=$_config" ]
}
}
args += [ "--static-library-dependent-configs=$_dependent_configs" ]
}

Просмотреть файл

@ -1919,7 +1919,6 @@ if (enable_java_templates) {
# Variables:
# use_final_fields: True to use final fields. All other variables are
# ignored when this is false.
# build_config: Path to build_config used for locale list
# enable_multidex: Value for ENABLE_MULTIDEX.
# min_sdk_version: Value for MIN_SDK_VERSION.
#
@ -1956,15 +1955,6 @@ if (enable_java_templates) {
if (invoker.enable_multidex) {
defines += [ "ENABLE_MULTIDEX" ]
}
inputs = [
invoker.build_config,
]
_rebased_build_config =
rebase_path(invoker.build_config, root_build_dir)
defines += [
"COMPRESSED_LOCALE_LIST=" + "@FileArg($_rebased_build_config:deps_info:compressed_locales_java_list)",
"UNCOMPRESSED_LOCALE_LIST=" + "@FileArg($_rebased_build_config:deps_info:uncompressed_locales_java_list)",
]
if (defined(invoker.min_sdk_version)) {
defines += [ "_MIN_SDK_VERSION=${invoker.min_sdk_version}" ]
}
@ -1977,6 +1967,35 @@ if (enable_java_templates) {
}
}
# Creates LocaleConfig.java, a file containing the list of compressed and
# uncompressed locale .pak files in an APK.
#
# Variables:
# build_config: Path to build_config used for locale lists.
# java_package: Java package for the generated class.
template("generate_locale_config_srcjar") {
java_cpp_template(target_name) {
package_path = string_replace(invoker.java_package, ".", "/")
sources = [
"//build/android/java/templates/LocaleConfig.template",
]
defines = [ "PACKAGE=${invoker.java_package}" ]
if (defined(invoker.build_config)) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
_rebased_build_config =
rebase_path(invoker.build_config, root_build_dir)
defines += [
"COMPRESSED_LOCALE_LIST=" + "@FileArg($_rebased_build_config:deps_info:compressed_locales_java_list)",
"UNCOMPRESSED_LOCALE_LIST=" + "@FileArg($_rebased_build_config:deps_info:uncompressed_locales_java_list)",
]
}
}
}
# Declare an Android app module target, which is used as the basis for an
# Android APK or an Android app bundle module.
#
@ -2055,14 +2074,16 @@ if (enable_java_templates) {
# static_library_dependent_targets: A list of scopes describing targets that
# use this target as a static library. Common Java code from the targets
# listed in static_library_dependent_targets will be moved into this
# target. Scope members are name, is_resource_ids_provider,
# is_compressed_locales_provider, is_uncompressed_locales_provider.
# target. Scope members are name and is_resource_ids_provider.
# TODO(estevenson): Add a README for static library targets and document
# additions to "deps_info" in write_build_config.py.
# static_library_provider: Specifies a single target that this target will
# use as a static library APK. When proguard is enabled, the
# static_library_provider target will provide the dex file(s) for this
# target.
# locale_config_java_packages: Optional list of java packages. If given, a
# LocaleConfig.java file will be generated for each package, and will
# contain the list of compressed and uncompressed locale pak files.
template("android_apk_or_module") {
forward_variables_from(invoker, [ "testonly" ])
@ -2275,6 +2296,8 @@ if (enable_java_templates) {
_generate_buildconfig_java = invoker.generate_buildconfig_java
}
_generate_localeconfig_java = defined(invoker.locale_config_java_packages)
# JNI generation usually goes hand-in-hand with buildconfig generation.
_generate_final_jni = _generate_buildconfig_java
if (defined(invoker.generate_final_jni)) {
@ -2646,7 +2669,6 @@ if (enable_java_templates) {
generate_build_config_srcjar("${_template_name}__build_config_srcjar") {
forward_variables_from(invoker, [ "min_sdk_version" ])
use_final_fields = true
build_config = _build_config
enable_multidex = _enable_multidex
if (defined(invoker.product_version_resources_dep)) {
resources_version_variable =
@ -2659,6 +2681,21 @@ if (enable_java_templates) {
_srcjar_deps += [ ":${_template_name}__build_config_srcjar" ]
}
if (_generate_localeconfig_java) {
foreach(_package, invoker.locale_config_java_packages) {
_locale_target_name =
"${_template_name}_${_package}__locale_config_srcjar"
generate_locale_config_srcjar("$_locale_target_name") {
build_config = _build_config
java_package = _package
deps = [
":$_build_config_target",
]
}
_srcjar_deps += [ ":$_locale_target_name" ]
}
}
if (_generate_final_jni) {
generate_jni_registration("${_template_name}__final_jni") {
target = ":$_template_name"
@ -3285,6 +3322,7 @@ if (enable_java_templates) {
"keystore_path",
"load_library_from_apk",
"loadable_modules",
"locale_config_java_packages",
"min_sdk_version",
"native_lib_placeholders",
"native_lib_version_arg",
@ -3401,6 +3439,7 @@ if (enable_java_templates) {
"jni_registration_header",
"jni_sources_blacklist",
"load_library_from_apk",
"locale_config_java_packages",
"min_sdk_version",
"native_lib_version_arg",
"native_lib_version_rule",