android: Introduce ProductConfig and use it for Locales and Linker.

ProductConfig is a class used for product-specific configuration. This is
specifically targeted at providing different settings for TrichromeChrome and
TrichromeWebView, without interfering with synchronized proguarding.

This CL contains two things:
1. Renaming LocaleConfig -> ProductConfig, as it is used more broadly than Locales
2. Adding support for setting up the linker with it.

The second point is required as TrichromeWebView must not be loaded with the
Chromium linker, yet the configuration class currently lives in //base, which is
in the library APK.

To ease the migration, some targets still use the "default" configuration, which
falls back to the existing mechanism, using NativeLibraries.java in base/android.

Change-Id: Id034b1b24d3aee836442253c4b398231271ca107
Bug: 979638
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1886682
Commit-Queue: Benoit L <lizeb@chromium.org>
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: John Budorick <jbudorick@chromium.org>
Reviewed-by: Sergey Volk <servolk@chromium.org>
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Eric Stevenson <estevenson@chromium.org>
Reviewed-by: Benoit L <lizeb@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#713410}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: d8b8f74730a0e52ff2cdc3ec6eb3a62a36f91df8
This commit is contained in:
Benoît Lizé 2019-11-07 12:50:07 +00:00 коммит произвёл Commit Bot
Родитель 6ebec49385
Коммит 18b75d1e1b
3 изменённых файлов: 63 добавлений и 30 удалений

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

@ -10,16 +10,16 @@ NATIVE_LIBRARIES_TEMPLATE = """\
package org.chromium.base.library_loader;
public class NativeLibraries {{
public static final int CPU_FAMILY_UNKNOWN = 0;
public static final int CPU_FAMILY_ARM = 1;
public static final int CPU_FAMILY_MIPS = 2;
public static final int CPU_FAMILY_X86 = 3;
static final int CPU_FAMILY_UNKNOWN = 0;
static final int CPU_FAMILY_ARM = 1;
static final int CPU_FAMILY_MIPS = 2;
static final int CPU_FAMILY_X86 = 3;
// Set to true to enable the use of the Chromium Linker.
public static {MAYBE_FINAL}boolean sUseLinker{USE_LINKER};
public static {MAYBE_FINAL}boolean sUseLibraryInZipFile{USE_LIBRARY_IN_ZIP_FILE};
public static {MAYBE_FINAL}boolean sEnableLinkerTests{ENABLE_LINKER_TESTS};
public static {MAYBE_FINAL}boolean sUseModernLinker{USE_MODERN_LINKER};
static {MAYBE_FINAL}boolean sUseLinker{USE_LINKER};
static {MAYBE_FINAL}boolean sUseLibraryInZipFile{USE_LIBRARY_IN_ZIP_FILE};
static {MAYBE_FINAL}boolean sEnableLinkerTests{ENABLE_LINKER_TESTS};
static {MAYBE_FINAL}boolean sUseModernLinker{USE_MODERN_LINKER};
// This is the list of native libraries to be loaded (in the correct order)
// by LibraryLoader.java.
@ -30,11 +30,8 @@ public class NativeLibraries {{
// This is the expected version of the 'main' native library, which is the one that
// implements the initial set of base JNI functions including
// base::android::nativeGetVersionName()
// TODO(torne): This is public to work around classloader issues in Trichrome
// where NativeLibraries is not in the same dex as LibraryLoader.
// We should instead split up Java code along package boundaries.
public static {MAYBE_FINAL}String sVersionNumber = {VERSION_NUMBER};
static {MAYBE_FINAL}String sVersionNumber = {VERSION_NUMBER};
public static {MAYBE_FINAL}int sCpuFamily = {CPU_FAMILY};
static {MAYBE_FINAL}int sCpuFamily = {CPU_FAMILY};
}}
"""

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

