blob: 06c0702f6d409f650b9c6c3a8d0bfa71654768a4 [file] [log] [blame]
# Copyright 2014 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.
# Do not add any imports to non-//build directories here.
# Some projects (e.g. V8) do not have non-build directories DEPS'ed in.
import("//build/config/android/config.gni")
import("//build/config/android/copy_ex.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/compute_inputs_for_analyze.gni")
import("//build/config/coverage/coverage.gni")
import("//build/config/python.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/toolchain/goma.gni")
import("//build/toolchain/kythe.gni")
import("//build/util/generate_wrapper.gni")
import("//build_overrides/build.gni")
if (current_toolchain == default_toolchain) {
import("//build/toolchain/concurrent_links.gni")
}
assert(is_android)
# The following _java_*_types variables capture all the existing target types.
# If a new type is introduced, please add it to one of these categories,
# preferring the more specific resource/library types.
_java_resource_types = [
"android_assets",
"android_resources",
]
_java_library_types = [
"java_library",
"system_java_library",
"android_app_bundle_module",
]
# These are leaf java target types. They cannot be passed as deps to other
# targets. Thus their naming schemes are not enforced.
_java_leaf_types = [
"android_apk",
"android_app_bundle",
"dist_aar",
"dist_jar",
"java_annotation_processor",
"java_binary",
"junit_binary",
]
# All _java_resource_types targets must conform to these patterns.
_java_resource_patterns = [
"*:*_assets",
"*android*:assets",
"*:*_apk_*resources",
"*android*:resources",
"*:*_resources",
"*:*_grd",
"*:*locale_paks",
"*:*_java_strings",
"*:*strings_java",
]
# All _java_library_types targets must conform to these patterns. This includes
# all non-leaf targets that use java_library_impl.
_java_library_patterns = [
"*:*_java",
"*:*_javalib",
"*:*_java_*", # e.g. chrome_java_test_support
"*:java",
"*:junit",
"*:junit_*",
"*:*_junit_*",
"*:*javatests",
"*:*_bundle_module",
# TODO(agrieve): Rename targets below to match above patterns.
"//android_webview/glue:glue",
]
# These identify all non-leaf targets that have .build_config files. This is the
# set of patterns that other targets can use to filter out java targets.
java_target_patterns = _java_library_patterns + _java_resource_patterns
_r8_path = "//third_party/r8/lib/r8.jar"
_custom_d8_path = "//third_party/r8/custom_d8.jar"
_desugar_jdk_libs_json = "//third_party/r8/desugar_jdk_libs.json"
_desugar_jdk_libs_jar = "//third_party/android_deps/libs/com_android_tools_desugar_jdk_libs/desugar_jdk_libs-1.1.1.jar"
_desugar_jdk_libs_configuration_jar = "//third_party/android_deps/libs/com_android_tools_desugar_jdk_libs_configuration/desugar_jdk_libs_configuration-1.1.1.jar"
_desugar_runtime_jar = "$root_build_dir/obj/third_party/bazel/desugar/Desugar_runtime.processed.jar"
_dexdump_path = "$android_sdk_build_tools/dexdump"
_dexlayout_path = "//third_party/android_build_tools/art/dexlayout"
_profman_path = "//third_party/android_build_tools/art/profman"
_art_lib_file_names = [
"libartbase.so",
"libart-compiler.so",
"libart-dexlayout.so",
"libart-disassembler.so",
"libart-gtest.so",
"libart.so",
"libbacktrace.so",
"libbase.so",
"libcrypto-host.so",
"libc++.so",
"libcutils.so",
"libdexfile.so",
"libexpat-host.so",
"libicui18n-host.so",
"libicuuc-host.so",
"libjavacore.so",
"libjavacrypto.so",
"liblog.so",
"liblz4.so",
"liblzma.so",
"libnativebridge.so",
"libnativehelper.so",
"libnativeloader.so",
"libopenjdkjvm.so",
"libopenjdkjvmti.so",
"libopenjdk.so",
"libprofile.so",
"libsigchain.so",
"libssl-host.so",
"libunwindstack.so",
"libvixl-arm64.so",
"libvixl-arm.so",
"libvixld-arm64.so",
"libvixld-arm.so",
"libz-host.so",
"libziparchive.so",
"slicer.so",
]
_default_art_libs = []
foreach(lib, _art_lib_file_names) {
_default_art_libs += [ "//third_party/android_build_tools/art/lib/$lib" ]
}
# Put the bug number in the target name so that false-positives have a hint in
# the error message about why non-existent dependencies are there.
build_config_target_suffix = "__build_config_crbug_908819"
# Write the target's .build_config file. This is a json file that contains a
# dictionary of information about how to build this target (things that
# require knowledge about this target's dependencies and cannot be calculated
# at gn-time). There is a special syntax to add a value in that dictionary to
# an action/action_foreachs args:
# --python-arg=@FileArg($rebased_build_config_path:key0:key1)
# At runtime, such an arg will be replaced by the value in the build_config.
# See build/android/gyp/write_build_config.py and
# build/android/gyp/util/build_utils.py:ExpandFileArgs
template("write_build_config") {
_type = invoker.type
_parent_invoker = invoker.invoker
_target_label =
get_label_info(":${_parent_invoker.target_name}", "label_no_toolchain")
# Ensure targets match naming patterns so that __assetres, __header, __impl
# targets work properly. Those generated targets allow for effective deps
# filtering.
if (filter_exclude([ _type ], _java_resource_types) == []) {
if (filter_exclude([ _target_label ], _java_resource_patterns) != []) {
assert(false, "Invalid java resource target name: $_target_label")
}
} else if (filter_exclude([ _type ], _java_library_types) == []) {
if (filter_exclude([ _target_label ], _java_library_patterns) != [] ||
filter_exclude([ _target_label ], _java_resource_patterns) == []) {
assert(false, "Invalid java library target name: $_target_label")
}
} else if (_type == "group") {
if (filter_exclude([ _target_label ], java_target_patterns) != []) {
assert(false, "Invalid java target name: $_target_label")
}
} else if (filter_exclude([ _type ], _java_leaf_types) != []) {
assert(false, "This java type needs a category: $_type")
}
if (defined(invoker.public_target_label)) {
_target_label = invoker.public_target_label
}
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
if (!defined(deps)) {
deps = []
}
if (defined(invoker.android_manifest_dep)) {
deps += [ invoker.android_manifest_dep ]
}
script = "//build/android/gyp/write_build_config.py"
depfile = "$target_gen_dir/$target_name.d"
inputs = []
outputs = [ invoker.build_config ]
_deps_configs = []
_public_deps_configs = []
if (defined(invoker.possible_config_deps)) {
foreach(_possible_dep, invoker.possible_config_deps) {
_dep_label = get_label_info(_possible_dep, "label_no_toolchain")
if (filter_exclude([ _dep_label ], java_target_patterns) == []) {
# Put the bug number in the target name so that false-positives
# have a hint in the error message about non-existent dependencies.
deps += [ "$_dep_label$build_config_target_suffix" ]
_dep_gen_dir = get_label_info(_possible_dep, "target_gen_dir")
_dep_name = get_label_info(_possible_dep, "name")
_dep_config = "$_dep_gen_dir/$_dep_name.build_config"
_deps_configs += [ _dep_config ]
if (defined(invoker.possible_config_public_deps)) {
if (filter_include([ _possible_dep ],
invoker.possible_config_public_deps) != []) {
_public_deps_configs += [ _dep_config ]
}
}
}
}
}
_rebased_deps_configs = rebase_path(_deps_configs, root_build_dir)
_rebased_public_deps_configs =
rebase_path(_public_deps_configs, root_build_dir)
args = [
"--type=$_type",
"--depfile",
rebase_path(depfile, root_build_dir),
"--deps-configs=$_rebased_deps_configs",
"--public-deps-configs=$_rebased_public_deps_configs",
"--build-config",
rebase_path(invoker.build_config, root_build_dir),
"--gn-target",
_target_label,
]
if (defined(invoker.ignore_dependency_public_deps) &&
invoker.ignore_dependency_public_deps) {
args += [ "--ignore-dependency-public-deps" ]
}
if (defined(invoker.aar_path)) {
args += [
"--aar-path",
rebase_path(invoker.aar_path, root_build_dir),
]
}
if (defined(invoker.chromium_code) && !invoker.chromium_code) {
# Default to chromium code if invoker did not pass anything.
args += [ "--non-chromium-code" ]
}
if (defined(invoker.device_jar_path)) {
args += [
"--device-jar-path",
rebase_path(invoker.device_jar_path, root_build_dir),
]
}
if (defined(invoker.host_jar_path)) {
args += [
"--host-jar-path",
rebase_path(invoker.host_jar_path, root_build_dir),
]
}
if (defined(invoker.unprocessed_jar_path)) {
args += [
"--unprocessed-jar-path",
rebase_path(invoker.unprocessed_jar_path, root_build_dir),
]
}
if (defined(invoker.ijar_path)) {
args += [
"--interface-jar-path",
rebase_path(invoker.ijar_path, root_build_dir),
]
}
if (defined(invoker.java_resources_jar)) {
args += [
"--java-resources-jar-path",
rebase_path(invoker.java_resources_jar, root_build_dir),
]
}
if (defined(invoker.annotation_processor_deps) &&
invoker.annotation_processor_deps != []) {
_processor_configs = []
foreach(_processor_dep, invoker.annotation_processor_deps) {
_dep_label = get_label_info(_processor_dep, "label_no_toolchain")
_dep_gen_dir = get_label_info(_processor_dep, "target_gen_dir")
_dep_name = get_label_info(_processor_dep, "name")
deps += [ "$_dep_label$build_config_target_suffix" ]
_processor_configs += [ "$_dep_gen_dir/$_dep_name.build_config" ]
}
_rebased_processor_configs =
rebase_path(_processor_configs, root_build_dir)
args += [ "--annotation-processor-configs=$_rebased_processor_configs" ]
}
# Dex path for library targets, or the the intermediate library for apks.
if (defined(invoker.dex_path)) {
args += [
"--dex-path",
rebase_path(invoker.dex_path, root_build_dir),
]
}
# Dex path for the final apk.
if (defined(invoker.final_dex_path)) {
args += [
"--final-dex-path",
rebase_path(invoker.final_dex_path, root_build_dir),
]
}
if (defined(invoker.supports_android) && invoker.supports_android) {
args += [ "--supports-android" ]
}
if (defined(invoker.requires_android) && invoker.requires_android) {
args += [ "--requires-android" ]
}
if (defined(invoker.is_prebuilt) && invoker.is_prebuilt) {
args += [ "--is-prebuilt" ]
}
if (defined(invoker.bypass_platform_checks) &&
invoker.bypass_platform_checks) {
args += [ "--bypass-platform-checks" ]
}
if (defined(invoker.apk_under_test)) {
deps += [ "${invoker.apk_under_test}$build_config_target_suffix" ]
apk_under_test_gen_dir =
get_label_info(invoker.apk_under_test, "target_gen_dir")
apk_under_test_name = get_label_info(invoker.apk_under_test, "name")
apk_under_test_config =
"$apk_under_test_gen_dir/$apk_under_test_name.build_config"
args += [
"--tested-apk-config",
rebase_path(apk_under_test_config, root_build_dir),
]
}
if (defined(invoker.asset_sources)) {
_rebased_asset_sources =
rebase_path(invoker.asset_sources, root_build_dir)
args += [ "--asset-sources=$_rebased_asset_sources" ]
}
if (defined(invoker.asset_renaming_sources)) {
_rebased_asset_renaming_sources =
rebase_path(invoker.asset_renaming_sources, root_build_dir)
args += [ "--asset-renaming-sources=$_rebased_asset_renaming_sources" ]
# These are zip paths, so no need to rebase.
args += [
"--asset-renaming-destinations=${invoker.asset_renaming_destinations}",
]
}
if (defined(invoker.disable_compression) && invoker.disable_compression) {
args += [ "--disable-asset-compression" ]
}
if (defined(invoker.treat_as_locale_paks) && invoker.treat_as_locale_paks) {
args += [ "--treat-as-locale-paks" ]
}
if (defined(invoker.android_manifest)) {
inputs += [ invoker.android_manifest ]
args += [
"--android-manifest",
rebase_path(invoker.android_manifest, root_build_dir),
]
}
if (defined(invoker.resources_zip)) {
args += [
"--resources-zip",
rebase_path(invoker.resources_zip, root_build_dir),
]
}
if (defined(invoker.resource_overlay) && invoker.resource_overlay) {
args += [ "--resource-overlay" ]
}
if (defined(invoker.custom_package)) {
args += [
"--package-name",
invoker.custom_package,
]
}
if (defined(invoker.r_text)) {
args += [
"--r-text-path",
rebase_path(invoker.r_text, root_build_dir),
]
}
if (defined(invoker.res_size_info_path)) {
args += [
"--res-size-info",
rebase_path(invoker.res_size_info_path, root_build_dir),
]
}
if (defined(invoker.resource_dirs)) {
resource_dirs = rebase_path(invoker.resource_dirs, root_build_dir)
args += [ "--resource-dirs=$resource_dirs" ]
}
if (defined(invoker.res_sources_path)) {
_res_sources_path = rebase_path(invoker.res_sources_path, root_build_dir)
args += [ "--res-sources-path=$_res_sources_path" ]
}
if (defined(invoker.proto_resources_path)) {
_rebased_proto_resources =
rebase_path(invoker.proto_resources_path, root_build_dir)
args += [ "--apk-proto-resources=$_rebased_proto_resources" ]
}
if (defined(invoker.r_text_path)) {
_rebased_rtxt_path = rebase_path(invoker.r_text_path, root_build_dir)
args += [ "--r-text-path=$_rebased_rtxt_path" ]
}
if (defined(invoker.module_pathmap_path)) {
_rebased_pathmap_path =
rebase_path(invoker.module_pathmap_path, root_build_dir)
args += [ "--module-pathmap-path=$_rebased_pathmap_path" ]
}
if (defined(invoker.shared_libraries_runtime_deps_file)) {
# Don't list shared_libraries_runtime_deps_file as an input in order to
# avoid having to depend on the runtime_deps target. See comment in
# rules.gni for why we do this.
args += [
"--shared-libraries-runtime-deps",
rebase_path(invoker.shared_libraries_runtime_deps_file, root_build_dir),
]
}
if (defined(invoker.base_allowlist_rtxt_path)) {
args += [
"--base-allowlist-rtxt-path",
rebase_path(invoker.base_allowlist_rtxt_path, root_build_dir),
]
}
if (defined(invoker.is_base_module) && invoker.is_base_module) {
args += [ "--is-base-module" ]
}
if (defined(invoker.loadable_modules)) {
_rebased_loadable_modules =
rebase_path(invoker.loadable_modules, root_build_dir)
args += [ "--loadable-modules=$_rebased_loadable_modules" ]
}
if (defined(invoker.secondary_abi_shared_libraries_runtime_deps_file)) {
# Don't list secondary_abi_shared_libraries_runtime_deps_file as an
# input in order to avoid having to depend on the runtime_deps target.
# See comment in rules.gni for why we do this.
args += [
"--secondary-abi-shared-libraries-runtime-deps",
rebase_path(invoker.secondary_abi_shared_libraries_runtime_deps_file,
root_build_dir),
]
}
if (defined(invoker.secondary_abi_loadable_modules) &&
invoker.secondary_abi_loadable_modules != []) {
_rebased_secondary_abi_loadable_modules =
rebase_path(invoker.secondary_abi_loadable_modules, root_build_dir)
args += [ "--secondary-abi-loadable-modules=$_rebased_secondary_abi_loadable_modules" ]
}
if (defined(invoker.native_lib_placeholders) &&
invoker.native_lib_placeholders != []) {
args += [ "--native-lib-placeholders=${invoker.native_lib_placeholders}" ]
}
if (defined(invoker.secondary_native_lib_placeholders) &&
invoker.secondary_native_lib_placeholders != []) {
args += [ "--secondary-native-lib-placeholders=${invoker.secondary_native_lib_placeholders}" ]
}
if (defined(invoker.uncompress_shared_libraries) &&
invoker.uncompress_shared_libraries) {
args += [ "--uncompress-shared-libraries" ]
}
if (defined(invoker.library_always_compress)) {
args += [ "--library-always-compress=${invoker.library_always_compress}" ]
}
if (defined(invoker.library_renames)) {
args += [ "--library-renames=${invoker.library_renames}" ]
}
if (defined(invoker.apk_path)) {
# TODO(tiborg): Remove APK path from build config and use
# install_artifacts from metadata instead.
_rebased_apk_path = rebase_path(invoker.apk_path, root_build_dir)
args += [ "--apk-path=$_rebased_apk_path" ]
if (defined(invoker.incremental_apk_path)) {
_rebased_incremental_apk_path =
rebase_path(invoker.incremental_apk_path, root_build_dir)
_rebased_incremental_install_json_path =
rebase_path(invoker.incremental_install_json_path, root_build_dir)
args += [
"--incremental-install-json-path=$_rebased_incremental_install_json_path",
"--incremental-apk-path=$_rebased_incremental_apk_path",
]
}
}
if (defined(invoker.java_sources_file)) {
args += [
"--java-sources-file",
rebase_path(invoker.java_sources_file, root_build_dir),
]
}
if (defined(invoker.srcjar)) {
args += [
"--srcjar",
rebase_path(invoker.srcjar, root_build_dir),
]
}
if (defined(invoker.bundled_srcjars)) {
_rebased_bundled_srcjars =
rebase_path(invoker.bundled_srcjars, root_build_dir)
args += [ "--bundled-srcjars=$_rebased_bundled_srcjars" ]
}
if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) {
args += [ "--proguard-enabled" ]
}
if (defined(invoker.proguard_mapping_path)) {
_rebased_proguard_mapping_path =
rebase_path(invoker.proguard_mapping_path, root_build_dir)
args += [ "--proguard-mapping-path=$_rebased_proguard_mapping_path" ]
}
if (defined(invoker.input_jars_paths)) {
_rebased_input_jars_paths =
rebase_path(invoker.input_jars_paths, root_build_dir)
args += [ "--extra-classpath-jars=$_rebased_input_jars_paths" ]
}
if (defined(invoker.low_classpath_priority) &&
invoker.low_classpath_priority) {
args += [ "--low-classpath-priority" ]
}
if (defined(invoker.mergeable_android_manifests)) {
_rebased_mergeable_android_manifests =
rebase_path(invoker.mergeable_android_manifests, root_build_dir)
args += [
"--mergeable-android-manifests=$_rebased_mergeable_android_manifests",
]
}
if (defined(invoker.proguard_configs)) {
_rebased_proguard_configs =
rebase_path(invoker.proguard_configs, root_build_dir)
args += [ "--proguard-configs=$_rebased_proguard_configs" ]
}
if (defined(invoker.static_library_dependent_targets)) {
_dependent_configs = []
foreach(_dep, invoker.static_library_dependent_targets) {
_dep_name = _dep.name
_dep_label = get_label_info(_dep_name, "label_no_toolchain")
deps += [ "$_dep_label$build_config_target_suffix" ]
_dep_gen_dir = get_label_info(_dep_name, "target_gen_dir")
_dep_name = get_label_info(_dep_name, "name")
_config =
rebase_path("$_dep_gen_dir/$_dep_name.build_config", root_build_dir)
_dependent_configs += [ _config ]
}
args += [ "--static-library-dependent-configs=$_dependent_configs" ]
}
if (defined(invoker.gradle_treat_as_prebuilt) &&
invoker.gradle_treat_as_prebuilt) {
args += [ "--gradle-treat-as-prebuilt" ]
}
if (defined(invoker.main_class)) {
args += [
"--main-class",
invoker.main_class,
]
}
if (defined(invoker.base_module_target)) {
_base_label =
get_label_info(invoker.base_module_target, "label_no_toolchain")
_dep_gen_dir = get_label_info(_base_label, "target_gen_dir")
_dep_name = get_label_info(_base_label, "name")
deps += [ "$_base_label$build_config_target_suffix" ]
_base_module_build_config = "$_dep_gen_dir/$_dep_name.build_config"
inputs += [ _base_module_build_config ]
args += [
"--base-module-build-config",
rebase_path(_base_module_build_config, root_build_dir),
]
}
if (defined(invoker.module_build_configs)) {
inputs += invoker.module_build_configs
_rebased_configs =
rebase_path(invoker.module_build_configs, root_build_dir)
args += [ "--module-build-configs=$_rebased_configs" ]
}
if (defined(invoker.version_name)) {
args += [
"--version-name",
invoker.version_name,
]
}
if (defined(invoker.version_code)) {
args += [
"--version-code",
invoker.version_code,
]
}
if (defined(invoker.recursive_resource_deps) &&
invoker.recursive_resource_deps) {
args += [ "--recursive-resource-deps" ]
}
if (current_toolchain != default_toolchain) {
# This has to be a built-time error rather than a GN assert because many
# packages have a mix of java and non-java targets. For example, the
# following would fail even though nothing depends on :bar(//baz):
#
# shared_library("foo") {
# }
#
# android_library("bar") {
# deps = [ ":foo(//baz)" ]
# assert(current_toolchain == default_toolchain)
# }
_msg = [
"Tried to build an Android target in a non-default toolchain.",
"target: $_target_label",
"current_toolchain: $current_toolchain",
"default_toolchain: $default_toolchain",
]
args += [ "--fail=$_msg" ]
}
}
}
template("generate_android_wrapper") {
generate_wrapper(target_name) {
forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
generator_script = "//build/android/gyp/generate_android_wrapper.py"
sources = [
"//build/android/gyp/util/build_utils.py",
"//build/gn_helpers.py",
"//build/util/generate_wrapper.py",
]
}
}
template("generate_r_java") {
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ])
if (!defined(deps)) {
deps = []
}
if (defined(invoker.possible_resource_deps)) {
foreach(_dep, invoker.possible_resource_deps) {
_target_label = get_label_info(_dep, "label_no_toolchain")
if (filter_exclude([ _target_label ], _java_library_patterns) == [] &&
filter_exclude([ _target_label ], _java_resource_patterns) != []) {
# Depend on the java libraries' transitive __assetres target instead.
# This is required to ensure depending on java_groups works.
deps += [ "${_target_label}__assetres" ]
} else {
deps += [ _dep ]
}
}
}
depfile = "$target_gen_dir/${invoker.target_name}.d"
inputs = [ invoker.build_config ]
outputs = [ invoker.srcjar_path ]
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
script = "//build/android/gyp/create_r_java.py"
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--srcjar-out",
rebase_path(invoker.srcjar_path, root_build_dir),
"--deps-rtxts=@FileArg($_rebased_build_config:deps_info:dependency_r_txt_files)",
"--r-package=${invoker.package}",
]
}
}
# Generates a script in the build bin directory which runs the test
# target using the test runner script in build/android/test_runner.py.
template("test_runner_script") {
testonly = true
_test_name = invoker.test_name
_test_type = invoker.test_type
_incremental_apk = defined(invoker.incremental_apk) && invoker.incremental_apk
_runtime_deps =
!defined(invoker.ignore_all_data_deps) || !invoker.ignore_all_data_deps
if (_runtime_deps) {
# This runtime_deps file is used at runtime and thus cannot go in
# target_gen_dir.
_target_dir_name = get_label_info(":$target_name", "dir")
_runtime_deps_file =
"$root_out_dir/gen.runtime/$_target_dir_name/$target_name.runtime_deps"
_runtime_deps_target = "${target_name}__write_deps"
group(_runtime_deps_target) {
forward_variables_from(invoker,
[
"data",
"deps",
"public_deps",
])
data_deps = []
if (defined(invoker.data_deps)) {
data_deps += invoker.data_deps
}
if (defined(invoker.additional_apks)) {
data_deps += invoker.additional_apks
}
write_runtime_deps = _runtime_deps_file
}
}
if (defined(invoker.apk_under_test)) {
_install_artifacts_json =
"${target_gen_dir}/${target_name}.install_artifacts"
generated_file("${target_name}__install_artifacts") {
deps = [ invoker.apk_under_test ]
output_conversion = "json"
outputs = [ _install_artifacts_json ]
data_keys = [ "install_artifacts" ]
walk_keys = [ "install_artifacts_barrier" ]
rebase = root_build_dir
}
}
generate_android_wrapper(target_name) {
wrapper_script = "$root_build_dir/bin/run_${_test_name}"
executable = "//testing/test_env.py"
if (defined(android_test_runner_script)) {
_runner_script = android_test_runner_script
} else {
_runner_script = "//build/android/test_runner.py"
}
deps = []
if (defined(invoker.deps)) {
deps = invoker.deps
}
data_deps = [
"//build/android:test_runner_py",
"//testing:test_scripts_shared",
]
if (defined(invoker.data_deps)) {
data_deps += invoker.data_deps
}
data = []
if (defined(invoker.data)) {
data += invoker.data
}
executable_args = [
"@WrappedPath(" + rebase_path(_runner_script, root_build_dir) + ")",
_test_type,
"--output-directory",
"@WrappedPath(.)",
]
if (_runtime_deps) {
deps += [ ":$_runtime_deps_target" ]
data += [ _runtime_deps_file ]
_rebased_runtime_deps_file =
rebase_path(_runtime_deps_file, root_build_dir)
executable_args += [
"--runtime-deps-path",
"@WrappedPath(${_rebased_runtime_deps_file})",
]
}
# apk_target is not used for native executable tests
# (e.g. breakpad_unittests).
if (defined(invoker.apk_target)) {
assert(!defined(invoker.executable_dist_dir))
deps += [ "${invoker.apk_target}$build_config_target_suffix" ]
_apk_build_config =
get_label_info(invoker.apk_target, "target_gen_dir") + "/" +
get_label_info(invoker.apk_target, "name") + ".build_config"
_rebased_apk_build_config = rebase_path(_apk_build_config, root_build_dir)
not_needed([ "_rebased_apk_build_config" ])
} else if (_test_type == "gtest") {
assert(
defined(invoker.executable_dist_dir),
"Must define either apk_target or executable_dist_dir for test_runner_script()")
_rebased_executable_dist_dir =
rebase_path(invoker.executable_dist_dir, root_build_dir)
executable_args += [
"--executable-dist-dir",
"@WrappedPath(${_rebased_executable_dist_dir})",
]
}
_device_test = true
if (_test_type == "gtest") {
assert(defined(invoker.test_suite))
executable_args += [
"--suite",
invoker.test_suite,
]
if (use_clang_coverage) {
# Set a default coverage output directory (can be overridden by user
# passing the same flag).
_rebased_coverage_dir =
rebase_path("$root_out_dir/coverage", root_build_dir)
executable_args += [
"--coverage-dir",
"@WrappedPath(${_rebased_coverage_dir})",
]
}
} else if (_test_type == "instrumentation") {
_test_apk = "@WrappedPath(@FileArg($_rebased_apk_build_config:deps_info:apk_path))"
if (_incremental_apk) {
_test_apk = "@WrappedPath(@FileArg($_rebased_apk_build_config:deps_info:incremental_apk_path))"
}
_rebased_test_jar = rebase_path(invoker.test_jar, root_build_dir)
executable_args += [
"--test-apk",
_test_apk,
"--test-jar",
"@WrappedPath(${_rebased_test_jar})",
]
if (defined(invoker.apk_under_test)) {
if (_incremental_apk) {
deps += [ "${invoker.apk_under_test}$build_config_target_suffix" ]
_apk_under_test_build_config =
get_label_info(invoker.apk_under_test, "target_gen_dir") + "/" +
get_label_info(invoker.apk_under_test, "name") + ".build_config"
_rebased_apk_under_test_build_config =
rebase_path(_apk_under_test_build_config, root_build_dir)
_apk_under_test = "@WrappedPath(@FileArg($_rebased_apk_under_test_build_config:deps_info:incremental_apk_path))"
} else {
deps += [ ":${target_name}__install_artifacts" ]
_rebased_install_artifacts_json =
rebase_path(_install_artifacts_json, root_build_dir)
_apk_under_test =
"@WrappedPath(@FileArg($_rebased_install_artifacts_json[]))"
}
executable_args += [
"--apk-under-test",
_apk_under_test,
]
}
if (defined(invoker.use_webview_provider)) {
deps += [ "${invoker.use_webview_provider}$build_config_target_suffix" ]
_build_config =
get_label_info(invoker.use_webview_provider, "target_gen_dir") +
"/" + get_label_info(invoker.use_webview_provider, "name") +
".build_config"
_rebased_build_config = rebase_path(_build_config, root_build_dir)
executable_args += [
"--use-webview-provider",
"@WrappedPath(@FileArg($_rebased_build_config:deps_info:apk_path))",
]
}
if (defined(invoker.proguard_enabled) && invoker.proguard_enabled &&
!_incremental_apk) {
executable_args += [ "--enable-java-deobfuscation" ]
}
if (use_jacoco_coverage) {
# Set a default coverage output directory (can be overridden by user
# passing the same flag).
_rebased_coverage_dir =
rebase_path("$root_out_dir/coverage", root_build_dir)
executable_args += [
"--coverage-dir",
"@WrappedPath(${_rebased_coverage_dir})",
]
}
} else if (_test_type == "junit") {
assert(defined(invoker.test_suite))
_device_test = false
executable_args += [
"--test-suite",
invoker.test_suite,
]
deps += [ ":${invoker.test_suite}$build_config_target_suffix" ]
_junit_binary_build_config =
"${target_gen_dir}/${invoker.test_suite}.build_config"
_rebased_robolectric_runtime_deps_dir =
rebase_path("$root_build_dir/lib.java/third_party/robolectric",
root_build_dir)
_rebased_resource_apk = rebase_path(invoker.resource_apk, root_build_dir)
executable_args += [
"--resource-apk",
"@WrappedPath(${_rebased_resource_apk})",
"--robolectric-runtime-deps-dir",
"@WrappedPath(${_rebased_robolectric_runtime_deps_dir})",
]
if (use_jacoco_coverage) {
# Set a default coverage output directory (can be overridden by user
# passing the same flag).
_rebased_coverage_dir =
rebase_path("$root_out_dir/coverage", root_build_dir)
executable_args += [
"--coverage-dir",
"@WrappedPath(${_rebased_coverage_dir})",
]
}
} else if (_test_type == "linker") {
executable_args += [
"--test-apk",
"@WrappedPath(@FileArg($_rebased_apk_build_config:deps_info:apk_path))",
]
} else {
assert(false, "Invalid test type: $_test_type.")
}
if (defined(invoker.additional_apks)) {
foreach(additional_apk, invoker.additional_apks) {
deps += [ "$additional_apk$build_config_target_suffix" ]
_build_config = get_label_info(additional_apk, "target_gen_dir") + "/" +
get_label_info(additional_apk, "name") + ".build_config"
_rebased_build_config = rebase_path(_build_config, root_build_dir)
executable_args += [
"--additional-apk",
"@WrappedPath(@FileArg($_rebased_build_config:deps_info:apk_path))",
]
}
}
if (defined(invoker.shard_timeout)) {
executable_args += [ "--shard-timeout=${invoker.shard_timeout}" ]
}
if (_incremental_apk) {
executable_args += [
"--test-apk-incremental-install-json",
"@WrappedPath(@FileArg($_rebased_apk_build_config:deps_info:incremental_install_json_path))",
]
if (defined(invoker.apk_under_test)) {
executable_args += [
"--apk-under-test-incremental-install-json",
"@WrappedPath(@FileArg($_rebased_apk_under_test_build_config:deps_info:incremental_install_json_path))",
]
}
executable_args += [ "--fast-local-dev" ]
}
if (_device_test && is_asan) {
executable_args += [ "--tool=asan" ]
}
if (defined(invoker.modules)) {
foreach(module, invoker.modules) {
executable_args += [
"--module",
module,
]
}
}
if (defined(invoker.fake_modules)) {
foreach(fake_module, invoker.fake_modules) {
executable_args += [
"--fake-module",
fake_module,
]
}
}
if (defined(invoker.additional_locales)) {
foreach(locale, invoker.additional_locales) {
executable_args += [
"--additional-locale",
locale,
]
}
}
if (defined(invoker.extra_args)) {
executable_args += invoker.extra_args
}
}
}
if (enable_java_templates) {
template("android_lint") {
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
if (!defined(deps)) {
deps = []
}
# https://crbug.com/1098752 Fix for bot OOM (https://crbug.com/1098333).
if (defined(java_cmd_pool_size)) {
pool = "//build/config/android:java_cmd_pool($default_toolchain)"
} else {
pool = "//build/toolchain:link_pool($default_toolchain)"
}
# Lint requires generated sources and generated resources from the build.
# Turbine __header targets depend on all generated sources, and the
# __assetres targets depend on all generated resources.
if (defined(invoker.deps)) {
foreach(_dep, invoker.deps) {
_target_label = get_label_info(_dep, "label_no_toolchain")
if (filter_exclude([ _target_label ], _java_library_patterns) == [] &&
filter_exclude([ _target_label ], _java_resource_patterns) !=
[]) {
deps += [
"${_target_label}__assetres",
"${_target_label}__header",
]
} else {
# Keep non-java deps as they may generate files used only by lint.
# e.g. generated suppressions.xml files.
deps += [ _dep ]
}
}
}
if (defined(invoker.min_sdk_version)) {
_min_sdk_version = invoker.min_sdk_version
} else {
_min_sdk_version = default_min_sdk_version
}
_lint_binary_path = "$lint_android_sdk_root/cmdline-tools/latest/bin/lint"
_cache_dir = "$root_build_dir/android_lint_cache"
# Save generated xml files in a consistent location for debugging.
_lint_gen_dir = "$target_gen_dir/$target_name"
_backported_methods = "//third_party/r8/backported_methods.txt"
script = "//build/android/gyp/lint.py"
depfile = "$target_gen_dir/$target_name.d"
inputs = [
_lint_binary_path,
_backported_methods,
]
args = [
"--target-name",
get_label_info(target_name, "label_no_toolchain"),
"--depfile",
rebase_path(depfile, root_build_dir),
"--lint-binary-path",
rebase_path(_lint_binary_path, root_build_dir),
"--cache-dir",
rebase_path(_cache_dir, root_build_dir),
"--lint-gen-dir",
rebase_path(_lint_gen_dir, root_build_dir),
"--android-sdk-version=${lint_android_sdk_version}",
"--min-sdk-version=$_min_sdk_version",
"--android-sdk-root",
rebase_path(lint_android_sdk_root, root_build_dir),
"--backported-methods",
rebase_path(_backported_methods, root_build_dir),
]
if (defined(invoker.skip_build_server) && invoker.skip_build_server) {
# Nocompile tests need lint to fail through ninja.
args += [ "--skip-build-server" ]
}
if (defined(invoker.lint_suppressions_file)) {
inputs += [ invoker.lint_suppressions_file ]
args += [
"--config-path",
rebase_path(invoker.lint_suppressions_file, root_build_dir),
]
}
if (defined(testonly) && testonly) {
# Allows us to ignore unnecessary checks when linting test targets.
args += [ "--testonly" ]
}
if (defined(invoker.manifest_package)) {
args += [ "--manifest-package=${invoker.manifest_package}" ]
}
if (treat_warnings_as_errors) {
args += [ "--warnings-as-errors" ]
}
if (defined(invoker.lint_baseline_file)) {
if (compute_inputs_for_analyze) {
# The baseline file is included in lint.py as a depfile dep. Since
# removing it regenerates the file, it is useful to not have this as
# a gn input during local development. Add it only for bots' analyze.
inputs += [ invoker.lint_baseline_file ]
}
args += [
# Baseline allows us to turn on lint warnings without fixing all the
# pre-existing issues. This stops the flood of new issues while the
# existing ones are being fixed.
"--baseline",
rebase_path(invoker.lint_baseline_file, root_build_dir),
]
}
if (defined(invoker.create_cache) && invoker.create_cache) {
# Putting the stamp file in the cache dir allows us to depend on ninja
# to create the cache dir for us.
_stamp_path = "$_cache_dir/build.lint.stamp"
args += [ "--create-cache" ]
} else {
_stamp_path = "$target_out_dir/$target_name/build.lint.stamp"
deps += [
"//build/android:prepare_android_lint_cache",
invoker.build_config_dep,
]
inputs += [ invoker.build_config ]
_rebased_build_config =
rebase_path(invoker.build_config, root_build_dir)
args += [
"--manifest-path=@FileArg($_rebased_build_config:deps_info:lint_android_manifest)",
"--extra-manifest-paths=@FileArg($_rebased_build_config:deps_info:lint_extra_android_manifests)",
# Lint requires all source and all resource files to be passed in the
# same invocation for checks like UnusedResources.
"--java-sources=@FileArg($_rebased_build_config:deps_info:lint_java_sources)",
"--aars=@FileArg($_rebased_build_config:deps_info:lint_aars)",
"--srcjars=@FileArg($_rebased_build_config:deps_info:lint_srcjars)",
"--resource-sources=@FileArg($_rebased_build_config:deps_info:lint_resource_sources)",
"--resource-zips=@FileArg($_rebased_build_config:deps_info:lint_resource_zips)",
# The full classpath is required for annotation checks like @IntDef.
"--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)",
]
}
outputs = [ _stamp_path ]
args += [
"--stamp",
rebase_path(_stamp_path, root_build_dir),
]
}
}
template("proguard") {
forward_variables_from(invoker,
TESTONLY_AND_VISIBILITY + [
"data",
"data_deps",
"public_deps",
])
_script = "//build/android/gyp/proguard.py"
_deps = invoker.deps
_inputs = [
invoker.build_config,
_r8_path,
]
if (defined(invoker.inputs)) {
_inputs += invoker.inputs
}
if (defined(invoker.proguard_mapping_path)) {
_mapping_path = invoker.proguard_mapping_path
} else {
_mapping_path = "${invoker.output_path}.mapping"
}
_enable_jdk_library_desugaring = enable_jdk_library_desugaring
if (defined(invoker.supports_jdk_library_desugaring) &&
!invoker.supports_jdk_library_desugaring) {
_enable_jdk_library_desugaring = false
}
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
_args = [
"--mapping-output",
rebase_path(_mapping_path, root_build_dir),
"--classpath",
"@FileArg($_rebased_build_config:deps_info:proguard_classpath_jars)",
"--classpath",
"@FileArg($_rebased_build_config:android:sdk_jars)",
"--r8-path",
rebase_path(_r8_path, root_build_dir),
]
if (treat_warnings_as_errors) {
_args += [ "--warnings-as-errors" ]
}
if (defined(invoker.desugar_jars_paths)) {
_rebased_desugar_jars_paths =
rebase_path(invoker.desugar_jars_paths, root_build_dir)
args += [ "--classpath=${_rebased_desugar_jars_paths}" ]
}
if ((!defined(invoker.proguard_enable_obfuscation) ||
invoker.proguard_enable_obfuscation) && enable_proguard_obfuscation) {
_proguard_sourcefile_suffix = ""
if (defined(invoker.proguard_sourcefile_suffix)) {
_proguard_sourcefile_suffix = "-${invoker.proguard_sourcefile_suffix}"
}
# This is generally the apk name, and serves to identify the mapping
# file that would be required to deobfuscate a stacktrace.
_mapping_id = get_path_info(_mapping_path, "name")
_args += [
"--enable-obfuscation",
"--sourcefile",
"chromium-${_mapping_id}${_proguard_sourcefile_suffix}",
]
} else if (defined(invoker.proguard_sourcefile_suffix)) {
not_needed(invoker, [ "proguard_sourcefile_suffix" ])
}
if (defined(invoker.modules)) {
foreach(_feature_module, invoker.modules) {
_rebased_module_build_config =
rebase_path(_feature_module.build_config, root_build_dir)
_args += [
"--feature-name=${_feature_module.name}",
"--dex-dest=@FileArg($_rebased_module_build_config:final_dex:path)",
"--feature-jars=@FileArg($_rebased_module_build_config:deps_info:device_classpath)",
]
if (defined(_feature_module.uses_split)) {
_args += [ "--uses-split=${_feature_module.name}:${_feature_module.uses_split}" ]
}
_deps += [ _feature_module.build_config_target ]
}
_stamp = "${target_gen_dir}/${target_name}.r8.stamp"
_outputs = [ _stamp ]
_output_arg = [
"--stamp",
rebase_path(_stamp, root_build_dir),
]
} else {
# We don't directly set the output arg on the _args variable since it is
# shared with the expectation target that uses its own stamp file and
# does not take an --output-path.
_output_arg = [
"--output-path",
rebase_path(invoker.output_path, root_build_dir),
]
_outputs = [ invoker.output_path ]
}
_outputs += [ _mapping_path ]
if (defined(invoker.disable_r8_outlining) && invoker.disable_r8_outlining) {
_args += [ "--disable-outlining" ]
}
if (defined(invoker.enable_proguard_checks) &&
!invoker.enable_proguard_checks) {
_args += [ "--disable-checks" ]
}
if (defined(invoker.is_static_library) && invoker.is_static_library) {
_args += [
"--extra-mapping-output-paths",
"@FileArg($_rebased_build_config:deps_info:static_library_proguard_mapping_output_paths)",
]
}
if (_enable_jdk_library_desugaring) {
_args += [
"--desugar-jdk-libs-json",
rebase_path(_desugar_jdk_libs_json, root_build_dir),
]
_inputs += [ _desugar_jdk_libs_json ]
_args += [
"--desugar-jdk-libs-jar",
rebase_path(_desugar_jdk_libs_jar, root_build_dir),
"--desugar-jdk-libs-configuration-jar",
rebase_path(_desugar_jdk_libs_configuration_jar, root_build_dir),
]
_inputs += [
_desugar_jdk_libs_jar,
_desugar_jdk_libs_configuration_jar,
]
_desugared_library_keep_rule_output_path =
"$target_gen_dir/$target_name.desugared_library_keep_rules.flags"
_args += [
"--desugared-library-keep-rule-output",
rebase_path(_desugared_library_keep_rule_output_path, root_build_dir),
]
}
_ignore_desugar_missing_deps =
defined(invoker.ignore_desugar_missing_deps) &&
invoker.ignore_desugar_missing_deps
if (!_ignore_desugar_missing_deps && !enable_bazel_desugar) {
_args += [ "--show-desugar-default-interface-warnings" ]
}
if (enable_java_asserts) {
# The default for generating dex file format is
# --force-disable-assertions.
_args += [ "--force-enable-assertions" ]
}
if (defined(invoker.args)) {
_args += invoker.args
}
if (defined(invoker.expected_proguard_config)) {
_expectations_target =
"${invoker.top_target_name}_validate_proguard_config"
action_with_pydeps(_expectations_target) {
script = _script
# Need to depend on all deps so that proguard.txt within .aar files get
# extracted.
deps = _deps
depfile = "${target_gen_dir}/${target_name}.d"
inputs = [
invoker.build_config,
invoker.expected_proguard_config,
]
_actual_file = "$target_gen_dir/$target_name.proguard_configs"
_failure_file =
"$expectations_failure_dir/" +
string_replace(invoker.expected_proguard_config, "/", "_")
outputs = [
_actual_file,
_failure_file,
]
args = _args + [
"--depfile",
rebase_path(depfile, root_build_dir),
"--failure-file",
rebase_path(_failure_file, root_build_dir),
"--expected-file",
rebase_path(invoker.expected_proguard_config, root_build_dir),
"--actual-file",
rebase_path(_actual_file, root_build_dir),
"--only-verify-expectations",
]
if (defined(invoker.expected_proguard_config_base)) {
inputs += [ invoker.expected_proguard_config_base ]
args += [
"--expected-file-base",
rebase_path(invoker.expected_proguard_config_base, root_build_dir),
]
}
if (fail_on_android_expectations) {
args += [ "--fail-on-expectations" ]
}
}
_deps += [ ":$_expectations_target" ]
}
action_with_pydeps(target_name) {
script = _script
deps = _deps
inputs = _inputs
outputs = _outputs
depfile = "${target_gen_dir}/${target_name}.d"
args = _args + _output_arg + [
"--depfile",
rebase_path(depfile, root_build_dir),
]
# http://crbug.com/725224. Fix for bots running out of memory.
if (defined(java_cmd_pool_size)) {
pool = "//build/config/android:java_cmd_pool($default_toolchain)"
} else {
pool = "//build/toolchain:link_pool($default_toolchain)"
}
}
}
# Generates a script in the build bin directory to run a java binary.
#
# Variables
# main_class: The class containing the program entry point.
# build_config: Path to .build_config for the jar (contains classpath).
# script_name: Name of the script to generate.
# wrapper_script_args: List of extra arguments to pass to the executable.
# tiered_stop_at_level_one: Whether to pass --tiered-stop-at-level-one
#
template("java_binary_script") {
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ])
_main_class = invoker.main_class
_build_config = invoker.build_config
_script_name = invoker.script_name
script = "//build/android/gyp/create_java_binary_script.py"
inputs = [ _build_config ]
_java_script = "$root_build_dir/bin/$_script_name"
outputs = [ _java_script ]
_rebased_build_config = rebase_path(_build_config, root_build_dir)
args = [
"--output",
rebase_path(_java_script, root_build_dir),
"--main-class",
_main_class,
]
args += [
"--classpath=@FileArg($_rebased_build_config:deps_info:host_classpath)",
]
if (use_jacoco_coverage) {
args += [
"--classpath",
rebase_path("//third_party/jacoco/lib/jacocoagent.jar",
root_build_dir),
]
}
if (use_jacoco_coverage || !treat_warnings_as_errors) {
args += [ "--noverify" ]
}
if (defined(invoker.tiered_stop_at_level_one) &&
invoker.tiered_stop_at_level_one) {
args += [ "--tiered-stop-at-level-one" ]
}
if (defined(invoker.wrapper_script_args)) {
args += [ "--" ] + invoker.wrapper_script_args
}
}
}
# Variables
# apply_mapping: The path to the ProGuard mapping file to apply.
# disable_incremental: Disable incremental dexing.
template("dex") {
_min_sdk_version = default_min_sdk_version
if (defined(invoker.min_sdk_version)) {
_min_sdk_version = invoker.min_sdk_version
}
_proguard_enabled =
defined(invoker.proguard_enabled) && invoker.proguard_enabled
_is_dex_merging = defined(invoker.input_dex_filearg)
_enable_multidex =
!defined(invoker.enable_multidex) || invoker.enable_multidex
_enable_main_dex_list = _enable_multidex && _min_sdk_version < 21
_enable_desugar = !defined(invoker.enable_desugar) || invoker.enable_desugar
_desugar_needs_classpath = _enable_desugar && !enable_bazel_desugar
# It's not safe to dex merge with libraries dex'ed at higher api versions.
assert(!_is_dex_merging || _min_sdk_version >= default_min_sdk_version)
# For D8's backported method desugaring to work properly, the dex merge step
# must not be set to a higher minSdkVersion than it was for the libraries.
if (_enable_desugar && _is_dex_merging) {
_min_sdk_version = default_min_sdk_version
}
assert(defined(invoker.output) ||
(_proguard_enabled && defined(invoker.modules)))
assert(!_proguard_enabled || !(defined(invoker.input_dex_filearg) ||
defined(invoker.input_classes_filearg) ||
defined(invoker.input_class_jars)),
"Cannot explicitly set inputs when proguarding a dex.")
# Dex merging should not also be dexing.
assert(!(_is_dex_merging && defined(invoker.input_classes_filearg)))
assert(!(_is_dex_merging && defined(invoker.input_class_jars)))
assert(!(defined(invoker.apply_mapping) && !_proguard_enabled),
"apply_mapping can only be specified if proguard is enabled.")
if (_enable_main_dex_list) {
_main_dex_rules = "//build/android/main_dex_classes.flags"
}
if (_desugar_needs_classpath || _proguard_enabled) {
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
}
if (_proguard_enabled) {
_proguard_target_name = target_name
proguard(_proguard_target_name) {
forward_variables_from(invoker,
TESTONLY_AND_VISIBILITY + [
"build_config",
"data",
"data_deps",
"deps",
"desugar_jars_paths",
"disable_r8_outlining",
"enable_proguard_checks",
"expected_proguard_config",
"expected_proguard_config_base",
"ignore_desugar_missing_deps",
"is_static_library",
"modules",
"proguard_enable_obfuscation",
"proguard_mapping_path",
"proguard_sourcefile_suffix",
"supports_jdk_library_desugaring",
"top_target_name",
])
inputs = []
if (defined(invoker.inputs)) {
inputs += invoker.inputs
}
if (defined(invoker.proguard_configs)) {
inputs += invoker.proguard_configs
}
args = [
"--proguard-configs=@FileArg($_rebased_build_config:deps_info:proguard_all_configs)",
"--min-api=$_min_sdk_version",
]
if (defined(invoker.has_apk_under_test) && invoker.has_apk_under_test) {
args += [ "--input-paths=@FileArg($_rebased_build_config:deps_info:device_classpath_extended)" ]
} else {
args += [ "--input-paths=@FileArg($_rebased_build_config:deps_info:device_classpath)" ]
}
if (enable_bazel_desugar) {
deps += [ "//third_party/bazel/desugar:desugar_runtime_java" ]
inputs += [ _desugar_runtime_jar ]
args += [
"--input-paths",
rebase_path(_desugar_runtime_jar, root_build_dir),
]
}
if (defined(invoker.proguard_args)) {
args += invoker.proguard_args
}
if (defined(invoker.apply_mapping)) {
_rebased_apply_mapping_path =
rebase_path(invoker.apply_mapping, root_build_dir)
args += [ "--apply-mapping=$_rebased_apply_mapping_path" ]
}
if (_enable_main_dex_list) {
if (defined(invoker.extra_main_dex_proguard_config)) {
args += [
"--main-dex-rules-path",
rebase_path(invoker.extra_main_dex_proguard_config,
root_build_dir),
]
inputs += [ invoker.extra_main_dex_proguard_config ]
}
args += [
"--main-dex-rules-path",
rebase_path(_main_dex_rules, root_build_dir),
]
inputs += [ _main_dex_rules ]
}
if (defined(invoker.output)) {
output_path = invoker.output
} else if (!defined(proguard_mapping_path)) {
proguard_mapping_path = "$target_out_dir/$target_name.mapping"
}
}
} else { # !_proguard_enabled
_is_library = defined(invoker.is_library) && invoker.is_library
_input_class_jars = []
if (defined(invoker.input_class_jars)) {
_input_class_jars = invoker.input_class_jars
}
_deps = invoker.deps
if (!_is_library && enable_bazel_desugar) {
# It would be more efficient to use the pre-dex'ed copy of the runtime,
# but it's easier to add it in this way.
_deps += [ "//third_party/bazel/desugar:desugar_runtime_java" ]
_input_class_jars += [ _desugar_runtime_jar ]
}
if (_input_class_jars != []) {
_rebased_input_class_jars =
rebase_path(_input_class_jars, root_build_dir)
}
action_with_pydeps(target_name) {
forward_variables_from(invoker,
TESTONLY_AND_VISIBILITY + [
"data",
"data_deps",
])
script = "//build/android/gyp/dex.py"
deps = _deps
depfile = "$target_gen_dir/$target_name.d"
outputs = [ invoker.output ]
inputs = [
_r8_path,
_custom_d8_path,
]
if (!_is_library) {
# http://crbug.com/725224. Fix for bots running out of memory.
if (defined(java_cmd_pool_size)) {
pool = "//build/config/android:java_cmd_pool($default_toolchain)"
} else {
pool = "//build/toolchain:link_pool($default_toolchain)"
}
}
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--output",
rebase_path(outputs[0], root_build_dir),
"--min-api=$_min_sdk_version",
"--r8-jar-path",
rebase_path(_r8_path, root_build_dir),
"--custom-d8-jar-path",
rebase_path(_custom_d8_path, root_build_dir),
# Uncomment when rebuilding custom_d8.jar.
#"--skip-custom-d8",
]
if (treat_warnings_as_errors) {
args += [ "--warnings-as-errors" ]
}
if (enable_incremental_d8 && !(defined(invoker.disable_incremental) &&
invoker.disable_incremental)) {
# Don't use incremental dexing for ProGuarded inputs as a precaution.
args += [
"--incremental-dir",
rebase_path("$target_out_dir/$target_name", root_build_dir),
]
}
if (_enable_multidex) {
args += [ "--multi-dex" ]
if (_enable_main_dex_list) {
if (defined(invoker.extra_main_dex_proguard_config)) {
args += [
"--main-dex-rules-path",
rebase_path(invoker.extra_main_dex_proguard_config,
root_build_dir),
]
inputs += [ invoker.extra_main_dex_proguard_config ]
}
args += [
"--main-dex-rules-path",
rebase_path(_main_dex_rules, root_build_dir),
]
inputs += [ _main_dex_rules ]
}
}
if (_is_library) {
args += [ "--library" ]
}
if (defined(invoker.input_dex_filearg)) {
inputs += [ invoker.build_config ]
args += [ "--dex-inputs-filearg=${invoker.input_dex_filearg}" ]
}
if (defined(invoker.input_classes_filearg)) {
inputs += [ invoker.build_config ]
args += [ "--class-inputs-filearg=${invoker.input_classes_filearg}" ]
}
if (_input_class_jars != []) {
inputs += _input_class_jars
args += [ "--class-inputs=${_rebased_input_class_jars}" ]
}
if (defined(invoker.dexlayout_profile)) {
args += [
"--dexlayout-profile",
rebase_path(invoker.dexlayout_profile, root_build_dir),
"--dexlayout-path",
rebase_path(_dexlayout_path, root_build_dir),
"--profman-path",
rebase_path(_profman_path, root_build_dir),
"--dexdump-path",
rebase_path(_dexdump_path, root_build_dir),
]
inputs += [
_dexlayout_path,
_profman_path,
_dexdump_path,
invoker.dexlayout_profile,
]
inputs += _default_art_libs
}
# Never compile intemediates with --release in order to:
# 1) not require recompiles when toggling is_java_debug,
# 2) allow incremental_install=1 to still have local variable
# information even when is_java_debug=false.
if (!is_java_debug && !_is_library) {
args += [ "--release" ]
}
if (_enable_desugar) {
args += [ "--desugar" ]
# Passing the flag for dex merging causes invalid dex files to be created.
if (enable_jdk_library_desugaring && !_is_dex_merging) {
inputs += [ _desugar_jdk_libs_json ]
args += [
"--desugar-jdk-libs-json",
rebase_path(_desugar_jdk_libs_json, root_build_dir),
]
}
_ignore_desugar_missing_deps =
defined(invoker.ignore_desugar_missing_deps) &&
invoker.ignore_desugar_missing_deps
if (!_ignore_desugar_missing_deps && !enable_bazel_desugar) {
args += [ "--show-desugar-default-interface-warnings" ]
}
}
if (_desugar_needs_classpath) {
_desugar_dependencies_path =
"$target_gen_dir/$target_name.desugardeps"
args += [
"--desugar-dependencies",
rebase_path(_desugar_dependencies_path, root_build_dir),
"--bootclasspath=@FileArg($_rebased_build_config:android:sdk_jars)",
# Pass the full classpath to find new dependencies that are not in
# the .desugardeps file.
"--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)",
]
if (defined(invoker.desugar_jars_paths)) {
_rebased_desugar_jars_paths =
rebase_path(invoker.desugar_jars_paths, root_build_dir)
args += [ "--classpath=${_rebased_desugar_jars_paths}" ]
}
if (defined(invoker.final_ijar_path)) {
# Need to include the input .interface.jar on the classpath in order to make
# jar_excluded_patterns classes visible to desugar.
args += [
"--classpath",
rebase_path(invoker.final_ijar_path, root_build_dir),
]
inputs += [ invoker.final_ijar_path ]
}
} else {
not_needed(invoker, [ "desugar_jars_paths" ])
}
if (enable_java_asserts) {
# The default for generating dex file format is
# --force-disable-assertions.
args += [ "--force-enable-assertions" ]
}
}
}
}
# Variables
# output: Path to output ".l8.dex".
# min_sdk_version: The minimum Android SDK version this target supports.
template("dex_jdk_libs") {
action_with_pydeps(target_name) {
script = "//build/android/gyp/dex_jdk_libs.py"
inputs = [
_r8_path,
_desugar_jdk_libs_json,
_desugar_jdk_libs_jar,
_desugar_jdk_libs_configuration_jar,
]
outputs = [ invoker.output ]
args = [
"--r8-path",
rebase_path(_r8_path, root_build_dir),
"--desugar-jdk-libs-json",
rebase_path(_desugar_jdk_libs_json, root_build_dir),
"--desugar-jdk-libs-jar",
rebase_path(_desugar_jdk_libs_jar, root_build_dir),
"--desugar-jdk-libs-configuration-jar",
rebase_path(_desugar_jdk_libs_configuration_jar, root_build_dir),
"--output",
rebase_path(invoker.output, root_build_dir),
"--min-api=${invoker.min_sdk_version}",
]
if (treat_warnings_as_errors) {
args += [ "--warnings-as-errors" ]
}
}
}
template("jacoco_instr") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
TESTONLY_AND_VISIBILITY + [
"deps",
"public_deps",
])
# The name needs to match the SOURCES_JSON_FILES_SUFFIX in
# generate_coverage_metadata_for_java.py.
_sources_json_file = "$target_out_dir/${target_name}__jacoco_sources.json"
_jacococli_jar = "//third_party/jacoco/lib/jacococli.jar"
script = "//build/android/gyp/jacoco_instr.py"
inputs = invoker.java_files + [
_jacococli_jar,
invoker.input_jar_path,
]
outputs = [
_sources_json_file,
invoker.output_jar_path,
]
args = [
"--input-path",
rebase_path(invoker.input_jar_path, root_build_dir),
"--output-path",
rebase_path(invoker.output_jar_path, root_build_dir),
"--sources-json-file",
rebase_path(_sources_json_file, root_build_dir),
"--java-sources-file",
rebase_path(invoker.java_sources_file, root_build_dir),
"--jacococli-jar",
rebase_path(_jacococli_jar, root_build_dir),
]
if (coverage_instrumentation_input_file != "") {
args += [
"--files-to-instrument",
rebase_path(coverage_instrumentation_input_file, root_build_dir),
]
}
}
}
template("filter_jar") {
action_with_pydeps(target_name) {
script = "//build/android/gyp/filter_zip.py"
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ])
inputs = [ invoker.input_jar ]
if (defined(invoker.inputs)) {
inputs += invoker.inputs
}
outputs = [ invoker.output_jar ]
_jar_excluded_patterns = []
if (defined(invoker.jar_excluded_patterns)) {
_jar_excluded_patterns = invoker.jar_excluded_patterns
}
_jar_included_patterns = []
if (defined(invoker.jar_included_patterns)) {
_jar_included_patterns = invoker.jar_included_patterns
}
_strip_resource_classes = defined(invoker.strip_resource_classes) &&
invoker.strip_resource_classes
args = [
"--input",
rebase_path(invoker.input_jar, root_build_dir),
"--output",
rebase_path(invoker.output_jar, root_build_dir),
"--exclude-globs=${_jar_excluded_patterns}",
"--include-globs=${_jar_included_patterns}",
]
if (_strip_resource_classes) {
inputs += [ invoker.build_config ]
_rebased_build_config =
rebase_path(invoker.build_config, root_build_dir)
args += [ "--strip-resource-classes-for=@FileArg($_rebased_build_config:javac:resource_packages)" ]
}
}
}
template("process_java_prebuilt") {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
not_needed([ "_rebased_build_config" ])
not_needed(invoker, [ "build_config_dep" ])
_deps = invoker.jar_deps
_previous_output_jar = invoker.input_jar_path
# Create the .jar in lib.java for use by java_binary.
if (defined(invoker.host_jar_path)) {
if (defined(invoker.jacoco_instrument) && invoker.jacoco_instrument) {
_filter_jar_target_name = "${target_name}_host__filter_jar"
_filter_jar_output_jar = "$target_out_dir/$target_name.host_filter.jar"
} else {
_filter_jar_target_name = "${target_name}_host"
_filter_jar_output_jar = invoker.host_jar_path
}
filter_jar(_filter_jar_target_name) {
forward_variables_from(invoker,
[
"jar_excluded_patterns",
"jar_included_patterns",
"strip_resource_classes",
])
deps = _deps
input_jar = _previous_output_jar
output_jar = _filter_jar_output_jar
inputs = []
if (defined(strip_resource_classes) && strip_resource_classes) {
inputs += [ invoker.build_config ]
deps += [ invoker.build_config_dep ]
args += [ "--strip-resource-classes-for=@FileArg($_rebased_build_config:javac:resource_packages)" ]
}
if (defined(invoker.inputs)) {
inputs += invoker.inputs
deps += invoker.input_deps
}
}
if (defined(invoker.jacoco_instrument) && invoker.jacoco_instrument) {
# Jacoco must run after desugar (or else desugar sometimes fails).
# It must run after filtering to avoid the same (filtered) class mapping
# to multiple .jar files.
# We run offline code coverage processing here rather than with a
# javaagent as the desired coverage data was not being generated.
# See crbug.com/1097815.
jacoco_instr("${target_name}_host") {
deps = [ ":$_filter_jar_target_name" ] + invoker.jar_deps
forward_variables_from(invoker,
[
"java_files",
"java_sources_file",
])
input_jar_path = _filter_jar_output_jar
output_jar_path = invoker.host_jar_path
}
}
}
if (defined(invoker.device_jar_path)) {
if (invoker.enable_desugar) {
_desugar_target = "${target_name}_device__desugar"
_desugar_output_jar = "$target_out_dir/$target_name.desugar.jar"
action_with_pydeps(_desugar_target) {
script = "//build/android/gyp/desugar.py"
deps = _deps + invoker.classpath_deps
depfile = "$target_gen_dir/$target_name.d"
_desugar_jar = "//third_party/bazel/desugar/Desugar.jar"
inputs = [
invoker.build_config,
_previous_output_jar,
_desugar_jar,
]
outputs = [ _desugar_output_jar ]
args = [
"--desugar-jar",
rebase_path(_desugar_jar, root_build_dir),
"--input-jar",
rebase_path(_previous_output_jar, root_build_dir),
"--output-jar",
rebase_path(_desugar_output_jar, root_build_dir),
# Temporarily using java_full_interface_classpath until classpath validation of targets
# is implemented, see http://crbug.com/885273
"--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)",
"--bootclasspath=@FileArg($_rebased_build_config:android:sdk_interface_jars)",
"--depfile",
rebase_path(depfile, root_build_dir),
]
if (defined(invoker.desugar_jars_paths)) {
_rebased_desugar_jars_paths =
rebase_path(invoker.desugar_jars_paths, root_build_dir)
args += [ "--classpath=${_rebased_desugar_jars_paths}" ]
}
if (treat_warnings_as_errors) {
args += [ "--warnings-as-errors" ]
}
}
_deps = []
_deps = [ ":$_desugar_target" ]
_previous_output_jar = _desugar_output_jar
}
if (invoker.jacoco_instrument) {
_filter_jar_target_name = "${target_name}_device__filter_jar"
_filter_jar_output_jar =
"$target_out_dir/$target_name.device_filter.jar"
} else {
_filter_jar_target_name = "${target_name}_device"
_filter_jar_output_jar = invoker.device_jar_path
}
filter_jar(_filter_jar_target_name) {
forward_variables_from(invoker,
[
"jar_excluded_patterns",
"jar_included_patterns",
"strip_resource_classes",
])
deps = _deps
input_jar = _previous_output_jar
output_jar = _filter_jar_output_jar
inputs = []
if (defined(strip_resource_classes) && strip_resource_classes) {
inputs += [ invoker.build_config ]
deps += [ invoker.build_config_dep ]
args += [ "--strip-resource-classes-for=@FileArg($_rebased_build_config:javac:resource_packages)" ]
}
if (!defined(invoker.host_jar_path) && defined(invoker.inputs)) {
inputs += invoker.inputs
deps += invoker.input_deps
}
}
if (invoker.jacoco_instrument) {
# Jacoco must run after desugar (or else desugar sometimes fails).
# It must run after filtering to avoid the same (filtered) class mapping
# to multiple .jar files.
jacoco_instr("${target_name}_device") {
deps = [ ":$_filter_jar_target_name" ] + invoker.jar_deps
forward_variables_from(invoker,
[
"java_files",
"java_sources_file",
])
input_jar_path = _filter_jar_output_jar
output_jar_path = invoker.device_jar_path
}
}
}
}
template("bytecode_processor") {
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
_bytecode_checker_script = "$root_build_dir/bin/helper/bytecode_processor"
script = "//build/android/gyp/bytecode_processor.py"
inputs = [
invoker.build_config,
invoker.input_jar,
_bytecode_checker_script,
]
outputs = [ "$target_out_dir/$target_name.bytecode.stamp" ]
deps =
invoker.deps +
[ "//build/android/bytecode:bytecode_processor($default_toolchain)" ]
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
args = [
"--target-name",
get_label_info(target_name, "label_no_toolchain"),
"--script",
rebase_path(_bytecode_checker_script, root_build_dir),
"--gn-target=${invoker.target_label}",
"--input-jar",
rebase_path(invoker.input_jar, root_build_dir),
"--stamp",
rebase_path(outputs[0], root_build_dir),
"--direct-classpath-jars=@FileArg($_rebased_build_config:javac:classpath)",
"--full-classpath-jars=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)",
"--full-classpath-gn-targets=@FileArg($_rebased_build_config:deps_info:javac_full_classpath_targets)",
]
if (invoker.requires_android) {
args += [ "--sdk-classpath-jars=@FileArg($_rebased_build_config:android:sdk_jars)" ]
}
if (invoker.is_prebuilt) {
args += [ "--is-prebuilt" ]
}
if (treat_warnings_as_errors) {
args += [ "--warnings-as-errors" ]
}
if (defined(invoker.missing_classes_allowlist)) {
args += [
"--missing-classes-allowlist=${invoker.missing_classes_allowlist}",
]
}
}
}
template("merge_manifests") {
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ])
script = "//build/android/gyp/merge_manifest.py"
depfile = "$target_gen_dir/$target_name.d"
inputs = [
invoker.build_config,
invoker.input_manifest,
]
outputs = [ invoker.output_manifest ]
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--android-sdk-cmdline-tools",
rebase_path("${public_android_sdk_root}/cmdline-tools/latest",
root_build_dir),
"--root-manifest",
rebase_path(invoker.input_manifest, root_build_dir),
"--output",
rebase_path(invoker.output_manifest, root_build_dir),
"--extras",
"@FileArg($_rebased_build_config:extra_android_manifests)",
"--min-sdk-version=${invoker.min_sdk_version}",
"--target-sdk-version=${invoker.target_sdk_version}",
]
if (defined(invoker.manifest_package)) {
args += [ "--manifest-package=${invoker.manifest_package}" ]
}
if (defined(invoker.max_sdk_version)) {
args += [ "--max-sdk-version=${invoker.max_sdk_version}" ]
}
if (treat_warnings_as_errors) {
args += [ "--warnings-as-errors" ]
}
}
}
# This template is used to parse a set of resource directories and
# create the R.txt, .srcjar and .resources.zip for it.
#
# Input variables:
# deps: Specifies the input dependencies for this target.
#
# build_config: Path to the .build_config file corresponding to the target.
#
# resource_dirs (Deprecated):
# ** This is deprecated, please specify files using |sources| parameter **
# List of directories containing Android resources, layout should be
# similar to what aapt -S <dir> expects.
#
# sources:
# List of input resource files.
#
# custom_package: (optional)
# Package name for the generated R.java source file. Optional if
# android_manifest is not provided.
#
# android_manifest: (optional)
# If custom_package is not provided, path to an AndroidManifest.xml file
# that is only used to extract a package name out of it.
#
# r_text_in_path: (optional)
# Path to an input R.txt file to use to generate the R.java file.
# The default is to use 'aapt' to generate the file from the content
# of the resource directories.
#
# Output variables:
# resources_zip:
# Path to a .resources.zip that will simply contain all the
# input resources, collected in a single archive.
#
# r_text_out_path: Path for the generated R.txt file.
#
template("prepare_resources") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
TESTONLY_AND_VISIBILITY + [
"deps",
"sources",
])
script = "//build/android/gyp/prepare_resources.py"
depfile = "$target_gen_dir/${invoker.target_name}.d"
outputs = [
invoker.resources_zip,
invoker.resources_zip + ".info",
invoker.r_text_out_path,
]
inputs = [ invoker.res_sources_path ]
_rebased_res_sources_path =
rebase_path(invoker.res_sources_path, root_build_dir)
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--res-sources-path=$_rebased_res_sources_path",
"--resource-zip-out",
rebase_path(invoker.resources_zip, root_build_dir),
"--r-text-out",
rebase_path(invoker.r_text_out_path, root_build_dir),
]
if (defined(invoker.r_text_in_path)) {
_r_text_in_path = invoker.r_text_in_path
inputs += [ _r_text_in_path ]
args += [
"--r-text-in",
rebase_path(_r_text_in_path, root_build_dir),
]
}
if (defined(invoker.strip_drawables) && invoker.strip_drawables) {
args += [ "--strip-drawables" ]
}
}
}
# A template that is used to compile all resources needed by a binary
# (e.g. an android_apk or a junit_binary) into an intermediate .ar_
# archive. It can also generate an associated .srcjar that contains the
# final R.java sources for all resource packages the binary depends on.
#
# Input variables:
# android_sdk_dep: The sdk dep that these resources should compile against.
#
# deps: Specifies the input dependencies for this target.
#
# build_config: Path to the .build_config file corresponding to the target.
#
# build_config_dep: Dep target to generate the .build_config file.
#
# android_manifest: Path to root manifest for the binary.
#
# version_code: (optional)
#
# version_name: (optional)
#
# shared_resources: (optional)
# If true, make all variables in each generated R.java file non-final,
# and provide an onResourcesLoaded() method that can be used to reset
# their package index at load time. Useful when the APK corresponds to
# a library that is loaded at runtime, like system_webview_apk or
# monochrome_apk.
#
# app_as_shared_lib: (optional)
# If true, same effect as shared_resources, but also ensures that the
# resources can be used by the APK when it is loaded as a regular
# application as well. Useful for the monochrome_public_apk target
# which is both an application and a shared runtime library that
# implements the system webview feature.
#
# shared_resources_allowlist: (optional)
# Path to an R.txt file. If provided, acts similar to shared_resources
# except that it restricts the list of non-final resource variables
# to the list from the input R.txt file. Overrides shared_resources
# when both are specified.
#
# shared_resources_allowlist_locales: (optional)
# If shared_resources_allowlist is used, provide an optional list of
# Chromium locale names to determine which localized shared string
# resources to put in the final output, even if aapt_locale_allowlist
# is defined to a smaller subset.
#
# support_zh_hk: (optional)
# If true, support zh-HK in Chrome on Android by using the resources
# from zh-TW. See https://crbug.com/780847.
#
# aapt_locale_allowlist: (optional)
# Restrict compiled locale-dependent resources to a specific allowlist.
# NOTE: This is a list of Chromium locale names, not Android ones.
#
# r_java_root_package_name: (optional)
# Short package name for this target's root R java file (ex. input of
# "base" would become "gen.base_module" for the root R java package name).
# Optional as defaults to "base".
#
# resource_exclusion_regex: (optional)
#
# resource_exclusion_exceptions: (optional)
#
# resource_values_filter_rules: (optional)
#
# no_xml_namespaces: (optional)
#
# png_to_webp: (optional)
# If true, convert all PNG resources (except 9-patch files) to WebP.
#
# post_process_script: (optional)
#
# package_name: (optional)
# Name of the package for the purpose of creating R class.
#
# package_id: (optional)
# Use a custom package ID in resource IDs.
#
# arsc_package_name: (optional)
# Use this package name in the arsc file rather than the package name
# found in the AndroidManifest.xml. Does not affect the package name
# used in AndroidManifest.xml.
#
# resource_ids_provider_dep: (optional)
# Use resource IDs provided by another APK target when compiling resources
# (via. "aapt2 link --stable-ids")
#
# short_resource_paths: (optional)
# Rename the paths within a the apk to be randomly generated short
# strings to reduce binary size.
#
# strip_resource_names: (optional)
# Strip resource names from the resources table of the apk.
#
# Output variables:
# arsc_output: Path to output .ap_ file (optional).
#
# proto_output: Path to output .proto.ap_ file (optional).
#
# optimized_arsc_output: Path to optimized .ap_ file (optional).
#
# optimized_proto_output: Path to optimized .proto.ap_ file (optional).
#
# r_text_out_path: (optional):
# Path for the corresponding generated R.txt file.
#
# resources_path_map_out_path: (optional):
# Path for the generated map between original resource paths and
# shortend resource paths.
#
# proguard_file: (optional)
# Path to proguard configuration file for this apk target.
#
# proguard_file_main_dex: (optional)
#
template("compile_resources") {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
_deps = [
invoker.android_sdk_dep,
invoker.build_config_dep,
]
if (defined(invoker.android_manifest_dep)) {
_deps += [ invoker.android_manifest_dep ]
}
foreach(_dep, invoker.deps) {
_target_label = get_label_info(_dep, "label_no_toolchain")
if (filter_exclude([ _target_label ], _java_library_patterns) == [] &&
filter_exclude([ _target_label ], _java_resource_patterns) != []) {
# Depend on the java libraries' transitive __assetres target instead.
_deps += [ "${_target_label}__assetres" ]
} else {
_deps += [ _dep ]
}
}
if (defined(invoker.arsc_output)) {
_arsc_output = invoker.arsc_output
}
if (defined(invoker.optimized_arsc_output)) {
_optimized_arsc_output = invoker.optimized_arsc_output
}
_final_srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
_script = "//build/android/gyp/compile_resources.py"
_inputs = [
invoker.build_config,
android_sdk_tools_bundle_aapt2,
]
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
_args = [
"--include-resources=@FileArg($_rebased_build_config:android:sdk_jars)",
"--aapt2-path",
rebase_path(android_sdk_tools_bundle_aapt2, root_build_dir),
"--dependencies-res-zips=@FileArg($_rebased_build_config:deps_info:dependency_zips)",
"--extra-res-packages=@FileArg($_rebased_build_config:deps_info:extra_package_names)",
"--extra-main-r-text-files=@FileArg($_rebased_build_config:deps_info:extra_main_r_text_files)",
"--min-sdk-version=${invoker.min_sdk_version}",
"--target-sdk-version=${invoker.target_sdk_version}",
"--webp-cache-dir=obj/android-webp-cache",
]
_inputs += [ invoker.android_manifest ]
_outputs = [ _final_srcjar_path ]
_args += [
"--android-manifest",
rebase_path(invoker.android_manifest, root_build_dir),
"--srcjar-out",
rebase_path(_final_srcjar_path, root_build_dir),
]
if (defined(invoker.no_xml_namespaces) && invoker.no_xml_namespaces) {
_args += [ "--no-xml-namespaces" ]
}
if (defined(invoker.version_code)) {
_args += [
"--version-code",
invoker.version_code,
]
}
if (defined(invoker.version_name)) {
_args += [
"--version-name",
invoker.version_name,
]
}
if (defined(_arsc_output)) {
_outputs += [ _arsc_output ]
_args += [
"--arsc-path",
rebase_path(_arsc_output, root_build_dir),
]
}
if (defined(invoker.proto_output)) {
_outputs += [ invoker.proto_output ]
_args += [
"--proto-path",
rebase_path(invoker.proto_output, root_build_dir),
]
}
if (defined(invoker.size_info_path)) {
_outputs += [ invoker.size_info_path ]
_args += [
"--info-path",
rebase_path(invoker.size_info_path, root_build_dir),
]
}
if (defined(_optimized_arsc_output)) {
_outputs += [ _optimized_arsc_output ]
_args += [
"--optimized-arsc-path",
rebase_path(_optimized_arsc_output, root_build_dir),
]
}
if (defined(invoker.optimized_proto_output)) {
_outputs += [ invoker.optimized_proto_output ]
_args += [
"--optimized-proto-path",
rebase_path(invoker.optimized_proto_output, root_build_dir),
]
}
if (defined(invoker.resources_config_paths)) {
_inputs += invoker.resources_config_paths
_rebased_resource_configs =
rebase_path(invoker.resources_config_paths, root_build_dir)
_args += [ "--resources-config-paths=${_rebased_resource_configs}" ]
}
if (defined(invoker.short_resource_paths) && invoker.short_resource_paths) {
_args += [ "--short-resource-paths" ]
if (defined(invoker.resources_path_map_out_path)) {
_outputs += [ invoker.resources_path_map_out_path ]
_args += [
"--resources-path-map-out-path",
rebase_path(invoker.resources_path_map_out_path, root_build_dir),
]
}
}
if (defined(invoker.r_java_root_package_name)) {
_args += [
"--r-java-root-package-name",
invoker.r_java_root_package_name,
]
}
if (defined(invoker.strip_resource_names) && invoker.strip_resource_names) {
_args += [ "--strip-resource-names" ]
}
# 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.r_text_out_path)) {
_outputs += [ invoker.r_text_out_path ]
_args += [
"--r-text-out",
rebase_path(invoker.r_text_out_path, root_build_dir),
]
}
if (defined(invoker.rename_manifest_package)) {
_args += [
"--rename-manifest-package",
invoker.rename_manifest_package,
]
}
# Define the flags related to shared resources.
#
# Note the small sanity check to ensure that the package ID of the
# generated resources table is correct. It should be 0x02 for runtime
# shared libraries, and 0x7f otherwise.
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.package_id)) {
_args += [ "--package-id=${invoker.package_id}" ]
}
if (defined(invoker.package_name)) {
_args += [
"--package-name",
invoker.package_name,
]
}
if (defined(invoker.arsc_package_name)) {
_args += [
"--arsc-package-name",
invoker.arsc_package_name,
]
}
if (defined(invoker.shared_resources_allowlist)) {
_inputs += [ invoker.shared_resources_allowlist ]
_args += [
"--shared-resources-allowlist",
rebase_path(invoker.shared_resources_allowlist, root_build_dir),
]
}
if (defined(invoker.shared_resources_allowlist_locales)) {
_args += [ "--shared-resources-allowlist-locales=" +
"${invoker.shared_resources_allowlist_locales}" ]
}
if (!defined(testonly) || !testonly ||
(defined(invoker.enforce_resource_overlays_in_tests) &&
invoker.enforce_resource_overlays_in_tests)) {
_args += [ "--dependencies-res-zip-overlays=@FileArg($_rebased_build_config:deps_info:dependency_zip_overlays)" ]
} else {
_args += [ "--dependencies-res-zip-overlays=@FileArg($_rebased_build_config:deps_info:dependency_zips)" ]
}
if (defined(invoker.proguard_file)) {
_outputs += [ invoker.proguard_file ]
_args += [
"--proguard-file",
rebase_path(invoker.proguard_file, root_build_dir),
]
}
if (defined(invoker.proguard_file_main_dex)) {
_outputs += [ invoker.proguard_file_main_dex ]
_args += [
"--proguard-file-main-dex",
rebase_path(invoker.proguard_file_main_dex, root_build_dir),
]
}
if (defined(invoker.aapt_locale_allowlist)) {
_args += [ "--locale-allowlist=${invoker.aapt_locale_allowlist}" ]
}
if (defined(invoker.png_to_webp) && invoker.png_to_webp) {
_webp_target = "//third_party/libwebp:cwebp($host_toolchain)"
_webp_binary = get_label_info(_webp_target, "root_out_dir") + "/cwebp"
_deps += [ _webp_target ]
_inputs += [ _webp_binary ]
_args += [
"--png-to-webp",
"--webp-binary",
rebase_path(_webp_binary, root_build_dir),
]
}
if (defined(invoker.resource_exclusion_regex)) {
_args +=
[ "--resource-exclusion-regex=${invoker.resource_exclusion_regex}" ]
if (defined(invoker.resource_exclusion_exceptions)) {
_args += [ "--resource-exclusion-exceptions=${invoker.resource_exclusion_exceptions}" ]
}
}
if (defined(invoker.resource_values_filter_rules)) {
_args +=
[ "--values-filter-rules=${invoker.resource_values_filter_rules}" ]
}
if (defined(invoker.support_zh_hk) && invoker.support_zh_hk) {
_args += [ "--support-zh-hk" ]
}
if (defined(invoker.include_resource)) {
_rebased_include_resources =
rebase_path(invoker.include_resource, root_build_dir)
_args += [ "--include-resources=$_rebased_include_resources" ]
}
if (defined(invoker._args)) {
_args += invoker._args
}
if (defined(invoker.emit_ids_out_path)) {
_outputs += [ invoker.emit_ids_out_path ]
_rebased_emit_ids_path =
rebase_path(invoker.emit_ids_out_path, root_out_dir)
_args += [ "--emit-ids-out=$_rebased_emit_ids_path" ]
}
if (defined(invoker.resource_ids_provider_dep)) {
_compile_res_dep =
"${invoker.resource_ids_provider_dep}__compile_resources"
_gen_dir = get_label_info(_compile_res_dep, "target_gen_dir")
_name = get_label_info(_compile_res_dep, "name")
_resource_ids_path = "$_gen_dir/$_name.resource_ids"
_inputs += [ _resource_ids_path ]
_rebased_ids_path = rebase_path(_resource_ids_path, root_out_dir)
_args += [ "--use-resource-ids-path=$_rebased_ids_path" ]
_deps += [ _compile_res_dep ]
}
if (defined(invoker.max_sdk_version)) {
_max_sdk_version = invoker.max_sdk_version
_args += [ "--max-sdk-version=$_max_sdk_version" ]
}
if (defined(invoker.manifest_package)) {
_args += [ "--manifest-package=${invoker.manifest_package}" ]
}
if (defined(invoker.is_bundle_module) && invoker.is_bundle_module) {
_args += [ "--is-bundle-module" ]
}
if (defined(invoker.uses_split)) {
assert(invoker.is_bundle_module)
_args += [ "--uses-split=${invoker.uses_split}" ]
}
if (defined(invoker.expected_android_manifest)) {
_expectations_target =
"${invoker.top_target_name}_validate_android_manifest"
action_with_pydeps(_expectations_target) {
_actual_file = "${invoker.android_manifest}.normalized"
_failure_file =
"$expectations_failure_dir/" +
string_replace(invoker.expected_android_manifest, "/", "_")
inputs = [
invoker.android_manifest,
invoker.build_config,
invoker.expected_android_manifest,
]
outputs = [
_actual_file,
_failure_file,
]
deps = [
invoker.android_manifest_dep,
invoker.build_config_dep,
]
script = _script
args = _args + [
"--expected-file",
rebase_path(invoker.expected_android_manifest, root_build_dir),
"--actual-file",
rebase_path(_actual_file, root_build_dir),
"--failure-file",
rebase_path(_failure_file, root_build_dir),
"--only-verify-expectations",
]
if (defined(invoker.expected_android_manifest_base)) {
args += [
"--expected-file-base",
rebase_path(invoker.expected_android_manifest_base, root_build_dir),
]
inputs += [ invoker.expected_android_manifest_base ]
}
if (fail_on_android_expectations) {
args += [ "--fail-on-expectations" ]
}
if (defined(invoker.extra_verification_manifest)) {
inputs += [ invoker.extra_verification_manifest ]
args += [
"--extra-verification-manifest",
rebase_path(invoker.extra_verification_manifest, root_build_dir),
]
if (defined(invoker.extra_verification_manifest_dep)) {
deps += [ invoker.extra_verification_manifest_dep ]
}
}
}
_deps += [ ":$_expectations_target" ]
}
action_with_pydeps(target_name) {
script = _script
depfile = "$target_gen_dir/${target_name}.d"
inputs = _inputs
outputs = _outputs
deps = _deps
args = _args + [
"--depfile",
rebase_path(depfile, root_build_dir),
]
}
}
template("unused_resources") {
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
_shrinker_dep = "//build/android/gyp/resources_shrinker:resources_shrinker"
_shrinker_script = "$root_build_dir/bin/helper/resources_shrinker"
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ])
script = "//build/android/gyp/resources_shrinker/shrinker.py"
inputs = [
invoker.build_config,
invoker.proguard_mapping_path,
_shrinker_script,
]
outputs = [ invoker.output_config ]
if (!defined(deps)) {
deps = []
}
deps += [ _shrinker_dep ]
args = [
"--script",
rebase_path(_shrinker_script, root_build_dir),
"--dependencies-res-zips=@FileArg($_rebased_build_config:deps_info:dependency_zips)",
"--proguard-mapping",
rebase_path(invoker.proguard_mapping_path, root_build_dir),
"--r-text=@FileArg($_rebased_build_config:deps_info:r_text_path)",
"--dex=@FileArg($_rebased_build_config:final_dex:path)",
"--android-manifest=@FileArg($_rebased_build_config:deps_info:android_manifest)",
"--output-config",
rebase_path(invoker.output_config, root_build_dir),
]
}
}
# Create an .jar.info file by merging several .jar.info files into one.
#
# Variables:
# build_config: Path to APK's build config file. Used to extract the
# list of input .jar files from its dependencies.
# name: Name of the apk or app bundle (e.g. "Foo.apk").
# res_size_info_path: Path to input .ap_.info file (for apks).
#
template("create_size_info_files") {
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ])
script = "//build/android/gyp/create_size_info_files.py"
_jar_info_path = "$root_build_dir/size-info/${invoker.name}.jar.info"
_pak_info_path = "$root_build_dir/size-info/${invoker.name}.pak.info"
_res_info_path = "$root_build_dir/size-info/${invoker.name}.res.info"
outputs = [
_jar_info_path,
_pak_info_path,
_res_info_path,
]
depfile = "$target_gen_dir/$target_name.d"
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--jar-info-path",
rebase_path(_jar_info_path, root_build_dir),
"--pak-info-path",
rebase_path(_pak_info_path, root_build_dir),
"--res-info-path",
rebase_path(_res_info_path, root_build_dir),
]
_is_bundle = defined(invoker.module_build_configs)
if (_is_bundle) {
inputs = invoker.module_build_configs
foreach(_build_config, invoker.module_build_configs) {
_rebased_build_config = rebase_path(_build_config, root_build_dir)
args += [
"--jar-files=@FileArg($_rebased_build_config:deps_info:unprocessed_jar_path)",
"--jar-files=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)",
"--in-res-info-path=@FileArg($_rebased_build_config:deps_info:res_size_info)",
"--assets=@FileArg($_rebased_build_config:assets)",
"--uncompressed-assets=@FileArg($_rebased_build_config:uncompressed_assets)",
]
}
} else {
inputs = [
invoker.build_config,
invoker.res_size_info_path,
]
_rebased_build_config =
rebase_path(invoker.build_config, root_build_dir)
args += [
"--jar-files=@FileArg($_rebased_build_config:deps_info:unprocessed_jar_path)",
"--jar-files=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)",
"--in-res-info-path",
rebase_path(invoker.res_size_info_path, root_build_dir),
"--assets=@FileArg($_rebased_build_config:assets)",
"--uncompressed-assets=@FileArg($_rebased_build_config:uncompressed_assets)",
]
}
}
}
# Creates a signed and aligned .apk.
#
# Variables
# apk_name: (optional) APK name (without .apk suffix). If provided, will
# be used to generate .info files later used by the supersize tool.
# assets_build_config: Path to android_apk .build_config containing merged
# asset information.
# deps: Specifies the dependencies of this target.
# dex_path: Path to classes.dex file to include (optional).
# expected_libs_and_assets: Verify the list of included native libraries
# and assets is consistent with the given expectation file.
# expected_libs_and_assets_base: Treat expected_libs_and_assets as a diff
# with this file as the base.
# jdk_libs_dex: Path to classes.dex for desugar_jdk_libs.
# packaged_resources_path: Path to .ap_ to use.
# output_apk_path: Output path for the generated .apk.
# min_sdk_version: The minimum Android SDK version this target supports.
# native_lib_placeholders: List of placeholder filenames to add to the apk
# (optional).
# secondary_native_lib_placeholders: List of placeholder filenames to add to
# the apk for the secondary ABI (optional).
# loadable_modules: List of native libraries.