blob: f1f0c2d63deb3985e66b2b341444055454ed1559 [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/dcheck_always_on.gni")
import("//build/config/python.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/util/generate_wrapper.gni")
import("//build_overrides/build.gni")
assert(is_android)
# These identify targets that have .build_config files (except for android_apk,
# java_binary, resource_rewriter, android_app_bundle since we never need to
# depend on these).
_java_target_whitelist = [
"*:*_java",
"*:*_javalib",
"*:*_java_*", # e.g. java_test_support
"*:java",
"*:junit",
"*:junit_*",
"*:*_junit_*",
"*:*javatests",
"*:*_assets",
"*android*:assets",
"*:*_apk_*resources",
"*android*:resources",
"*:*_resources",
"*:*_grd",
"*:*locale_paks",
"*_bundle_module",
# TODO(agrieve): Rename targets below to match above patterns.
"*android_webview/glue:glue",
]
# Targets that match the whitelist but are not actually java targets.
_java_target_blacklist = [ "*:*_unpack_aar" ]
_default_proguard_jar_path = "//third_party/proguard/lib/proguard.jar"
_r8_path = "//third_party/r8/lib/r8.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
# Don't need to enforce naming scheme for these targets since we never
# consider them in dependency chains.
if (_type != "android_apk" && _type != "java_binary" &&
_type != "resource_rewriter" && _type != "dist_jar" &&
_type != "java_annotation_processor" && _type != "dist_aar" &&
_type != "android_app_bundle") {
set_sources_assignment_filter(_java_target_whitelist)
_parent_invoker = invoker.invoker
_target_label =
get_label_info(":${_parent_invoker.target_name}", "label_no_toolchain")
sources = [
_target_label,
]
if (sources != []) {
set_sources_assignment_filter(_java_target_blacklist)
sources = []
sources = [
_target_label,
]
if (sources != []) {
assert(false, "Invalid java target name: $_target_label")
}
}
sources = []
}
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 = []
if (defined(invoker.possible_config_deps)) {
foreach(_possible_dep, invoker.possible_config_deps) {
set_sources_assignment_filter(_java_target_whitelist)
_target_label = get_label_info(_possible_dep, "label_no_toolchain")
sources = [
_target_label,
]
if (sources == []) {
set_sources_assignment_filter(_java_target_blacklist)
sources = []
sources = [
_target_label,
]
if (sources != []) {
# Put the bug number in the target name so that false-positives
# have a hint in the error message about non-existent dependencies.
deps += [ "$_target_label$build_config_target_suffix" ]
_dep_gen_dir = get_label_info(_possible_dep, "target_gen_dir")
_dep_name = get_label_info(_possible_dep, "name")
_deps_configs += [ "$_dep_gen_dir/$_dep_name.build_config" ]
}
}
sources = []
}
}
_rebased_deps_configs = rebase_path(_deps_configs, root_build_dir)
args = [
"--type=$_type",
"--depfile",
rebase_path(depfile, root_build_dir),
"--deps-configs=$_rebased_deps_configs",
"--build-config",
rebase_path(invoker.build_config, root_build_dir),
]
if (defined(invoker.jar_path)) {
args += [
"--jar-path",
rebase_path(invoker.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)) {
_processor_configs = []
foreach(_processor_dep, invoker.annotation_processor_deps) {
_target_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 += [ "$_target_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" ]
}
if (defined(invoker.dex_path)) {
args += [
"--dex-path",
rebase_path(invoker.dex_path, root_build_dir),
]
}
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.custom_package)) {
args += [
"--package-name",
invoker.custom_package,
]
}
if (defined(invoker.r_text)) {
args += [
"--r-text",
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.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.module_rtxt_path)) {
_rebased_rtxt_path = rebase_path(invoker.module_rtxt_path, root_build_dir)
args += [ "--module-rtxt-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_whitelist_rtxt_path)) {
args += [
"--base-whitelist-rtxt-path",
rebase_path(invoker.base_whitelist_rtxt_path, root_build_dir),
]
}
if (defined(invoker.is_base_module) && invoker.is_base_module) {
args += [ "--is-base-module" ]
}
if (defined(invoker.loadable_modules) && invoker.loadable_modules != []) {
_rebased_modules = rebase_path(invoker.loadable_modules, root_build_dir)
args += [ "--native-libs=$_rebased_modules" ]
}
if (defined(invoker.extra_shared_libraries)) {
_rebased_extra_shared_libraries =
rebase_path(invoker.extra_shared_libraries, root_build_dir)
args += [ "--native-libs=$_rebased_extra_shared_libraries" ]
}
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_modules =
rebase_path(invoker.secondary_abi_loadable_modules, root_build_dir)
args += [ "--secondary-native-libs=$_rebased_secondary_abi_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.apk_path)) {
_rebased_apk_path = rebase_path(invoker.apk_path, root_build_dir)
_incremental_allowed =
defined(invoker.incremental_allowed) && invoker.incremental_allowed
args += [ "--apk-path=$_rebased_apk_path" ]
if (_incremental_allowed) {
_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.classpath_deps)) {
_classpath_deps_configs = []
foreach(d, invoker.classpath_deps) {
_target_label = get_label_info(d, "label_no_toolchain")
deps += [ "$_target_label$build_config_target_suffix" ]
_dep_gen_dir = get_label_info(d, "target_gen_dir")
_dep_name = get_label_info(d, "name")
_classpath_deps_configs += [ "$_dep_gen_dir/$_dep_name.build_config" ]
}
_rebased_classpath_deps_configs =
rebase_path(_classpath_deps_configs, root_build_dir)
args += [ "--classpath-deps-configs=$_rebased_classpath_deps_configs" ]
}
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.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.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)) {
assert(defined(invoker.static_library_jar_path))
args += [
"--static-library-jar-path",
rebase_path(invoker.static_library_jar_path, root_build_dir),
]
_dependent_configs = []
foreach(_target, invoker.static_library_dependent_targets) {
_target_name = _target.name
_target_label = get_label_info(_target_name, "label_no_toolchain")
deps += [ "$_target_label$build_config_target_suffix" ]
_dep_gen_dir = get_label_info(_target_name, "target_gen_dir")
_dep_name = get_label_info(_target_name, "name")
_config =
rebase_path("$_dep_gen_dir/$_dep_name.build_config", root_build_dir)
_dependent_configs += [ _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" ]
}
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)) {
_target_label =
get_label_info(invoker.base_module_target, "label_no_toolchain")
_dep_gen_dir = get_label_info(_target_label, "target_gen_dir")
_dep_name = get_label_info(_target_label, "name")
deps += [ "$_target_label$build_config_target_suffix" ]
args += [
"--base-module-build-config",
rebase_path("$_dep_gen_dir/$_dep_name.build_config", root_build_dir),
]
}
if (defined(invoker.module_build_configs)) {
_rebased_configs =
rebase_path(invoker.module_build_configs, root_build_dir)
args += [ "--module-build-configs=$_rebased_configs" ]
}
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: " + get_label_info(":$target_name", "label_with_toolchain"),
"default_toolchain: $default_toolchain",
]
args += [ "--fail=$_msg" ]
}
}
}
# Copy a list of file into a destination directory. Potentially renaming
# files are they are copied. This also ensures that symlinks are followed
# during the copy (i.e. the symlinks are never copied, only their content).
#
# Variables:
# dest: Destination directory path.
# sources: List of source files or directories to copy to dest.
# renaming_sources: Optional list of source file paths that will be renamed
# during the copy operation. If provided, renaming_destinations is required.
# renaming_destinations: Optional list of destination file paths, required
# when renaming_sources is provided. Both lists should have the same size
# and matching entries.
# args: Optional. Additionnal arguments to the copy_ex.py script.
#
# The following variables have the usual GN meaning: data, deps, inputs,
# outputs, testonly, visibility.
#
template("copy_ex") {
set_sources_assignment_filter([])
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"data",
"deps",
"outputs",
"testonly",
"visibility",
])
sources = []
if (defined(invoker.sources)) {
sources += invoker.sources
}
if (defined(invoker.inputs)) {
inputs = invoker.inputs
}
script = "//build/android/gyp/copy_ex.py"
args = [
"--dest",
rebase_path(invoker.dest, root_build_dir),
]
rebased_sources = rebase_path(sources, root_build_dir)
args += [ "--files=$rebased_sources" ]
if (defined(invoker.args)) {
args += invoker.args
}
if (defined(invoker.renaming_sources) &&
defined(invoker.renaming_destinations)) {
sources += invoker.renaming_sources
rebased_renaming_sources =
rebase_path(invoker.renaming_sources, root_build_dir)
args += [ "--renaming-sources=$rebased_renaming_sources" ]
renaming_destinations = invoker.renaming_destinations
args += [ "--renaming-destinations=$renaming_destinations" ]
}
}
}
template("generate_android_wrapper") {
generate_wrapper(target_name) {
forward_variables_from(invoker, "*")
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",
]
}
}
# 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_install =
defined(invoker.incremental_install) && invoker.incremental_install
_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
}
}
generate_android_wrapper(target_name) {
forward_variables_from(invoker,
[
"data_deps",
"deps",
])
if (!defined(deps)) {
deps = []
}
if (!defined(data_deps)) {
data_deps = []
}
if (defined(android_test_runner_script)) {
executable = android_test_runner_script
} else {
executable = "//build/android/test_runner.py"
}
testonly = true
data_deps += [
"//build/android:test_runner_py",
"//build/android:logdog_wrapper_py",
]
data = []
executable_args = [
_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)
assert(_rebased_apk_build_config != "") # Mark as used.
} 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,
]
} else if (_test_type == "instrumentation") {
_test_apk = "@WrappedPath(@FileArg($_rebased_apk_build_config:deps_info:apk_path))"
if (_incremental_install) {
_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)) {
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:apk_path))"
if (_incremental_install) {
_apk_under_test = "@WrappedPath(@FileArg($_rebased_apk_under_test_build_config:deps_info:incremental_apk_path))"
}
executable_args += [
"--apk-under-test",
_apk_under_test,
]
}
if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) {
executable_args += [ "--enable-java-deobfuscation" ]
}
if (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,
]
if (defined(invoker.android_manifest_path)) {
_rebased_android_manifest_path =
rebase_path(invoker.android_manifest_path, root_build_dir)
executable_args += [
"--android-manifest-path",
"@WrappedPath(${_rebased_android_manifest_path})",
]
} else if (defined(invoker.package_name)) {
executable_args += [
"--package-name",
invoker.package_name,
]
} else {
assert(false, "Must specify a package_name or android_manifest_path")
}
deps += [ ":${invoker.test_suite}$build_config_target_suffix" ]
_junit_binary_build_config =
"${target_gen_dir}/${invoker.test_suite}.build_config"
_rebased_build_config =
rebase_path("$_junit_binary_build_config", root_build_dir)
executable_args += [ "@WrappedPathList(--resource-zip, @FileArg($_rebased_build_config:resources:dependency_zips))" ]
_rebased_robolectric_runtime_deps_dir =
rebase_path("$root_build_dir/lib.java/third_party/robolectric",
root_build_dir)
executable_args += [
"--robolectric-runtime-deps-dir",
"@WrappedPath(${_rebased_robolectric_runtime_deps_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))",
"--additional-apk-incremental",
"@WrappedPath(@FileArg($_rebased_build_config:deps_info:incremental_apk_path))",
]
}
}
if (defined(invoker.shard_timeout)) {
executable_args += [ "--shard-timeout=${invoker.shard_timeout}" ]
}
if (_incremental_install) {
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.generated_script)) {
assert(_test_name != "" || true) # Mark _test_name as used.
wrapper_script = invoker.generated_script
} else {
wrapper_script = "$root_build_dir/bin/run_${_test_name}"
}
}
}
template("stack_script") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"data_deps",
"deps",
"testonly",
])
if (!defined(deps)) {
deps = []
}
if (!defined(data_deps)) {
data_deps = []
}
data_deps +=
[ "//third_party/android_platform/development/scripts:stack_py" ]
script = "//build/android/gyp/create_stack_script.py"
_stack_target_name = invoker.stack_target_name
_stack_script = "//third_party/android_platform/development/scripts/stack"
_generated_script = "$root_build_dir/bin/stack_${_stack_target_name}"
outputs = [
_generated_script,
]
data = [
_generated_script,
]
args = [
"--output-directory",
rebase_path(root_build_dir, root_build_dir),
"--script-path",
rebase_path(_stack_script, root_build_dir),
"--script-output-path",
rebase_path(_generated_script, root_build_dir),
"--arch=$target_cpu",
]
if (defined(invoker.packed_libraries)) {
args += [
"--packed-libs",
invoker.packed_libraries,
]
}
}
}
if (enable_java_templates) {
android_sdk_jar = "$android_sdk/android.jar"
android_default_aapt_path = "$android_sdk_build_tools/aapt"
template("android_lint") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"deps",
"data_deps",
"public_deps",
"testonly",
])
if (!defined(deps)) {
deps = []
}
if (defined(invoker.srcjar_deps)) {
deps += invoker.srcjar_deps
}
if (defined(invoker.lint_suppressions_file)) {
lint_suppressions_file = invoker.lint_suppressions_file
} else if (!defined(lint_suppressions_file)) {
lint_suppressions_file = "//build/android/lint/suppressions.xml"
}
_lint_path = "$lint_android_sdk_root/tools-lint/bin/lint"
_cache_dir = "$root_build_dir/android_lint_cache"
_result_path = "$target_gen_dir/$target_name/result.xml"
_config_path = "$target_gen_dir/$target_name/config.xml"
_suppressions_file = lint_suppressions_file
_platform_xml_path =
"${android_sdk_root}/platform-tools/api/api-versions.xml"
script = "//build/android/gyp/lint.py"
depfile = "$target_gen_dir/$target_name.d"
inputs = [
_platform_xml_path,
_suppressions_file,
]
outputs = [
_result_path,
_config_path,
]
args = [
"--lint-path",
rebase_path(_lint_path, root_build_dir),
"--cache-dir",
rebase_path(_cache_dir, root_build_dir),
"--platform-xml-path",
rebase_path(_platform_xml_path, root_build_dir),
"--android-sdk-version=${lint_android_sdk_version}",
"--depfile",
rebase_path(depfile, root_build_dir),
"--config-path",
rebase_path(_suppressions_file, root_build_dir),
"--product-dir=.",
"--processed-config-path",
rebase_path(_config_path, root_build_dir),
"--result-path",
rebase_path(_result_path, root_build_dir),
"--include-unexpected-failures",
]
if (defined(invoker.android_manifest)) {
inputs += [ invoker.android_manifest ]
args += [
"--manifest-path",
rebase_path(invoker.android_manifest, root_build_dir),
]
}
if (defined(invoker.disable)) {
args += [ "--disable=${invoker.disable}" ]
}
if (defined(invoker.create_cache) && invoker.create_cache) {
args += [
"--create-cache",
"--silent",
]
} else {
inputs += invoker.java_files
inputs += [ invoker.build_config ]
if (invoker.java_files != []) {
inputs += [ invoker.java_sources_file ]
_rebased_java_sources_file =
rebase_path(invoker.java_sources_file, root_build_dir)
args += [ "--java-sources-file=$_rebased_java_sources_file" ]
}
deps += [ "//build/android:prepare_android_lint_cache" ]
_rebased_build_config =
rebase_path(invoker.build_config, root_build_dir)
args += [
"--srcjars=@FileArg($_rebased_build_config:gradle:bundled_srcjars)",
"--can-fail-build",
]
if (invoker.requires_android) {
args += [
"--resource-sources=@FileArg($_rebased_build_config:deps_info:owned_resources_dirs)",
"--resource-sources=@FileArg($_rebased_build_config:deps_info:owned_resources_zips)",
]
}
}
}
}
template("proguard") {
action_with_pydeps(target_name) {
set_sources_assignment_filter([])
forward_variables_from(invoker,
[
"data",
"data_deps",
"deps",
"public_deps",
"testonly",
])
script = "//build/android/gyp/proguard.py"
# http://crbug.com/725224. Fix for bots running out of memory.
pool = "//build/toolchain:link_pool($default_toolchain)"
_output_path = invoker.output_path
inputs = [
invoker.build_config,
]
if (defined(invoker.inputs)) {
inputs += invoker.inputs
}
_mapping_path = "$_output_path.mapping"
if (defined(invoker.proguard_mapping_path)) {
_mapping_path = invoker.proguard_mapping_path
}
depfile = "${target_gen_dir}/${target_name}.d"
outputs = [
_output_path,
_mapping_path,
]
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--output-path",
rebase_path(_output_path, root_build_dir),
"--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)",
]
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 (defined(invoker.config_output_path)) {
_config_output_path = invoker.config_output_path
outputs += [ _config_output_path ]
args += [
"--output-config",
rebase_path(_config_output_path, root_build_dir),
]
if (defined(invoker.proguard_expectations_file)) {
_expected_configs_file = invoker.proguard_expectations_file
inputs += [ _expected_configs_file ]
args += [
"--expected-configs-file",
rebase_path(_expected_configs_file, root_build_dir),
]
if (check_android_configuration) {
args += [ "--verify-expected-configs" ]
}
}
}
if (!defined(invoker.proguard_jar_path) || use_r8) {
if (defined(invoker.proguard_jar_path)) {
not_needed(invoker, [ "proguard_jar_path" ])
}
args += [
"--r8-path",
rebase_path(_r8_path, root_build_dir),
]
inputs += [ _r8_path ]
} else {
_proguard_jar_path = invoker.proguard_jar_path
args += [
"--proguard-path",
rebase_path(_proguard_jar_path, root_build_dir),
]
inputs += [ _proguard_jar_path ]
}
if (defined(invoker.args)) {
args += invoker.args
}
}
}
# 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).
# jar_path: Optional. First classpath entry to be inserted before
# the classpath extracted from the build_config.
# script_name: Name of the script to generate.
# wrapper_script_args: List of extra arguments to pass to the executable.
# bootclasspath: Optional. list of zip/jar file paths to add to the boot
# class path when the script will invoke javac.
#
template("java_binary_script") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
_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,
]
if (defined(invoker.jar_path)) {
_jar_path_list = [ rebase_path(invoker.jar_path, root_build_dir) ]
args += [ "--classpath=$_jar_path_list" ]
}
args += [ "--classpath=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)" ]
if (jacoco_coverage) {
args += [
"--classpath",
rebase_path("//third_party/jacoco/lib/jacocoagent.jar",
root_build_dir),
"--noverify",
]
}
if (defined(invoker.wrapper_script_args)) {
args += [ "--" ] + invoker.wrapper_script_args
}
if (defined(invoker.bootclasspath)) {
args += [
"--bootclasspath",
rebase_path(invoker.bootclasspath, root_build_dir),
]
}
}
}
# Variables
# apply_mapping: The path to the ProGuard mapping file to apply.
template("dex") {
assert(defined(invoker.output))
_proguard_enabled =
defined(invoker.proguard_enabled) && invoker.proguard_enabled
_proguarding_with_r8 =
_proguard_enabled && (!defined(invoker.proguard_jar_path) || use_r8)
_enable_multidex =
!defined(invoker.enable_multidex) || invoker.enable_multidex
_enable_main_dex_list =
_enable_multidex &&
(!defined(invoker.min_sdk_version) || invoker.min_sdk_version < 21)
if (!_enable_main_dex_list) {
if (defined(invoker.negative_main_dex_globs)) {
not_needed(invoker, [ "negative_main_dex_globs" ])
}
}
assert(!(defined(invoker.input_jars) && _proguard_enabled),
"input_jars can't be specified when proguarding a dex.")
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 (!_proguarding_with_r8) {
_dexing_jars = []
if (defined(invoker.input_jars)) {
_dexing_jars += invoker.input_jars
}
}
if (_proguard_enabled) {
if (_proguarding_with_r8) {
_proguard_output_path = invoker.output
_proguard_target_name = target_name
_proguard_config_output_path = "$_proguard_output_path.proguard_flags"
} else {
_proguard_output_path = invoker.output + ".proguard.jar"
_proguard_target_name = "${target_name}__proguard"
_dexing_jars += [ _proguard_output_path ]
}
proguard(_proguard_target_name) {
forward_variables_from(invoker,
[
"build_config",
"deps",
"proguard_expectations_file",
"proguard_jar_path",
"proguard_mapping_path",
"is_static_library",
"testonly",
])
inputs = []
if (defined(invoker.inputs)) {
inputs += invoker.inputs
}
if (defined(invoker.proguard_configs)) {
inputs += invoker.proguard_configs
}
_rebased_build_config = rebase_path(build_config, root_build_dir)
args = [
"--proguard-configs=@FileArg($_rebased_build_config:deps_info:proguard_all_configs)",
"--input-paths=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)",
]
if (defined(invoker.proguard_config_exclusions)) {
_rebased_proguard_config_exclusions =
rebase_path(invoker.proguard_config_exclusions, root_build_dir)
args += [
"--proguard-config-exclusions=$_rebased_proguard_config_exclusions",
]
}
if (defined(invoker.proguard_args)) {
args += invoker.proguard_args
}
if (defined(invoker.repackage_classes)) {
args += [
"--repackage-classes",
"${invoker.repackage_classes}",
]
}
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 (defined(invoker.min_sdk_version)) {
args += [
"--min-api",
"${invoker.min_sdk_version}",
]
}
if (_enable_multidex && _proguarding_with_r8) {
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 ]
} else {
args += [
"--main-dex-rules-path",
rebase_path("//build/android/arbitrary_main_dex.flags",
root_build_dir),
]
}
}
output_path = _proguard_output_path
if (_proguarding_with_r8) {
config_output_path = _proguard_config_output_path
}
}
}
if (!_proguarding_with_r8) {
if (_enable_main_dex_list) {
_main_dex_list_path = invoker.output + ".main_dex_list"
_main_dex_list_target_name = "${target_name}__main_dex_list"
action_with_pydeps(_main_dex_list_target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
script = "//build/android/gyp/main_dex_list.py"
depfile = "$target_gen_dir/$target_name.d"
# http://crbug.com/725224. Fix for bots running out of memory.
pool = "//build/toolchain:link_pool($default_toolchain)"
if (defined(invoker.proguard_jar_path)) {
_proguard_jar_path = invoker.proguard_jar_path
} else {
_proguard_jar_path = _default_proguard_jar_path
}
_shrinked_android = "$android_sdk_build_tools/lib/shrinkedAndroid.jar"
_dx = "$android_sdk_build_tools/lib/dx.jar"
inputs = [
_main_dex_rules,
_dx,
_proguard_jar_path,
_shrinked_android,
]
outputs = [
_main_dex_list_path,
]
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--dx-path",
rebase_path(_dx, root_build_dir),
"--shrinked-android-path",
rebase_path(_shrinked_android, root_build_dir),
"--main-dex-list-path",
rebase_path(_main_dex_list_path, root_build_dir),
"--main-dex-rules-path",
rebase_path(_main_dex_rules, root_build_dir),
"--proguard-path",
rebase_path(_proguard_jar_path, root_build_dir),
]
if (defined(invoker.extra_main_dex_proguard_config)) {
inputs += [ invoker.extra_main_dex_proguard_config ]
args += [
"--main-dex-rules-path",
rebase_path(invoker.extra_main_dex_proguard_config,
root_build_dir),
]
}
if (_proguard_enabled) {
deps += [ ":${_proguard_target_name}" ]
}
if (defined(invoker.negative_main_dex_globs)) {
args += [
"--negative-main-dex-globs=${invoker.negative_main_dex_globs}",
]
}
if (defined(invoker.input_jar_classpath)) {
inputs += [ invoker.build_config ]
args += [ "--inputs=@FileArg(${invoker.input_jar_classpath})" ]
}
inputs += _dexing_jars
if (_dexing_jars != []) {
args += rebase_path(_dexing_jars, root_build_dir)
}
}
}
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
script = "//build/android/gyp/dex.py"
depfile = "$target_gen_dir/$target_name.d"
inputs = []
outputs = [
invoker.output,
]
_rebased_output = rebase_path(invoker.output, root_build_dir)
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--dex-path",
_rebased_output,
]
if (_proguard_enabled) {
deps += [ ":${_proguard_target_name}" ]
}
if (_enable_multidex) {
args += [ "--multi-dex" ]
if (_enable_main_dex_list) {
args += [
"--main-dex-list-path",
rebase_path(_main_dex_list_path, root_build_dir),
]
deps += [ ":${_main_dex_list_target_name}" ]
inputs += [ _main_dex_list_path ]
}
}
if (defined(invoker.input_dex_classpath)) {
inputs += [ invoker.build_config ]
args += [ "--inputs=@FileArg(${invoker.input_dex_classpath})" ]
}
inputs += _dexing_jars
if (_dexing_jars != []) {
args += rebase_path(_dexing_jars, root_build_dir)
}
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
if (_proguard_enabled) {
args += [
"--proguard-mapping-path",
rebase_path(invoker.proguard_mapping_path, root_build_dir),
]
inputs += [ invoker.proguard_mapping_path ]
}
}
if (!is_java_debug) {
args += [ "--release" ]
}
if (defined(invoker.min_sdk_version)) {
args += [
"--min-api",
"${invoker.min_sdk_version}",
]
}
_d8_path = "//third_party/r8/lib/d8.jar"
inputs += [ _d8_path ]
args += [
"--d8-jar-path",
rebase_path(_d8_path, root_build_dir),
]
}
}
}
template("jacoco_instr") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
"testonly",
])
_source_dirs_listing_file = "$target_out_dir/${target_name}_sources.txt"
_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 = [
_source_dirs_listing_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-list-file",
rebase_path(_source_dirs_listing_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),
]
}
}
# TODO(digit): Document this!
#
# Variables:
# testonly:
# build_config:
# input_jar_path:
# output_jar_path:
# enable_build_hooks:
# enable_build_hooks_android:
# supports_android:
# jacoco_instrument: Use Jacoco-instrumented classes to generate Java
# coverage data.
# jar_excluded_patterns: Optional list of .class file patterns to exclude
# from the final .jar file.
# jar_included_patterns: OPtional list of .class file patterns to include
# in the final .jar file. jar_excluded_patterns take precedence over this.
# strip_resource_classes:
# deps:
# java_files:
# java_sources_file:
# inputs:
# data_deps:
# visibility:
#
template("process_java_prebuilt") {
set_sources_assignment_filter([])
forward_variables_from(invoker, [ "testonly" ])
assert(invoker.build_config != "")
_build_config = invoker.build_config
_rebased_build_config = rebase_path(_build_config, root_build_dir)
assert(_rebased_build_config != "" || true) # Mark used.
_input_jar_path = invoker.input_jar_path
_output_jar_path = invoker.output_jar_path
_enable_assert =
defined(invoker.enable_build_hooks) && invoker.enable_build_hooks &&
(is_java_debug || dcheck_always_on || report_java_assert)
_enable_custom_resources = defined(invoker.enable_build_hooks_android) &&
invoker.enable_build_hooks_android
# Turned off because of existing code which fails the assertion
_enable_thread_annotations = false
_desugar = defined(invoker.supports_android) && invoker.supports_android
_jacoco_instrument = invoker.jacoco_instrument
_enable_split_compat = defined(invoker.split_compat_class_names)
_enable_class_deps_output = defined(invoker.enable_class_deps_output)
_enable_bytecode_rewriter =
_enable_assert || _enable_custom_resources ||
_enable_thread_annotations || _enable_split_compat ||
_enable_class_deps_output
_is_prebuilt = defined(invoker.is_prebuilt) && invoker.is_prebuilt
_enable_bytecode_checks = !defined(invoker.enable_bytecode_checks) ||
invoker.enable_bytecode_checks
# Release builds don't have asserts enabled, so they often will not run the
# bytecode rewriter. We are okay with having release builds not run the
# bytecode checks at all, since the dependency errors can be caught in debug
# mode.
not_needed([
"_is_prebuilt",
"_enable_bytecode_checks",
])
if (defined(invoker.enable_bytecode_rewriter)) {
not_needed([
"_enable_assert",
"_enable_custom_resources",
"_enable_thread_annotations",
])
_enable_bytecode_rewriter = invoker.enable_bytecode_rewriter
}
_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
_filter_jar = _jar_excluded_patterns != [] ||
_jar_included_patterns != [] || _strip_resource_classes
_deps = []
_previous_output_jar = _input_jar_path
if (_enable_bytecode_rewriter) {
_java_bytecode_rewriter_target = "${target_name}__bytecode_rewrite"
_java_bytecode_rewriter_input_jar = _previous_output_jar
_java_bytecode_rewriter_output_jar =
"$target_out_dir/$target_name-bytecode-rewritten.jar"
action_with_pydeps(_java_bytecode_rewriter_target) {
script = "//build/android/gyp/bytecode_processor.py"
_bytecode_rewriter_script =
"$root_build_dir/bin/helper/java_bytecode_rewriter"
deps = _deps + [ "//build/android/bytecode:java_bytecode_rewriter($default_toolchain)" ]
if (defined(invoker.deps)) {
deps += invoker.deps
}
inputs = [
_bytecode_rewriter_script,
_java_bytecode_rewriter_input_jar,
_build_config,
]
outputs = [
_java_bytecode_rewriter_output_jar,
]
args = [
"--script",
rebase_path(_bytecode_rewriter_script, root_build_dir),
"--input-jar",
rebase_path(_java_bytecode_rewriter_input_jar, root_build_dir),
"--output-jar",
rebase_path(_java_bytecode_rewriter_output_jar, root_build_dir),
]
if (_is_prebuilt) {
args += [ "--is-prebuilt" ]
}
if (_enable_assert) {
args += [ "--enable-assert" ]
}
if (_enable_custom_resources) {
args += [ "--enable-custom-resources" ]
}
if (_enable_thread_annotations) {
args += [ "--enable-thread-annotations" ]
}
if (_enable_bytecode_checks) {
args += [ "--enable-check-class-path" ]
}
if (_enable_split_compat) {
args += [ "--split-compat-class-names" ] +
invoker.split_compat_class_names
}
if (_enable_class_deps_output) {
args += [ "--enable-class-deps-output" ] +
[ invoker.enable_class_deps_output ]
}
args += [
"--direct-classpath-jars",
"@FileArg($_rebased_build_config:javac:classpath)",
"--sdk-classpath-jars",
"@FileArg($_rebased_build_config:android:sdk_jars)",
"--extra-classpath-jars",
"@FileArg($_rebased_build_config:deps_info:javac_full_classpath)",
]
}
_deps = []
_deps = [ ":$_java_bytecode_rewriter_target" ]
_previous_output_jar = _java_bytecode_rewriter_output_jar
}
if (_desugar) {
_desugar_target = "${target_name}__desugar"
_desugar_input_jar = _previous_output_jar
_desugar_output_jar = "$target_out_dir/$target_name-desugar.jar"
action_with_pydeps(_desugar_target) {
script = "//build/android/gyp/desugar.py"
deps = _deps
depfile = "$target_gen_dir/$target_name.d"
if (defined(invoker.deps)) {
deps += invoker.deps
}
_desugar_jar = "//third_party/bazel/desugar/Desugar.jar"
inputs = [
_build_config,
_desugar_input_jar,
_desugar_jar,
]
outputs = [
_desugar_output_jar,
]
args = [
"--desugar-jar",
rebase_path(_desugar_jar, root_build_dir),
"--input-jar",
rebase_path(_desugar_input_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),
]
}
_deps = []
_deps = [ ":$_desugar_target" ]
_previous_output_jar = _desugar_output_jar
}
if (_filter_jar) {
_filter_target = "${target_name}__filter"
_filter_input_jar = _previous_output_jar
_filter_output_jar = "$target_out_dir/$target_name-filtered.jar"
action_with_pydeps(_filter_target) {
script = "//build/android/gyp/filter_zip.py"
deps = _deps
if (defined(invoker.deps)) {
deps += invoker.deps
}
inputs = [
_build_config,
_filter_input_jar,
]
outputs = [
_filter_output_jar,
]
args = [
"--input",
rebase_path(_filter_input_jar, root_build_dir),
"--output",
rebase_path(_filter_output_jar, root_build_dir),
"--exclude-globs=$_jar_excluded_patterns",
"--include-globs=$_jar_included_patterns",
]
if (_strip_resource_classes) {
args += [ "--strip-resource-classes-for=@FileArg($_rebased_build_config:javac:resource_packages)" ]
}
}
_deps = []
_deps = [ ":$_filter_target" ]
_previous_output_jar = _filter_output_jar
}
if (_jacoco_instrument) {
# Jacoco must run after desugar (or else desugar sometimes fails).
_jacoco_target = "${target_name}__jacoco"
_jacoco_input_jar = _previous_output_jar
_jacoco_output_jar = "$target_out_dir/$target_name-instrumented.jar"
jacoco_instr(_jacoco_target) {
deps = _deps
if (defined(invoker.deps)) {
deps += invoker.deps
}
forward_variables_from(invoker,
[
"java_files",
"java_sources_file",
])
input_jar_path = _jacoco_input_jar
output_jar_path = _jacoco_output_jar
}
_deps = []
_deps = [ ":$_jacoco_target" ]
_previous_output_jar = _jacoco_output_jar
}
_output_jar_target = "${target_name}__copy"
# This is copy_ex rather than copy to ensure that JARs (rather than
# possibly broken symlinks to them) get copied into the output
# directory.
copy_ex(_output_jar_target) {
forward_variables_from(invoker, [ "inputs" ])
deps = _deps
if (defined(invoker.deps)) {
deps += invoker.deps
}
dest = _output_jar_path
sources = [
_previous_output_jar,
]
outputs = [
_output_jar_path,
]
}
group(target_name) {
forward_variables_from(invoker,
[
"data_deps",
"visibility",
])
public_deps = [
":$_output_jar_target",
]
}
}
template("merge_manifests") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
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),
"--build-vars",
rebase_path(android_build_vars, 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)",
]
if (defined(invoker.expected_manifest)) {
inputs += [ invoker.expected_manifest ]
_normalized_output = "${invoker.output_manifest}.normalized"
outputs += [ _normalized_output ]
args += [
"--expected-manifest",
rebase_path(invoker.expected_manifest, root_build_dir),
"--normalized-output",
rebase_path(_normalized_output, root_build_dir),
]
if (check_android_configuration) {
args += [ "--verify-expected-manifest" ]
}
}
}
}
# 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:
# List of directories containing Android resources, layout should be
# similar to what aapt -S <dir> expects.
#
# generated_resource_dirs: (optional)
# List of directories containing generated resources.
#
# generated_resource_files: (optional)
# If generated_resources_dirs is not empty, must list all the files
# within these directories (the directory must appear at the start of
# the file path).
#
# 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.
#
# shared_resources: (optional)
# If true, generate an R.java file that uses non-final resource ID
# variables and an onResourcesLoaded() method.
#
# v14_skip: (optional)
# If true, skip generation of v14 compatible resources.
# (see generate_v14_compatible_resources.py for details).
#
# Output variables:
# zip_path: (optional)
# Path to a .resources.zip that will simply contain all the
# input resources, collected in a single archive.
#
# r_text_out_path: (optional): Path for the generated R.txt file.
#
# srcjar_path: (optional) Path to a generated .srcjar containing the
# generated R.java source file.
#
template("prepare_resources") {
if (defined(invoker.srcjar_path)) {
_srcjar_path = invoker.srcjar_path
}
action_with_pydeps(target_name) {
set_sources_assignment_filter([])
forward_variables_from(invoker,
[
"deps",
"testonly",
"visibility",
])
script = "//build/android/gyp/prepare_resources.py"
depfile = "$target_gen_dir/${invoker.target_name}.d"
outputs = []
_all_resource_dirs = []
sources = []
if (defined(invoker.resource_dirs)) {
_all_resource_dirs += invoker.resource_dirs
# Speed up "gn gen" by short-circuiting the empty directory.
if (invoker.resource_dirs != [ "//build/android/empty" ] &&
invoker.resource_dirs != []) {
_sources_build_rel =
exec_script("//build/android/gyp/find.py",
rebase_path(invoker.resource_dirs, root_build_dir),
"list lines")
sources += rebase_path(_sources_build_rel, ".", root_build_dir)
}
}
if (defined(invoker.generated_resource_dirs)) {
assert(defined(invoker.generated_resource_files))
_all_resource_dirs += invoker.generated_resource_dirs
sources += invoker.generated_resource_files
}
_android_aapt_path = android_default_aapt_path
inputs = [
invoker.build_config,
_android_aapt_path,
]
_rebased_all_resource_dirs =
rebase_path(_all_resource_dirs, root_build_dir)
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--include-resources=@FileArg($_rebased_build_config:android:sdk_jars)",
"--aapt-path",
rebase_path(_android_aapt_path, root_build_dir),
"--dependencies-res-zips=@FileArg($_rebased_build_config:resources:dependency_zips)",
"--extra-res-packages=@FileArg($_rebased_build_config:resources:extra_package_names)",
"--extra-r-text-files=@FileArg($_rebased_build_config:resources:extra_r_text_files)",
]
if (defined(invoker.android_manifest)) {
if (defined(invoker.android_manifest_dep)) {
deps += [ invoker.android_manifest_dep ]
}
inputs += [ invoker.android_manifest ]
args += [
"--android-manifest",
rebase_path(invoker.android_manifest, root_build_dir),
]
}
if (_rebased_all_resource_dirs != []) {
args += [ "--resource-dirs=$_rebased_all_resource_dirs" ]
}
if (defined(invoker.zip_path)) {
outputs += [
invoker.zip_path,
invoker.zip_path + ".info",
]
args += [
"--resource-zip-out",
rebase_path(invoker.zip_path, root_build_dir),
]
}
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(_srcjar_path)) {
outputs += [ _srcjar_path ]
args += [
"--srcjar-out",
rebase_path(_srcjar_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.custom_package)) {
args += [
"--custom-package",
invoker.custom_package,
]
}
if (defined(invoker.strip_drawables) && invoker.strip_drawables) {
args += [ "--strip-drawables" ]
}
if (defined(invoker.shared_resources) && invoker.shared_resources) {
args += [ "--shared-resources" ]
}
if (defined(invoker.v14_skip) && invoker.v14_skip) {
args += [ "--v14-skip" ]
}
}
}
# 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:
# deps: Specifies the input dependencies for this target.
#
# build_config: Path to the .build_config file corresponding to the target.
#
# 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_whitelist: (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_whitelist_locales: (optional)
# If shared_resources_whitelist 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_whitelist
# 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_whitelist: (optional)
# Restrict compiled locale-dependent resources to a specific whitelist.
# NOTE: This is a list of Chromium locale names, not Android ones.
#
# resource_blacklist_regex: (optional)
#
# resource_blacklist_exceptions: (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 assigning package ID.
#
# package_name_to_id_mapping: (optional)
# List containing mapping from package names to package IDs. It will be
# used to determine which package ID to assign if package_name variable
# was passed in.
#
# package_id: (optional)
# Use a custom package ID in resource IDs (same purpose as
# package_name_to_id_mapping)
#
# 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.
#
# srcjar_path: (optional)
# Path to a generated .srcjar containing the generated R.java sources
# for all dependent resource libraries.
#
# proguard_file: (optional)
# Path to proguard configuration file for this apk target.
#
# proguard_file_main_dex: (optional)
#
template("compile_resources") {
_compile_resources_target_name = target_name
if (defined(invoker.arsc_output)) {
_arsc_output = invoker.arsc_output
}
if (defined(invoker.optimized_arsc_output)) {
_optimized_arsc_output = invoker.optimized_arsc_output
}
if (defined(invoker.srcjar_path)) {
_srcjar_path = invoker.srcjar_path
}
if (defined(invoker.post_process_script)) {
_compile_resources_target_name = "${target_name}__intermediate"
_srcjar_path = "${_srcjar_path}.intermediate.srcjar"
_intermediate_path =
get_path_info(_arsc_output, "dir") + "/" +
get_path_info(_arsc_output, "name") + ".intermediate.ap_"
if (defined(_optimized_arsc_output)) {
_optimized_arsc_output = _intermediate_path
} else {
_arsc_output = _intermediate_path
}
}
# NOTE: Regarding the names of the depfiles used by this template:
# They all have the same prefix, related to invoker.target_name,
# instead of $target_name, so it is important they have different
# file paths. Otherwise, extra-rebuilds or even incorrect builds
# may happen due to incorrect dependency information. The suffixes
# used are:
#
# _1.d for the unprocessed compiled resources.
# _2.d for the optional processed compiled resources.
action_with_pydeps(_compile_resources_target_name) {
set_sources_assignment_filter([])
forward_variables_from(invoker,
[
"deps",
"testonly",
"visibility",
])
script = "//build/android/gyp/compile_resources.py"
depfile = "$target_gen_dir/${invoker.target_name}_1.d"
outputs = []
inputs = [
invoker.build_config,
android_sdk_tools_bundle_aapt2,
]
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--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:resources:dependency_zips)",
"--extra-res-packages=@FileArg($_rebased_build_config:resources:extra_package_names)",
"--extra-r-text-files=@FileArg($_rebased_build_config:resources:extra_r_text_files)",
]
inputs += [ invoker.android_manifest ]
args += [
"--android-manifest",
rebase_path(invoker.android_manifest, 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_path)) {
inputs += [ invoker.resources_config_path ]
args += [
"--resources-config-path",
rebase_path(invoker.resources_config_path, root_build_dir),
]
}
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.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(_srcjar_path)) {
outputs += [ _srcjar_path ]
args += [
"--srcjar-out",
rebase_path(_srcjar_path, root_build_dir),
]
}
if (defined(invoker.custom_package)) {
args += [
"--custom-package",
invoker.custom_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}",
"--package-name-to-id-mapping=${invoker.package_name_to_id_mapping}",
]
}
if (defined(invoker.arsc_package_name)) {
args += [
"--arsc-package-name",
invoker.arsc_package_name,
]
}
if (defined(invoker.shared_resources_whitelist)) {
inputs += [ invoker.shared_resources_whitelist ]
args += [
"--shared-resources-whitelist",
rebase_path(invoker.shared_resources_whitelist, root_build_dir),
]
}
if (defined(invoker.shared_resources_whitelist_locales)) {
args += [ "--shared-resources-whitelist-locales=" +
"${invoker.shared_resources_whitelist_locales}" ]
}
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_whitelist)) {
args += [ "--locale-whitelist=${invoker.aapt_locale_whitelist}" ]
}
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_blacklist_regex)) {
args +=
[ "--resource-blacklist-regex=${invoker.resource_blacklist_regex}" ]
if (defined(invoker.resource_blacklist_exceptions)) {
args += [ "--resource-blacklist-exceptions=${invoker.resource_blacklist_exceptions}" ]
}
}
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.post_process_script)) {
action(target_name) {
depfile = "${target_gen_dir}/${invoker.target_name}_2.d"
script = invoker.post_process_script
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--srcjar-in",
rebase_path(_srcjar_path, root_build_dir),
"--srcjar-out",
rebase_path(invoker.srcjar_path, root_build_dir),
]
if (defined(_optimized_arsc_output)) {
_input_apk = _optimized_arsc_output
_output_apk = invoker.optimized_arsc_output
} else {
_input_apk = _arsc_output
_output_apk = invoker.arsc_output
}
args += [
"--apk-path",
rebase_path(_input_apk, root_build_dir),
"--output",
rebase_path(_output_apk, root_build_dir),
]
if (defined(invoker.shared_resources_whitelist)) {
args += [
"--r-text-whitelist",
rebase_path(invoker.shared_resources_whitelist, root_build_dir),
"--r-text",
rebase_path(invoker.r_text_out_path, root_build_dir),
]
}
inputs = [
_input_apk,
_srcjar_path,
]
if (defined(invoker.post_process_script_inputs)) {
inputs += invoker.post_process_script_inputs
}
outputs = [
_output_apk,
invoker.srcjar_path,
]
public_deps = [
":${_compile_resources_target_name}",
]
}
}
}
# 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",
"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:resources: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: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).
# packaged_resources_path: Path to .ap_ to use.
# output_apk_path: Output path for the generated .apk.
# 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).
# native_libs: List of native libraries.
# native_libs_filearg: @FileArg() of additionally native libraries.
# secondary_abi_native_libs: (optional) List of native libraries for
# secondary ABI.
# secondary_abi_native_libs_filearg: (optional). @FileArg() of additional
# secondary ABI native libs.
# write_asset_list: Adds an extra file to the assets, which contains a list of
# all other asset files.
# keystore_path: Path to keystore to use for signing.
# keystore_name: Key alias to use.
# keystore_password: Keystore password.
# uncompress_shared_libraries: (optional, default false) Whether to store
# native libraries inside the APK uncompressed and page-aligned.
template("package_apk") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
"testonly",
])
_native_lib_placeholders = []
if (defined(invoker.native_lib_placeholders)) {
_native_lib_placeholders = invoker.native_lib_placeholders
}
_secondary_native_lib_placeholders = []
if (defined(invoker.secondary_native_lib_placeholders)) {
_secondary_native_lib_placeholders =
invoker.secondary_native_lib_placeholders
}
script = "//build/android/gyp/apkbuilder.py"
depfile = "$target_gen_dir/$target_name.d"
_apksigner = "$android_sdk_build_tools/apksigner"
_zipalign = "$android_sdk_build_tools/zipalign"
data_deps = [
"//tools/android/md5sum",
] # Used when deploying APKs
inputs = invoker.native_libs + [
invoker.keystore_path,
invoker.packaged_resources_path,
_apksigner,
_zipalign,
]
outputs = [
invoker.output_apk_path,
]
data = [
invoker.output_apk_path,
]
_rebased_compiled_resources_path =
rebase_path(invoker.packaged_resources_path, root_build_dir)
_rebased_packaged_apk_path =
rebase_path(invoker.output_apk_path, root_build_dir)
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--resource-apk=$_rebased_compiled_resources_path",
"--output-apk=$_rebased_packaged_apk_path",
"--apksigner-path",
rebase_path(_apksigner, root_build_dir),
"--zipalign-path",
rebase_path(_zipalign, root_build_dir),
"--key-path",
rebase_path(invoker.keystore_path, root_build_dir),
"--key-name",
invoker.keystore_name,
"--key-passwd",
invoker.keystore_password,
]
if (defined(invoker.uncompress_dex) && invoker.uncompress_dex) {
args += [ "--uncompress-dex" ]
}
if (defined(invoker.assets_build_config)) {
inputs += [ invoker.assets_build_config ]
_rebased_build_config =
rebase_path(invoker.assets_build_config, root_build_dir)
args += [
"--assets=@FileArg($_rebased_build_config:assets)",
"--uncompressed-assets=@FileArg($_rebased_build_config:uncompressed_assets)",
]
# TODO(mlopatkin) We are relying on the fact that assets_build_config is
# an APK build_config.
args += [ "--java-resources=@FileArg($_rebased_build_config:java_resources_jars)" ]
}
if (defined(invoker.write_asset_list) && invoker.write_asset_list) {
args += [ "--write-asset-list" ]
}
if (defined(invoker.dex_path)) {
_rebased_dex_path = rebase_path(invoker.dex_path, root_build_dir)
args += [ "--dex-file=$_rebased_dex_path" ]
}
if (invoker.native_libs != [] || defined(invoker.native_libs_filearg) ||
_native_lib_placeholders != []) {
args += [ "--android-abi=$android_app_abi" ]
}
if (defined(android_app_secondary_abi)) {
args += [ "--secondary-android-abi=$android_app_secondary_abi" ]
}
if (invoker.native_libs != []) {
_rebased_native_libs = rebase_path(invoker.native_libs, root_build_dir)
args += [ "--native-libs=$_rebased_native_libs" ]
}
if (defined(invoker.native_libs_filearg)) {
args += [ "--native-libs=${invoker.native_libs_filearg}" ]
}
if (_native_lib_placeholders != []) {
args += [ "--native-lib-placeholders=$_native_lib_placeholders" ]
}
if (_secondary_native_lib_placeholders != []) {
args += [ "--secondary-native-lib-placeholders=$_secondary_native_lib_placeholders" ]
}
if (defined(invoker.secondary_abi_native_libs_filearg)) {
args += [ "--secondary-native-libs=${invoker.secondary_abi_native_libs_filearg}" ]
}
if (defined(invoker.uncompress_shared_libraries) &&
invoker.uncompress_shared_libraries) {
args += [ "--uncompress-shared-libraries=True" ]
}
}
}
# Packages resources, assets, dex, and native libraries into an apk. Signs and
# zipaligns the apk.
template("create_apk") {
set_sources_assignment_filter([])
forward_variables_from(invoker, [ "testonly" ])
_final_apk_path = invoker.apk_path
if (defined(invoker.dex_path)) {
_dex_path = invoker.dex_path
}
_load_library_from_apk = invoker.load_library_from_apk
assert(_load_library_from_apk || true)
_deps = []
if (defined(invoker.deps)) {
_deps = invoker.deps
}
_incremental_deps = []
if (defined(invoker.incremental_deps)) {
_incremental_deps = invoker.incremental_deps
}
_native_libs = []
if (defined(invoker.native_libs)) {
_native_libs = invoker.native_libs
}
_native_libs_even_when_incremental = []
if (defined(invoker.native_libs_even_when_incremental) &&
invoker.native_libs_even_when_incremental != []) {
_native_libs_even_when_incremental =
invoker.native_libs_even_when_incremental
}
_shared_resources =
defined(invoker.shared_resources) && invoker.shared_resources
assert(_shared_resources || true) # Mark as used.
_keystore_path = invoker.keystore_path
_keystore_name = invoker.keystore_name
_keystore_password = invoker.keystore_password
package_apk(target_name) {
forward_variables_from(invoker,
[
"apk_name",
"assets_build_config",
"native_lib_placeholders",
"native_libs_filearg",
"secondary_native_lib_placeholders",
"secondary_abi_native_libs_filearg",
"secondary_abi_loadable_modules",
"uncompress_dex",
"uncompress_shared_libraries",
"write_asset_list",
])
if (!defined(uncompress_shared_libraries)) {
uncompress_shared_libraries = _load_library_from_apk
}
if (defined(invoker.optimized_resources_path)) {
packaged_resources_path = invoker.optimized_resources_path
not_needed(invoker, [ "packaged_resources_path" ])
} else {
packaged_resources_path = invoker.packaged_resources_path
}
deps = _deps
native_libs = _native_libs + _native_libs_even_when_incremental
keystore_path = _keystore_path
keystore_name = _keystore_name
keystore_password = _keystore_password
if (defined(_dex_path)) {
dex_path = _dex_path
}
output_apk_path = _final_apk_path
}
_incremental_allowed =
defined(invoker.incremental_allowed) && invoker.incremental_allowed
if (_incremental_allowed) {
_android_manifest = invoker.android_manifest
_base_path = invoker.base_path
_incremental_final_apk_path_helper =
process_file_template(
[ _final_apk_path ],
"{{source_dir}}/{{source_name_part}}_incremental.apk")
_incremental_final_apk_path = _incremental_final_apk_path_helper[0]
_incremental_compiled_resources_path = "${_base_path}_incremental.ap_"
_incremental_compile_resources_target_name =
"${target_name}_incremental__compile_resources"
_rebased_build_config =
rebase_path(invoker.assets_build_config, root_build_dir)
action_with_pydeps(_incremental_compile_resources_target_name) {
deps = _incremental_deps
script =
"//build/android/incremental_install/generate_android_manifest.py"
inputs = [
_android_manifest,
invoker.assets_build_config,
invoker.packaged_resources_path,
]
outputs = [
_incremental_compiled_resources_path,
]