@ -4,10 +4,20 @@
package PACKAGE;
#if defined(USE_FINAL)
#define MAYBE_FINAL final
#define MAYBE_USE_CHROMIUM_LINKER = USE_CHROMIUM_LINKER_VALUE
#define MAYBE_USE_MODERN_LINKER = USE_MODERN_LINKER_VALUE
#else
#define MAYBE_FINAL
#define MAYBE_USE_CHROMIUM_LINKER
#define MAYBE_USE_MODERN_LINKER
#endif
/**
* Locale configuration. Generated on a per-target basis.
* Product configuration. Generated on a per-target basis.
*/
public class LocaleConfig {
public class ProductConfig {
// Sorted list of locales that have a compressed .pak within assets.
// Stored as an array because AssetManager.list() is slow.
@ -24,4 +34,7 @@ public class LocaleConfig {
#else
public static final String[] UNCOMPRESSED_LOCALES = {};
#endif
public static MAYBE_FINAL boolean USE_CHROMIUM_LINKER MAYBE_USE_CHROMIUM_LINKER;
public static MAYBE_FINAL boolean USE_MODERN_LINKER MAYBE_USE_MODERN_LINKER;
}

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

@ -1973,19 +1973,40 @@ if (enable_java_templates) {
}
}
# Creates LocaleConfig.java, a file containing the list of compressed and
# uncompressed locale .pak files in an APK.
# Creates ProductConfig.java, a file containing product-specific configuration.
#
# Currently, this includes the list of locales, both in their compressed and
# uncompressed format, as well as library loading
#
# Variables:
# build_config: Path to build_config used for locale lists.
# java_package: Java package for the generated class.
template("generate_locale_config_srcjar") {
# use_chromium_linker:
# use_modern_linker:
template("generate_product_config_srcjar") {
java_cpp_template(target_name) {
defines = []
_use_final = defined(invoker.build_config) ||
defined(invoker.use_chromium_linker) ||
defined(invoker.use_modern_linker)
if (_use_final) {
defines += [ "USE_FINAL" ]
}
package_path = string_replace(invoker.java_package, ".", "/")
sources = [
"//build/android/java/templates/LocaleConfig.template",
"//build/android/java/templates/ProductConfig.template",
]
defines += [ "PACKAGE=${invoker.java_package}" ]
_use_chromium_linker =
defined(invoker.use_chromium_linker) && invoker.use_chromium_linker
_use_modern_linker =
defined(invoker.use_modern_linker) && invoker.use_modern_linker
defines += [
"USE_CHROMIUM_LINKER_VALUE=$_use_chromium_linker",
"USE_MODERN_LINKER_VALUE=$_use_modern_linker",
]
defines = [ "PACKAGE=${invoker.java_package}" ]
if (defined(invoker.build_config)) {
forward_variables_from(invoker,
[
@ -2099,9 +2120,8 @@ if (enable_java_templates) {
# enable_native_mocks: Allow native calls using
# org.chromium.base.annotations.NativeMethods to be mocked in tests
# (optional).
# 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.
# product_config_java_packages: Optional list of java packages. If given, a
# ProductConfig.java file will be generated for each package.
# disable_r8_outlining: Turn off outlining during the proguard step.
# annotation_processor_deps: List of java_annotation_processor targets to
# use when compiling the java_files given to this target (optional).
@ -2316,7 +2336,7 @@ if (enable_java_templates) {
_generate_buildconfig_java = invoker.generate_buildconfig_java
}
_generate_localeconfig_java = defined(invoker.locale_config_java_packages)
_generate_productconfig_java = defined(invoker.product_config_java_packages)
# JNI generation usually goes hand-in-hand with buildconfig generation.
_generate_final_jni = _generate_buildconfig_java
@ -2699,13 +2719,15 @@ if (enable_java_templates) {
_srcjar_deps += [ ":${_template_name}__build_config_srcjar" ]
}
if (_generate_localeconfig_java) {
foreach(_package, invoker.locale_config_java_packages) {
if (_generate_productconfig_java) {
foreach(_package, invoker.product_config_java_packages) {
_locale_target_name =
"${_template_name}_${_package}__locale_config_srcjar"
generate_locale_config_srcjar("$_locale_target_name") {
"${_template_name}_${_package}__product_config_srcjar"
generate_product_config_srcjar("$_locale_target_name") {
build_config = _build_config
java_package = _package
use_chromium_linker = _use_chromium_linker
use_modern_linker = _use_modern_linker
deps = [
":$_build_config_target",
]
@ -3404,7 +3426,7 @@ if (enable_java_templates) {
"loadable_modules",
"manifest_package",
"max_sdk_version",
"locale_config_java_packages",
"product_config_java_packages",
"min_sdk_version",
"native_lib_placeholders",
"native_lib_version_arg",
@ -3528,7 +3550,7 @@ if (enable_java_templates) {
"jni_sources_blacklist",
"load_library_from_apk",
"loadable_modules",
"locale_config_java_packages",
"product_config_java_packages",
"manifest_package",
"max_sdk_version",
"min_sdk_version",
@ -3565,6 +3587,7 @@ if (enable_java_templates) {
"testonly",
"uncompress_shared_libraries",
"use_chromium_linker",
"use_modern_linker",
"verify_manifest",
"version_code",
"version_name",