diff --git a/android/gyp/write_build_config.py b/android/gyp/write_build_config.py index 2c9617325..855277a59 100755 --- a/android/gyp/write_build_config.py +++ b/android/gyp/write_build_config.py @@ -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)) diff --git a/android/java/templates/LocaleConfig.template b/android/java/templates/LocaleConfig.template new file mode 100644 index 000000000..95f60510b --- /dev/null +++ b/android/java/templates/LocaleConfig.template @@ -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 +} diff --git a/config/android/internal_rules.gni b/config/android/internal_rules.gni index f1d72f7b7..669a93676 100644 --- a/config/android/internal_rules.gni +++ b/config/android/internal_rules.gni @@ -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" ] } diff --git a/config/android/rules.gni b/config/android/rules.gni index 562ce09f8..8aee53b96 100644 --- a/config/android/rules.gni +++ b/config/android/rules.gni @@ -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",