summaryrefslogtreecommitdiff
path: root/deps/v8/build/config/android
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/build/config/android')
-rw-r--r--deps/v8/build/config/android/BUILD.gn175
-rw-r--r--deps/v8/build/config/android/OWNERS6
-rw-r--r--deps/v8/build/config/android/abi.gni80
-rw-r--r--deps/v8/build/config/android/config.gni380
-rw-r--r--deps/v8/build/config/android/extract_unwind_tables.gni56
-rw-r--r--deps/v8/build/config/android/internal_rules.gni3816
-rw-r--r--deps/v8/build/config/android/linker_version_script.gni37
-rw-r--r--deps/v8/build/config/android/rules.gni4584
-rw-r--r--deps/v8/build/config/android/sdk.gni10
9 files changed, 9144 insertions, 0 deletions
diff --git a/deps/v8/build/config/android/BUILD.gn b/deps/v8/build/config/android/BUILD.gn
new file mode 100644
index 0000000000..b69d42b700
--- /dev/null
+++ b/deps/v8/build/config/android/BUILD.gn
@@ -0,0 +1,175 @@
+# 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.
+
+import("//build/config/android/config.gni")
+import("//build/config/c++/c++.gni")
+import("//build/config/compiler/compiler.gni")
+import("//build/config/sanitizers/sanitizers.gni")
+
+assert(is_android)
+
+# This is included by reference in the //build/config/compiler config that
+# is applied to all targets. It is here to separate out the logic that is
+# Android-only.
+config("compiler") {
+ cflags = [
+ "-ffunction-sections",
+ "-fno-short-enums",
+ ]
+ defines = [
+ "ANDROID",
+
+ # The NDK has these things, but doesn't define the constants to say that it
+ # does. Define them here instead.
+ "HAVE_SYS_UIO_H",
+
+ # Forces full rebuilds on NDK rolls. To rebuild everything when NDK version
+ # stays the same, increment the suffix number.
+ "ANDROID_NDK_VERSION_ROLL=${android_ndk_version}_1",
+ ]
+
+ if (current_cpu == "mips64el") {
+ cflags += [
+ # Have to force IAS for mips64.
+ "-fintegrated-as",
+ ]
+ }
+
+ ldflags = [
+ # Don't allow visible symbols from libgcc or libc++ to be
+ # re-exported.
+ "-Wl,--exclude-libs=libgcc.a",
+
+ # Don't allow visible symbols from libraries that contain
+ # assembly code with symbols that aren't hidden properly.
+ # http://crbug.com/448386
+ "-Wl,--exclude-libs=libvpx_assembly_arm.a",
+ ]
+
+ # $compile_api_level corresponds to the API level used for the sysroot path
+ # calculation in //build/config/android/config.gni
+ if (current_cpu == "arm") {
+ abi_target = "arm-linux-androideabi"
+ compile_api_level = android32_ndk_api_level
+ } else if (current_cpu == "x86") {
+ abi_target = "i686-linux-android"
+ compile_api_level = android32_ndk_api_level
+ } else if (current_cpu == "arm64") {
+ abi_target = "aarch64-linux-android"
+ compile_api_level = android64_ndk_api_level
+ } else if (current_cpu == "x64") {
+ # Place holder for x64 support, not tested.
+ # TODO: Enable clang support for Android x64. http://crbug.com/539781
+ abi_target = "x86_64-linux-android"
+ compile_api_level = android64_ndk_api_level
+ } else if (current_cpu == "mipsel") {
+ abi_target = "mipsel-linux-android"
+ compile_api_level = android32_ndk_api_level
+ } else if (current_cpu == "mips64el") {
+ # Place holder for mips64 support, not tested.
+ abi_target = "mips64el-linux-android"
+ compile_api_level = android64_ndk_api_level
+ } else {
+ assert(false, "Architecture not supported")
+ }
+ cflags += [
+ "--target=$abi_target",
+ "-isystem" +
+ rebase_path("$android_ndk_root/sysroot/usr/include/$abi_target",
+ root_build_dir),
+ "-D__ANDROID_API__=$compile_api_level",
+ ]
+ ldflags += [ "--target=$abi_target" ]
+
+ # TODO(crbug.com/771171): Remove this define once code that uses it has been
+ # updated to no longer need it. This is leftover from older Android NDK
+ # versions.
+ if (compile_api_level < 20) {
+ cflags += [ "-DHAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC=1" ]
+ }
+
+ # Assign any flags set for the C compiler to asmflags so that they are sent
+ # to the assembler.
+ asmflags = cflags
+}
+
+# This is included by reference in the //build/config/compiler:runtime_library
+# config that is applied to all targets. It is here to separate out the logic
+# that is Android-only. Please see that target for advice on what should go in
+# :runtime_library vs. :compiler.
+config("runtime_library") {
+ # NOTE: The libc++ header include paths below are specified in cflags_cc
+ # rather than include_dirs because they need to come after include_dirs.
+ # Think of them like system headers, but don't use '-isystem' because the
+ # arm-linux-androideabi-4.4.3 toolchain (circa Gingerbread) will exhibit
+ # strange errors. The include ordering here is important; change with
+ # caution.
+ cflags_cc = [ "-isystem" +
+ rebase_path("$android_ndk_root/sources/android/support/include",
+ root_build_dir) ]
+
+ defines = [
+ "__GNU_SOURCE=1", # Necessary for clone().
+ "CHROMIUM_CXX_TWEAK_INLINES", # Saves binary size.
+ ]
+ ldflags = [ "-nostdlib" ]
+ lib_dirs = [ android_libcpp_lib_dir ]
+
+ libs = []
+ libs += [ "android_support" ]
+
+ # arm builds of libc++ starting in NDK r12 depend on unwind.
+ if (current_cpu == "arm") {
+ libs += [ "unwind" ]
+ }
+
+ # Manually link the libgcc.a that the cross compiler uses. This is
+ # absolute because the linker will look inside the sysroot if it's not.
+ libs += [
+ rebase_path(android_libgcc_file),
+ "c",
+ ]
+
+ if (current_cpu == "arm" && arm_version == 6) {
+ libs += [ "atomic" ]
+ }
+
+ if (current_cpu == "mipsel") {
+ libs += [ "atomic" ]
+ }
+
+ # TODO(jdduke) Re-enable on mips after resolving linking
+ # issues with libc++ (crbug.com/456380).
+ if (current_cpu != "mipsel" && current_cpu != "mips64el") {
+ ldflags += [ "-Wl,--warn-shared-textrel" ]
+ }
+}
+
+config("hide_all_but_jni_onload") {
+ ldflags = [ "-Wl,--version-script=" + rebase_path(
+ "//build/android/android_only_explicit_jni_exports.lst",
+ root_build_dir) ]
+}
+
+config("hide_all_but_jni") {
+ ldflags = [ "-Wl,--version-script=" +
+ rebase_path("//build/android/android_only_jni_exports.lst",
+ root_build_dir) ]
+}
+
+config("lld_pack_relocations") {
+ ldflags = [ "-Wl,--pack-dyn-relocs=android" ]
+}
+
+# Used for instrumented build to generate the orderfile.
+config("default_orderfile_instrumentation") {
+ if (use_order_profiling) {
+ cflags = [ "-finstrument-function-entry-bare" ]
+ if (use_thin_lto) {
+ # TODO(pcc): This should not be necessary. Remove once
+ # https://reviews.llvm.org/D50017 lands and gets rolled in.
+ ldflags = [ "-Wl,-u,__cyg_profile_func_enter_bare" ]
+ }
+ }
+}
diff --git a/deps/v8/build/config/android/OWNERS b/deps/v8/build/config/android/OWNERS
new file mode 100644
index 0000000000..74dca6f718
--- /dev/null
+++ b/deps/v8/build/config/android/OWNERS
@@ -0,0 +1,6 @@
+agrieve@chromium.org
+estevenson@chromium.org
+digit@chromium.org
+wnwen@chromium.org
+
+# COMPONENT: Build
diff --git a/deps/v8/build/config/android/abi.gni b/deps/v8/build/config/android/abi.gni
new file mode 100644
index 0000000000..79e98b8a8c
--- /dev/null
+++ b/deps/v8/build/config/android/abi.gni
@@ -0,0 +1,80 @@
+# Copyright 2017 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.
+
+# Logic separated out from config.gni so that it can be used by compiler.gni
+# without introducing a circular dependency.
+
+# NOTE: Because Chrome OS builds may depend on targets built with the Android
+# toolchain, this GNI file may be read and processed from within Chrome OS
+# toolchains. Checking |is_android| here would therefore be too restrictive.
+assert(is_android || is_chromeos)
+
+declare_args() {
+ # Adds intrumentation to each function. Writes a file with the order that
+ # functions are called at startup.
+ use_order_profiling = false
+
+ # Only effective if use_order_profiling = true. When this is true,
+ # instrumentation switches from startup profiling after a delay, and
+ # then waits for a devtools memory dump request to dump all
+ # profiling information. When false, the same delay is used to switch from
+ # startup, and then after a second delay all profiling information is dumped.
+ # See base::android::orderfile::StartDelayedDump for more information.
+ devtools_instrumentation_dumping = false
+
+ # Builds secondary abi for APKs, supports build 32-bit arch as secondary
+ # abi in 64-bit Monochrome and WebView.
+ build_apk_secondary_abi = true
+}
+
+assert(!devtools_instrumentation_dumping || use_order_profiling,
+ "devtools_instrumentation_dumping requires use_order_profiling")
+
+if (current_cpu == "x86") {
+ android_app_abi = "x86"
+} else if (current_cpu == "arm") {
+ import("//build/config/arm.gni")
+ if (arm_version < 7) {
+ android_app_abi = "armeabi"
+ } else {
+ android_app_abi = "armeabi-v7a"
+ }
+} else if (current_cpu == "mipsel") {
+ android_app_abi = "mips"
+} else if (current_cpu == "x64") {
+ android_app_abi = "x86_64"
+} else if (current_cpu == "arm64") {
+ android_app_abi = "arm64-v8a"
+} else if (current_cpu == "mips64el") {
+ android_app_abi = "mips64"
+} else {
+ assert(false, "Unknown Android ABI: " + current_cpu)
+}
+
+if (target_cpu == "arm64" || target_cpu == "x64" || target_cpu == "mips64el") {
+ android_64bit_target_cpu = true
+} else if (target_cpu == "arm" || target_cpu == "x86" ||
+ target_cpu == "mipsel") {
+ android_64bit_target_cpu = false
+} else {
+ assert(false, "Unknown target CPU: $target_cpu")
+}
+
+# Intentionally do not define android_app_secondary_abi_cpu and
+# android_app_secondary_abi for 32-bit target_cpu, since they are not used.
+if (target_cpu == "arm64") {
+ android_secondary_abi_cpu = "arm"
+ android_app_secondary_abi = "armeabi-v7a"
+} else if (target_cpu == "x64") {
+ android_secondary_abi_cpu = "x86"
+ android_app_secondary_abi = "x86"
+} else if (target_cpu == "mips64el") {
+ android_secondary_abi_cpu = "mipsel"
+ android_app_secondary_abi = "mips"
+}
+
+if (defined(android_secondary_abi_cpu)) {
+ android_secondary_abi_toolchain =
+ "//build/toolchain/android:android_clang_${android_secondary_abi_cpu}"
+}
diff --git a/deps/v8/build/config/android/config.gni b/deps/v8/build/config/android/config.gni
new file mode 100644
index 0000000000..a4e230c763
--- /dev/null
+++ b/deps/v8/build/config/android/config.gni
@@ -0,0 +1,380 @@
+# 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.
+
+# This file contains common system config stuff for the Android build.
+
+# NOTE: Because Chrome OS builds may depend on targets built with the Android
+# toolchain, this GNI file may be read and processed from within Chrome OS
+# toolchains. Checking |is_android| here would therefore be too restrictive.
+if (is_android || is_chromeos) {
+ import("//build/config/chromecast_build.gni")
+ import("//build_overrides/build.gni")
+ import("abi.gni")
+
+ if (build_with_chromium) {
+ # Some non-chromium projects (e.g. WebRTC) use our build configs
+ # heavily but don't write gclient args files.
+
+ import("//build/config/gclient_args.gni")
+ if (defined(checkout_android_native_support)) {
+ n = "$0x0A" # Newline
+ assert(checkout_android_native_support,
+ "Missing native Android toolchain support. |target_os| in your " +
+ ".gclient configuration file (in the parent directory of " +
+ "src) must include \"android\" and/or \"chromeos\". For " +
+ "example:${n}${n}solutions = [${n}...${n}]${n}" +
+ "target_os=[\"chromeos\"]${n}${n}" +
+ "After adding |target_os| please re-run \"gclient sync\".${n}")
+ }
+ }
+
+ has_chrome_android_internal =
+ exec_script("//build/dir_exists.py",
+ [ rebase_path("//clank", root_build_dir) ],
+ "string") == "True"
+
+ # We are using a separate declare_args block for only this argument so that
+ # we can decide if we have to pull in definitions from the internal config
+ # early.
+ declare_args() {
+ # Enables using the internal Chrome for Android repository. The default
+ # value depends on whether the repository is available, and if it's not but
+ # this argument is manually set to True, the generation will fail.
+ # The main purpose of this argument is to avoid having to maintain 2
+ # repositories to support both public only and internal builds.
+ enable_chrome_android_internal = has_chrome_android_internal
+
+ # Android API level for 32 bits platforms
+ android32_ndk_api_level = 16
+
+ # Android API level for 64 bits platforms
+ android64_ndk_api_level = 21
+ }
+
+ if (enable_chrome_android_internal) {
+ import("//clank/config.gni")
+ } else {
+ import("//build/config/android/sdk.gni")
+ declare_args() {
+ # Android SDK release. Currently, only "o_mr1" is publicly supported.
+ android_sdk_release = default_android_sdk_release
+ }
+ }
+
+ if (!defined(extra_chrome_shared_library_configs)) {
+ extra_chrome_shared_library_configs = []
+ }
+ if (!defined(extra_chrome_shared_library_deps)) {
+ extra_chrome_shared_library_deps = []
+ }
+
+ if (!defined(default_android_ndk_root)) {
+ default_android_ndk_root = "//third_party/android_ndk"
+ default_android_ndk_version = "r16"
+ default_android_ndk_major_version = 16
+ } else {
+ assert(defined(default_android_ndk_version))
+ assert(defined(default_android_ndk_major_version))
+ }
+
+ if (android_sdk_release == "o_mr1") {
+ default_android_sdk_root = "//third_party/android_sdk/public"
+ default_android_sdk_version = 27
+ default_android_sdk_build_tools_version = "27.0.3"
+ default_android_sdk_tools_version_suffix = "-26.0.0-dev"
+ public_android_sdk = true
+ }
+
+ if (android_sdk_release == "p") {
+ default_android_sdk_root = "//third_party/android_sdk/public"
+ default_android_sdk_version = 28
+ default_android_sdk_build_tools_version = "27.0.3"
+ default_android_sdk_tools_version_suffix = "-26.0.0-dev"
+ public_android_sdk = true
+ }
+
+ if (!defined(default_lint_android_sdk_root)) {
+ # Purposefully repeated so that downstream can change
+ # default_android_sdk_root without changing lint version.
+ default_lint_android_sdk_root = "//third_party/android_sdk/public"
+ default_lint_android_sdk_version = 26
+ }
+
+ if (!defined(default_extras_android_sdk_root)) {
+ # Purposefully repeated so that downstream can change
+ # default_android_sdk_root without changing where we load the SDK extras
+ # from. (Google Play services, etc.)
+ default_extras_android_sdk_root = "//third_party/android_sdk/public"
+ }
+
+ if (!defined(default_android_keystore_path)) {
+ default_android_keystore_path = "//build/android/chromium-debug.keystore"
+ default_android_keystore_name = "chromiumdebugkey"
+ default_android_keystore_password = "chromium"
+ }
+
+ # google_play_services_package contains the path where individual client
+ # targets (e.g. google_play_services_base_java) are located.
+ if (!defined(google_play_services_package)) {
+ if (is_chromecast && chromecast_branding != "public") {
+ google_play_services_package = "//chromecast/internal/android/prebuilt/google-play-services-first-party"
+ } else {
+ google_play_services_package = "//third_party/android_deps"
+ }
+ }
+
+ if (!defined(system_webview_apk_target)) {
+ system_webview_apk_target = "//android_webview:system_webview_apk"
+ }
+
+ webview_public_framework_dep =
+ "//third_party/android_sdk:public_framework_system_java"
+ if (!defined(webview_framework_dep)) {
+ webview_framework_dep = webview_public_framework_dep
+ }
+
+ assert(defined(default_android_sdk_root),
+ "SDK release " + android_sdk_release + " not recognized.")
+
+ declare_args() {
+ android_ndk_root = default_android_ndk_root
+ android_ndk_version = default_android_ndk_version
+ android_ndk_major_version = default_android_ndk_major_version
+
+ android_sdk_root = default_android_sdk_root
+ android_sdk_version = default_android_sdk_version
+ android_sdk_build_tools_version = default_android_sdk_build_tools_version
+ android_sdk_tools_version_suffix = default_android_sdk_tools_version_suffix
+
+ lint_android_sdk_root = default_lint_android_sdk_root
+ lint_android_sdk_version = default_lint_android_sdk_version
+
+ # Libc++ library directory. Override to use a custom libc++ binary.
+ android_libcpp_lib_dir = ""
+
+ # Android versionCode for android_apk()s that don't explicitly set one.
+ android_default_version_code = "1"
+
+ # Android versionName for android_apk()s that don't explicitly set one.
+ android_default_version_name = "Developer Build"
+
+ # Forced Android versionCode
+ android_override_version_code = ""
+
+ # Forced Android versionName
+ android_override_version_name = ""
+
+ # The path to the keystore to use for signing builds.
+ android_keystore_path = default_android_keystore_path
+
+ # The name of the keystore to use for signing builds.
+ android_keystore_name = default_android_keystore_name
+
+ # The password for the keystore to use for signing builds.
+ android_keystore_password = default_android_keystore_password
+
+ # Java debug on Android. Having this on enables multidexing, and turning it
+ # off will enable proguard.
+ is_java_debug = is_debug
+
+ # Report Java assert failure on Android. Turning it on will report Java
+ # assert failure without crash.
+ report_java_assert = false
+
+ # Mark APKs as android:debuggable="true".
+ debuggable_apks = !is_official_build
+
+ # Set to false to disable the Errorprone compiler
+ use_errorprone_java_compiler = true
+
+ # Enables EMMA Java code coverage. Instruments classes during build to
+ # produce .ec files during runtime
+ emma_coverage = false
+
+ # EMMA filter string consisting of a list of inclusion/exclusion patterns
+ # separated with whitespace and/or comma. Only has effect if
+ # emma_coverage==true
+ emma_filter = ""
+
+ # Disables process isolation when building _incremental targets.
+ # Required for Android M+ due to SELinux policies (stronger sandboxing).
+ disable_incremental_isolated_processes = false
+
+ # Build incremental targets whenever possible.
+ # Ex. with this arg set to true, the chrome_public_apk target result in
+ # chrome_public_apk_incremental being built.
+ incremental_apk_by_default = false
+
+ # When true, updates all android_aar_prebuilt() .info files during gn gen.
+ # Refer to android_aar_prebuilt() for more details.
+ update_android_aar_prebuilts = false
+
+ # Turns off android lint. Useful for prototyping or for faster local builds.
+ disable_android_lint = false
+
+ # Location of aapt2 binary used for app bundles. For now, a more recent version
+ # than the one distributed with the Android SDK is required.
+ android_sdk_tools_bundle_aapt2 =
+ "//third_party/android_build_tools/aapt2/aapt2"
+
+ # Use R8 for Java optimization rather than ProGuard for all targets. R8 is
+ # already used as the default for public targets. This will evenutally be
+ # the default. https://crbug.com/908988
+ use_r8 = false
+
+ # Checks that proguard flags have not changed (!is_java_debug only).
+ check_android_configuration = false
+
+ # Enable the chrome build for devices without touchscreens.
+ notouch_build = false
+
+ # Move Trichrome assets to the shared library APK. This will be removed
+ # once P builds are no longer supported. https://crbug.com/943637
+ trichrome_shared_assets = android_sdk_release == "q"
+ }
+
+ if (notouch_build && defined(extra_keymappings)) {
+ keycode_conversion_data_android_path = extra_keymappings
+ }
+
+ assert(!(check_android_configuration && is_java_debug),
+ "check_android_configuration only works when proguard is enabled")
+
+ # We need a second declare_args block to make sure we are using the overridden
+ # value of the arguments set above.
+ declare_args() {
+ if (defined(default_android_sdk_platform_version)) {
+ android_sdk_platform_version = default_android_sdk_platform_version
+ } else {
+ android_sdk_platform_version = android_sdk_version
+ }
+
+ # Speed up dexing using dx --incremental.
+ enable_incremental_dx = is_java_debug
+
+ # Use hashed symbol names to reduce JNI symbol overhead.
+ use_hashed_jni_names = !is_java_debug
+ }
+
+ # This should not be used for release builds since dx --incremental is known
+ # to not produce byte-for-byte identical output.
+ assert(!(enable_incremental_dx && !is_java_debug))
+
+ # Path to where selected build variables are written to.
+ android_build_vars = "$root_build_dir/build_vars.txt"
+
+ # Host stuff -----------------------------------------------------------------
+
+ # Defines the name the Android build gives to the current host CPU
+ # architecture, which is different than the names GN uses.
+ if (host_cpu == "x64") {
+ android_host_arch = "x86_64"
+ } else if (host_cpu == "x86") {
+ android_host_arch = "x86"
+ } else {
+ assert(false, "Need Android toolchain support for your build CPU arch.")
+ }
+
+ # Defines the name the Android build gives to the current host CPU
+ # architecture, which is different than the names GN uses.
+ if (host_os == "linux") {
+ android_host_os = "linux"
+ } else if (host_os == "mac") {
+ android_host_os = "darwin"
+ } else {
+ assert(false, "Need Android toolchain support for your build OS.")
+ }
+
+ # Directories and files ------------------------------------------------------
+ #
+ # We define may of the dirs strings here for each output architecture (rather
+ # than just the current one) since these are needed by the Android toolchain
+ # file to define toolchains for all possible targets in one pass.
+
+ android_sdk =
+ "${android_sdk_root}/platforms/android-${android_sdk_platform_version}"
+ android_sdk_tools = "${android_sdk_root}/tools"
+ android_sdk_build_tools =
+ "${android_sdk_root}/build-tools/$android_sdk_build_tools_version"
+
+ # Path to the SDK's android.jar
+ android_sdk_jar = "$android_sdk/android.jar"
+
+ # Subdirectories inside android_ndk_root that contain the sysroot for the
+ # associated platform.
+ x86_android_sysroot_subdir =
+ "platforms/android-${android32_ndk_api_level}/arch-x86"
+ arm_android_sysroot_subdir =
+ "platforms/android-${android32_ndk_api_level}/arch-arm"
+ mips_android_sysroot_subdir =
+ "platforms/android-${android32_ndk_api_level}/arch-mips"
+ x86_64_android_sysroot_subdir =
+ "platforms/android-${android64_ndk_api_level}/arch-x86_64"
+ arm64_android_sysroot_subdir =
+ "platforms/android-${android64_ndk_api_level}/arch-arm64"
+ mips64_android_sysroot_subdir =
+ "platforms/android-${android64_ndk_api_level}/arch-mips64"
+
+ # Toolchain root directory for each build. The actual binaries are inside
+ # a "bin" directory inside of these.
+ _android_toolchain_version = "4.9"
+ _android_toolchain_detailed_version = "4.9.x"
+ x86_android_toolchain_root = "$android_ndk_root/toolchains/x86-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}"
+ arm_android_toolchain_root = "$android_ndk_root/toolchains/arm-linux-androideabi-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}"
+ mips_android_toolchain_root = "$android_ndk_root/toolchains/mipsel-linux-android-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}"
+ x86_64_android_toolchain_root = "$android_ndk_root/toolchains/x86_64-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}"
+ arm64_android_toolchain_root = "$android_ndk_root/toolchains/aarch64-linux-android-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}"
+ mips64_android_toolchain_root = "$android_ndk_root/toolchains/mips64el-linux-android-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}"
+
+ # Location of libgcc. This is only needed for the current GN toolchain, so we
+ # only need to define the current one, rather than one for every platform
+ # like the toolchain roots.
+ if (current_cpu == "x86") {
+ android_prebuilt_arch = "android-x86"
+ _binary_prefix = "i686-linux-android"
+ android_toolchain_root = "$x86_android_toolchain_root"
+ android_libgcc_file = "$android_toolchain_root/lib/gcc/i686-linux-android/${_android_toolchain_detailed_version}/libgcc.a"
+ } else if (current_cpu == "arm") {
+ android_prebuilt_arch = "android-arm"
+ _binary_prefix = "arm-linux-androideabi"
+ android_toolchain_root = "$arm_android_toolchain_root"
+ android_libgcc_file = "$android_toolchain_root/lib/gcc/arm-linux-androideabi/${_android_toolchain_detailed_version}/libgcc.a"
+ } else if (current_cpu == "mipsel") {
+ android_prebuilt_arch = "android-mips"
+ _binary_prefix = "mipsel-linux-android"
+ android_toolchain_root = "$mips_android_toolchain_root"
+ android_libgcc_file = "$android_toolchain_root/lib/gcc/mipsel-linux-android/${_android_toolchain_detailed_version}/libgcc.a"
+ } else if (current_cpu == "x64") {
+ android_prebuilt_arch = "android-x86_64"
+ _binary_prefix = "x86_64-linux-android"
+ android_toolchain_root = "$x86_64_android_toolchain_root"
+ android_libgcc_file = "$android_toolchain_root/lib/gcc/x86_64-linux-android/${_android_toolchain_detailed_version}/libgcc.a"
+ } else if (current_cpu == "arm64") {
+ android_prebuilt_arch = "android-arm64"
+ _binary_prefix = "aarch64-linux-android"
+ android_toolchain_root = "$arm64_android_toolchain_root"
+ android_libgcc_file = "$android_toolchain_root/lib/gcc/aarch64-linux-android/${_android_toolchain_detailed_version}/libgcc.a"
+ } else if (current_cpu == "mips64el") {
+ android_prebuilt_arch = "android-mips64"
+ _binary_prefix = "mips64el-linux-android"
+ android_toolchain_root = "$mips64_android_toolchain_root"
+ android_libgcc_file = "$android_toolchain_root/lib/gcc/mips64el-linux-android/${_android_toolchain_detailed_version}/libgcc.a"
+ } else {
+ assert(false, "Need android libgcc support for your target arch.")
+ }
+
+ android_tool_prefix = "$android_toolchain_root/bin/$_binary_prefix-"
+ android_readelf = "${android_tool_prefix}readelf"
+ android_objcopy = "${android_tool_prefix}objcopy"
+ android_gdbserver =
+ "$android_ndk_root/prebuilt/$android_prebuilt_arch/gdbserver/gdbserver"
+
+ # Toolchain stuff ------------------------------------------------------------
+
+ android_libcpp_root = "$android_ndk_root/sources/cxx-stl/llvm-libc++"
+
+ if (android_libcpp_lib_dir == "") {
+ android_libcpp_lib_dir = "${android_libcpp_root}/libs/${android_app_abi}"
+ }
+}
diff --git a/deps/v8/build/config/android/extract_unwind_tables.gni b/deps/v8/build/config/android/extract_unwind_tables.gni
new file mode 100644
index 0000000000..2cf9887747
--- /dev/null
+++ b/deps/v8/build/config/android/extract_unwind_tables.gni
@@ -0,0 +1,56 @@
+# Copyright 2018 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.
+
+import("//build/config/android/rules.gni")
+
+template("unwind_table_asset") {
+ # Note: This file name is used in multiple monochrome build scripts.
+ _asset_path = "${target_gen_dir}/${target_name}/unwind_cfi_32"
+ _unwind_action = "${target_name}__extract"
+
+ action(_unwind_action) {
+ if (defined(invoker.testonly)) {
+ testonly = invoker.testonly
+ }
+
+ _root_dir = "$root_out_dir"
+ if (build_apk_secondary_abi && defined(android_secondary_abi_cpu)) {
+ _root_dir = get_label_info(":foo($android_secondary_abi_toolchain)",
+ "root_out_dir")
+ }
+
+ script = "//build/android/gyp/extract_unwind_tables.py"
+ outputs = [
+ _asset_path,
+ ]
+ inputs = [
+ "${_root_dir}/lib.unstripped/$shlib_prefix${invoker.library_target}$shlib_extension",
+ ]
+
+ args = [
+ "--input_path",
+ rebase_path(
+ "${_root_dir}/lib.unstripped/$shlib_prefix${invoker.library_target}$shlib_extension",
+ root_build_dir),
+ "--output_path",
+ rebase_path(_asset_path, root_build_dir),
+ "--dump_syms_path",
+ rebase_path("$root_out_dir/dump_syms", root_build_dir),
+ ]
+ deps = invoker.deps
+ deps += [ "//third_party/breakpad:dump_syms" ]
+ }
+ android_assets(target_name) {
+ if (defined(invoker.testonly)) {
+ testonly = invoker.testonly
+ }
+ sources = [
+ _asset_path,
+ ]
+ disable_compression = true
+ deps = [
+ ":$_unwind_action",
+ ]
+ }
+}
diff --git a/deps/v8/build/config/android/internal_rules.gni b/deps/v8/build/config/android/internal_rules.gni
new file mode 100644
index 0000000000..264514adaf
--- /dev/null
+++ b/deps/v8/build/config/android/internal_rules.gni
@@ -0,0 +1,3816 @@
+# 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.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.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.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)) {
+ _dependent_configs = []
+ foreach(d, invoker.static_library_dependent_targets) {
+ _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")
+ _dependent_configs += [ "$_dep_gen_dir/$_dep_name.build_config" ]
+ }
+ _rebased_depdent_configs = rebase_path(_dependent_configs, root_build_dir)
+ args += [ "--static-library-dependent-configs=$_rebased_depdent_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 (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 (emma_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.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 (emma_coverage) {
+ args += [
+ "--classpath",
+ rebase_path("//third_party/android_sdk/public/tools/lib/emma.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),
+ ]
+ }
+ }
+ }
+
+ 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.")
+
+ 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",
+ "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.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 {
+ if (defined(invoker.extra_main_dex_proguard_config)) {
+ not_needed(invoker, [ "extra_main_dex_proguard_config" ])
+ }
+ }
+ }
+
+ 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("emma_instr") {
+ action_with_pydeps(target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "public_deps",
+ "testonly",
+ ])
+
+ _coverage_file = "$target_out_dir/${target_name}.em"
+ _source_dirs_listing_file = "$target_out_dir/${target_name}_sources.txt"
+ _emma_jar = "${android_sdk_root}/tools/lib/emma.jar"
+
+ script = "//build/android/gyp/emma_instr.py"
+ inputs = invoker.java_files + [
+ _emma_jar,
+ invoker.input_jar_path,
+ ]
+ outputs = [
+ _coverage_file,
+ _source_dirs_listing_file,
+ invoker.output_jar_path,
+ ]
+ args = [
+ "instrument_jar",
+ "--input-path",
+ rebase_path(invoker.input_jar_path, root_build_dir),
+ "--output-path",
+ rebase_path(invoker.output_jar_path, root_build_dir),
+ "--coverage-file",
+ rebase_path(_coverage_file, root_build_dir),
+ "--sources-list-file",
+ rebase_path(_source_dirs_listing_file, root_build_dir),
+ "--src-root",
+ rebase_path("//", root_build_dir),
+ "--emma-jar",
+ rebase_path(_emma_jar, root_build_dir),
+ ]
+ _rebased_java_sources_file =
+ rebase_path(invoker.java_sources_file, root_build_dir)
+ args += [ "--java-sources-file=$_rebased_java_sources_file" ]
+
+ if (emma_filter != "") {
+ args += [
+ "--filter-string",
+ emma_filter,
+ ]
+ }
+ }
+ }
+
+ # TODO(digit): Document this!
+ #
+ # Variables:
+ # testonly:
+ # build_config:
+ # input_jar_path:
+ # output_jar_path:
+ # enable_build_hooks:
+ # enable_build_hooks_android:
+ # supports_android:
+ # emma_instrument:
+ # 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
+ _emma_instrument = invoker.emma_instrument
+ _enable_split_compat = defined(invoker.split_compat_class_names)
+ _enable_bytecode_rewriter =
+ _enable_assert || _enable_custom_resources ||
+ _enable_thread_annotations || _enable_split_compat
+ _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
+ }
+ 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 (_emma_instrument) {
+ # Emma must run after desugar (or else desugar sometimes fails).
+ _emma_target = "${target_name}__emma"
+ _emma_input_jar = _previous_output_jar
+ _emma_output_jar = "$target_out_dir/$target_name-instrumented.jar"
+
+ emma_instr(_emma_target) {
+ deps = _deps
+ if (defined(invoker.deps)) {
+ deps += invoker.deps
+ }
+
+ forward_variables_from(invoker,
+ [
+ "java_files",
+ "java_sources_file",
+ ])
+
+ input_jar_path = _emma_input_jar
+ output_jar_path = _emma_output_jar
+ }
+
+ _deps = []
+ _deps = [ ":$_emma_target" ]
+ _previous_output_jar = _emma_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)
+ #
+ # proto_format: (optional). If true, compiles resources into protocol
+ # buffer format.
+ #
+ # 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.
+ #
+ # Output variables:
+ # output: Path to a zip file containing the compiled resources.
+ #
+ # r_text_out_path: (optional):
+ # Path for the corresponding generated R.txt file.
+ #
+ # 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
+ _compiled_resources_path = invoker.output
+
+ if (defined(invoker.srcjar_path)) {
+ _srcjar_path = invoker.srcjar_path
+ }
+ if (defined(invoker.post_process_script)) {
+ _compile_resources_target_name = "${target_name}__intermediate"
+ _compiled_resources_path =
+ get_path_info(_compiled_resources_path, "dir") + "/" +
+ get_path_info(_compiled_resources_path, "name") + ".intermediate.ap_"
+ _srcjar_path = "${_srcjar_path}.intermediate.srcjar"
+ }
+
+ _proto_format = defined(invoker.proto_format) && invoker.proto_format
+
+ # 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.
+ # _3.d for the proto-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 = []
+
+ _android_aapt_path = android_default_aapt_path
+ _android_aapt2_path = android_sdk_tools_bundle_aapt2
+ if (_proto_format) {
+ depfile = "$target_gen_dir/${invoker.target_name}_3.d"
+ }
+
+ inputs = [
+ invoker.build_config,
+ _android_aapt_path,
+ _android_aapt2_path,
+ ]
+
+ _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_aapt2_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)",
+ ]
+
+ 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(_compiled_resources_path)) {
+ _info_path = invoker.output + ".info"
+ outputs += [
+ _compiled_resources_path,
+ _info_path,
+ ]
+ args += [
+ "--apk-path",
+ rebase_path(_compiled_resources_path, root_build_dir),
+ "--apk-info-path",
+ rebase_path(_info_path, root_build_dir),
+ ]
+ }
+
+ if (defined(invoker.optimized_resources_path)) {
+ args += [
+ "--optimized-resources-path",
+ rebase_path(invoker.optimized_resources_path, root_build_dir),
+ ]
+ outputs += [ invoker.optimized_resources_path ]
+
+ if (defined(invoker.resources_config_path)) {
+ inputs += [ invoker.resources_config_path ]
+ args += [
+ "--resources-config-path",
+ rebase_path(invoker.resources_config_path, root_build_dir),
+ ]
+ }
+ }
+
+ # 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,
+ ]
+ }
+
+ if (_proto_format) {
+ args += [ "--proto-format" ]
+ }
+
+ # 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),
+ "--apk-path",
+ rebase_path(_compiled_resources_path, root_build_dir),
+ "--output",
+ rebase_path(invoker.output, root_build_dir),
+ "--srcjar-in",
+ rebase_path(_srcjar_path, root_build_dir),
+ "--srcjar-out",
+ rebase_path(invoker.srcjar_path, 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 = [
+ _srcjar_path,
+ _compiled_resources_path,
+ ]
+ if (defined(invoker.post_process_script_inputs)) {
+ inputs += invoker.post_process_script_inputs
+ }
+ outputs = [
+ invoker.output,
+ 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").
+ # packaged_resources_path: Path to .ap_ file.
+ #
+ 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)",
+ "--resource-apk=@FileArg($_rebased_build_config:deps_info:proto_resources_path)",
+ "--assets=@FileArg($_rebased_build_config:assets)",
+ "--uncompressed-assets=@FileArg($_rebased_build_config:uncompressed_assets)",
+ ]
+ }
+ } else {
+ inputs = [
+ invoker.build_config,
+ invoker.packaged_resources_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)",
+ "--resource-apk",
+ rebase_path(invoker.packaged_resources_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,
+ ]
+ if (defined(invoker.dex_path)) {
+ inputs += [ invoker.dex_path ]
+ }
+
+ 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,
+ ]
+
+ args = [
+ "--src-manifest",
+ rebase_path(_android_manifest, root_build_dir),
+ "--in-apk",
+ rebase_path(invoker.packaged_resources_path, root_build_dir),
+ "--out-apk",
+ rebase_path(_incremental_compiled_resources_path, root_build_dir),
+ "--aapt2-path",
+ rebase_path(android_sdk_tools_bundle_aapt2, root_build_dir),
+ "--android-sdk-jars=@FileArg($_rebased_build_config:android:sdk_jars)",
+ ]
+ if (disable_incremental_isolated_processes) {
+ args += [ "--disable-isolated-processes" ]
+ }
+ }
+
+ package_apk("${target_name}_incremental") {
+ forward_variables_from(invoker,
+ [
+ "assets_build_config",
+ "secondary_abi_loadable_modules",
+ "uncompress_shared_libraries",
+ ])
+ _dex_target = "//build/android/incremental_install:bootstrap_java__dex"
+ deps = _incremental_deps + [
+ ":${_incremental_compile_resources_target_name}",
+ _dex_target,
+ ]
+
+ if (defined(_dex_path)) {
+ dex_path =
+ get_label_info(_dex_target, "target_gen_dir") + "/bootstrap.dex"
+ }
+
+ native_libs = _native_libs_even_when_incremental
+ keystore_path = _keystore_path
+ keystore_name = _keystore_name
+ keystore_password = _keystore_password
+
+ # http://crbug.com/384638
+ _has_native_libs =
+ defined(invoker.native_libs_filearg) || _native_libs != []
+ if (_has_native_libs && _native_libs_even_when_incremental == []) {
+ native_lib_placeholders = [ "libfix.crbug.384638.so" ]
+ }
+
+ output_apk_path = _incremental_final_apk_path
+ packaged_resources_path = _incremental_compiled_resources_path
+ }
+ }
+ }
+
+ # Compile Java source files into a .jar file, potentially using an
+ # annotation processor, and/or the errorprone compiler.
+ #
+ # Note that the only way to specify custom annotation processors is
+ # by using build_config to point to a file that corresponds to a java-related
+ # target that includes javac:processor_classes entries (i.e. there is no
+ # variable here that can be used for this purpose).
+ #
+ # Note also the peculiar use of java_files / java_sources_file. The content
+ # of the java_files list and the java_sources_file file must match exactly.
+ # This rule uses java_files only to list the inputs to the action that
+ # calls the javac.py script, but will pass the list of Java source files
+ # with the '@${java_sources_file}" command-line syntax. Not a problem in
+ # practice since this is only called from java_library_impl() that sets up
+ # the variables properly.
+ #
+ # Variables:
+ # main_target_name: Used when extracting srcjars for codesearch.
+ # java_files: Optional list of Java source file paths.
+ # srcjar_deps: Optional list of .srcjar dependencies (not file paths).
+ # The corresponding source files they contain will be compiled too.
+ # srcjar_filearg: Optional @FileArg for additional srcjars.
+ # java_sources_file: Optional path to file containing list of Java source
+ # file paths. This must always be provided if java_files is not empty
+ # and must match it exactly.
+ # build_config: Path to the .build_config file of the corresponding
+ # java_library_impl() target. The following entries will be used by this
+ # template: javac:srcjars, deps_info:javac_full_classpath,
+ # deps_info:javac_full_interface_classpath, javac:processor_classpath,
+ # javac:processor_classes
+ # javac_jar_path: Path to the final output .jar file.
+ # javac_args: Optional list of extra arguments to pass to javac.
+ # chromium_code: Whether this corresponds to Chromium-specific sources.
+ # requires_android: True if these sources can only run on Android.
+ # additional_jar_files: Optional list of files to copy into the resulting
+ # .jar file (by default, only .class files are put there). Each entry
+ # has the 'srcPath:dstPath' format.
+ # enable_errorprone: Optional. If True, use the errorprone compiler to
+ # check for error-prone constructs in the language. If not provided,
+ # whether this is enabled depends on chromium_code and the global
+ # use_errorprone_java_compiler variable.
+ # apk_name: Optional APK name. If provided, will tell javac.py to also
+ # generate an .apk.jar.info file under size-info/${apk_name}.apk.jar.info
+ # provider_configurations: Optional list of paths to Java service
+ # provider configuration files [1]. These will be copied under
+ # META-INF/services/ in the final .jar file.
+ # processor_args_javac: List of annotation processor arguments, each one
+ # will be passed to javac as -A<entry>.
+ # deps: Dependencies for the corresponding target.
+ # testonly: Usual meaning (should be True for test-only targets)
+ #
+ # [1] https://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html
+ #
+ template("compile_java") {
+ forward_variables_from(invoker, [ "testonly" ])
+
+ _build_config = invoker.build_config
+ _chromium_code = invoker.chromium_code
+
+ _provider_configurations = []
+ if (defined(invoker.provider_configurations)) {
+ _provider_configurations = invoker.provider_configurations
+ }
+
+ _processor_args = []
+ if (defined(invoker.processor_args_javac)) {
+ _processor_args = invoker.processor_args_javac
+ }
+
+ _additional_jar_files = []
+ if (defined(invoker.additional_jar_files)) {
+ _additional_jar_files = invoker.additional_jar_files
+ }
+
+ _srcjar_deps = []
+ if (defined(invoker.srcjar_deps)) {
+ _srcjar_deps += invoker.srcjar_deps
+ }
+
+ _java_srcjars = []
+ foreach(dep, _srcjar_deps) {
+ _dep_gen_dir = get_label_info(dep, "target_gen_dir")
+ _dep_name = get_label_info(dep, "name")
+ _java_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ]
+ }
+
+ _javac_args = []
+ if (defined(invoker.javac_args)) {
+ _javac_args = invoker.javac_args
+ }
+
+ action_with_pydeps(target_name) {
+ script = "//build/android/gyp/javac.py"
+ depfile = "$target_gen_dir/$target_name.d"
+ deps = _srcjar_deps
+ if (defined(invoker.deps)) {
+ deps += invoker.deps
+ }
+
+ outputs = [
+ invoker.javac_jar_path,
+ invoker.javac_jar_path + ".info",
+ ]
+ inputs = invoker.java_files + _java_srcjars + [ _build_config ]
+ if (invoker.java_files != []) {
+ inputs += [ invoker.java_sources_file ]
+ }
+
+ _rebased_build_config = rebase_path(_build_config, root_build_dir)
+ _rebased_javac_jar_path =
+ rebase_path(invoker.javac_jar_path, root_build_dir)
+ _rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir)
+ _rebased_depfile = rebase_path(depfile, root_build_dir)
+ _rebased_generated_dir = rebase_path(
+ "$target_gen_dir/${invoker.main_target_name}/generated_java",
+ root_build_dir)
+ args = [
+ "--depfile=$_rebased_depfile",
+ "--generated-dir=$_rebased_generated_dir",
+ "--jar-path=$_rebased_javac_jar_path",
+ "--java-srcjars=$_rebased_java_srcjars",
+ "--java-version=1.8",
+ "--full-classpath=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)",
+ "--interface-classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)",
+ "--processorpath=@FileArg($_rebased_build_config:javac:processor_classpath)",
+ "--processors=@FileArg($_rebased_build_config:javac:processor_classes)",
+ ]
+ if (defined(invoker.srcjar_filearg)) {
+ args += [ "--java-srcjars=${invoker.srcjar_filearg}" ]
+ }
+ if (invoker.requires_android) {
+ args += [ "--bootclasspath=@FileArg($_rebased_build_config:android:sdk_interface_jars)" ]
+ }
+ if (_chromium_code) {
+ args += [ "--chromium-code=1" ]
+ }
+
+ # Use errorprone with checks disabled when !enable_errorprone so that
+ # compile results are the same across machines.
+ # TODO(crbug.com/693079): Add javac to DEPS and use it for the
+ # !enable_errorprone case.
+ deps += [ "//third_party/errorprone:errorprone($default_toolchain)" ]
+ args += [
+ "--errorprone-path",
+ "bin/errorprone",
+ ]
+
+ if (invoker.enable_errorprone) {
+ deps += [ "//tools/android/errorprone_plugin:errorprone_plugin_java($default_toolchain)" ]
+ _rebased_errorprone_processorpath = [
+ "lib.java/tools/android/errorprone_plugin/errorprone_plugin_java.jar",
+ ]
+ args += [
+ "--processorpath=$_rebased_errorprone_processorpath",
+ "--enable-errorprone",
+ ]
+ }
+ foreach(e, _provider_configurations) {
+ args += [ "--provider-configuration=" + rebase_path(e, root_build_dir) ]
+ }
+ foreach(e, _processor_args) {
+ args += [ "--processor-arg=" + e ]
+ }
+
+ foreach(file_tuple, _additional_jar_files) {
+ # Each element is of length two, [ path_to_file, path_to_put_in_jar ]
+ inputs += [ file_tuple[0] ]
+ args +=
+ [ "--additional-jar-file=" +
+ rebase_path(file_tuple[0], root_build_dir) + ":" + file_tuple[1] ]
+ }
+ if (invoker.java_files != []) {
+ args += [ "@" + rebase_path(invoker.java_sources_file, root_build_dir) ]
+ }
+ foreach(e, _javac_args) {
+ args += [ "--javac-arg=" + e ]
+ }
+ }
+ }
+
+ # Create an interface jar from a normal jar.
+ #
+ # Variables
+ # input_jar: Path to input .jar.
+ # output_jar: Path to output .ijar.
+ #
+ template("generate_interface_jar") {
+ action_with_pydeps(target_name) {
+ _ijar_target = "//third_party/ijar:ijar($host_toolchain)"
+ _ijar_executable = get_label_info(_ijar_target, "root_out_dir") + "/ijar"
+ forward_variables_from(invoker,
+ [
+ "data",
+ "data_deps",
+ "public_deps",
+ "testonly",
+ "visibility",
+ ])
+ script = "//build/android/gyp/ijar.py"
+ deps = [
+ _ijar_target,
+ ]
+ if (defined(invoker.deps)) {
+ deps += invoker.deps
+ }
+ inputs = [
+ invoker.input_jar,
+ _ijar_executable,
+ ]
+ if (defined(invoker.inputs)) {
+ inputs += invoker.inputs
+ }
+ outputs = [
+ invoker.output_jar,
+ ]
+ args = [
+ rebase_path(_ijar_executable, root_build_dir),
+ rebase_path(invoker.input_jar, root_build_dir),
+ rebase_path(invoker.output_jar, root_build_dir),
+ ]
+ }
+ }
+
+ # A rule that will handle multiple Java-related targets.
+ #
+ # The caller can provide a list of source files with 'java_files'
+ # and 'srcjar_deps', or a prebuilt .jar file through 'jar_path'.
+ #
+ # In the case of a 'java_binary' target type, it can even provide none of
+ # that (and the rule will just generate its wrapper script).
+ #
+ # The template will process the input .jar file (either the prebuilt one,
+ # or the result of compiling the sources), for example to apply Proguard,
+ # but also other ranges of bytecode-level rewriting schemes.
+ #
+ # Variables:
+ # type: type of Java target, valid values: 'java_library', 'java_binary',
+ # 'junit_binary', 'java_annotation_processor', and 'android_apk'
+ # main_target_name: optional. If provided, overrides target_name when
+ # creating sub-targets (e.g. "${main_target_name}__dex") and
+ # some output files (e.g. "${main_target_name}.sources"). Only used
+ # for 'android_apk' types at the moment, where main_target_name will
+ # be the name of the main APK target.
+ # supports_android: Optional. True if target can run on Android.
+ # requires_android: Optional. True if target can only run on Android.
+ # java_files: Optional list of Java source file paths for this target.
+ # javac_args: Optional list of extra arguments to pass to javac.
+ # errorprone_args: Optional list of extra arguments to pass to .
+ # srcjar_deps: Optional list of .srcjar targets (not file paths). The Java
+ # source files they contain will also be compiled for this target.
+ # java_sources_file: Optional path to a file which will be written with
+ # the content of java_files. If not provided, the file will be written
+ # under $target_gen_dir/$main_target_name.sources. Ignored if
+ # java_files is empty. If not
+ # jar_path: Optional path to a prebuilt .jar file for this target.
+ # Mutually exclusive with java_files and srcjar_deps.
+ # final_jar_path: Optional path to the final output .jar file (after
+ # processing). If not provided, the output will go under
+ # $root_build_dir/lib.java/
+ # output_name: Optional output name for the final jar path. Ignored if
+ # final_jar_path is provided. Otherwise, used to determine the name
+ # of the final jar. If not provided, the default is to use the same
+ # name as jar_path, if provided, or main_target_name.
+ # dex_path: Optional. Path to the output dex.jar file for this target.
+ # Ignored if !supports_android.
+ # main_class: Main Java class name for 'java_binary', 'junit_binary' and
+ # 'java_annotation_processor' target types. Should not be set for other
+ # ones.
+ # deps: Dependencies for this target.
+ # testonly: True iff target should only be used for tests.
+ # no_build_hooks: Disables bytecode rewriting of asserts and android
+ # resources methods.
+ # chromium_code: Optional. Whether this is Chromium-specific code. If not
+ # provided, this is determined automatically, based on the location of
+ # the source files (i.e. anything under third_party/ is not
+ # Chromium-specific unless it is in a 'chromium' sub-directory).
+ # emma_never_instrument: Optional. If provided, whether to forbid
+ # instrumentation with the Emma coverage processor. If not provided,
+ # this is controlled by the global emma_coverage build arg variable
+ # and only used for non-test Chromium code.
+ # include_android_sdk: Optional. Whether or not the android SDK dep
+ # should be added to deps. Defaults to true for non-system libraries
+ # that support android.
+ # alternative_android_sdk_dep: Optional. Alternative Android system
+ # android java target to use.
+ # annotation_processor_deps: Optional list of dependencies corresponding
+ # to annotation processors used to compile these sources.
+ # input_jars_paths: Optional list of additional .jar file paths, which will
+ # be added to the compile-time classpath when building this target (but
+ # not to the runtime classpath).
+ # classpath_deps: Optional list of additional java library dependencies,
+ # whose .jar files will be added to the compile-time classpath when
+ # building this target (but not to the runtime classpath).
+ # gradle_treat_as_prebuilt: Cause generate_gradle.py to reference this
+ # library via its built .jar rather than including its .java sources.
+ # proguard_enabled: Optional. True to enable ProGuard obfuscation.
+ # proguard_configs: Optional list of additional proguard config file paths.
+ # bypass_platform_checks: Optional. If True, platform checks will not
+ # be performed. They are used to verify that every target with
+ # requires_android only depends on targets that, at least supports_android.
+ # Similarly, if a target has !supports_android, then it cannot depend on
+ # any other target that has requires_android.
+ # include_java_resources: Optional. If True, include Java (not Android)
+ # resources into final .jar file.
+ # android_manifest_for_lint: Optional path to Android manifest to use
+ # if Android linting is enabled. Ignored for 'android_apk' types
+ # (since the value of android_manifest will be used instead).
+ # lint_suppressions_file: Optional lint suppressions input file.
+ # 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.
+ #
+ # For 'android_apk' and 'android_app_bundle_module' targets only:
+ #
+ # apk_path: Path to the final APK file.
+ # android_manifest: Path to AndroidManifest.xml file for the APK.
+ # android_manifest_dep: Optional. Dependency target that generates
+ # android_manifest.
+ # apk_under_test: For 'android_apk' targets used to test other APKs,
+ # this is the target name of APK being tested.
+ # incremental_allowed: Optional (default false). True to allow the
+ # generation of incremental APKs ('android_apk' targets only).
+ # incremental_apk_path: If incremental_allowed, path to the incremental
+ # output APK.
+ # incremental_install_json_path: If incremental_allowed, path to the output
+ # incremental install json configuration file.
+ # native_lib_placeholders: Optional. List of placeholder filenames to add to
+ # the APK.
+ # proguard_mapping_path: Path to .mapping file produced from ProGuard step.
+ # shared_libraries_runtime_deps_file: Optional. Path to a file listing the
+ # native shared libraries required at runtime by the APK.
+ # secondary_abi_shared_libraries_runtime_deps_file:
+ # secondary_native_lib_placeholders: Optional. List of placeholder filenames
+ # to add to the APK for the secondary ABI.
+ # extra_shared_libraries: Optional list of extra native libraries to
+ # be stored in the APK.
+ # uncompress_shared_libraries: Optional. True to store native shared
+ # libraries uncompressed and page-aligned.
+ # proto_resources_path: The path of an zip archive containing the APK's
+ # resources compiled to the protocol buffer format (instead of regular
+ # binary xml + resources.arsc).
+ # module_rtxt_path: The path of the R.txt file generated when compiling the
+ # resources for the bundle module.
+ # base_whitelist_rtxt_path: The path of the R.txt file containing the
+ # list of string resources to keep in the base split APK for any bundle
+ # that uses this target.
+ #
+ # For 'java_binary' and 'junit_binary' targets only. Ignored by others:
+ #
+ # bootclasspath: Optional list of boot class paths used by the generated
+ # wrapper script.
+ # wrapper_script_name: Optional name for the generated wrapper script.
+ # Default is main target name.
+ # wrapper_script_args: Optional list of extra arguments used by the
+ # generated wrapper script.
+ #
+ template("java_library_impl") {
+ set_sources_assignment_filter([])
+ forward_variables_from(invoker, [ "testonly" ])
+ _is_prebuilt = defined(invoker.jar_path)
+ _is_annotation_processor = invoker.type == "java_annotation_processor"
+ _is_java_binary =
+ invoker.type == "java_binary" || invoker.type == "junit_binary"
+ _is_system_library = invoker.type == "system_java_library"
+ _supports_android =
+ defined(invoker.supports_android) && invoker.supports_android
+ _requires_android =
+ defined(invoker.requires_android) && invoker.requires_android
+
+ _main_target_name = target_name
+ if (defined(invoker.main_target_name)) {
+ _main_target_name = invoker.main_target_name
+ }
+ _java_files = []
+ if (defined(invoker.java_files)) {
+ _java_files = invoker.java_files
+ }
+ _srcjar_deps = []
+ if (defined(invoker.srcjar_deps)) {
+ _srcjar_deps = invoker.srcjar_deps
+ }
+ _has_sources = _java_files != [] || _srcjar_deps != []
+
+ if (_is_prebuilt) {
+ assert(!_has_sources)
+ } else {
+ # Allow java_binary to not specify any sources. This is needed when a prebuilt
+ # is needed as a library as well as a binary.
+ assert(_is_annotation_processor || _is_java_binary || _has_sources)
+ }
+
+ if (_is_java_binary) {
+ assert(defined(invoker.main_class),
+ "${invoker.type}() must set main_class")
+ } else if (_is_annotation_processor) {
+ assert(defined(invoker.main_class),
+ "java_annotation_processor() must set main_class")
+ } else {
+ assert(!defined(invoker.main_class),
+ "main_class cannot be used for target of type ${invoker.type}")
+ }
+
+ # The only target that might have no prebuilt and no sources is a java_binary.
+ if (_is_prebuilt || _has_sources) {
+ if (defined(invoker.output_name)) {
+ _output_name = invoker.output_name
+ } else if (_is_prebuilt) {
+ _output_name = get_path_info(invoker.jar_path, "name")
+ } else {
+ _output_name = _main_target_name
+ }
+
+ # Jar files can be needed at runtime (by Robolectric tests or java binaries),
+ # so do not put them under gen/.
+ _target_dir_name = get_label_info(":$_main_target_name", "dir")
+ _final_jar_path =
+ "$root_out_dir/lib.java$_target_dir_name/$_output_name.jar"
+ if (defined(invoker.final_jar_path)) {
+ _final_jar_path = invoker.final_jar_path
+ }
+ _final_ijar_path =
+ get_path_info(_final_jar_path, "dir") + "/" +
+ get_path_info(_final_jar_path, "name") + ".interface.jar"
+
+ if (_has_sources) {
+ _javac_jar_path = "$target_gen_dir/$_main_target_name.javac.jar"
+ }
+
+ if (_is_prebuilt) {
+ _unprocessed_jar_path = invoker.jar_path
+ } else {
+ _unprocessed_jar_path = _javac_jar_path
+ }
+
+ if (_supports_android) {
+ _dex_path = "$target_gen_dir/$_main_target_name.dex.jar"
+ if (defined(invoker.dex_path)) {
+ _dex_path = invoker.dex_path
+ }
+ }
+ }
+
+ _accumulated_public_deps = []
+ _accumulated_deps = []
+ if (defined(invoker.deps)) {
+ _accumulated_deps = invoker.deps
+ }
+
+ _enable_build_hooks =
+ _supports_android &&
+ (!defined(invoker.no_build_hooks) || !invoker.no_build_hooks)
+ if (_enable_build_hooks) {
+ _accumulated_deps += [ "//build/android/buildhooks:build_hooks_java" ]
+ }
+
+ # Some testonly targets use their own resources and the code being
+ # tested will use custom resources so there's no need to enable this
+ # for testonly targets.
+ _enable_build_hooks_android =
+ _enable_build_hooks && _requires_android &&
+ (!defined(invoker.testonly) || !invoker.testonly)
+ if (_enable_build_hooks_android) {
+ _accumulated_deps +=
+ [ "//build/android/buildhooks:build_hooks_android_java" ]
+ }
+
+ # Don't enable coverage or lint unless the target has some non-generated
+ # files.
+ if (defined(invoker.chromium_code)) {
+ _chromium_code = invoker.chromium_code
+ } else {
+ # Default based on whether target is in third_party.
+ set_sources_assignment_filter([ "*\bthird_party\b*" ])
+ sources = [
+ get_label_info(":$_main_target_name", "dir"),
+ ]
+ _chromium_code = sources != []
+ if (!_chromium_code && !_is_prebuilt && _java_files != []) {
+ # Unless third_party code has an org.chromium file in it.
+ set_sources_assignment_filter([ "*\bchromium\b*" ])
+ sources = _java_files
+ _chromium_code = _java_files != sources
+ }
+ set_sources_assignment_filter([])
+ sources = []
+ }
+
+ if (defined(_final_jar_path)) {
+ _emma_instrument = emma_coverage && _chromium_code && _java_files != [] &&
+ (!defined(invoker.testonly) || !invoker.testonly)
+ if (defined(invoker.emma_never_instrument)) {
+ _emma_instrument = !invoker.emma_never_instrument && _emma_instrument
+ }
+ if (_emma_instrument) {
+ _accumulated_deps += [ "//third_party/android_sdk:emma_device_java" ]
+ }
+ }
+
+ if (_java_files != []) {
+ _java_sources_file = "$target_gen_dir/$_main_target_name.sources"
+ if (defined(invoker.java_sources_file)) {
+ _java_sources_file = invoker.java_sources_file
+ }
+ write_file(_java_sources_file, rebase_path(_java_files, root_build_dir))
+ }
+
+ _include_android_sdk = !_is_system_library && _supports_android
+ if (defined(invoker.include_android_sdk)) {
+ _include_android_sdk = invoker.include_android_sdk
+ }
+ if (_include_android_sdk) {
+ if (defined(invoker.alternative_android_sdk_dep)) {
+ _accumulated_deps += [ invoker.alternative_android_sdk_dep ]
+ } else {
+ _accumulated_deps += [ "//third_party/android_sdk:android_sdk_java" ]
+ }
+ }
+
+ # Define build_config_deps which will be a list of targets required to
+ # build the _build_config.
+ _build_config = "$target_gen_dir/$_main_target_name.build_config"
+ _build_config_target_name =
+ "${_main_target_name}$build_config_target_suffix"
+
+ write_build_config(_build_config_target_name) {
+ forward_variables_from(invoker,
+ [
+ "annotation_processor_deps",
+ "base_whitelist_rtxt_path",
+ "classpath_deps",
+ "gradle_treat_as_prebuilt",
+ "input_jars_paths",
+ "loadable_modules",
+ "main_class",
+ "proguard_configs",
+ "proguard_enabled",
+ "proguard_mapping_path",
+ "secondary_abi_loadable_modules",
+ "type",
+ ])
+ if (type == "android_apk" || type == "android_app_bundle_module") {
+ forward_variables_from(
+ invoker,
+ [
+ "android_manifest",
+ "android_manifest_dep",
+ "extra_shared_libraries",
+ "final_dex_path",
+ "native_lib_placeholders",
+ "secondary_abi_shared_libraries_runtime_deps_file",
+ "secondary_native_lib_placeholders",
+ "shared_libraries_runtime_deps_file",
+ "static_library_dependent_targets",
+ "uncompress_shared_libraries",
+ ])
+ }
+ if (type == "android_apk") {
+ forward_variables_from(invoker,
+ [
+ "apk_path",
+ "apk_under_test",
+ "incremental_allowed",
+ "incremental_apk_path",
+ "incremental_install_json_path",
+ ])
+ }
+ if (type == "android_app_bundle_module") {
+ forward_variables_from(invoker,
+ [
+ "base_module_target",
+ "module_rtxt_path",
+ "proto_resources_path",
+ ])
+ }
+ build_config = _build_config
+ is_prebuilt = _is_prebuilt
+ possible_config_deps = _accumulated_deps
+ if (defined(apk_under_test)) {
+ possible_config_deps += [ apk_under_test ]
+ }
+ supports_android = _supports_android
+ requires_android = _requires_android
+ bypass_platform_checks = defined(invoker.bypass_platform_checks) &&
+ invoker.bypass_platform_checks
+
+ if (defined(_final_jar_path)) {
+ jar_path = _final_jar_path
+ ijar_path = _final_ijar_path
+ unprocessed_jar_path = _unprocessed_jar_path
+ }
+ if (defined(_dex_path)) {
+ dex_path = _dex_path
+ }
+ if (_java_files != []) {
+ java_sources_file = _java_sources_file
+ }
+
+ bundled_srcjars = []
+ foreach(d, _srcjar_deps) {
+ _dep_gen_dir = get_label_info(d, "target_gen_dir")
+ _dep_name = get_label_info(d, "name")
+ bundled_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ]
+ }
+ if (defined(invoker.include_java_resources) &&
+ invoker.include_java_resources) {
+ if (defined(invoker.jar_path)) {
+ # Use original jar_path because _jar_path points to a library without
+ # resources.
+ java_resources_jar = invoker.jar_path
+ } else {
+ java_resources_jar = _final_jar_path
+ }
+ }
+ }
+ _accumulated_public_deps += [ ":$_build_config_target_name" ]
+
+ # Don't need to depend on the apk-under-test to be packaged.
+ if (defined(invoker.apk_under_test)) {
+ _accumulated_deps += [ "${invoker.apk_under_test}__java" ]
+ }
+ if (defined(invoker.android_manifest_dep)) {
+ _accumulated_deps += [ invoker.android_manifest_dep ]
+ }
+ if (defined(invoker.classpath_deps)) {
+ _accumulated_deps += invoker.classpath_deps
+ }
+ if (defined(invoker.annotation_processor_deps)) {
+ _accumulated_deps += invoker.annotation_processor_deps
+ }
+
+ # TODO(agrieve): Enable lint for _has_sources rather than just _java_files.
+ _lint_enabled = _java_files != [] && _supports_android && _chromium_code &&
+ !disable_android_lint
+ if (defined(invoker.enable_errorprone)) {
+ _enable_errorprone = invoker.enable_errorprone
+ } else {
+ _enable_errorprone =
+ _java_files != [] && _chromium_code && use_errorprone_java_compiler
+ }
+
+ if (_has_sources) {
+ _type = invoker.type
+ template("compile_java_helper") {
+ compile_java(target_name) {
+ forward_variables_from(invoker, "*")
+ enable_errorprone = invoker.enable_errorprone
+ javac_jar_path = invoker.javac_jar_path
+
+ main_target_name = _main_target_name
+ build_config = _build_config
+ java_files = _java_files
+ if (_java_files != []) {
+ java_sources_file = _java_sources_file
+ }
+ srcjar_deps = _srcjar_deps
+ chromium_code = _chromium_code
+ requires_android = _requires_android
+ deps = _accumulated_deps + _accumulated_public_deps
+
+ # android_apk and junit_binary pass R.java srcjars via srcjar_deps.
+ if (_type == "java_library" && _requires_android) {
+ _rebased_build_config = rebase_path(_build_config, root_build_dir)
+ srcjar_filearg = "@FileArg($_rebased_build_config:deps_info:owned_resource_srcjars)"
+ }
+ }
+ }
+ _analysis_public_deps = []
+ _compile_java_target = "${_main_target_name}__compile_java"
+ _compile_java_forward_variables = [
+ "additional_jar_files",
+ "apk_name",
+ "processor_args_javac",
+ "provider_configurations",
+ "javac_args",
+ ]
+ compile_java_helper(_compile_java_target) {
+ forward_variables_from(invoker, _compile_java_forward_variables)
+ enable_errorprone = false
+ javac_jar_path = _javac_jar_path
+ }
+ if (_enable_errorprone) {
+ _compile_java_errorprone_target =
+ "${_main_target_name}__compile_java_errorprone"
+ compile_java_helper(_compile_java_errorprone_target) {
+ forward_variables_from(invoker, _compile_java_forward_variables)
+ enable_errorprone = true
+ if (defined(invoker.errorprone_args)) {
+ if (!defined(javac_args)) {
+ javac_args = []
+ }
+ javac_args += invoker.errorprone_args
+ }
+ javac_jar_path = _javac_jar_path + ".errorprone.jar"
+ }
+ _analysis_public_deps += [ ":$_compile_java_errorprone_target" ]
+ }
+ if (defined(invoker.android_manifest_for_lint)) {
+ _android_manifest_for_lint = invoker.android_manifest_for_lint
+ assert(_android_manifest_for_lint != "") # Mark as used.
+ }
+ if (_lint_enabled) {
+ _android_lint_target = "${_main_target_name}__lint"
+ android_lint(_android_lint_target) {
+ if (invoker.type == "android_apk" ||
+ invoker.type == "android_app_bundle_module") {
+ forward_variables_from(invoker, [ "android_manifest" ])
+ } else if (defined(_android_manifest_for_lint)) {
+ android_manifest = _android_manifest_for_lint
+ }
+ srcjar_deps = _srcjar_deps
+ build_config = _build_config
+ requires_android = _requires_android
+ deps = _accumulated_deps + _accumulated_public_deps
+ java_files = _java_files
+ if (_java_files != []) {
+ java_sources_file = _java_sources_file
+ }
+ if (defined(invoker.lint_suppressions_file)) {
+ lint_suppressions_file = invoker.lint_suppressions_file
+ }
+ }
+ _analysis_public_deps += [ ":$_android_lint_target" ]
+ }
+
+ if (_analysis_public_deps != []) {
+ # Use an intermediate group() rather as the data_deps target in order to
+ # avoid errorprone or lint artifacts showing up as runtime_deps (while
+ # still having them run in parallel to other targets).
+ group("${_main_target_name}__analysis") {
+ public_deps = _analysis_public_deps
+ }
+ }
+
+ # Update this after lint so that lint does not depend on javac.
+ _accumulated_public_deps += [ ":$_compile_java_target" ]
+ } # _has_sources
+
+ if (defined(_final_jar_path)) {
+ if (_is_system_library) {
+ _copy_system_library_target_name = "${target_name}__copy_system_library"
+
+ # Use copy_ex rather than copy to ensure that we copy symlink targets
+ # rather than the symlink itself.
+ copy_ex(_copy_system_library_target_name) {
+ sources = [
+ _unprocessed_jar_path,
+ ]
+ dest = _final_jar_path
+ outputs = [
+ _final_jar_path,
+ ]
+ }
+ _accumulated_public_deps += [ ":$_copy_system_library_target_name" ]
+ } else {
+ _process_prebuilt_target_name = "${target_name}__process_prebuilt"
+ process_java_prebuilt(_process_prebuilt_target_name) {
+ forward_variables_from(invoker,
+ [
+ "enable_bytecode_checks",
+ "enable_bytecode_rewriter",
+ "jar_excluded_patterns",
+ "jar_included_patterns",
+ "split_compat_class_names",
+ ])
+ is_prebuilt = _is_prebuilt
+ supports_android = _supports_android
+ enable_build_hooks = _enable_build_hooks
+ enable_build_hooks_android = _enable_build_hooks_android
+ build_config = _build_config
+ input_jar_path = _unprocessed_jar_path
+ emma_instrument = _emma_instrument
+ if (_emma_instrument) {
+ java_files = _java_files
+ java_sources_file = _java_sources_file
+ }
+ output_jar_path = _final_jar_path
+ if (_has_sources) {
+ deps = _accumulated_public_deps # compile & build_config
+ } else {
+ deps = _accumulated_deps + _accumulated_public_deps
+ }
+ }
+ _accumulated_public_deps += [ ":$_process_prebuilt_target_name" ]
+
+ if (defined(_dex_path)) {
+ dex("${target_name}__dex") {
+ input_jars = [ _final_jar_path ]
+ output = _dex_path
+ deps = [
+ ":$_process_prebuilt_target_name",
+ ]
+ }
+ _accumulated_public_deps += [ ":${target_name}__dex" ]
+ }
+ }
+
+ if (!_is_java_binary) {
+ # Export the interface jar as the main target (rather than a group)
+ # so that ninja will notice when the output is unchanged and not rebuild
+ # reverse-dependencies. Targets that should be rebuilt when the
+ # non-interface .jar changes use a depfile to indicate that they should
+ # be rebuilt even when the interface jar does not change.
+ generate_interface_jar(target_name) {
+ forward_variables_from(invoker,
+ [
+ "data",
+ "data_deps",
+ "deps",
+ "visibility",
+ ])
+
+ # Export all of our steps as "public", so that all outputs can be used
+ # as inputs to other targets.
+ public_deps = _accumulated_public_deps
+
+ # Always used the unfiltered .jar to create the interface jar so that
+ # other targets will resolve filtered classes when depending on
+ # BuildConfig, NativeLibraries, etc.
+ input_jar = _unprocessed_jar_path
+ output_jar = _final_ijar_path
+ if (_lint_enabled || _enable_errorprone) {
+ if (!defined(data_deps)) {
+ data_deps = []
+ }
+ data_deps += [ ":${_main_target_name}__analysis" ]
+ }
+
+ # proguard_configs listed on java_library targets need to be marked
+ # as inputs to at least one action so that "gn analyze" will know
+ # about them. Although ijar doesn't use them, it's a convenient spot
+ # to list them.
+ # https://crbug.com/827197
+ if (defined(invoker.proguard_configs)) {
+ inputs = invoker.proguard_configs
+ if (!defined(deps)) {
+ deps = []
+ }
+ deps += _srcjar_deps # For the aapt-generated proguard rules.
+ }
+ }
+ }
+ }
+
+ if (_is_java_binary) {
+ # Targets might use the generated script while building, so make it a dep
+ # rather than a data_dep.
+ java_binary_script("${target_name}__java_binary_script") {
+ forward_variables_from(invoker,
+ [
+ "bootclasspath",
+ "main_class",
+ "wrapper_script_args",
+ ])
+ build_config = _build_config
+ if (defined(_final_jar_path)) {
+ jar_path = _final_jar_path
+ }
+ script_name = _main_target_name
+ if (defined(invoker.wrapper_script_name)) {
+ script_name = invoker.wrapper_script_name
+ }
+ deps = _accumulated_public_deps
+ }
+ _accumulated_public_deps += [ ":${target_name}__java_binary_script" ]
+ }
+
+ if (_is_java_binary ||
+ (_is_annotation_processor && !defined(_final_jar_path))) {
+ group(target_name) {
+ forward_variables_from(invoker,
+ [
+ "data",
+ "deps",
+ "data_deps",
+ "visibility",
+ ])
+ public_deps = _accumulated_public_deps
+ if (_lint_enabled || _enable_errorprone) {
+ if (!defined(data_deps)) {
+ data_deps = []
+ }
+ data_deps += [ ":${_main_target_name}__analysis" ]
+ }
+ }
+ }
+ }
+}
+
+# Create a zip archive corresponding to an application bundle module.
+#
+# Compile all the components of a given android_apk_or_module() target into a zip archive
+# suitable to later create an android_app_bundle() target. This archive's format is very
+# similar to that on an APK, except for a few differences in internal directory
+# layouts, and the fact that resources, as well ass xml files, are compiled using a
+# protocol-buffer based format (instead of the regular binary xml + resources.arsc).
+#
+# A final application bundle is built from one or more module bundle modules,
+# plus some configuration file.
+#
+# Variables:
+# module_zip_path: Output module path.
+#
+# build_config: Path to build_config of the android_apk_or_module() target.
+#
+# dex_path: If module is proguarded separately from the base module, dex_path is the
+# path to its dex file and is passed directly to the creation script.
+# Otherwise, dex_path is undefined and we retrieve the module's dex file
+# using its build_config.
+#
+template("create_android_app_bundle_module") {
+ _build_config = invoker.build_config
+ _rebased_build_config = rebase_path(_build_config, root_build_dir)
+
+ action_with_pydeps(target_name) {
+ forward_variables_from(invoker,
+ [
+ "testonly",
+ "visibility",
+ "deps",
+ ])
+ script = "//build/android/gyp/apkbuilder.py"
+ depfile = "$target_gen_dir/$target_name.d"
+
+ # NOTE: Compared to the inputs of the "package_apk" template action,
+ # this list is much smaller, since finalize_apk is never called
+ # by apkbuild.py --format=bundle-module. This means not using
+ # apksigner and zipalign as well, nor the keystore. Other
+ # dependencies like extra native libraries are all pulled from the
+ # .build_config through @FileArg() references (see below) and
+ # will be listed in the generated depfile instead.
+ inputs = [
+ _build_config,
+ ]
+ outputs = [
+ invoker.module_zip_path,
+ ]
+ args = [
+ "--depfile",
+ rebase_path(depfile, root_build_dir),
+ "--format=bundle-module",
+ "--output-apk",
+ rebase_path(invoker.module_zip_path, root_build_dir),
+ "--resource-apk=@FileArg(" +
+ "$_rebased_build_config:deps_info:proto_resources_path)",
+ "--assets=@FileArg($_rebased_build_config:assets)",
+ "--uncompressed-assets=@FileArg(" +
+ "$_rebased_build_config:uncompressed_assets)",
+ "--native-libs=@FileArg($_rebased_build_config:native:libraries)",
+ "--native-libs=@FileArg($_rebased_build_config:native:extra_shared_libraries)",
+ "--native-lib-placeholders=@FileArg($_rebased_build_config:native:native_library_placeholders)",
+ "--secondary-native-lib-placeholders=@FileArg($_rebased_build_config:native:secondary_native_library_placeholders)",
+ "--android-abi=$android_app_abi",
+ "--uncompress-shared-libraries=@FileArg(" +
+ "$_rebased_build_config:native:uncompress_shared_libraries)",
+ ]
+ if (defined(android_app_secondary_abi)) {
+ args += [
+ "--secondary-native-libs=@FileArg(" +
+ "$_rebased_build_config:native:secondary_abi_libraries)",
+ "--secondary-android-abi=$android_app_secondary_abi",
+ ]
+ }
+
+ # Use either provided dex path or build config path based on type of module.
+ if (defined(invoker.dex_path)) {
+ inputs += [ invoker.dex_path ]
+ _rebased_dex_path = rebase_path(invoker.dex_path, root_build_dir)
+ args += [ "--dex-file=$_rebased_dex_path" ]
+ } else {
+ args += [ "--dex-file=@FileArg($_rebased_build_config:final_dex:path)" ]
+ }
+ }
+}
+
+# Splits input dex file(s) based on given feature jars into seperate dex files
+# for each feature.
+#
+# Variables:
+# proguard_mapping: Path to input proguard mapping produced by synchronized
+# proguarding.
+# input_dex_zip: Path to zipped dex files to split.
+# all_modules: Path to list of all modules. Each Module must have
+# build_config, name, and build_config_target properties.
+template("dexsplitter") {
+ action_with_pydeps(target_name) {
+ forward_variables_from(invoker, [ "deps" ])
+ script = "//build/android/gyp/dexsplitter.py"
+ inputs = [
+ invoker.input_dex_zip,
+ ]
+ _stamp = "${target_gen_dir}/${target_name}.stamp"
+ outputs = [
+ _stamp,
+ ]
+
+ depfile = "${target_gen_dir}/${target_name}.d"
+ args = [
+ "--stamp",
+ rebase_path(_stamp, root_build_dir),
+ "--depfile",
+ rebase_path(depfile, root_build_dir),
+ "--r8-path",
+ rebase_path(_r8_path, root_build_dir),
+ "--input-dex-zip",
+ rebase_path(invoker.input_dex_zip, root_build_dir),
+ "--proguard-mapping-file",
+ rebase_path(invoker.proguard_mapping, root_build_dir),
+ ]
+
+ foreach(_feature_module, invoker.all_modules) {
+ _rebased_module_build_config =
+ rebase_path(_feature_module.build_config, root_build_dir)
+ args += [
+ "--feature-name",
+ _feature_module.name,
+ "--feature-jars=@FileArg($_rebased_module_build_config:deps_info:java_runtime_classpath)",
+ "--dex-dest=@FileArg($_rebased_module_build_config:final_dex:path)",
+ ]
+ deps += [ _feature_module.build_config_target ]
+ }
+ }
+}
diff --git a/deps/v8/build/config/android/linker_version_script.gni b/deps/v8/build/config/android/linker_version_script.gni
new file mode 100644
index 0000000000..6cb3b09013
--- /dev/null
+++ b/deps/v8/build/config/android/linker_version_script.gni
@@ -0,0 +1,37 @@
+# Copyright 2018 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.
+
+import("//build/config/python.gni")
+
+# Generate a custom linker version script that can later be used with
+# "-Wl,--version-script=<path>" ldflags.
+#
+# Variables:
+# export_java_symbols: Optional. If true, also export all Java_* symbols
+# exported for JNI.
+# export_symbol_whitelist_file: Optional. Path to an input file containing
+# a whitelist of exported symbols.
+# linker_script: Path to output linker version script.
+#
+template("generate_linker_version_script") {
+ action_with_pydeps(target_name) {
+ script = "//build/android/gyp/generate_linker_version_script.py"
+ outputs = [
+ invoker.linker_script,
+ ]
+ inputs = []
+ args = [ "--output=" + rebase_path(invoker.linker_script, root_build_dir) ]
+
+ if (defined(invoker.export_java_symbols) && invoker.export_java_symbols) {
+ args += [ "--export-java-symbols" ]
+ }
+
+ if (defined(invoker.export_symbol_whitelist_file)) {
+ inputs += [ invoker.export_symbol_whitelist_file ]
+ args +=
+ [ "--export-symbol-whitelist-file=" +
+ rebase_path(invoker.export_symbol_whitelist_file, root_build_dir) ]
+ }
+ }
+}
diff --git a/deps/v8/build/config/android/rules.gni b/deps/v8/build/config/android/rules.gni
new file mode 100644
index 0000000000..4846ade15c
--- /dev/null
+++ b/deps/v8/build/config/android/rules.gni
@@ -0,0 +1,4584 @@
+# 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/internal_rules.gni")
+import("//build/config/clang/clang.gni")
+import("//build/config/compiler/compiler.gni")
+import("//build/config/dcheck_always_on.gni")
+import("//build/config/python.gni")
+import("//build/config/zip.gni")
+import("//build/toolchain/toolchain.gni")
+assert(is_android)
+
+declare_args() {
+ enable_jni_tracing = false
+}
+
+if (target_cpu == "arm") {
+ _sanitizer_arch = "arm"
+} else if (target_cpu == "arm64") {
+ _sanitizer_arch = "aarch64"
+} else if (target_cpu == "x86") {
+ _sanitizer_arch = "i686"
+}
+
+_sanitizer_runtimes = []
+if (use_cfi_diag || is_ubsan || is_ubsan_security || is_ubsan_vptr) {
+ _sanitizer_runtimes = [ "$clang_base_path/lib/clang/$clang_version/lib/linux/libclang_rt.ubsan_standalone-$_sanitizer_arch-android.so" ]
+}
+
+if (is_hwasan) {
+ _sanitizer_runtimes = [ "$clang_base_path/lib/clang/$clang_version/lib/linux/libclang_rt.hwasan-$_sanitizer_arch-android.so" ]
+}
+
+# Creates a dist directory for a native executable.
+#
+# Running a native executable on a device requires all the shared library
+# dependencies of that executable. To make it easier to install and run such an
+# executable, this will create a directory containing the native exe and all
+# it's library dependencies.
+#
+# Note: It's usually better to package things as an APK than as a native
+# executable.
+#
+# Variables
+# dist_dir: Directory for the exe and libraries. Everything in this directory
+# will be deleted before copying in the exe and libraries.
+# binary: Path to (stripped) executable.
+# extra_files: List of extra files to copy in (optional).
+#
+# Example
+# create_native_executable_dist("foo_dist") {
+# dist_dir = "$root_build_dir/foo_dist"
+# binary = "$root_build_dir/foo"
+# deps = [ ":the_thing_that_makes_foo" ]
+# }
+template("create_native_executable_dist") {
+ forward_variables_from(invoker, [ "testonly" ])
+
+ _libraries_list = "${target_gen_dir}/${target_name}_library_dependencies.list"
+
+ _runtime_deps_file = "$target_gen_dir/${target_name}.runtimedeps"
+ _runtime_deps_target_name = "${target_name}__runtime_deps"
+ group(_runtime_deps_target_name) {
+ data = _sanitizer_runtimes
+ data_deps = []
+ if (defined(invoker.deps)) {
+ data_deps += invoker.deps
+ }
+ write_runtime_deps = _runtime_deps_file
+ }
+
+ _find_deps_target_name = "${target_name}__find_library_dependencies"
+
+ # TODO(agrieve): Extract dependent libs from GN rather than readelf.
+ action_with_pydeps(_find_deps_target_name) {
+ deps = invoker.deps + [ ":$_runtime_deps_target_name" ]
+ script = "//build/android/gyp/write_ordered_libraries.py"
+ depfile = "$target_gen_dir/$target_name.d"
+ inputs = [
+ invoker.binary,
+ _runtime_deps_file,
+ android_readelf,
+ ]
+ outputs = [
+ _libraries_list,
+ ]
+ args = [
+ "--depfile",
+ rebase_path(depfile, root_build_dir),
+ "--runtime-deps",
+ rebase_path(_runtime_deps_file, root_build_dir),
+ "--output",
+ rebase_path(_libraries_list, root_build_dir),
+ "--readelf",
+ rebase_path(android_readelf, root_build_dir),
+ ]
+ }
+
+ copy_ex(target_name) {
+ inputs = [
+ _libraries_list,
+ invoker.binary,
+ ]
+
+ dest = invoker.dist_dir
+ data = [
+ "${invoker.dist_dir}/",
+ ]
+
+ _rebased_libraries_list = rebase_path(_libraries_list, root_build_dir)
+ _rebased_binaries_list = rebase_path([ invoker.binary ], root_build_dir)
+ args = [
+ "--clear",
+ "--files=@FileArg($_rebased_libraries_list:lib_paths)",
+ "--files=$_rebased_binaries_list",
+ ]
+ if (defined(invoker.extra_files)) {
+ _rebased_extra_files = rebase_path(invoker.extra_files, root_build_dir)
+ args += [ "--files=$_rebased_extra_files" ]
+ }
+
+ _depfile = "$target_gen_dir/$target_name.d"
+ _stamp_file = "$target_gen_dir/$target_name.stamp"
+ outputs = [
+ _stamp_file,
+ ]
+ args += [
+ "--depfile",
+ rebase_path(_depfile, root_build_dir),
+ "--stamp",
+ rebase_path(_stamp_file, root_build_dir),
+ ]
+
+ deps = [
+ ":$_find_deps_target_name",
+ ]
+ if (defined(invoker.deps)) {
+ deps += invoker.deps
+ }
+ }
+}
+
+# Writes a script to root_out_dir/bin that passes --output-directory to the
+# wrapped script, in addition to forwarding arguments. Most / all of these
+# wrappers should be made deps of //tools/android:android_tools.
+#
+# Variables
+# target: Script to wrap.
+# flag_name: Default is "--output-directory"
+#
+# Example
+# wrapper_script("foo_wrapper") {
+# target = "//pkg/foo.py"
+# }
+template("wrapper_script") {
+ action_with_pydeps(target_name) {
+ _name = get_path_info(invoker.target, "name")
+ _output = "$root_out_dir/bin/$_name"
+
+ script = "//build/android/gyp/create_tool_wrapper.py"
+ outputs = [
+ _output,
+ ]
+
+ # The target isn't actually used by the script, but it's nice to have GN
+ # check that it exists.
+ inputs = [
+ invoker.target,
+ ]
+ args = [
+ "--output",
+ rebase_path(_output, root_build_dir),
+ "--target",
+ rebase_path(invoker.target, root_build_dir),
+ "--output-directory",
+ rebase_path(root_out_dir, root_build_dir),
+ ]
+ if (defined(invoker.flag_name)) {
+ args += [ "--flag-name=${invoker.flag_name}" ]
+ }
+ }
+}
+
+if (enable_java_templates) {
+ import("//build/config/sanitizers/sanitizers.gni")
+ import("//tools/grit/grit_rule.gni")
+
+ # Declare a jni target
+ #
+ # This target generates the native jni bindings for a set of .java files.
+ #
+ # See base/android/jni_generator/jni_generator.py for more info about the
+ # format of generating JNI bindings.
+ #
+ # Variables
+ # sources: list of .java files to generate jni for
+ # jni_package: subdirectory path for generated bindings
+ #
+ # Example
+ # generate_jni("foo_jni") {
+ # sources = [
+ # "android/java/src/org/chromium/foo/Foo.java",
+ # "android/java/src/org/chromium/foo/FooUtil.java",
+ # ]
+ # jni_package = "foo"
+ # }
+ template("generate_jni") {
+ set_sources_assignment_filter([])
+ forward_variables_from(invoker, [ "testonly" ])
+
+ _base_output_dir = "${target_gen_dir}/${target_name}"
+ _package_output_dir = "${_base_output_dir}/${invoker.jni_package}"
+ _jni_output_dir = "${_package_output_dir}/jni"
+
+ if (defined(invoker.jni_generator_include)) {
+ _jni_generator_include = invoker.jni_generator_include
+ _jni_generator_include_deps = []
+ } else {
+ _jni_generator_include =
+ "//base/android/jni_generator/jni_generator_helper.h"
+ _jni_generator_include_deps = [
+ # Using //base/android/jni_generator/jni_generator_helper.h introduces
+ # a dependency on debugging_buildflags indirectly through
+ # base/android/jni_android.h, which is part of the //base target.
+ # This can't depend directly on //base without causing a dependency
+ # cycle, though.
+ "//base:debugging_buildflags",
+ ]
+ }
+
+ _foreach_target_name = "${target_name}__jni_gen"
+ action_foreach_with_pydeps(_foreach_target_name) {
+ script = "//base/android/jni_generator/jni_generator.py"
+ sources = invoker.sources
+ outputs = [
+ "${_jni_output_dir}/{{source_name_part}}_jni.h",
+ ]
+
+ args = [
+ "--input_file={{source}}",
+ "--ptr_type=long",
+ "--output_dir",
+ rebase_path(_jni_output_dir, root_build_dir),
+ "--includes",
+ rebase_path(_jni_generator_include, _jni_output_dir),
+ ]
+
+ if (use_hashed_jni_names) {
+ args += [ "--use_proxy_hash" ]
+ }
+
+ if (enable_profiling) {
+ args += [ "--enable_profiling" ]
+ }
+ if (defined(invoker.namespace)) {
+ args += [ "-n ${invoker.namespace}" ]
+ }
+ if (enable_jni_tracing) {
+ args += [ "--enable_tracing" ]
+ }
+ }
+
+ config("jni_includes_${target_name}") {
+ # TODO(cjhopman): #includes should probably all be relative to
+ # _base_output_dir. Remove that from this config once the includes are
+ # updated.
+ include_dirs = [
+ _base_output_dir,
+ _package_output_dir,
+ ]
+ }
+
+ group(target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "public_deps",
+ "visibility",
+ ])
+ if (!defined(public_deps)) {
+ public_deps = []
+ }
+ public_deps += [ ":$_foreach_target_name" ]
+ public_deps += _jni_generator_include_deps
+ public_configs = [ ":jni_includes_${target_name}" ]
+ }
+ }
+
+ # Declare a jni target for a prebuilt jar
+ #
+ # This target generates the native jni bindings for a set of classes in a .jar.
+ #
+ # See base/android/jni_generator/jni_generator.py for more info about the
+ # format of generating JNI bindings.
+ #
+ # Variables
+ # classes: list of .class files in the jar to generate jni for. These should
+ # include the full path to the .class file.
+ # jni_package: subdirectory path for generated bindings
+ # jar_file: the path to the .jar. If not provided, will default to the sdk's
+ # android.jar
+ # always_mangle: Mangle all generated method names. By default, the script
+ # only mangles methods that cause ambiguity due to method overload.
+ #
+ # deps, public_deps: As normal
+ #
+ # Example
+ # generate_jar_jni("foo_jni") {
+ # classes = [
+ # "android/view/Foo.class",
+ # ]
+ # jni_package = "foo"
+ # }
+ template("generate_jar_jni") {
+ forward_variables_from(invoker, [ "testonly" ])
+
+ if (defined(invoker.jar_file)) {
+ _jar_file = invoker.jar_file
+ } else {
+ _jar_file = android_sdk_jar
+ }
+
+ _always_mangle = defined(invoker.always_mangle) && invoker.always_mangle
+
+ _base_output_dir = "${target_gen_dir}/${target_name}/${invoker.jni_package}"
+ _jni_output_dir = "${_base_output_dir}/jni"
+
+ if (defined(invoker.jni_generator_include)) {
+ _jni_generator_include = invoker.jni_generator_include
+ } else {
+ _jni_generator_include =
+ "//base/android/jni_generator/jni_generator_helper.h"
+ }
+
+ # TODO(cjhopman): make jni_generator.py support generating jni for multiple
+ # .class files from a .jar.
+ _jni_actions = []
+ foreach(_class, invoker.classes) {
+ _classname = get_path_info(_class, "name")
+ _jni_target_name = "${target_name}__jni_${_classname}"
+ _jni_actions += [ ":$_jni_target_name" ]
+ action_with_pydeps(_jni_target_name) {
+ # The sources aren't compiled so don't check their dependencies.
+ check_includes = false
+ script = "//base/android/jni_generator/jni_generator.py"
+ inputs = [
+ _jar_file,
+ ]
+ outputs = [
+ "${_jni_output_dir}/${_classname}_jni.h",
+ ]
+
+ args = [
+ "--jar_file",
+ rebase_path(_jar_file, root_build_dir),
+ "--input_file",
+ _class,
+ "--ptr_type=long",
+ "--output_dir",
+ rebase_path(_jni_output_dir, root_build_dir),
+ "--includes",
+ rebase_path(_jni_generator_include, _jni_output_dir),
+ ]
+
+ if (enable_profiling) {
+ args += [ "--enable_profiling" ]
+ }
+ if (enable_jni_tracing) {
+ args += [ "--enable_tracing" ]
+ }
+ if (_always_mangle) {
+ args += [ "--always_mangle" ]
+ }
+ }
+ }
+
+ config("jni_includes_${target_name}") {
+ include_dirs = [ _base_output_dir ]
+ }
+
+ group(target_name) {
+ public_deps = []
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "public_deps",
+ "visibility",
+ ])
+ public_deps += _jni_actions
+ public_configs = [ ":jni_includes_${target_name}" ]
+ }
+ }
+
+ # Declare a jni registration target.
+ #
+ # This target generates a srcjar containing a copy of GEN_JNI.java, which has
+ # the native methods of all dependent java files. It can also create a .h file
+ # for use with manual JNI registration.
+ #
+ # The script does not scan any generated sources (those within .srcjars, or
+ # within root_build_dir). This could be fixed by adding deps & logic to scan
+ # .srcjars, but isn't currently needed.
+ #
+ # See base/android/jni_generator/jni_registration_generator.py for more info
+ # about the format of the header file.
+ #
+ # Variables
+ # target: The Apk target to use for the java sources list.
+ # header_output: Path to the generated .h file (optional).
+ # sources_blacklist: List of .java files that should be skipped. (optional)
+ # namespace: Registration functions will be wrapped into this. (optional)
+ #
+ # Example
+ # generate_jni_registration("chrome_jni_registration") {
+ # target = ":chrome_public_apk"
+ # header_output = "$target_gen_dir/$target_name.h"
+ # sources_blacklist = [
+ # "//path/to/Exception.java",
+ # ]
+ # }
+ template("generate_jni_registration") {
+ action_with_pydeps(target_name) {
+ forward_variables_from(invoker, [ "testonly" ])
+ _build_config = get_label_info(invoker.target, "target_gen_dir") + "/" +
+ get_label_info(invoker.target, "name") + ".build_config"
+ _rebased_build_config = rebase_path(_build_config, root_build_dir)
+ _srcjar_output = "$target_gen_dir/$target_name.srcjar"
+
+ script = "//base/android/jni_generator/jni_registration_generator.py"
+ deps = [
+ "${invoker.target}$build_config_target_suffix",
+ ]
+ inputs = [
+ _build_config,
+ ]
+ outputs = [
+ _srcjar_output,
+ ]
+ depfile = "$target_gen_dir/$target_name.d"
+
+ args = [
+ # This is a list of .sources files.
+ "--sources-files=@FileArg($_rebased_build_config:deps_info:jni:all_source)",
+ "--srcjar-path",
+ rebase_path(_srcjar_output, root_build_dir),
+ "--depfile",
+ rebase_path(depfile, root_build_dir),
+ ]
+
+ if (use_hashed_jni_names) {
+ args += [ "--use_proxy_hash" ]
+ }
+
+ if (defined(invoker.enable_native_mocks) && invoker.enable_native_mocks) {
+ args += [ "--enable_proxy_mocks" ]
+ }
+
+ if (defined(invoker.require_native_mocks) &&
+ invoker.require_native_mocks) {
+ args += [ "--require_mocks" ]
+ }
+
+ if (defined(invoker.header_output)) {
+ outputs += [ invoker.header_output ]
+ args += [
+ "--header-path",
+ rebase_path(invoker.header_output, root_build_dir),
+ ]
+ }
+
+ if (defined(invoker.sources_blacklist)) {
+ _rebase_sources_blacklist =
+ rebase_path(invoker.sources_blacklist, root_build_dir)
+ args += [ "--sources-blacklist=$_rebase_sources_blacklist" ]
+ }
+
+ if (defined(invoker.namespace)) {
+ args += [ "--namespace=${invoker.namespace}" ]
+ }
+ }
+ }
+
+ # Declare a target for c-preprocessor-generated java files
+ #
+ # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum
+ # rule instead.
+ #
+ # This target generates java files using the host C pre-processor. Each file in
+ # sources will be compiled using the C pre-processor. If include_path is
+ # specified, it will be passed (with --I) to the pre-processor.
+ #
+ # This target will create a single .srcjar. Adding this target to an
+ # android_library target's srcjar_deps will make the generated java files be
+ # included in that library's final outputs.
+ #
+ # Variables
+ # sources: list of files to be processed by the C pre-processor. For each
+ # file in sources, there will be one .java file in the final .srcjar. For a
+ # file named FooBar.template, a java file will be created with name
+ # FooBar.java.
+ # inputs: additional compile-time dependencies. Any files
+ # `#include`-ed in the templates should be listed here.
+ # package_path: this will be the subdirectory for each .java file in the
+ # .srcjar.
+ #
+ # Example
+ # java_cpp_template("foo_generated_enum") {
+ # sources = [
+ # "android/java/templates/Foo.template",
+ # ]
+ # inputs = [
+ # "android/java/templates/native_foo_header.h",
+ # ]
+ #
+ # package_path = "org/chromium/base/library_loader"
+ # include_path = "android/java/templates"
+ # }
+ template("java_cpp_template") {
+ set_sources_assignment_filter([])
+ forward_variables_from(invoker, [ "testonly" ])
+
+ _include_path = "//"
+ if (defined(invoker.include_path)) {
+ _include_path = invoker.include_path
+ }
+
+ _apply_gcc_target_name = "${target_name}__apply_gcc"
+ _base_gen_dir = "${target_gen_dir}/${target_name}/java_cpp_template"
+ _package_path = invoker.package_path
+
+ action_foreach_with_pydeps(_apply_gcc_target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "inputs",
+ "public_deps",
+ "data_deps",
+ ])
+ script = "//build/android/gyp/gcc_preprocess.py"
+ depfile =
+ "${target_gen_dir}/${invoker.target_name}_{{source_name_part}}.d"
+
+ sources = invoker.sources
+
+ outputs = [
+ "$_base_gen_dir/${_package_path}/{{source_name_part}}.java",
+ ]
+
+ args = [
+ "--depfile",
+ rebase_path(depfile, root_build_dir),
+ "--include-path",
+ rebase_path(_include_path, root_build_dir),
+ "--output",
+ rebase_path(outputs[0], root_build_dir),
+ "--template={{source}}",
+ ]
+
+ if (defined(invoker.defines)) {
+ foreach(_def, invoker.defines) {
+ args += [
+ "--defines",
+ _def,
+ ]
+ }
+ }
+ }
+
+ # Filter out .d files.
+ set_sources_assignment_filter([ "*.d" ])
+ sources = get_target_outputs(":$_apply_gcc_target_name")
+
+ zip(target_name) {
+ forward_variables_from(invoker, [ "visibility" ])
+ inputs = sources
+ output = "${target_gen_dir}/${target_name}.srcjar"
+ base_dir = _base_gen_dir
+ deps = [
+ ":$_apply_gcc_target_name",
+ ]
+ }
+ }
+
+ # Declare a target for generating Java classes from C++ enums.
+ #
+ # This target generates Java files from C++ enums using a script.
+ #
+ # This target will create a single .srcjar. Adding this target to an
+ # android_library target's srcjar_deps will make the generated java files be
+ # included in that library's final outputs.
+ #
+ # Variables
+ # sources: list of files to be processed by the script. For each annotated
+ # enum contained in the sources files the script will generate a .java
+ # file with the same name as the name of the enum.
+ #
+ # Example
+ # java_cpp_enum("foo_generated_enum") {
+ # sources = [
+ # "src/native_foo_header.h",
+ # ]
+ # }
+ template("java_cpp_enum") {
+ set_sources_assignment_filter([])
+ action_with_pydeps(target_name) {
+ forward_variables_from(invoker,
+ [
+ "sources",
+ "testonly",
+ "visibility",
+ ])
+
+ # The sources aren't compiled so don't check their dependencies.
+ check_includes = false
+ script = "//build/android/gyp/java_cpp_enum.py"
+ depfile = "$target_gen_dir/$target_name.d"
+
+ _srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
+ _rebased_srcjar_path = rebase_path(_srcjar_path, root_build_dir)
+ _rebased_sources = rebase_path(invoker.sources, root_build_dir)
+
+ args = [
+ "--depfile",
+ rebase_path(depfile, root_build_dir),
+ "--srcjar=$_rebased_srcjar_path",
+ ] + _rebased_sources
+ outputs = [
+ _srcjar_path,
+ ]
+ }
+ }
+
+ # Declare a target for generating Java classes with string constants matching
+ # those found in C++ files using a python script.
+ #
+ # This target will create a single .srcjar. Adding this target to an
+ # android_library target's srcjar_deps will make the generated java files be
+ # included in that library's final outputs.
+ #
+ # Variables
+ # sources: list of files to be processed by the script. For each string
+ # constant in the source files, the script will add a corresponding
+ # Java string to the specified template file.
+ # Example
+ # java_cpp_strings("foo_switches") {
+ # sources = [
+ # "src/foo_switches.cc",
+ # ]
+ # template = "src/templates/FooSwitches.java.tmpl
+ # }
+ #
+ # foo_switches.cc:
+ #
+ # // A switch.
+ # const char kASwitch = "a-switch";
+ #
+ # FooSwitches.java.tmpl
+ #
+ # // Copyright {YEAR} 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.
+ #
+ # // This file is autogenerated by
+ # // {SCRIPT_NAME}
+ # // From
+ # // {SOURCE_PATH}, and
+ # // {TEMPLATE_PATH}
+ #
+ # package my.java.package;
+ #
+ # public abstract class FooSwitches {{
+ # // ...snip...
+ # {NATIVE_STRINGS}
+ # // ...snip...
+ # }}
+ #
+ # result:
+ # A FooSwitches.java file, defining a class named FooSwitches in the package
+ # my.java.package.
+ template("java_cpp_strings") {
+ set_sources_assignment_filter([])
+ action_with_pydeps(target_name) {
+ forward_variables_from(invoker,
+ [
+ "sources",
+ "testonly",
+ "visibility",
+ ])
+
+ # The sources aren't compiled so don't check their dependencies.
+ check_includes = false
+ script = "//build/android/gyp/java_cpp_strings.py"
+
+ _srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
+ _rebased_srcjar_path = rebase_path(_srcjar_path, root_build_dir)
+ _rebased_sources = rebase_path(invoker.sources, root_build_dir)
+ _rebased_template = rebase_path(invoker.template, root_build_dir)
+
+ args = [
+ "--srcjar=$_rebased_srcjar_path",
+ "--template=$_rebased_template",
+ ]
+ args += _rebased_sources
+ sources += [ invoker.template ]
+
+ outputs = [
+ _srcjar_path,
+ ]
+ }
+ }
+
+ # Declare a target for processing a Jinja template.
+ #
+ # Variables
+ # input: The template file to be processed.
+ # includes: List of files {% include %}'ed by input.
+ # output: Where to save the result.
+ # variables: (Optional) A list of variables to make available to the template
+ # processing environment, e.g. ["name=foo", "color=red"].
+ #
+ # Example
+ # jinja_template("chrome_public_manifest") {
+ # input = "java/AndroidManifest.xml"
+ # output = "$target_gen_dir/AndroidManifest.xml"
+ # }
+ template("jinja_template") {
+ action_with_pydeps(target_name) {
+ forward_variables_from(invoker,
+ [
+ "visibility",
+ "deps",
+ "testonly",
+ ])
+ inputs = [
+ invoker.input,
+ ]
+ if (defined(invoker.includes)) {
+ inputs += invoker.includes
+ }
+ script = "//build/android/gyp/jinja_template.py"
+
+ outputs = [
+ invoker.output,
+ ]
+
+ args = [
+ "--loader-base-dir",
+ rebase_path("//", root_build_dir),
+ "--inputs",
+ rebase_path(invoker.input, root_build_dir),
+ "--output",
+ rebase_path(invoker.output, root_build_dir),
+ "--check-includes",
+ ]
+ if (defined(invoker.includes)) {
+ _rebased_includes = rebase_path(invoker.includes, root_build_dir)
+ args += [ "--includes=$_rebased_includes" ]
+ }
+ if (defined(invoker.variables)) {
+ args += [ "--variables=${invoker.variables}" ]
+ }
+ }
+ }
+
+ # Declare a target for a set of Android resources generated at build
+ # time and stored in a single zip archive. The content of the archive
+ # should match the layout of a regular Android res/ folder (but the
+ # archive should not include a top-level res/ directory).
+ #
+ # Note that there is no associated .srcjar, R.txt or package name
+ # associated with this target.
+ #
+ # Variables:
+ # generated_resources_zip: Generated zip archive path.
+ # generating_target_name: Name of the target generating
+ # generated_resources_zip. This rule will check that it is part
+ # of its outputs.
+ # deps: Specifies the dependencies of this target. Any Android resources
+ # listed here will be also be included *after* this one when compiling
+ # all resources for a final apk or junit binary. This is useful to
+ # ensure that the resources of the current target override those of the
+ # dependency as well (and would not work if you have these deps to the
+ # generating target's dependencies).
+ #
+ # Example
+ # _zip_archive = "$target_gen_dir/${target_name}.resources_zip"
+ #
+ # action("my_resources__create_zip") {
+ # _depfile = "$target_gen_dir/${target_name}.d"
+ # script = "//build/path/to/create_my_resources_zip.py"
+ # args = [
+ # "--depfile", rebase_path(_depfile, root_build_dir),
+ # "--output-zip", rebase_path(_zip_archive, root_build_dir),
+ # ]
+ # inputs = []
+ # outputs = _zip_archive
+ # depfile = _depfile
+ # }
+ #
+ # android_generated_resources("my_resources") {
+ # generated_resources_zip = _zip_archive
+ # generating_target_name = ":my_resources__create_zip"
+ # }
+ #
+ template("android_generated_resources") {
+ forward_variables_from(invoker, [ "testonly" ])
+
+ _build_config = "$target_gen_dir/${target_name}.build_config"
+
+ write_build_config("$target_name$build_config_target_suffix") {
+ build_config = _build_config
+ resources_zip = invoker.generated_resources_zip
+ type = "android_resources"
+ if (defined(invoker.deps)) {
+ possible_config_deps = invoker.deps
+ }
+ }
+
+ group(target_name) {
+ public_deps = [
+ ":$target_name$build_config_target_suffix",
+ invoker.generating_target_name,
+ ]
+ }
+ }
+
+ # Declare a target for processing Android resources as Jinja templates.
+ #
+ # This takes an Android resource directory where each resource is a Jinja
+ # template, processes each template, then packages the results in a zip file
+ # which can be consumed by an android resources, library, or apk target.
+ #
+ # If this target is included in the deps of an android resources/library/apk,
+ # the resources will be included with that target.
+ #
+ # Variables
+ # resources: The list of resources files to process.
+ # res_dir: The resource directory containing the resources.
+ # variables: (Optional) A list of variables to make available to the template
+ # processing environment, e.g. ["name=foo", "color=red"].
+ #
+ # Example
+ # jinja_template_resources("chrome_public_template_resources") {
+ # res_dir = "res_template"
+ # resources = ["res_template/xml/syncable.xml"]
+ # variables = ["color=red"]
+ # }
+ template("jinja_template_resources") {
+ # JUnit tests use resource zip files. These must not be put in gen/
+ # directory or they will not be available to tester bots.
+ _resources_zip_rebased_path = rebase_path(target_gen_dir, root_gen_dir)
+ _resources_zip = "${root_out_dir}/resource_zips/${_resources_zip_rebased_path}/${target_name}.resources.zip"
+
+ _generating_target_name = "${target_name}__template"
+
+ action_with_pydeps(_generating_target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "testonly",
+ ])
+ inputs = invoker.resources
+ script = "//build/android/gyp/jinja_template.py"
+
+ outputs = [
+ _resources_zip,
+ ]
+
+ _rebased_resources = rebase_path(invoker.resources, root_build_dir)
+ args = [
+ "--inputs=${_rebased_resources}",
+ "--inputs-base-dir",
+ rebase_path(invoker.res_dir, root_build_dir),
+ "--outputs-zip",
+ rebase_path(_resources_zip, root_build_dir),
+ "--check-includes",
+ ]
+ if (defined(invoker.variables)) {
+ variables = invoker.variables
+ args += [ "--variables=${variables}" ]
+ }
+ }
+
+ android_generated_resources(target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "testonly",
+ ])
+ generating_target_name = ":$_generating_target_name"
+ generated_resources_zip = _resources_zip
+ }
+ }
+
+ # Declare an Android resources target
+ #
+ # This creates a resources zip file that will be used when building an Android
+ # library or apk and included into a final apk.
+ #
+ # To include these resources in a library/apk, this target should be listed in
+ # the library's deps. A library/apk will also include any resources used by its
+ # own dependencies.
+ #
+ # Variables
+ # deps: Specifies the dependencies of this target. Any Android resources
+ # listed in deps will be included by libraries/apks that depend on this
+ # target.
+ # alternative_android_sdk_dep: Optional. Alternative Android system
+ # android java target to use.
+ # resource_dirs: List of directories containing resources for this target.
+ # generated_resource_dirs: List of directories containing resources for this
+ # target which are *generated* by a dependency. |generated_resource_files|
+ # must be specified if |generated_resource_dirs| is specified.
+ # generated_resource_files: List of all files in |generated_resource_dirs|.
+ # |generated_resource_dirs| must be specified in |generated_resource_files|
+ # is specified.
+ # android_manifest: AndroidManifest.xml for this target (optional). Will be
+ # merged into apks that directly or indirectly depend on this target.
+ # android_manifest_dep: Target that generates AndroidManifest (if applicable)
+ # custom_package: java package for generated .java files.
+ # v14_skip: If true, don't run v14 resource generator on this. Defaults to
+ # false. (see build/android/gyp/generate_v14_compatible_resources.py)
+ # shared_resources: If true make a resource package that can be loaded by a
+ # different application at runtime to access the package's resources.
+ # r_text_file: (optional) path to pre-generated R.txt to be used when
+ # generating R.java instead of resource-based aapt-generated one.
+ # create_srcjar: If false, does not create an R.java file. Needed only for
+ # prebuilts that have R.txt files that do not match their res/
+ # (Play Services).
+ #
+ # Example:
+ # android_resources("foo_resources") {
+ # deps = [":foo_strings_grd"]
+ # resource_dirs = ["res"]
+ # custom_package = "org.chromium.foo"
+ # }
+ #
+ # android_resources("foo_resources_overrides") {
+ # deps = [":foo_resources"]
+ # resource_dirs = ["res_overrides"]
+ # }
+ template("android_resources") {
+ forward_variables_from(invoker, [ "testonly" ])
+
+ _base_path = "$target_gen_dir/$target_name"
+
+ # JUnit tests use resource zip files. These must not be put in gen/
+ # directory or they will not be available to tester bots.
+ _resources_zip_rebased_path = rebase_path(target_gen_dir, root_gen_dir)
+ _zip_path = "${root_out_dir}/resource_zips/${_resources_zip_rebased_path}/${target_name}.resources.zip"
+ _r_text_out_path = _base_path + "_R.txt"
+ _build_config = _base_path + ".build_config"
+ _build_config_target_name = "$target_name$build_config_target_suffix"
+
+ if (!defined(invoker.create_srcjar) || invoker.create_srcjar) {
+ _srcjar_path = _base_path + ".srcjar"
+ }
+
+ _deps = []
+ if (defined(invoker.deps)) {
+ _deps += invoker.deps
+ }
+
+ if (defined(invoker.alternative_android_sdk_dep)) {
+ _deps += [ invoker.alternative_android_sdk_dep ]
+ } else {
+ _deps += [ "//third_party/android_sdk:android_sdk_java" ]
+ }
+
+ write_build_config(_build_config_target_name) {
+ type = "android_resources"
+ build_config = _build_config
+ resources_zip = _zip_path
+
+ resource_dirs = invoker.resource_dirs
+ if (defined(invoker.generated_resource_dirs)) {
+ resource_dirs += invoker.generated_resource_dirs
+ }
+
+ if (defined(_srcjar_path)) {
+ forward_variables_from(invoker,
+ [
+ "android_manifest",
+ "android_manifest_dep",
+ "custom_package",
+ ])
+
+ # No package means resources override their deps.
+ if (defined(custom_package) || defined(android_manifest)) {
+ r_text = _r_text_out_path
+ } else {
+ assert(defined(invoker.deps),
+ "Must specify deps when custom_package is omitted.")
+ }
+ srcjar = _srcjar_path
+ }
+
+ possible_config_deps = _deps
+ }
+
+ prepare_resources(target_name) {
+ forward_variables_from(invoker,
+ [
+ "android_manifest",
+ "custom_package",
+ "generated_resource_dirs",
+ "generated_resource_files",
+ "resource_dirs",
+ "v14_skip",
+ "strip_drawables",
+ ])
+ deps = _deps
+ deps += [ ":$_build_config_target_name" ]
+ if (defined(invoker.android_manifest_dep)) {
+ deps += [ invoker.android_manifest_dep ]
+ }
+
+ build_config = _build_config
+ zip_path = _zip_path
+ r_text_out_path = _r_text_out_path
+
+ if (defined(invoker.r_text_file)) {
+ r_text_in_path = invoker.r_text_file
+ }
+ if (defined(_srcjar_path)) {
+ srcjar_path = _srcjar_path
+ }
+
+ # Always generate R.onResourcesLoaded() method, it is required for
+ # compiling ResourceRewriter, there is no side effect because the
+ # generated R.class isn't used in final apk.
+ shared_resources = true
+ }
+ }
+
+ # Declare an Android assets target.
+ #
+ # Defines a set of files to include as assets in a dependent apk.
+ #
+ # To include these assets in an apk, this target should be listed in
+ # the apk's deps, or in the deps of a library target used by an apk.
+ #
+ # Variables
+ # deps: Specifies the dependencies of this target. Any Android assets
+ # listed in deps will be included by libraries/apks that depend on this
+ # target.
+ # sources: List of files to include as assets.
+ # renaming_sources: List of files to include as assets and be renamed.
+ # renaming_destinations: List of asset paths for files in renaming_sources.
+ # disable_compression: Whether to disable compression for files that are
+ # known to be compressable (default: false).
+ # treat_as_locale_paks: Causes base's BuildConfig.java to consider these
+ # assets to be locale paks.
+ #
+ # Example:
+ # android_assets("content_shell_assets") {
+ # deps = [
+ # ":generates_foo",
+ # ":other_assets",
+ # ]
+ # sources = [
+ # "//path/asset1.png",
+ # "//path/asset2.png",
+ # "$target_gen_dir/foo.dat",
+ # ]
+ # }
+ #
+ # android_assets("overriding_content_shell_assets") {
+ # deps = [ ":content_shell_assets" ]
+ # # Override foo.dat from content_shell_assets.
+ # sources = [ "//custom/foo.dat" ]
+ # renaming_sources = [ "//path/asset2.png" ]
+ # renaming_destinations = [ "renamed/asset2.png" ]
+ # }
+ template("android_assets") {
+ forward_variables_from(invoker, [ "testonly" ])
+
+ _build_config = "$target_gen_dir/$target_name.build_config"
+ _build_config_target_name = "$target_name$build_config_target_suffix"
+
+ write_build_config(_build_config_target_name) {
+ type = "android_assets"
+ build_config = _build_config
+
+ forward_variables_from(invoker,
+ [
+ "disable_compression",
+ "treat_as_locale_paks",
+ ])
+
+ if (defined(invoker.deps)) {
+ possible_config_deps = invoker.deps
+ }
+
+ if (defined(invoker.sources)) {
+ asset_sources = invoker.sources
+ }
+ if (defined(invoker.renaming_sources)) {
+ assert(defined(invoker.renaming_destinations))
+ _source_count = 0
+ foreach(_, invoker.renaming_sources) {
+ _source_count += 1
+ }
+ _dest_count = 0
+ foreach(_, invoker.renaming_destinations) {
+ _dest_count += 1
+ }
+ assert(
+ _source_count == _dest_count,
+ "android_assets() renaming_sources.length != renaming_destinations.length")
+ asset_renaming_sources = invoker.renaming_sources
+ asset_renaming_destinations = invoker.renaming_destinations
+ }
+ }
+
+ group(target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "visibility",
+ ])
+ public_deps = [
+ ":$_build_config_target_name",
+ ]
+ }
+ }
+
+ # Declare a group() that supports forwarding java dependency information.
+ #
+ # Example
+ # java_group("conditional_deps") {
+ # if (enable_foo) {
+ # deps = [":foo_java"]
+ # }
+ # }
+ template("java_group") {
+ forward_variables_from(invoker,
+ [
+ "testonly",
+ "input_jars_paths",
+ ])
+ write_build_config("$target_name$build_config_target_suffix") {
+ type = "group"
+ build_config = "$target_gen_dir/${invoker.target_name}.build_config"
+ supports_android = true
+ if (defined(invoker.deps)) {
+ possible_config_deps = invoker.deps
+ }
+ }
+ group(target_name) {
+ forward_variables_from(invoker, "*")
+ if (!defined(deps)) {
+ deps = []
+ }
+ deps += [ ":$target_name$build_config_target_suffix" ]
+ }
+ }
+
+ # Declare a target that generates localized strings.xml from a .grd file.
+ #
+ # If this target is included in the deps of an android resources/library/apk,
+ # the strings.xml will be included with that target.
+ #
+ # Variables
+ # deps: Specifies the dependencies of this target.
+ # grd_file: Path to the .grd file to generate strings.xml from.
+ # outputs: Expected grit outputs (see grit rule).
+ #
+ # Example
+ # java_strings_grd("foo_strings_grd") {
+ # grd_file = "foo_strings.grd"
+ # }
+ template("java_strings_grd") {
+ forward_variables_from(invoker, [ "testonly" ])
+
+ # JUnit tests use resource zip files. These must not be put in gen/
+ # directory or they will not be available to tester bots.
+ _resources_zip_rebased_path = rebase_path(target_gen_dir, root_gen_dir)
+ _resources_zip = "${root_out_dir}/resource_zips/${_resources_zip_rebased_path}/${target_name}.resources.zip"
+
+ _grit_target_name = "${target_name}__grit"
+ _grit_output_dir = "$target_gen_dir/${target_name}_grit_output"
+
+ grit(_grit_target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "defines",
+ ])
+ grit_flags = [
+ "-E",
+ "ANDROID_JAVA_TAGGED_ONLY=false",
+ ]
+ output_dir = _grit_output_dir
+ resource_ids = ""
+ source = invoker.grd_file
+ outputs = invoker.outputs
+ }
+
+ _zip_target_name = "${target_name}__zip"
+
+ zip(_zip_target_name) {
+ base_dir = _grit_output_dir
+
+ # This needs to get outputs from grit's internal target, not the final
+ # source_set.
+ inputs = get_target_outputs(":${_grit_target_name}_grit")
+ output = _resources_zip
+ deps = [
+ ":$_grit_target_name",
+ ]
+ }
+
+ android_generated_resources(target_name) {
+ generating_target_name = ":$_zip_target_name"
+ generated_resources_zip = _resources_zip
+ }
+ }
+
+ # Declare a target that packages strings.xml generated from a grd file.
+ #
+ # If this target is included in the deps of an android resources/library/apk,
+ # the strings.xml will be included with that target.
+ #
+ # Variables
+ # grit_output_dir: directory containing grit-generated files.
+ # generated_files: list of android resource files to package.
+ #
+ # Example
+ # java_strings_grd_prebuilt("foo_strings_grd") {
+ # grit_output_dir = "$root_gen_dir/foo/grit"
+ # generated_files = [
+ # "values/strings.xml"
+ # ]
+ # }
+ template("java_strings_grd_prebuilt") {
+ forward_variables_from(invoker, [ "testonly" ])
+
+ # JUnit tests use resource zip files. These must not be put in gen/
+ # directory or they will not be available to tester bots.
+ _resources_zip_rebased_path = rebase_path(target_gen_dir, root_gen_dir)
+ _resources_zip = "${root_out_dir}/resource_zips/${_resources_zip_rebased_path}/${target_name}.resources.zip"
+
+ _zip_target_name = "${target_name}__zip"
+
+ zip(_zip_target_name) {
+ forward_variables_from(invoker, [ "visibility" ])
+
+ base_dir = invoker.grit_output_dir
+ inputs = rebase_path(invoker.generated_files, ".", base_dir)
+ output = _resources_zip
+ if (defined(invoker.deps)) {
+ deps = invoker.deps
+ }
+ }
+
+ android_generated_resources(target_name) {
+ generating_target_name = ":$_zip_target_name"
+ generated_resources_zip = _resources_zip
+ }
+ }
+
+ # Declare a Java executable target
+ #
+ # Same as java_library, but also creates a wrapper script within
+ # $root_out_dir/bin.
+ #
+ # Supports all variables of java_library(), plus:
+ # main_class: When specified, a wrapper script is created within
+ # $root_build_dir/bin to launch the binary with the given class as the
+ # entrypoint.
+ # wrapper_script_name: Filename for the wrapper script (default=target_name)
+ # wrapper_script_args: List of additional arguments for the wrapper script.
+ #
+ # Example
+ # java_binary("foo") {
+ # java_files = [ "org/chromium/foo/FooMain.java" ]
+ # deps = [ ":bar_java" ]
+ # main_class = "org.chromium.foo.FooMain"
+ # }
+ #
+ # java_binary("foo") {
+ # jar_path = "lib/prebuilt.jar"
+ # deps = [ ":bar_java" ]
+ # main_class = "org.chromium.foo.FooMain"
+ # }
+ template("java_binary") {
+ java_library_impl(target_name) {
+ forward_variables_from(invoker, "*")
+ type = "java_binary"
+ }
+ }
+
+ # Declare a Java Annotation Processor.
+ #
+ # Supports all variables of java_library(), plus:
+ # jar_path: Path to a prebuilt jar. Mutually exclusive with java_files &
+ # srcjar_deps.
+ # main_class: The fully-quallified class name of the processor's entry
+ # point.
+ #
+ # Example
+ # java_annotation_processor("foo_processor") {
+ # java_files = [ "org/chromium/foo/FooProcessor.java" ]
+ # deps = [ ":bar_java" ]
+ # main_class = "org.chromium.foo.FooProcessor"
+ # }
+ #
+ # java_annotation_processor("foo_processor") {
+ # jar_path = "lib/prebuilt.jar"
+ # main_class = "org.chromium.foo.FooMain"
+ # }
+ #
+ # java_library("...") {
+ # annotation_processor_deps = [":foo_processor"]
+ # }
+ #
+ template("java_annotation_processor") {
+ java_library_impl(target_name) {
+ forward_variables_from(invoker, "*")
+ type = "java_annotation_processor"
+ }
+ }
+
+ # Declare a Junit executable target
+ #
+ # This target creates an executable from java code for running as a junit test
+ # suite. The executable will be in the output folder's /bin/ directory.
+ #
+ # Supports all variables of java_binary().
+ #
+ # Example
+ # junit_binary("foo") {
+ # java_files = [ "org/chromium/foo/FooTest.java" ]
+ # deps = [ ":bar_java" ]
+ # }
+ template("junit_binary") {
+ testonly = true
+
+ _java_binary_target_name = "${target_name}__java_binary"
+ _test_runner_target_name = "${target_name}__test_runner_script"
+ _main_class = "org.chromium.testing.local.JunitTestMain"
+
+ _build_config = "$target_gen_dir/$target_name.build_config"
+ _build_config_target_name = "$target_name$build_config_target_suffix"
+ _deps = [
+ "//testing/android/junit:junit_test_support",
+ "//third_party/junit",
+ "//third_party/mockito:mockito_java",
+ "//third_party/robolectric:robolectric_all_java",
+
+ # This dep is required if any deps require android (but it doesn't hurt
+ # to add it regardless) and is used by bytecode rewritten classes.
+ "//build/android/buildhooks:build_hooks_android_impl_java",
+ ]
+ if (defined(invoker.deps)) {
+ _deps += invoker.deps
+ }
+
+ # a package name or a manifest is required to have resources. This is
+ # added so that junit tests that do not care about the package name can
+ # still use resources without having to explicitly set one.
+ if (defined(invoker.package_name)) {
+ _package_name = invoker.package_name
+ } else if (!defined(invoker.android_manifest_path)) {
+ _package_name = "org.chromium.test"
+ }
+
+ _prepare_resources_target = "${target_name}__prepare_resources"
+ prepare_resources(_prepare_resources_target) {
+ deps = _deps + [ ":$_build_config_target_name" ]
+ build_config = _build_config
+ srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
+ if (defined(_package_name)) {
+ custom_package = _package_name
+ }
+ if (defined(invoker.android_manifest_path)) {
+ android_manifest = invoker.android_manifest_path
+ } else {
+ android_manifest = "//build/android/AndroidManifest.xml"
+ }
+ }
+
+ _jni_srcjar_target = "${target_name}__final_jni"
+ _outer_target_name = target_name
+ generate_jni_registration(_jni_srcjar_target) {
+ enable_native_mocks = true
+ require_native_mocks = true
+ target = ":$_outer_target_name"
+ }
+
+ java_library_impl(_java_binary_target_name) {
+ forward_variables_from(invoker, "*", [ "deps" ])
+ type = "junit_binary"
+ main_target_name = invoker.target_name
+
+ # Include the android SDK jar(s) for resource processing.
+ include_android_sdk = true
+
+ # Robolectric can handle deps that set !supports_android as well those
+ # that set requires_android.
+ bypass_platform_checks = true
+ deps = _deps
+ testonly = true
+ main_class = _main_class
+ wrapper_script_name = "helper/$main_target_name"
+ if (!defined(srcjar_deps)) {
+ srcjar_deps = []
+ }
+ srcjar_deps += [
+ ":$_jni_srcjar_target",
+ ":$_prepare_resources_target",
+
+ # This dep is required for any targets that depend on //base:base_java.
+ "//base:base_build_config_gen",
+ ]
+ }
+
+ test_runner_script(_test_runner_target_name) {
+ test_name = invoker.target_name
+ test_suite = invoker.target_name
+ test_type = "junit"
+ ignore_all_data_deps = true
+ forward_variables_from(invoker, [ "android_manifest_path" ])
+ if (defined(_package_name)) {
+ package_name = _package_name
+ }
+ }
+
+ group(target_name) {
+ public_deps = [
+ ":$_build_config_target_name",
+ ":$_java_binary_target_name",
+ ":$_test_runner_target_name",
+ ]
+ }
+ }
+
+ # Declare a java library target
+ #
+ # Variables
+ # deps: Specifies the dependencies of this target. Java targets in this list
+ # will be added to the javac classpath.
+ # annotation_processor_deps: List of java_annotation_processor targets to
+ # use when compiling.
+ #
+ # jar_path: Path to a prebuilt jar. Mutually exclusive with java_files &
+ # srcjar_deps.
+ # java_files: List of .java files included in this library.
+ # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
+ # will be added to java_files and be included in this library.
+ #
+ # input_jars_paths: A list of paths to the jars that should be included
+ # in the compile-time classpath. These are in addition to library .jars
+ # that appear in deps.
+ # classpath_deps: Deps that should added to the classpath for this target,
+ # but not linked into the apk (use this for annotation processors).
+ #
+ # chromium_code: If true, extra analysis warning/errors will be enabled.
+ # enable_errorprone: If true, enables the errorprone compiler.
+ #
+ # jar_excluded_patterns: List of patterns of .class files to exclude.
+ # jar_included_patterns: List of patterns of .class files to include.
+ # When omitted, all classes not matched by jar_excluded_patterns are
+ # included. When specified, all non-matching .class files are stripped.
+ #
+ # output_name: File name for the output .jar (not including extension).
+ # Defaults to the input .jar file name.
+ #
+ # proguard_configs: List of proguard configs to use in final apk step for
+ # any apk that depends on this library.
+ #
+ # supports_android: If true, Android targets (android_library, android_apk)
+ # may depend on this target. Note: if true, this target must only use the
+ # subset of Java available on Android.
+ # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
+ # dependencies for this target. This will allow depending on an
+ # android_library target, for example.
+ #
+ # additional_jar_files: Use to package additional files (Java resources)
+ # into the output jar. Pass a list of length-2 lists with format:
+ # [ [ path_to_file, path_to_put_in_jar ] ]
+ #
+ # javac_args: Additional arguments to pass to javac.
+ # errorprone_args: Additional arguments to pass to errorprone.
+ #
+ # data_deps, testonly
+ #
+ # Example
+ # java_library("foo_java") {
+ # java_files = [
+ # "org/chromium/foo/Foo.java",
+ # "org/chromium/foo/FooInterface.java",
+ # "org/chromium/foo/FooService.java",
+ # ]
+ # deps = [
+ # ":bar_java"
+ # ]
+ # srcjar_deps = [
+ # ":foo_generated_enum"
+ # ]
+ # jar_excluded_patterns = [
+ # "*/FooService.class", "org/chromium/FooService\$*.class"
+ # ]
+ # }
+ template("java_library") {
+ java_library_impl(target_name) {
+ forward_variables_from(invoker, "*")
+ type = "java_library"
+ }
+ }
+
+ # Declare a java library target for a prebuilt jar
+ #
+ # Supports all variables of java_library().
+ #
+ # Example
+ # java_prebuilt("foo_java") {
+ # jar_path = "foo.jar"
+ # deps = [
+ # ":foo_resources",
+ # ":bar_java"
+ # ]
+ # }
+ template("java_prebuilt") {
+ java_library_impl(target_name) {
+ forward_variables_from(invoker, "*")
+ type = "java_library"
+ }
+ }
+
+ # Combines all dependent .jar files into a single .jar file.
+ #
+ # Variables:
+ # output: Path to the output jar.
+ # override_build_config: Use a pre-existing .build_config. Must be of type
+ # "apk".
+ # use_interface_jars: Use all dependent interface .jars rather than
+ # implementation .jars.
+ # use_unprocessed_jars: Use unprocessed / undesugared .jars.
+ # direct_deps_only: Do not recurse on deps.
+ # jar_excluded_patterns (optional)
+ # List of globs for paths to exclude.
+ #
+ # Example
+ # dist_jar("lib_fatjar") {
+ # deps = [ ":my_java_lib" ]
+ # output = "$root_build_dir/MyLibrary.jar"
+ # }
+ # dist_jar("sideloaded_dex") {
+ # deps = [ ":my_java_lib" ]
+ # output = "$root_build_dir/MyLibrary.jar"
+ # dex_path = "$root_build_dir/MyLibrary.dex"
+ # }
+ template("dist_jar") {
+ forward_variables_from(invoker, [ "testonly" ])
+ _supports_android =
+ !defined(invoker.supports_android) || invoker.supports_android
+ _requires_android =
+ defined(invoker.requires_android) && invoker.requires_android
+ _use_interface_jars =
+ defined(invoker.use_interface_jars) && invoker.use_interface_jars
+ _use_unprocessed_jars =
+ defined(invoker.use_unprocessed_jars) && invoker.use_unprocessed_jars
+ _direct_deps_only =
+ defined(invoker.direct_deps_only) && invoker.direct_deps_only
+ assert(!(_use_unprocessed_jars && _use_interface_jars),
+ "Cannot set both use_interface_jars and use_unprocessed_jars")
+
+ _jar_target_name = target_name
+
+ _deps = []
+ if (defined(invoker.deps)) {
+ _deps = invoker.deps
+ }
+ if (_supports_android) {
+ _deps += [ "//third_party/android_sdk:android_sdk_java" ]
+ }
+ _enable_build_hooks =
+ _supports_android &&
+ (!defined(invoker.no_build_hooks) || !invoker.no_build_hooks)
+ if (_enable_build_hooks && _requires_android) {
+ _deps += [ "//build/android/buildhooks:build_hooks_android_impl_java" ]
+ }
+
+ if (defined(invoker.override_build_config)) {
+ _build_config = invoker.override_build_config
+ } else {
+ _build_config = "$target_gen_dir/$target_name.build_config"
+ _build_config_target_name = "$target_name$build_config_target_suffix"
+
+ write_build_config(_build_config_target_name) {
+ type = "dist_jar"
+ supports_android = _supports_android
+ requires_android = _requires_android
+ possible_config_deps = _deps
+ build_config = _build_config
+ }
+
+ _deps += [ ":$_build_config_target_name" ]
+ }
+
+ _rebased_build_config = rebase_path(_build_config, root_build_dir)
+ action_with_pydeps(_jar_target_name) {
+ forward_variables_from(invoker, [ "data" ])
+ script = "//build/android/gyp/zip.py"
+ depfile = "$target_gen_dir/$target_name.d"
+ deps = _deps
+
+ inputs = [
+ _build_config,
+ ]
+
+ outputs = [
+ invoker.output,
+ ]
+
+ args = [
+ "--depfile",
+ rebase_path(depfile, root_build_dir),
+ "--output",
+ rebase_path(invoker.output, root_build_dir),
+ "--no-compress",
+ ]
+
+ if (_direct_deps_only) {
+ if (_use_interface_jars) {
+ args += [ "--input-zips=@FileArg($_rebased_build_config:javac:interface_classpath)" ]
+ } else if (_use_unprocessed_jars) {
+ args += [
+ "--input-zips=@FileArg($_rebased_build_config:javac:classpath)",
+ ]
+ } else {
+ assert(
+ false,
+ "direct_deps_only does not work without use_interface_jars or use_unprocessed_jars")
+ }
+ } else {
+ if (_use_interface_jars) {
+ args += [ "--input-zips=@FileArg($_rebased_build_config:dist_jar:all_interface_jars)" ]
+ } else if (_use_unprocessed_jars) {
+ args += [ "--input-zips=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)" ]
+ } else {
+ args += [ "--input-zips=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)" ]
+ }
+ }
+ if (defined(invoker.jar_excluded_patterns)) {
+ args +=
+ [ "--input-zips-excluded-globs=${invoker.jar_excluded_patterns}" ]
+ }
+ }
+ }
+
+ # Combines all dependent .jar files into a single proguarded .dex file.
+ #
+ # Variables:
+ # output: Path to the output dex.
+ # proguard_configs: List of proguard configs.
+ # proguard_jar_path: The path to proguard.jar you wish to use. If undefined,
+ # the proguard used will be the checked in one in //third_party/proguard.
+ #
+ # Example
+ # dist_dex("lib_fatjar") {
+ # deps = [ ":my_java_lib" ]
+ # output = "$root_build_dir/MyLibrary.jar"
+ # }
+ # dist_jar("sideloaded_dex") {
+ # deps = [ ":my_java_lib" ]
+ # output = "$root_build_dir/MyLibrary.jar"
+ # dex_path = "$root_build_dir/MyLibrary.dex"
+ # }
+ template("proguarded_dist_dex") {
+ _deps = [
+ "//third_party/android_sdk:android_sdk_java",
+ "//build/android/buildhooks:build_hooks_android_impl_java",
+ ]
+ if (defined(invoker.deps)) {
+ _deps += invoker.deps
+ }
+
+ _build_config = "$target_gen_dir/$target_name.build_config"
+ _build_config_target_name = "$target_name$build_config_target_suffix"
+
+ write_build_config(_build_config_target_name) {
+ type = "dist_jar"
+ forward_variables_from(invoker, [ "proguard_configs" ])
+ supports_android = true
+ requires_android = true
+ proguard_enabled = true
+ possible_config_deps = _deps
+ build_config = _build_config
+ }
+
+ _deps += [ ":$_build_config_target_name" ]
+
+ dex(target_name) {
+ deps = _deps
+ build_config = _build_config
+ proguard_enabled = true
+ forward_variables_from(invoker,
+ [
+ "proguard_configs",
+ "min_sdk_version",
+ ])
+ output = invoker.output
+ }
+ }
+
+ # Creates an Android .aar library.
+ #
+ # Currently supports:
+ # * AndroidManifest.xml
+ # * classes.jar
+ # * jni/
+ # * res/
+ # * R.txt
+ # * proguard.txt
+ # Does not yet support:
+ # * public.txt
+ # * annotations.zip
+ # * assets/
+ # See: https://developer.android.com/studio/projects/android-library.html#aar-contents
+ #
+ # Variables:
+ # output: Path to the output .aar.
+ # proguard_configs: List of proguard configs (optional).
+ # android_manifest: Path to AndroidManifest.xml (optional).
+ # native_libraries: list of native libraries (optional).
+ # direct_deps_only: Do not recurse on deps. (optional, defaults false).
+ #
+ # Example
+ # dist_aar("my_aar") {
+ # deps = [ ":my_java_lib" ]
+ # output = "$root_build_dir/MyLibrary.aar"
+ # }
+ template("dist_aar") {
+ forward_variables_from(invoker, [ "testonly" ])
+
+ _deps = []
+ if (defined(invoker.deps)) {
+ _deps = invoker.deps
+ }
+
+ _direct_deps_only =
+ defined(invoker.direct_deps_only) && invoker.direct_deps_only
+
+ _build_config = "$target_gen_dir/$target_name.build_config"
+ _build_config_target_name = "$target_name$build_config_target_suffix"
+
+ write_build_config(_build_config_target_name) {
+ type = "dist_aar"
+ forward_variables_from(invoker, [ "proguard_configs" ])
+ possible_config_deps = _deps
+ supports_android = true
+ requires_android = true
+ build_config = _build_config
+ }
+
+ _deps += [ ":$_build_config_target_name" ]
+
+ _rebased_build_config = rebase_path(_build_config, root_build_dir)
+
+ action_with_pydeps(target_name) {
+ forward_variables_from(invoker, [ "data" ])
+ depfile = "$target_gen_dir/$target_name.d"
+ deps = _deps
+ script = "//build/android/gyp/dist_aar.py"
+
+ inputs = [
+ _build_config,
+ ]
+
+ # Although these will be listed as deps in the depfile, they must also
+ # appear here so that "gn analyze" knows about them.
+ # https://crbug.com/827197
+ if (defined(invoker.proguard_configs)) {
+ inputs += invoker.proguard_configs
+ }
+
+ outputs = [
+ invoker.output,
+ ]
+
+ args = [
+ "--depfile",
+ rebase_path(depfile, root_build_dir),
+ "--output",
+ rebase_path(invoker.output, root_build_dir),
+ "--dependencies-res-zips=@FileArg($_rebased_build_config:resources:dependency_zips)",
+ "--r-text-files=@FileArg($_rebased_build_config:resources:extra_r_text_files)",
+ "--proguard-configs=@FileArg($_rebased_build_config:deps_info:proguard_all_configs)",
+ ]
+ if (_direct_deps_only) {
+ args += [ "--jars=@FileArg($_rebased_build_config:javac:classpath)" ]
+ } else {
+ args += [ "--jars=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)" ]
+ }
+ if (defined(invoker.android_manifest)) {
+ args += [
+ "--android-manifest",
+ rebase_path(invoker.android_manifest, root_build_dir),
+ ]
+ }
+ if (defined(invoker.native_libraries) && invoker.native_libraries != []) {
+ inputs += invoker.native_libraries
+ _rebased_native_libraries =
+ rebase_path(invoker.native_libraries, root_build_dir)
+
+ args += [
+ "--native-libraries=$_rebased_native_libraries",
+ "--abi=$android_app_abi",
+ ]
+ }
+ }
+ }
+
+ # Declare an Android library target
+ #
+ # This target creates an Android library containing java code and Android
+ # resources.
+ #
+ # Supports all variables of java_library(), plus:
+ # android_manifest_for_lint: Path to AndroidManifest.xml (optional). This
+ # manifest will be used by Android lint, but will not be merged into apks.
+ # To have a manifest merged, add it to an android_resources() target.
+ # deps: In addition to defining java deps, this can also include
+ # android_assets() and android_resources() targets.
+ # dex_path: If set, the resulting .dex.jar file will be placed under this
+ # path.
+ # alternative_android_sdk_ijar: if set, the given android_sdk_ijar file
+ # replaces the default android_sdk_ijar.
+ # alternative_android_sdk_ijar_dep: the target that generates
+ # alternative_android_sdk_ijar, must be set if alternative_android_sdk_ijar
+ # is used.
+ # alternative_android_sdk_jar: actual jar corresponding to
+ # alternative_android_sdk_ijar, must be set if alternative_android_sdk_ijar
+ # is used.
+ #
+ # Example
+ # android_library("foo_java") {
+ # java_files = [
+ # "android/org/chromium/foo/Foo.java",
+ # "android/org/chromium/foo/FooInterface.java",
+ # "android/org/chromium/foo/FooService.java",
+ # ]
+ # deps = [
+ # ":bar_java"
+ # ]
+ # srcjar_deps = [
+ # ":foo_generated_enum"
+ # ]
+ # jar_excluded_patterns = [
+ # "*/FooService.class", "org/chromium/FooService\$*.class"
+ # ]
+ # }
+ template("android_library") {
+ java_library(target_name) {
+ forward_variables_from(invoker, "*")
+
+ supports_android = true
+ requires_android = true
+
+ if (!defined(jar_excluded_patterns)) {
+ jar_excluded_patterns = []
+ }
+ jar_excluded_patterns += [
+ "*/R.class",
+ "*/R\$*.class",
+ "*/Manifest.class",
+ "*/Manifest\$*.class",
+ ]
+ if (use_hashed_jni_names) {
+ jar_excluded_patterns += [ "J/N.class" ]
+ } else {
+ jar_excluded_patterns += [ "*/GEN_JNI.class" ]
+ }
+ }
+ }
+
+ # Declare an Android library target for a prebuilt jar
+ #
+ # This target creates an Android library containing java code and Android
+ # resources.
+ #
+ # Supports all variables of android_library().
+ #
+ # Example
+ # android_java_prebuilt("foo_java") {
+ # jar_path = "foo.jar"
+ # deps = [
+ # ":foo_resources",
+ # ":bar_java"
+ # ]
+ # }
+ template("android_java_prebuilt") {
+ android_library(target_name) {
+ forward_variables_from(invoker, "*")
+ }
+ }
+
+ template("android_system_java_prebuilt") {
+ java_library_impl(target_name) {
+ forward_variables_from(invoker, "*")
+ no_build_hooks = true
+ supports_android = true
+ type = "system_java_library"
+ }
+ }
+
+ # Creates org/chromium/base/BuildConfig.java
+ # This doesn't really belong in //build since it genates a file for //base.
+ # However, we don't currently have a better way to include this file in all
+ # apks that depend on //base:base_java.
+ #
+ # Variables:
+ # use_final_fields: True to use final fields. All other variables are
+ # ignored when this is false.
+ # build_config: Path to build_config used for locale list
+ # enable_multidex: Value for ENABLE_MULTIDEX.
+ # firebase_app_id: Value for FIREBASE_APP_ID.
+ # min_sdk_version: Value for MIN_SDK_VERSION.
+ #
+ template("generate_build_config_srcjar") {
+ java_cpp_template(target_name) {
+ package_path = "org/chromium/base"
+ sources = [
+ "//base/android/java/templates/BuildConfig.template",
+ ]
+ defines = []
+
+ # TODO(agrieve): These two are not target-specific and should be moved
+ # to BuildHooks.java.
+ # Set these even when !use_final_fields so that they have correct default
+ # values withnin junit_binary().
+ if (is_java_debug || dcheck_always_on) {
+ defines += [ "_DCHECK_IS_ON" ]
+ }
+ if (use_cfi_diag || is_ubsan || is_ubsan_security || is_ubsan_vptr) {
+ defines += [ "_IS_UBSAN" ]
+ }
+
+ if (invoker.use_final_fields) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "testonly",
+ ])
+ defines += [ "USE_FINAL" ]
+ if (invoker.enable_multidex) {
+ defines += [ "ENABLE_MULTIDEX" ]
+ }
+ inputs = [
+ invoker.build_config,
+ ]
+ _rebased_build_config =
+ rebase_path(invoker.build_config, root_build_dir)
+ defines += [
+ "COMPRESSED_LOCALE_LIST=" +
+ "@FileArg($_rebased_build_config:compressed_locales_java_list)",
+ "UNCOMPRESSED_LOCALE_LIST=" +
+ "@FileArg($_rebased_build_config:uncompressed_locales_java_list)",
+ ]
+ if (defined(invoker.firebase_app_id)) {
+ defines += [ "_FIREBASE_APP_ID=${invoker.firebase_app_id}" ]
+ }
+ if (defined(invoker.min_sdk_version)) {
+ defines += [ "_MIN_SDK_VERSION=${invoker.min_sdk_version}" ]
+ }
+ if (defined(invoker.resources_version_variable)) {
+ defines += [
+ "_RESOURCES_VERSION_VARIABLE=${invoker.resources_version_variable}",
+ ]
+ }
+ }
+ }
+ }
+
+ # Declare an Android app module target, which is used as the basis for an
+ # Android APK or an Android app bundle module.
+ #
+ # Supports all variables of android_library(), plus:
+ # android_manifest: Path to AndroidManifest.xml.
+ # android_manifest_dep: Target that generates AndroidManifest (if applicable)
+ # png_to_webp: If true, pngs (with the exception of 9-patch) are
+ # converted to webp during resource packaging.
+ # loadable_modules: List of paths to native libraries to include. Different
+ # from |shared_libraries| in that:
+ # * dependencies of this .so are not automatically included
+ # * ".cr.so" is never added
+ # * they are not side-loaded for _incremental targets.
+ # * load_library_from_apk, use_chromium_linker,
+ # and enable_relocation_packing do not apply
+ # Use this instead of shared_libraries when you are going to load the library
+ # conditionally, and only when shared_libraries doesn't work for you.
+ # secondary_abi_loadable_modules: This is the loadable_modules analog to
+ # secondary_abi_shared_libraries.
+ # shared_libraries: List shared_library targets to bundle. If these
+ # libraries depend on other shared_library targets, those dependencies will
+ # also be included in the apk (e.g. for is_component_build).
+ # secondary_abi_shared_libraries: secondary abi shared_library targets to
+ # bundle. If these libraries depend on other shared_library targets, those
+ # dependencies will also be included in the apk (e.g. for is_component_build).
+ # 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).
+ # write_asset_list: Adds an extra file to the assets, which contains a list of
+ # all other asset files.
+ # generate_buildconfig_java: If defined and false, skip generating the
+ # BuildConfig java class describing the build configuration. The default
+ # is true for non-test APKs.
+ # generate_final_jni: If defined and false, skip generating the
+ # GEN_JNI srcjar.
+ # jni_registration_header: If specified, causes the
+ # ${target_name}__final_jni target to additionally output a
+ # header file to this path for use with manual JNI registration.
+ # jni_sources_blacklist: List of source path to exclude from the
+ # final_jni step.
+ # firebase_app_id: The value for BuildConfig.FIREBASE_APP_ID (optional).
+ # Identifier is sent with crash reports to enable Java stack deobfuscation.
+ # aapt_locale_whitelist: If set, all locales not in this list will be
+ # stripped from resources.arsc.
+ # resource_blacklist_regex: Causes all drawable images matching the regex to
+ # be excluded (mipmaps are still included).
+ # resource_blacklist_exceptions: A list of globs used when
+ # resource_blacklist_regex is set. Files that match this whitelist will
+ # still be included.
+ # shared_resources: True if this is a runtime shared library APK, like
+ # the system_webview_apk target. Ensures that its resources can be
+ # used by the loading application process.
+ # app_as_shared_lib: True if this is a regular application apk that can
+ # also serve as a runtime shared library, like the monochrome_public_apk
+ # target. Ensures that the resources are usable both by the APK running
+ # as an application, or by another process that loads it at runtime.
+ # shared_resources_whitelist_target: Optional name of a target specifying
+ # an input R.txt file that lists the resources that can be exported
+ # by the APK when shared_resources or app_as_shared_lib is defined.
+ # uncompress_shared_libraries: True if shared libraries should be stored
+ # uncompressed in the APK. Must be unset or true if load_library_from_apk
+ # is set to true.
+ # uncompress_dex: Store final .dex files uncompressed in the apk.
+ # optimize_resources: True if resource names should be stripped from the
+ # resources.arsc file in the apk or module.
+ # resources_config_path: Path to the aapt2 optimize config file that tags
+ # resources with acceptable/non-acceptable optimizations.
+ # verify_android_configuration: Enables verification of expected merged
+ # manifest and proguard flags based on a golden file.
+ template("android_apk_or_module") {
+ forward_variables_from(invoker, [ "testonly" ])
+
+ assert(defined(invoker.final_apk_path) || defined(invoker.name))
+ assert(defined(invoker.android_manifest))
+ _gen_dir = "$target_gen_dir/$target_name"
+ _base_path = "$_gen_dir/$target_name"
+ _build_config = "$target_gen_dir/$target_name.build_config"
+ _build_config_target = "$target_name$build_config_target_suffix"
+
+ # Mark as used
+ assert(!defined(invoker.min_sdk_version) || invoker.min_sdk_version != 0)
+
+ # JUnit tests use resource zip files. These must not be put in gen/
+ # directory or they will not be available to tester bots.
+ _jar_path = "$_base_path.jar"
+ _lib_dex_path = "$_base_path.dex.jar"
+ _template_name = target_name
+
+ _is_bundle_module =
+ defined(invoker.is_bundle_module) && invoker.is_bundle_module
+ _is_base_module = defined(invoker.is_base_module) && invoker.is_base_module
+
+ _enable_multidex =
+ !defined(invoker.enable_multidex) || invoker.enable_multidex
+ _final_dex_path = "$_gen_dir/classes.dex.zip"
+
+ if (defined(invoker.final_apk_path)) {
+ _final_apk_path = invoker.final_apk_path
+ } else {
+ _final_apk_path = "$root_build_dir/apks/${invoker.name}.apk"
+ }
+ if (!_is_bundle_module) {
+ _final_rtxt_path = "${_final_apk_path}.R.txt"
+ }
+ _final_apk_path_no_ext_list =
+ process_file_template([ _final_apk_path ],
+ "{{source_dir}}/{{source_name_part}}")
+ _final_apk_path_no_ext = _final_apk_path_no_ext_list[0]
+ assert(_final_apk_path_no_ext != "") # Mark as used.
+
+ # Non-base bundle modules create only proto resources.
+ if (!_is_bundle_module || _is_base_module) {
+ _packaged_resources_path = "$target_out_dir/$target_name.ap_"
+ }
+ if (_is_bundle_module) {
+ # Path to the intermediate proto-format resources zip file.
+ _proto_resources_path = "$target_gen_dir/$target_name.proto.ap_"
+ } else {
+ # resource_sizes.py needs to be able to find the unpacked resources.arsc
+ # file based on apk name to compute normatlized size.
+ _resource_sizes_arsc_path =
+ "$root_out_dir/arsc/" +
+ rebase_path(_final_apk_path_no_ext, root_build_dir) + ".ap_"
+ }
+ _optimize_resources =
+ defined(invoker.optimize_resources) && invoker.optimize_resources
+ if (_optimize_resources) {
+ _optimized_resources_path = "$target_out_dir/$_template_name.optimized."
+ if (_is_bundle_module) {
+ _optimized_resources_path += ".proto.ap_"
+ } else {
+ _optimized_resources_path += ".ap_"
+ }
+ }
+
+ if (defined(invoker.version_code)) {
+ _version_code = invoker.version_code
+ } else {
+ _version_code = android_default_version_code
+ }
+
+ if (android_override_version_code != "") {
+ _version_code = android_override_version_code
+ }
+
+ if (defined(invoker.version_name)) {
+ _version_name = invoker.version_name
+ } else {
+ _version_name = android_default_version_name
+ }
+
+ if (android_override_version_name != "") {
+ _version_name = android_override_version_name
+ }
+
+ _deps = []
+ if (defined(invoker.deps)) {
+ _deps = invoker.deps
+ }
+
+ _srcjar_deps = []
+ if (defined(invoker.srcjar_deps)) {
+ _srcjar_deps = invoker.srcjar_deps
+ }
+
+ _use_build_hooks =
+ !defined(invoker.no_build_hooks) || !invoker.no_build_hooks
+ if (defined(invoker.build_hooks_android_impl_deps)) {
+ assert(_use_build_hooks,
+ "Cannot set no_build_hooks and build_hooks_android_impl_deps at " +
+ "the same time")
+ _deps += invoker.build_hooks_android_impl_deps
+ } else if (_use_build_hooks) {
+ _deps += [ "//build/android/buildhooks:build_hooks_android_impl_java" ]
+ }
+
+ _android_root_manifest_deps = []
+ if (defined(invoker.android_manifest_dep)) {
+ _android_root_manifest_deps = [ invoker.android_manifest_dep ]
+ }
+ _android_root_manifest = invoker.android_manifest
+
+ _use_chromium_linker =
+ defined(invoker.use_chromium_linker) && invoker.use_chromium_linker
+
+ _load_library_from_apk =
+ defined(invoker.load_library_from_apk) && invoker.load_library_from_apk
+
+ assert(_use_chromium_linker || true) # Mark as used.
+ assert(!_load_library_from_apk || _use_chromium_linker,
+ "load_library_from_apk requires use_chromium_linker")
+
+ # Make sure that uncompress_shared_libraries is set to true if
+ # load_library_from_apk is true.
+ if (defined(invoker.uncompress_shared_libraries)) {
+ _uncompress_shared_libraries = invoker.uncompress_shared_libraries
+ assert(!_load_library_from_apk || _uncompress_shared_libraries)
+ } else {
+ _uncompress_shared_libraries = _load_library_from_apk
+ }
+
+ # The dependency that makes the chromium linker, if any is needed.
+ _native_libs_deps = []
+ _shared_libraries_is_valid =
+ defined(invoker.shared_libraries) && invoker.shared_libraries != []
+ _secondary_abi_native_libs_deps = []
+ assert(_secondary_abi_native_libs_deps == []) # mark as used.
+ _secondary_abi_shared_libraries_is_valid =
+ defined(invoker.secondary_abi_shared_libraries) &&
+ invoker.secondary_abi_shared_libraries != []
+
+ if (_shared_libraries_is_valid) {
+ _native_libs_deps += invoker.shared_libraries
+
+ # To determine the filenames of all dependent shared libraries, write the
+ # runtime deps of |shared_libraries| to a file during "gn gen".
+ # write_build_config.py will then grep this file for *.so to obtain the
+ # complete list.
+ _runtime_deps_file =
+ "$target_gen_dir/${_template_name}.native.runtimedeps"
+ group("${_template_name}__runtime_deps") {
+ deps = _native_libs_deps
+ write_runtime_deps = _runtime_deps_file
+ }
+ } else {
+ # Must exist for instrumentation_test_apk() to depend on.
+ group("${_template_name}__runtime_deps") {
+ }
+ }
+
+ if (_secondary_abi_shared_libraries_is_valid) {
+ _secondary_abi_native_libs_deps += invoker.secondary_abi_shared_libraries
+
+ # To determine the filenames of all dependent shared libraries, write the
+ # runtime deps of |shared_libraries| to a file during "gn gen".
+ # write_build_config.py will then grep this file for *.so to obtain the
+ # complete list.
+ _secondary_abi_runtime_deps_file =
+ "$target_gen_dir/${_template_name}.secondary.abi.native.runtimedeps"
+ group("${_template_name}__secondary_abi__runtime_deps") {
+ deps = _secondary_abi_native_libs_deps
+ write_runtime_deps = _secondary_abi_runtime_deps_file
+ }
+ } else {
+ # Must exist for instrumentation_test_apk() to depend on.
+ group("${_template_name}__secondary_abi__runtime_deps") {
+ }
+ }
+
+ if (_shared_libraries_is_valid ||
+ _secondary_abi_shared_libraries_is_valid) {
+ _native_lib_version_rule = ""
+ if (defined(invoker.native_lib_version_rule)) {
+ _native_lib_version_rule = invoker.native_lib_version_rule
+ }
+ _native_lib_version_arg = "\"\""
+ if (defined(invoker.native_lib_version_arg)) {
+ _native_lib_version_arg = invoker.native_lib_version_arg
+ }
+ }
+
+ _rebased_build_config = rebase_path(_build_config, root_build_dir)
+ assert(_rebased_build_config != "") # Mark as used.
+
+ _generate_buildconfig_java = !defined(invoker.apk_under_test)
+ if (defined(invoker.generate_buildconfig_java)) {
+ _generate_buildconfig_java = invoker.generate_buildconfig_java
+ }
+
+ # JNI generation usually goes hand-in-hand with buildconfig generation.
+ _generate_final_jni = _generate_buildconfig_java
+ if (defined(invoker.generate_final_jni)) {
+ _generate_final_jni = invoker.generate_final_jni
+ }
+
+ _proguard_enabled =
+ defined(invoker.proguard_enabled) && invoker.proguard_enabled
+ if (_proguard_enabled) {
+ _proguard_mapping_path = "$_final_apk_path.mapping"
+ }
+
+ # TODO(crbug.com/864142): Allow incremental installs of bundle modules.
+ _incremental_allowed =
+ !_is_bundle_module &&
+ !(defined(invoker.never_incremental) && invoker.never_incremental)
+ if (_incremental_allowed) {
+ _target_dir_name = get_label_info(target_name, "dir")
+ _incremental_install_json_path = "$root_out_dir/gen.runtime/$_target_dir_name/$target_name.incremental.json"
+ }
+
+ _verify_android_configuration =
+ defined(invoker.verify_android_configuration) &&
+ invoker.verify_android_configuration && !is_java_debug
+ if (_verify_android_configuration) {
+ _target_src_dir = get_label_info(":$target_name", "dir")
+ }
+
+ _android_manifest =
+ "$target_gen_dir/${_template_name}_manifest/AndroidManifest.xml"
+ _merge_manifest_target = "${_template_name}__merge_manifests"
+ merge_manifests(_merge_manifest_target) {
+ input_manifest = _android_root_manifest
+ output_manifest = _android_manifest
+ build_config = _build_config
+ if (_verify_android_configuration) {
+ expected_manifest =
+ "$_target_src_dir/java/$_template_name.AndroidManifest.expected"
+ }
+ deps = _android_root_manifest_deps + [ ":$_build_config_target" ]
+ }
+
+ _final_deps = []
+
+ _enable_main_dex_list =
+ _enable_multidex &&
+ (!defined(invoker.min_sdk_version) || invoker.min_sdk_version < 21)
+ if (_enable_main_dex_list) {
+ _generated_proguard_main_dex_config =
+ "$_base_path.resources.main-dex-proguard.txt"
+ }
+ _generated_proguard_config = "$_base_path.resources.proguard.txt"
+
+ if (_generate_buildconfig_java &&
+ defined(invoker.product_version_resources_dep)) {
+ _deps += [ invoker.product_version_resources_dep ]
+ }
+
+ if (defined(invoker.alternative_android_sdk_dep)) {
+ _android_sdk_dep = invoker.alternative_android_sdk_dep
+ } else {
+ _android_sdk_dep = "//third_party/android_sdk:android_sdk_java"
+ }
+
+ if (defined(invoker.shared_resources_whitelist_target)) {
+ _whitelist_gen_dir =
+ get_label_info(invoker.shared_resources_whitelist_target,
+ "target_gen_dir")
+ _whitelist_target_name =
+ get_label_info(invoker.shared_resources_whitelist_target, "name")
+ _whitelist_r_txt_path =
+ "${_whitelist_gen_dir}/${_whitelist_target_name}" +
+ "__compile_resources_R.txt"
+ _whitelist_deps =
+ "${invoker.shared_resources_whitelist_target}__compile_resources"
+ }
+
+ _compile_resources_target = "${_template_name}__compile_resources"
+ _compile_resources_rtxt_out =
+ "${target_gen_dir}/${_compile_resources_target}_R.txt"
+ _compile_resources_emit_ids_out =
+ "${target_gen_dir}/${_compile_resources_target}.resource_ids"
+ compile_resources(_compile_resources_target) {
+ forward_variables_from(invoker,
+ [
+ "aapt_locale_whitelist",
+ "app_as_shared_lib",
+ "no_xml_namespaces",
+ "package_name",
+ "package_name_to_id_mapping",
+ "png_to_webp",
+ "resource_blacklist_exceptions",
+ "resource_blacklist_regex",
+ "resource_ids_provider_dep",
+ "resources_config_path",
+ "shared_resources",
+ "shared_resources_whitelist_locales",
+ "support_zh_hk",
+ ])
+ android_manifest = _android_manifest
+ version_code = _version_code
+ version_name = _version_name
+
+ if (defined(invoker.post_process_package_resources_script)) {
+ post_process_script = invoker.post_process_package_resources_script
+ }
+ srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
+ r_text_out_path = _compile_resources_rtxt_out
+ emit_ids_out_path = _compile_resources_emit_ids_out
+ proguard_file = _generated_proguard_config
+ if (_enable_main_dex_list) {
+ proguard_file_main_dex = _generated_proguard_main_dex_config
+ }
+
+ build_config = _build_config
+ deps = _deps + [
+ ":$_merge_manifest_target",
+ ":$_build_config_target",
+ _android_sdk_dep,
+ ]
+
+ if (defined(invoker.apk_under_test)) {
+ # Set the arsc package name to match the apk_under_test package name
+ # So that test resources can references under_test resources via
+ # @type/name syntax.
+ arsc_package_name =
+ "@FileArg($_rebased_build_config:resources:arsc_package_name)"
+
+ # Passing in the --emit-ids mapping will cause aapt2 to assign resources
+ # IDs that do not conflict with those from apk_under_test.
+ assert(!defined(resource_ids_provider_dep))
+ resource_ids_provider_dep = invoker.apk_under_test
+
+ deps += [ "${invoker.apk_under_test}__compile_resources" ]
+ include_resource =
+ get_label_info(invoker.apk_under_test, "target_out_dir") + "/" +
+ get_label_info(invoker.apk_under_test, "name") + ".ap_"
+ }
+
+ if (_is_bundle_module) {
+ proto_format = true
+ output = _proto_resources_path
+
+ if (defined(invoker.base_module_target)) {
+ deps += [ "${invoker.base_module_target}__compile_arsc_resources" ]
+ include_resource =
+ get_label_info(invoker.base_module_target, "target_out_dir") +
+ "/" + get_label_info(invoker.base_module_target, "name") + ".ap_"
+ }
+ } else {
+ output = _packaged_resources_path
+ }
+
+ if (_optimize_resources) {
+ optimized_resources_path = _optimized_resources_path
+ }
+
+ if (defined(invoker.shared_resources_whitelist_target)) {
+ # Used to ensure that the WebView resources are properly shared
+ # (i.e. are non-final and with package ID 0).
+ shared_resources_whitelist = _whitelist_r_txt_path
+ deps += [ _whitelist_deps ]
+ }
+ }
+ if (defined(_resource_sizes_arsc_path)) {
+ _copy_arsc_target = "${_template_name}__copy_arsc"
+ copy(_copy_arsc_target) {
+ deps = [
+ ":$_compile_resources_target",
+ ]
+
+ # resource_sizes.py doesn't care if it gets the optimized .arsc.
+ sources = [
+ _packaged_resources_path,
+ ]
+ outputs = [
+ _resource_sizes_arsc_path,
+ ]
+ }
+ _final_deps += [ ":$_copy_arsc_target" ]
+ }
+
+ if (!_is_bundle_module) {
+ # Output the R.txt file to a more easily discoverable location for
+ # archiving. This is necessary when stripping resource names so that we
+ # have an archive of resource names to ids for shipped apks (for
+ # debugging purposes). We copy the file rather than change the location
+ # of the original because other targets rely on the location of the R.txt
+ # file.
+ _copy_rtxt_target = "${_template_name}__copy_rtxt"
+ copy(_copy_rtxt_target) {
+ deps = [
+ ":$_compile_resources_target",
+ ]
+ sources = [
+ _compile_resources_rtxt_out,
+ ]
+ outputs = [
+ _final_rtxt_path,
+ ]
+ }
+ _final_deps += [ ":$_copy_rtxt_target" ]
+ }
+
+ if (_is_base_module && _is_bundle_module) {
+ # Bundle modules have to reference resources from the base module.
+ # However, to compile the bundle module's resources we have to give it an
+ # arsc resource to link against (aapt2 fails with proto resources). Thus,
+ # add an arsc resource compilation step to make the bundle module's link
+ # step work.
+ compile_resources("${_template_name}__compile_arsc_resources") {
+ forward_variables_from(invoker,
+ [
+ "support_zh_hk",
+ "aapt_locale_whitelist",
+ "resource_blacklist_regex",
+ "resource_blacklist_exceptions",
+ "png_to_webp",
+ "no_xml_namespaces",
+ ])
+ android_manifest = _android_manifest
+ version_code = _version_code
+ version_name = _version_name
+
+ proto_format = false
+ output = _packaged_resources_path
+
+ build_config = _build_config
+ deps = _deps + [
+ ":$_merge_manifest_target",
+ ":$_build_config_target",
+ _android_sdk_dep,
+ ]
+ }
+ }
+
+ _srcjar_deps += [ ":$_compile_resources_target" ]
+
+ if (_native_libs_deps != [] || _secondary_abi_native_libs_deps != []) {
+ _enable_chromium_linker_tests = false
+ if (defined(invoker.enable_chromium_linker_tests)) {
+ _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
+ }
+ _ordered_libraries_json =
+ "$target_gen_dir/$target_name.ordered_libraries.json"
+ _rebased_ordered_libraries_json =
+ rebase_path(_ordered_libraries_json, root_build_dir)
+ _ordered_libraries_target = "${_template_name}__write_ordered_libraries"
+
+ # TODO(agrieve): Make GN write runtime deps in dependency order so as to
+ # not need this manual sorting step.
+ action_with_pydeps(_ordered_libraries_target) {
+ script = "//build/android/gyp/write_ordered_libraries.py"
+ deps = [
+ ":$_build_config_target",
+ ":${_template_name}__runtime_deps",
+ ":${_template_name}__secondary_abi__runtime_deps",
+ ]
+ if (_native_libs_deps != []) {
+ _deps_file_to_use = _runtime_deps_file
+ } else {
+ _deps_file_to_use = _secondary_abi_runtime_deps_file
+ }
+ inputs = [
+ _deps_file_to_use,
+ ]
+ outputs = [
+ _ordered_libraries_json,
+ ]
+ _rebased_android_readelf = rebase_path(android_readelf, root_build_dir)
+ args = [
+ "--readelf=$_rebased_android_readelf",
+ "--output=$_rebased_ordered_libraries_json",
+ "--runtime-deps=" + rebase_path(_deps_file_to_use, root_build_dir),
+ ]
+ if (defined(invoker.dont_load_shared_libraries)) {
+ args += [ "--exclude-shared-libraries=" +
+ invoker.dont_load_shared_libraries ]
+ }
+ }
+
+ java_cpp_template("${_template_name}__native_libraries_srcjar") {
+ package_path = "org/chromium/base/library_loader"
+ sources = [
+ "//base/android/java/templates/NativeLibraries.template",
+ ]
+ inputs = [
+ _ordered_libraries_json,
+ ]
+ deps = [
+ ":${_ordered_libraries_target}",
+ ]
+ if (_native_lib_version_rule != "") {
+ deps += [ _native_lib_version_rule ]
+ }
+
+ defines = [
+ "NATIVE_LIBRARIES_LIST=" +
+ "@FileArg($_rebased_ordered_libraries_json:java_libraries_list)",
+ "NATIVE_LIBRARIES_VERSION_NUMBER=$_native_lib_version_arg",
+ ]
+ if (current_cpu == "arm" || current_cpu == "arm64") {
+ defines += [ "ANDROID_APP_CPU_FAMILY_ARM" ]
+ } else if (current_cpu == "x86" || current_cpu == "x64") {
+ defines += [ "ANDROID_APP_CPU_FAMILY_X86" ]
+ } else if (current_cpu == "mipsel" || current_cpu == "mips64el") {
+ defines += [ "ANDROID_APP_CPU_FAMILY_MIPS" ]
+ } else {
+ assert(false, "Unsupported CPU family")
+ }
+ if (_use_chromium_linker) {
+ defines += [ "ENABLE_CHROMIUM_LINKER" ]
+ }
+ if (_load_library_from_apk) {
+ defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
+ }
+ if (_enable_chromium_linker_tests) {
+ defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
+ }
+ }
+ _srcjar_deps += [ ":${_template_name}__native_libraries_srcjar" ]
+ }
+
+ _extra_native_libs = []
+ _extra_native_libs_deps = []
+ assert(_extra_native_libs_deps == []) # Mark as used.
+ if (_native_libs_deps != []) {
+ _extra_native_libs += _sanitizer_runtimes
+ if (_use_chromium_linker) {
+ _extra_native_libs +=
+ [ "$root_out_dir/libchromium_android_linker$shlib_extension" ]
+ _extra_native_libs_deps +=
+ [ "//base/android/linker:chromium_android_linker" ]
+ }
+ }
+
+ if (_generate_buildconfig_java) {
+ generate_build_config_srcjar("${_template_name}__build_config_srcjar") {
+ forward_variables_from(invoker,
+ [
+ "firebase_app_id",
+ "min_sdk_version",
+ ])
+ use_final_fields = true
+ build_config = _build_config
+ enable_multidex = _enable_multidex
+ if (defined(invoker.product_version_resources_dep)) {
+ resources_version_variable =
+ "org.chromium.base.R.string.product_version"
+ }
+ deps = [
+ ":$_build_config_target",
+ ]
+ }
+ _srcjar_deps += [ ":${_template_name}__build_config_srcjar" ]
+ }
+
+ if (_generate_final_jni) {
+ generate_jni_registration("${_template_name}__final_jni") {
+ target = ":$_template_name"
+ if (defined(invoker.jni_registration_header)) {
+ header_output = invoker.jni_registration_header
+ }
+ if (defined(invoker.jni_sources_blacklist)) {
+ sources_blacklist = invoker.jni_sources_blacklist
+ }
+ }
+ _srcjar_deps += [ ":${_template_name}__final_jni" ]
+ }
+
+ _java_target = "${_template_name}__java"
+ java_library_impl(_java_target) {
+ forward_variables_from(invoker,
+ [
+ "alternative_android_sdk_dep",
+ "android_manifest",
+ "android_manifest_dep",
+ "apk_under_test",
+ "base_module_target",
+ "chromium_code",
+ "classpath_deps",
+ "emma_never_instrument",
+ "java_files",
+ "javac_args",
+ "loadable_modules",
+ "native_lib_placeholders",
+ "no_build_hooks",
+ "secondary_abi_loadable_modules",
+ "secondary_native_lib_placeholders",
+ "static_library_dependent_targets",
+ ])
+ if (_is_bundle_module) {
+ type = "android_app_bundle_module"
+ } else {
+ type = "android_apk"
+ }
+ main_target_name = _template_name
+ supports_android = true
+ requires_android = true
+ deps = _deps
+
+ srcjar_deps = _srcjar_deps
+ final_jar_path = _jar_path
+ dex_path = _lib_dex_path
+ final_dex_path = _final_dex_path
+
+ if (_is_bundle_module) {
+ proto_resources_path = _proto_resources_path
+ module_rtxt_path = _compile_resources_rtxt_out
+ } else {
+ apk_path = _final_apk_path
+ incremental_allowed = _incremental_allowed
+ if (_incremental_allowed) {
+ incremental_apk_path = "${_final_apk_path_no_ext}_incremental.apk"
+ incremental_install_json_path = _incremental_install_json_path
+ }
+ }
+
+ proguard_enabled = _proguard_enabled
+ if (_proguard_enabled) {
+ proguard_configs = [ _generated_proguard_config ]
+ if (defined(invoker.proguard_configs)) {
+ proguard_configs += invoker.proguard_configs
+ }
+ if (_enable_main_dex_list) {
+ proguard_configs += [ "//build/android/multidex.flags" ]
+ }
+ proguard_mapping_path = _proguard_mapping_path
+ }
+
+ # Don't depend on the runtime_deps target in order to avoid having to
+ # build the native libraries just to create the .build_config file.
+ # The dep is unnecessary since the runtime_deps file is created by gn gen
+ # and the runtime_deps file is added to write_build_config.py's depfile.
+ if (_native_libs_deps != []) {
+ shared_libraries_runtime_deps_file = _runtime_deps_file
+ }
+ if (_secondary_abi_native_libs_deps != []) {
+ secondary_abi_shared_libraries_runtime_deps_file =
+ _secondary_abi_runtime_deps_file
+ }
+
+ extra_shared_libraries = _extra_native_libs
+
+ uncompress_shared_libraries = _uncompress_shared_libraries
+
+ if (defined(_whitelist_r_txt_path) && _is_bundle_module) {
+ # Used to write the file path to the target's .build_config only.
+ base_whitelist_rtxt_path = _whitelist_r_txt_path
+ }
+ }
+
+ # TODO(cjhopman): This is only ever needed to calculate the list of tests to
+ # run. See build/android/pylib/instrumentation/test_jar.py. We should be
+ # able to just do that calculation at build time instead.
+ if (defined(invoker.dist_ijar_path)) {
+ _dist_ijar_path = invoker.dist_ijar_path
+ dist_jar("${_template_name}_dist_ijar") {
+ override_build_config = _build_config
+ output = _dist_ijar_path
+ data = [
+ _dist_ijar_path,
+ ]
+ use_interface_jars = true
+ deps = [
+ ":$_build_config_target",
+ ":$_java_target",
+ ]
+ }
+ }
+
+ # Dex generation for app bundle modules with proguarding enabled takes
+ # place later due to synchronized proguarding. For more details,
+ # read build/android/docs/android_app_bundles.md
+ if (!(_is_bundle_module && _proguard_enabled)) {
+ _final_dex_target_name = "${_template_name}__final_dex"
+ dex(_final_dex_target_name) {
+ forward_variables_from(invoker,
+ [
+ "min_sdk_version",
+ "dexlayout_profile",
+ ])
+ proguard_enabled = _proguard_enabled
+ build_config = _build_config
+ deps = [
+ ":$_build_config_target",
+ ":$_java_target",
+ ]
+ if (_proguard_enabled) {
+ forward_variables_from(invoker, [ "proguard_jar_path" ])
+ deps += _deps + [ ":$_compile_resources_target" ]
+ proguard_mapping_path = _proguard_mapping_path
+ if (!defined(invoker.proguard_jar_path) &&
+ _verify_android_configuration) {
+ proguard_expectations_file =
+ "$_target_src_dir/java/$_template_name.proguard_flags.expected"
+ }
+ } else {
+ input_jars = [ _lib_dex_path ]
+ input_dex_classpath =
+ "${_rebased_build_config}:final_dex:dependency_dex_files"
+ if (_enable_main_dex_list) {
+ input_jar_classpath =
+ "${_rebased_build_config}:deps_info:java_runtime_classpath"
+ }
+ }
+
+ output = _final_dex_path
+ enable_multidex = _enable_multidex
+
+ if (_enable_main_dex_list) {
+ forward_variables_from(invoker, [ "negative_main_dex_globs" ])
+ extra_main_dex_proguard_config = _generated_proguard_main_dex_config
+ deps += [ ":$_compile_resources_target" ]
+ } else if (_enable_multidex) {
+ if (defined(invoker.negative_main_dex_globs)) {
+ not_needed(invoker, [ "negative_main_dex_globs" ])
+ }
+ }
+ }
+ } else {
+ # A small sanity check to help developers with a subtle point!
+ assert(
+ !defined(invoker.proguard_jar_path),
+ "proguard_jar_path should not be used for app bundle modules " +
+ "when proguard is enabled. Pass it to the android_app_bundle() " +
+ "target instead!")
+
+ _final_deps += [ ":$_java_target" ]
+ }
+
+ _extra_native_libs_even_when_incremental = []
+ assert(_extra_native_libs_even_when_incremental == []) # Mark as used.
+ if (_native_libs_deps != []) {
+ _create_stack_script_rule_name = "${_template_name}__stack_script"
+ _final_deps += [ ":${_create_stack_script_rule_name}" ]
+ stack_script(_create_stack_script_rule_name) {
+ stack_target_name = invoker.target_name
+ deps = _native_libs_deps
+ }
+ }
+
+ if (defined(invoker.loadable_modules) && invoker.loadable_modules != []) {
+ _extra_native_libs_even_when_incremental += invoker.loadable_modules
+ }
+
+ _all_native_libs_deps = []
+ if (_native_libs_deps != [] ||
+ _extra_native_libs_even_when_incremental != []) {
+ _native_libs_file_arg_dep = ":$_build_config_target"
+ if (!_is_bundle_module) {
+ _native_libs_file_arg =
+ "@FileArg($_rebased_build_config:native:libraries)"
+ }
+ _all_native_libs_deps += _native_libs_deps + _extra_native_libs_deps +
+ [ _native_libs_file_arg_dep ]
+ }
+
+ if (!_is_bundle_module) {
+ # Generate size-info/*.jar.info files.
+ if (defined(invoker.name)) {
+ # Create size info files for targets that care about size
+ # (have proguard enabled).
+ if (_proguard_enabled) {
+ _size_info_target = "${target_name}__size_info"
+ create_size_info_files(_size_info_target) {
+ name = "${invoker.name}.apk"
+ build_config = _build_config
+ packaged_resources_path = _packaged_resources_path
+ deps = _deps + [
+ ":$_build_config_target",
+ ":$_compile_resources_target",
+ ":$_java_target",
+ ]
+ }
+ _final_deps += [ ":$_size_info_target" ]
+ } else {
+ not_needed(invoker, [ "name" ])
+ }
+ }
+
+ _keystore_path = android_keystore_path
+ _keystore_name = android_keystore_name
+ _keystore_password = android_keystore_password
+
+ if (defined(invoker.keystore_path)) {
+ _keystore_path = invoker.keystore_path
+ _keystore_name = invoker.keystore_name
+ _keystore_password = invoker.keystore_password
+ }
+
+ _create_apk_target = "${_template_name}__create"
+ _final_deps += [ ":$_create_apk_target" ]
+ create_apk("$_create_apk_target") {
+ forward_variables_from(invoker,
+ [
+ "native_lib_placeholders",
+ "public_deps",
+ "secondary_native_lib_placeholders",
+ "shared_resources",
+ "write_asset_list",
+ "uncompress_dex",
+ ])
+ packaged_resources_path = _packaged_resources_path
+ if (_optimize_resources) {
+ optimized_resources_path = _optimized_resources_path
+ }
+
+ apk_path = _final_apk_path
+ assets_build_config = _build_config
+ dex_path = _final_dex_path
+ load_library_from_apk = _load_library_from_apk
+
+ keystore_name = _keystore_name
+ keystore_path = _keystore_path
+ keystore_password = _keystore_password
+
+ incremental_allowed = _incremental_allowed
+ if (_incremental_allowed) {
+ android_manifest = _android_manifest
+ base_path = _base_path
+ }
+
+ # Incremental apk does not use native libs nor final dex.
+ incremental_deps = _deps + [
+ ":$_merge_manifest_target",
+ ":$_build_config_target",
+ ":$_compile_resources_target",
+ ]
+
+ # This target generates the input file _all_resources_zip_path.
+ deps = _deps + [
+ ":$_merge_manifest_target",
+ ":$_build_config_target",
+ ":$_final_dex_target_name",
+ ":$_compile_resources_target",
+ ]
+
+ if (_native_libs_deps != [] ||
+ _extra_native_libs_even_when_incremental != []) {
+ native_libs_filearg = _native_libs_file_arg
+ native_libs = _extra_native_libs
+ native_libs_even_when_incremental =
+ _extra_native_libs_even_when_incremental
+ }
+ deps += _all_native_libs_deps
+ deps += _secondary_abi_native_libs_deps
+ secondary_abi_native_libs_filearg =
+ "@FileArg($_rebased_build_config:native:secondary_abi_libraries)"
+
+ uncompress_shared_libraries = _uncompress_shared_libraries
+ }
+ } else {
+ _final_deps += [
+ ":$_merge_manifest_target",
+ ":$_build_config_target",
+ ":$_compile_resources_target",
+ ] + _all_native_libs_deps + _secondary_abi_native_libs_deps
+ }
+
+ if (_incremental_allowed) {
+ _write_installer_json_rule_name = "${_template_name}__incremental_json"
+ action_with_pydeps(_write_installer_json_rule_name) {
+ script = "//build/android/incremental_install/write_installer_json.py"
+ deps = [
+ ":$_build_config_target",
+ ]
+
+ data = [
+ _incremental_install_json_path,
+ ]
+ inputs = [
+ _build_config,
+ ]
+ outputs = [
+ _incremental_install_json_path,
+ ]
+
+ _rebased_apk_path_no_ext =
+ rebase_path(_final_apk_path_no_ext, root_build_dir)
+ _rebased_incremental_install_json_path =
+ rebase_path(_incremental_install_json_path, root_build_dir)
+ _rebased_lib_dex_path = rebase_path(_lib_dex_path, root_build_dir)
+ _dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
+ args = [
+ "--apk-path=${_rebased_apk_path_no_ext}_incremental.apk",
+ "--output-path=$_rebased_incremental_install_json_path",
+ "--dex-file=$_rebased_lib_dex_path",
+ "--dex-file-list=@FileArg($_dex_arg_key)",
+ ]
+ if (_proguard_enabled) {
+ args += [ "--show-proguard-warning" ]
+ }
+ if (_native_libs_deps != []) {
+ args += [ "--native-libs=$_native_libs_file_arg" ]
+ deps += [ _native_libs_file_arg_dep ]
+ }
+ if (_extra_native_libs != []) {
+ _rebased_extra_native_libs =
+ rebase_path(_extra_native_libs, root_build_dir)
+ args += [ "--native-libs=$_rebased_extra_native_libs" ]
+ }
+ if (_load_library_from_apk) {
+ args += [ "--dont-even-try=Incremental builds do not work with load_library_from_apk. Try setting is_component_build=true in your GN args." ]
+ }
+ }
+ _incremental_apk_operations = []
+ }
+
+ _apk_operations = []
+
+ # Generate apk operation related script.
+ if (!_is_bundle_module &&
+ (!defined(invoker.create_apk_script) || invoker.create_apk_script)) {
+ _apk_operations_target_name = "${target_name}__apk_operations"
+ action_with_pydeps(_apk_operations_target_name) {
+ _generated_script = "$root_build_dir/bin/${invoker.target_name}"
+ script = "//build/android/gyp/create_apk_operations_script.py"
+ outputs = [
+ _generated_script,
+ ]
+ if (_proguard_enabled) {
+ # Required by logcat command.
+ data_deps = [
+ "//build/android/stacktrace:java_deobfuscate",
+ ]
+ }
+ args = [
+ "--script-output-path",
+ rebase_path(_generated_script, root_build_dir),
+ "--apk-path",
+ rebase_path(_final_apk_path, root_build_dir),
+ "--target-cpu=$target_cpu",
+ ]
+ if (defined(invoker.command_line_flags_file)) {
+ args += [
+ "--command-line-flags-file",
+ invoker.command_line_flags_file,
+ ]
+ }
+ if (_incremental_allowed) {
+ args += [
+ "--incremental-install-json-path",
+ rebase_path(_incremental_install_json_path, root_build_dir),
+ ]
+ }
+ if (_proguard_enabled) {
+ args += [
+ "--proguard-mapping-path",
+ rebase_path("$_final_apk_path.mapping", root_build_dir),
+ ]
+ }
+ }
+ _apk_operations += [ ":$_apk_operations_target_name" ]
+ if (_incremental_allowed) {
+ _incremental_apk_operations += [ ":$_apk_operations_target_name" ]
+ }
+ }
+
+ group(target_name) {
+ if (_incremental_allowed && incremental_apk_by_default) {
+ deps = [
+ ":${target_name}_incremental",
+ ]
+ assert(_apk_operations != [] || true) # Prevent "unused variable".
+ } else {
+ forward_variables_from(invoker,
+ [
+ "data",
+ "data_deps",
+ ])
+ public_deps = _final_deps
+
+ # Generate apk related operations at runtime.
+ public_deps += _apk_operations
+ }
+ }
+
+ if (_incremental_allowed) {
+ group("${target_name}_incremental") {
+ forward_variables_from(invoker,
+ [
+ "data",
+ "data_deps",
+ ])
+ if (!defined(data_deps)) {
+ data_deps = []
+ }
+
+ # device/commands is used by the installer script to push files via .zip.
+ data_deps += [ "//build/android/pylib/device/commands" ] +
+ _native_libs_deps + _extra_native_libs_deps
+
+ # Since the _incremental.apk does not include use .so nor .dex from the
+ # actual target, but instead loads them at runtime, we need to explicitly
+ # depend on them here.
+ public_deps = [
+ ":${_java_target}",
+ ":${_template_name}__create_incremental",
+ ":${_write_installer_json_rule_name}",
+ ]
+
+ # Generate incremental apk related operations at runtime.
+ public_deps += _incremental_apk_operations
+ }
+ }
+ }
+
+ # Declare an Android APK target
+ #
+ # This target creates an Android APK containing java code, resources, assets,
+ # and (possibly) native libraries.
+ #
+ # Supports all variables of android_apk_or_module(), plus:
+ # apk_name: Name for final apk.
+ #
+ # Example
+ # android_apk("foo_apk") {
+ # android_manifest = "AndroidManifest.xml"
+ # java_files = [
+ # "android/org/chromium/foo/FooApplication.java",
+ # "android/org/chromium/foo/FooActivity.java",
+ # ]
+ # deps = [
+ # ":foo_support_java"
+ # ":foo_resources"
+ # ]
+ # srcjar_deps = [
+ # ":foo_generated_enum"
+ # ]
+ # shared_libraries = [
+ # ":my_shared_lib",
+ # ]
+ # }
+ template("android_apk") {
+ android_apk_or_module(target_name) {
+ forward_variables_from(invoker,
+ [
+ "aapt_locale_whitelist",
+ "additional_jar_files",
+ "alternative_android_sdk_dep",
+ "android_manifest",
+ "android_manifest_dep",
+ "apk_under_test",
+ "app_as_shared_lib",
+ "build_hooks_android_impl_deps",
+ "chromium_code",
+ "classpath_deps",
+ "command_line_flags_file",
+ "create_apk_script",
+ "data",
+ "data_deps",
+ "deps",
+ "dexlayout_profile",
+ "dist_ijar_path",
+ "dont_load_shared_libraries",
+ "emit_resource_ids",
+ "emma_never_instrument",
+ "enable_chromium_linker_tests",
+ "enable_multidex",
+ "final_apk_path",
+ "firebase_app_id",
+ "generate_buildconfig_java",
+ "generate_final_jni",
+ "input_jars_paths",
+ "java_files",
+ "javac_args",
+ "jni_registration_header",
+ "jni_sources_blacklist",
+ "keystore_name",
+ "keystore_password",
+ "keystore_path",
+ "load_library_from_apk",
+ "loadable_modules",
+ "min_sdk_version",
+ "native_lib_placeholders",
+ "native_lib_version_arg",
+ "native_lib_version_rule",
+ "negative_main_dex_globs",
+ "never_incremental",
+ "no_build_hooks",
+ "no_xml_namespaces",
+ "optimize_resources",
+ "png_to_webp",
+ "post_process_package_resources_script",
+ "product_version_resources_dep",
+ "proguard_configs",
+ "proguard_enabled",
+ "verify_android_configuration",
+ "proguard_jar_path",
+ "resource_blacklist_regex",
+ "resource_blacklist_exceptions",
+ "resource_ids_provider_dep",
+ "resources_config_path",
+ "secondary_abi_loadable_modules",
+ "secondary_abi_shared_libraries",
+ "secondary_native_lib_placeholders",
+ "shared_libraries",
+ "shared_resources",
+ "shared_resources_whitelist_locales",
+ "shared_resources_whitelist_target",
+ "srcjar_deps",
+ "static_library_dependent_targets",
+ "support_zh_hk",
+ "testonly",
+ "uncompress_shared_libraries",
+ "uncompress_dex",
+ "use_chromium_linker",
+ "version_code",
+ "version_name",
+ "write_asset_list",
+ ])
+ is_bundle_module = false
+ if (defined(invoker.apk_name)) {
+ name = invoker.apk_name
+ }
+ }
+ }
+
+ # Declare an Android app bundle module target.
+ #
+ # The module can be used for an android_apk_or_module().
+ #
+ # Supports all variables of android_library(), plus:
+ # module_name: Name of the module.
+ # is_base_module: If defined and true, indicates that this is the bundle's
+ # base module (optional).
+ # base_module_target: Base module target of the bundle this module will be
+ # added to (optional). Can only be specified for non-base modules.
+ # native_switches: Forwarded switches to decide how to assign native
+ # libraries and placeholders (optional). Its members are:
+ # * is_64_bit_browser
+ # * include_32_bit_webview
+ # loadable_modules_if_32_bit: Native libraries to use if the binary ABI is
+ # 32-bit (optional).
+ # loadable_modules_if_64_bit: Native libraries to use if the binary ABI is
+ # 64-bit (optional).
+ template("android_app_bundle_module") {
+ _is_base_module = defined(invoker.is_base_module) && invoker.is_base_module
+
+ if (_is_base_module) {
+ assert(!defined(invoker.base_module_target))
+ } else {
+ assert(!defined(invoker.write_asset_list))
+ assert(!defined(invoker.firebase_app_id))
+ assert(!defined(invoker.app_as_shared_lib))
+ assert(!defined(invoker.shared_resources))
+ assert(!defined(invoker.shared_resources_whitelist_target))
+ assert(!defined(invoker.shared_resources_whitelist_locales))
+ assert(!defined(invoker.build_hooks_android_impl_deps))
+ assert(!defined(invoker.shared_libraries))
+ assert(defined(invoker.base_module_target))
+ }
+
+ # TODO(tiborg): We have several flags that are necessary for workarounds
+ # that come from the fact that the resources get compiled in the bundle
+ # module target, but bundle modules have to have certain flags in
+ # common or bundle modules have to know information about the base module.
+ # Those flags include version_code, version_name, and base_module_target.
+ # It would be better to move the resource compile target into the bundle
+ # target. Doing so would keep the bundle modules independent from the bundle
+ # and potentially reuse the same bundle modules for multiple bundles.
+ android_apk_or_module(target_name) {
+ forward_variables_from(invoker,
+ [
+ "aapt_locale_whitelist",
+ "additional_jar_files",
+ "alternative_android_sdk_dep",
+ "android_manifest",
+ "android_manifest_dep",
+ "app_as_shared_lib",
+ "base_module_target",
+ "chromium_code",
+ "classpath_deps",
+ "data",
+ "data_deps",
+ "deps",
+ "emma_never_instrument",
+ "enable_chromium_linker_tests",
+ "enable_multidex",
+ "firebase_app_id",
+ "generate_buildconfig_java",
+ "generate_final_jni",
+ "input_jars_paths",
+ "is_base_module",
+ "java_files",
+ "javac_args",
+ "jni_registration_header",
+ "jni_sources_blacklist",
+ "load_library_from_apk",
+ "min_sdk_version",
+ "native_lib_version_arg",
+ "native_lib_version_rule",
+ "negative_main_dex_globs",
+ "no_xml_namespaces",
+ "optimize_resources",
+ "package_name",
+ "package_name_to_id_mapping",
+ "png_to_webp",
+ "product_version_resources_dep",
+ "proguard_configs",
+ "proguard_enabled",
+ "proguard_jar_path",
+ "resource_blacklist_exceptions",
+ "resource_blacklist_regex",
+ "resources_config_path",
+ "secondary_abi_shared_libraries",
+ "shared_libraries",
+ "shared_resources",
+ "shared_resources_whitelist_locales",
+ "shared_resources_whitelist_target",
+ "srcjar_deps",
+ "support_zh_hk",
+ "testonly",
+ "uncompress_shared_libraries",
+ "use_chromium_linker",
+ "verify_android_configuration",
+ "version_code",
+ "version_name",
+ "write_asset_list",
+ ])
+
+ # Specify native libraries and placeholders.
+ if (defined(invoker.native_switches)) {
+ assert(invoker.loadable_modules_if_32_bit != [])
+ assert(invoker.loadable_modules_if_64_bit != [])
+
+ # Decision logic: Assign decision variables:
+ # loadable_modules_to_use: Either |loadable_modules_if_64_bit| or
+ # |loadable_modules_if_32_bit|.
+ # native_is_primary: Whether |loadable_modules_to_use| should be
+ # assigned as primary ABI or secondary ABI.
+ # native_need_placeholder: Whether a placeholder is needed for the
+ # complementary ABI to the library.
+ _native_switches = invoker.native_switches
+ if (_native_switches.is_64_bit_browser) {
+ _loadable_modules_to_use = invoker.loadable_modules_if_64_bit
+ _native_is_primary =
+ !build_apk_secondary_abi || android_64bit_target_cpu
+ _native_need_placeholder =
+ build_apk_secondary_abi && _native_switches.include_32_bit_webview
+ } else {
+ _loadable_modules_to_use = invoker.loadable_modules_if_32_bit
+ _native_is_primary =
+ !build_apk_secondary_abi || !android_64bit_target_cpu
+ _native_need_placeholder =
+ build_apk_secondary_abi && android_64bit_target_cpu
+ }
+
+ # Realization logic: Assign libraries and placeholders.
+ if (_native_is_primary) {
+ loadable_modules = _loadable_modules_to_use
+ if (_native_need_placeholder) {
+ secondary_native_lib_placeholders = [ "libdummy.so" ]
+ }
+ } else {
+ secondary_abi_loadable_modules = _loadable_modules_to_use
+ if (_native_need_placeholder) {
+ native_lib_placeholders = [ "libdummy.so" ]
+ }
+ }
+ } else {
+ assert(!defined(invoker.loadable_modules_if_32_bit))
+ assert(!defined(invoker.loadable_modules_if_64_bit))
+ forward_variables_from(invoker,
+ [
+ "loadable_modules",
+ "native_lib_placeholders",
+ "secondary_abi_loadable_modules",
+ "secondary_native_lib_placeholders",
+ ])
+ }
+
+ is_bundle_module = true
+ generate_buildconfig_java = _is_base_module
+ no_build_hooks = !_is_base_module
+ if (defined(invoker.module_name)) {
+ name = invoker.module_name
+ }
+ }
+ }
+
+ # Declare an Android instrumentation test apk
+ #
+ # This target creates an Android instrumentation test apk.
+ #
+ # Supports all variables of android_apk(), plus:
+ # apk_under_test: The apk being tested (optional).
+ #
+ # Example
+ # instrumentation_test_apk("foo_test_apk") {
+ # android_manifest = "AndroidManifest.xml"
+ # apk_name = "FooTest"
+ # apk_under_test = "Foo"
+ # java_files = [
+ # "android/org/chromium/foo/FooTestCase.java",
+ # "android/org/chromium/foo/FooExampleTest.java",
+ # ]
+ # deps = [
+ # ":foo_test_support_java"
+ # ]
+ # }
+ template("instrumentation_test_apk") {
+ assert(defined(invoker.apk_name))
+ testonly = true
+ _incremental_allowed =
+ !defined(invoker.never_incremental) || !invoker.never_incremental
+ _apk_target_name = "${target_name}__apk"
+ _test_runner_target_name = "${target_name}__test_runner_script"
+ _dist_ijar_path =
+ "$root_build_dir/test.lib.java/" + invoker.apk_name + ".jar"
+ if (_incremental_allowed) {
+ _incremental_test_runner_target_name =
+ "${_test_runner_target_name}_incremental"
+ _incremental_test_name = "${invoker.target_name}_incremental"
+ }
+
+ if (incremental_apk_by_default && _incremental_allowed) {
+ _incremental_test_runner_target_name = _test_runner_target_name
+ _incremental_test_name = invoker.target_name
+ }
+
+ if (!incremental_apk_by_default ||
+ (incremental_apk_by_default && !_incremental_allowed)) {
+ test_runner_script(_test_runner_target_name) {
+ forward_variables_from(invoker,
+ [
+ "additional_apks",
+ "apk_under_test",
+ "data",
+ "data_deps",
+ "deps",
+ "ignore_all_data_deps",
+ "proguard_enabled",
+ "public_deps",
+ ])
+ test_name = invoker.target_name
+ test_type = "instrumentation"
+ apk_target = ":$_apk_target_name"
+ test_jar = _dist_ijar_path
+ }
+ }
+ if (_incremental_allowed) {
+ test_runner_script(_incremental_test_runner_target_name) {
+ forward_variables_from(invoker,
+ [
+ "additional_apks",
+ "apk_under_test",
+ "data",
+ "data_deps",
+ "deps",
+ "ignore_all_data_deps",
+ "public_deps",
+ ])
+ test_name = _incremental_test_name
+ test_type = "instrumentation"
+ apk_target = ":$_apk_target_name"
+ test_jar = _dist_ijar_path
+ incremental_install = true
+ }
+ }
+
+ android_apk(_apk_target_name) {
+ deps = []
+ data_deps = []
+ forward_variables_from(invoker, "*")
+ deps += [ "//testing/android/broker:broker_java" ]
+ data_deps += [
+ "//build/android/pylib/device/commands",
+ "//tools/android/forwarder2",
+ "//tools/android/md5sum",
+ ]
+ if (defined(invoker.apk_under_test)) {
+ data_deps += [ invoker.apk_under_test ]
+ }
+ if (defined(invoker.additional_apks)) {
+ data_deps += invoker.additional_apks
+ }
+ if (defined(invoker.apk_under_test)) {
+ # Prevent a build_hooks_android_impl exising in both the test apks as
+ # well as the apk_under_test.
+ no_build_hooks = true
+ }
+
+ if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) {
+ # When ProGuard is on, we use ProGuard to combine the under test java
+ # code and the test java code. This is to allow us to apply all ProGuard
+ # optimizations that we ship with, but not have them break tests. The
+ # apk under test will still have the same resources, assets, and
+ # manifest, all of which are the ones used in the tests.
+ if (!defined(invoker.proguard_configs)) {
+ proguard_configs = []
+ }
+ proguard_configs += [ "//testing/android/proguard_for_test.flags" ]
+ if (defined(final_apk_path)) {
+ _final_apk_path = final_apk_path
+ } else {
+ _final_apk_path = "$root_build_dir/apks/${apk_name}.apk"
+ }
+ data = [
+ "$_final_apk_path.mapping",
+ ]
+ data_deps += [ "//build/android/stacktrace:java_deobfuscate" ]
+ }
+
+ dist_ijar_path = _dist_ijar_path
+ create_apk_script = false
+ }
+
+ group(target_name) {
+ if (incremental_apk_by_default && _incremental_allowed) {
+ public_deps = [
+ ":${target_name}_incremental",
+ ]
+ } else {
+ public_deps = [
+ ":$_apk_target_name",
+ ":$_test_runner_target_name",
+
+ # Required by test runner to enumerate test list.
+ ":${_apk_target_name}_dist_ijar",
+ ]
+ if (defined(invoker.apk_under_test)) {
+ public_deps += [ invoker.apk_under_test ]
+ }
+ }
+
+ # Ensure unstripped libraries are included in runtime deps so that
+ # symbolization can be done.
+ deps = [
+ ":${_apk_target_name}__runtime_deps",
+ ":${_apk_target_name}__secondary_abi__runtime_deps",
+ ]
+ if (defined(invoker.apk_under_test)) {
+ _under_test_label =
+ get_label_info(invoker.apk_under_test, "label_no_toolchain")
+ deps += [
+ "${_under_test_label}__runtime_deps",
+ "${_under_test_label}__secondary_abi__runtime_deps",
+ ]
+ }
+ }
+
+ if (_incremental_allowed) {
+ group("${target_name}_incremental") {
+ public_deps = [
+ ":$_incremental_test_runner_target_name",
+ ":${_apk_target_name}_dist_ijar",
+ ":${_apk_target_name}_incremental",
+ ]
+ if (defined(invoker.apk_under_test)) {
+ public_deps += [ "${invoker.apk_under_test}_incremental" ]
+ }
+ }
+ }
+ }
+
+ # Declare an Android gtest apk
+ #
+ # This target creates an Android apk for running gtest-based unittests.
+ #
+ # Variables
+ # deps: Specifies the dependencies of this target. These will be passed to
+ # the underlying android_apk invocation and should include the java and
+ # resource dependencies of the apk.
+ # shared_library: shared_library target that contains the unit tests.
+ # apk_name: The name of the produced apk. If unspecified, it uses the name
+ # of the shared_library target suffixed with "_apk"
+ # use_default_launcher: Whether the default activity (NativeUnitTestActivity)
+ # should be used for launching tests.
+ # use_native_activity: Test implements ANativeActivity_onCreate().
+ #
+ # Example
+ # unittest_apk("foo_unittests_apk") {
+ # deps = [ ":foo_java", ":foo_resources" ]
+ # shared_library = ":foo_unittests"
+ # }
+ template("unittest_apk") {
+ _use_native_activity =
+ defined(invoker.use_native_activity) && invoker.use_native_activity
+ _android_manifest = "$target_gen_dir/$target_name/AndroidManifest.xml"
+ assert(invoker.shared_library != "")
+
+ # This trivial assert is needed in case android_manifest is defined,
+ # as otherwise _use_native_activity and _android_manifest would not be used.
+ assert(_use_native_activity != "" && _android_manifest != "")
+
+ if (!defined(invoker.android_manifest)) {
+ jinja_template("${target_name}_manifest") {
+ _native_library_name = get_label_info(invoker.shared_library, "name")
+ input = "//testing/android/native_test/java/AndroidManifest.xml.jinja2"
+ output = _android_manifest
+ variables = [
+ "is_component_build=${is_component_build}",
+ "native_library_name=${_native_library_name}",
+ "use_native_activity=${_use_native_activity}",
+ ]
+ }
+ }
+
+ android_apk(target_name) {
+ data_deps = []
+ forward_variables_from(invoker, "*")
+ testonly = true
+ create_apk_script = false
+
+ assert(!defined(invoker.proguard_enabled) || !invoker.proguard_enabled ||
+ invoker.proguard_configs != [])
+
+ if (!defined(apk_name)) {
+ apk_name = get_label_info(invoker.shared_library, "name")
+ }
+
+ if (!defined(android_manifest)) {
+ android_manifest_dep = ":${target_name}_manifest"
+ android_manifest = _android_manifest
+ }
+
+ final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
+
+ if (!defined(use_default_launcher) || use_default_launcher) {
+ deps += [ "//testing/android/native_test:native_test_java" ]
+ }
+ shared_libraries = [ invoker.shared_library ]
+ deps += [
+ ":${target_name}__runtime_deps",
+ ":${target_name}__secondary_abi__runtime_deps",
+ "//base:base_java",
+ "//testing/android/reporter:reporter_java",
+ ]
+ data_deps += [
+ "//build/android/pylib/device/commands",
+ "//tools/android/md5sum",
+ ]
+ if (host_os == "linux") {
+ data_deps += [ "//tools/android/forwarder2" ]
+ }
+ }
+ }
+
+ # Generate .java files from .aidl files.
+ #
+ # This target will store the .java files in a srcjar and should be included in
+ # an android_library or android_apk's srcjar_deps.
+ #
+ # Variables
+ # sources: Paths to .aidl files to compile.
+ # import_include: Path to directory containing .java files imported by the
+ # .aidl files.
+ # interface_file: Preprocessed aidl file to import.
+ #
+ # Example
+ # android_aidl("foo_aidl") {
+ # import_include = "java/src"
+ # sources = [
+ # "java/src/com/foo/bar/FooBarService.aidl",
+ # "java/src/com/foo/bar/FooBarServiceCallback.aidl",
+ # ]
+ # }
+ template("android_aidl") {
+ action_with_pydeps(target_name) {
+ set_sources_assignment_filter([])
+ forward_variables_from(invoker, [ "testonly" ])
+
+ script = "//build/android/gyp/aidl.py"
+ sources = invoker.sources
+
+ _srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
+ _aidl_path = "${android_sdk_build_tools}/aidl"
+ _framework_aidl = "$android_sdk/framework.aidl"
+ _imports = [ _framework_aidl ]
+ if (defined(invoker.interface_file)) {
+ assert(invoker.interface_file != "")
+ _imports += [ invoker.interface_file ]
+ }
+
+ inputs = [ _aidl_path ] + _imports
+
+ outputs = [
+ _srcjar_path,
+ ]
+ _rebased_imports = rebase_path(_imports, root_build_dir)
+ args = [
+ "--aidl-path",
+ rebase_path(_aidl_path, root_build_dir),
+ "--imports=$_rebased_imports",
+ "--srcjar",
+ rebase_path(_srcjar_path, root_build_dir),
+ ]
+ if (defined(invoker.import_include) && invoker.import_include != []) {
+ # TODO(cjhopman): aidl supports creating a depfile. We should be able to
+ # switch to constructing a depfile for the overall action from that
+ # instead of having all the .java files in the include paths as inputs.
+ _rebased_import_paths = []
+ foreach(_import_path, invoker.import_include) {
+ _rebased_import_path = []
+ _rebased_import_path = [ rebase_path(_import_path, root_build_dir) ]
+ _rebased_import_paths += _rebased_import_path
+ _java_files_build_rel = []
+ _java_files_build_rel =
+ exec_script("//build/android/gyp/find.py",
+ [ "--pattern=*.java" ] + _rebased_import_path,
+ "list lines")
+ inputs += rebase_path(_java_files_build_rel, ".", root_build_dir)
+ }
+ args += [ "--includes=$_rebased_import_paths" ]
+ }
+ args += rebase_path(sources, root_build_dir)
+ }
+ }
+
+ # Compile a protocol buffer to java.
+ #
+ # This generates java files from protocol buffers and creates an Android library
+ # containing the classes.
+ #
+ # Variables
+ # sources (required)
+ # Paths to .proto files to compile.
+ #
+ # proto_path (required)
+ # Root directory of .proto files.
+ #
+ # generate_nano (optional, default false)
+ # Whether to generate nano protos. If false, this will use the lite proto generator.
+ # Nano protos are deprecated, so please use lite new proto libraries.
+ #
+ # Example:
+ # proto_java_library("foo_proto_java") {
+ # proto_path = "src/foo"
+ # sources = [ "$proto_path/foo.proto" ]
+ # }
+ template("proto_java_library") {
+ set_sources_assignment_filter([])
+ forward_variables_from(invoker, [ "testonly" ])
+ _generate_nano =
+ defined(invoker.generate_nano) && invoker.generate_nano == true
+
+ if (_generate_nano) {
+ # Use the legacy Android nano proto generator.
+ _protoc_dep =
+ "//third_party/android_protobuf:android_protoc($host_toolchain)"
+ _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
+ _protoc_bin = "$_protoc_out_dir/android_protoc"
+ _proto_runtime = "//third_party/android_protobuf:protobuf_nano_javalib"
+ } else {
+ # Use the regular proto library to generate lite protos.
+ _protoc_dep = "//third_party/protobuf:protoc($host_toolchain)"
+ _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
+ _protoc_bin = "$_protoc_out_dir/protoc"
+ _proto_runtime =
+ "//third_party/android_deps:com_google_protobuf_protobuf_lite_java"
+ _protoc_javalite_plugin_dir = "//third_party/protoc_javalite/"
+ }
+ _proto_path = invoker.proto_path
+ _template_name = target_name
+
+ action_with_pydeps("${_template_name}__protoc_java") {
+ _srcjar_path = "$target_gen_dir/$target_name.srcjar"
+ script = "//build/protoc_java.py"
+
+ deps = [
+ _protoc_dep,
+ ]
+ if (defined(invoker.deps)) {
+ deps += invoker.deps
+ }
+
+ sources = invoker.sources
+ depfile = "$target_gen_dir/$target_name.d"
+ outputs = [
+ _srcjar_path,
+ ]
+ args = [
+ "--depfile",
+ rebase_path(depfile, root_build_dir),
+ "--protoc",
+ rebase_path(_protoc_bin, root_build_dir),
+ "--proto-path",
+ rebase_path(_proto_path, root_build_dir),
+ "--srcjar",
+ rebase_path(_srcjar_path, root_build_dir),
+ ] + rebase_path(sources, root_build_dir)
+ if (_generate_nano) {
+ args += [ "--nano" ]
+ } else {
+ args += [
+ "--protoc-javalite-plugin-dir",
+ rebase_path(_protoc_javalite_plugin_dir, root_build_dir),
+ ]
+ }
+ }
+
+ android_library(target_name) {
+ chromium_code = false
+ java_files = []
+ srcjar_deps = [ ":${_template_name}__protoc_java" ]
+ deps = [
+ _proto_runtime,
+ ]
+ }
+ }
+
+ # Declare an Android library target for a prebuilt AAR.
+ #
+ # This target creates an Android library containing java code and Android
+ # resources. For libraries without resources, it will not generate
+ # corresponding android_resources targets.
+ #
+ # To avoid slowing down "gn gen", an associated .info file must be committed
+ # along with the .aar file. In order to create this file, define the target
+ # and then run once with the gn arg "update_android_aar_prebuilts = true".
+ #
+ # Variables
+ # aar_path: Path to the AAR.
+ # info_path: Path to the .aar.info file (generated via
+ # update_android_aar_prebuilts GN arg).
+ # proguard_configs: List of proguard configs to use in final apk step for
+ # any apk that depends on this library.
+ # ignore_aidl: Whether to ignore .aidl files found with the .aar.
+ # ignore_assets: Whether to ignore assets found in the .aar.
+ # ignore_native_libraries: Whether to ignore .so files found in the .aar.
+ # See also extract_native_libraries.
+ # extract_native_libraries: Whether to extract .so files found in the .aar.
+ # If the file contains .so, either extract_native_libraries or
+ # ignore_native_libraries must be set.
+ # split_compat_class_names: Names of the classes that will have their
+ # bytecode rewritten to inject the call to SplitCompat.install().
+ # Used to make dependencies compatible with SplitCompat to immediately
+ # access resources brought in by the modules.
+ # create_srcjar: If false, does not create an R.java file.
+ # TODO(jbudorick@): remove this arguments after crbug.com/522043 is fixed.
+ # requires_android: Whether this target can only be used for compiling
+ # Android related targets.
+ #
+ # Example
+ # android_aar_prebuilt("foo_java") {
+ # aar_path = "foo.aar"
+ # }
+ template("android_aar_prebuilt") {
+ _info_path = "$target_name.info"
+ if (defined(invoker.info_path)) {
+ _info_path = invoker.info_path
+ }
+ _output_path = "${target_gen_dir}/${target_name}"
+ _unpack_target_name = "${target_name}__unpack_aar"
+ _ignore_aidl = defined(invoker.ignore_aidl) && invoker.ignore_aidl
+ _ignore_assets = defined(invoker.ignore_assets) && invoker.ignore_assets
+ _ignore_native_libraries = defined(invoker.ignore_native_libraries) &&
+ invoker.ignore_native_libraries
+ _extract_native_libraries = defined(invoker.extract_native_libraries) &&
+ invoker.extract_native_libraries
+
+ # Scan the AAR file and determine the resources and jar files.
+ # Some libraries might not have resources; others might have two jars.
+ if (update_android_aar_prebuilts) {
+ print("Writing " + rebase_path(_info_path, "//"))
+ exec_script("//build/android/gyp/aar.py",
+ [
+ "list",
+ rebase_path(invoker.aar_path, root_build_dir),
+ "--output",
+ rebase_path(_info_path, root_build_dir),
+ ])
+ }
+
+ # If "gn gen" is failing on the following line, you need to generate an
+ # .info file for your new target by running:
+ # gn gen --args='target_os="android" update_android_aar_prebuilts=true' out/tmp
+ # rm -r out/tmp
+ _scanned_files = read_file(_info_path, "scope")
+
+ assert(_ignore_aidl || _scanned_files.aidl == [],
+ "android_aar_prebuilt() aidl not yet supported." +
+ " Implement or use ignore_aidl = true." +
+ " http://crbug.com/644439")
+ assert(_ignore_assets || _scanned_files.assets == [],
+ "android_aar_prebuilt() assets not yet supported." +
+ " Implement or use ignore_assets = true." +
+ " http://crbug.com/643966")
+ assert(
+ !_scanned_files.has_native_libraries ||
+ (_ignore_native_libraries || _extract_native_libraries),
+ "android_aar_prebuilt() contains .so files." +
+ " Please set ignore_native_libraries or extract_native_libraries.")
+ assert(
+ !(_ignore_native_libraries && _extract_native_libraries),
+ "ignore_native_libraries and extract_native_libraries cannot both be set.")
+ assert(!_scanned_files.has_native_libraries ||
+ _scanned_files.native_libraries != [])
+ assert(_scanned_files.has_classes_jar || _scanned_files.subjars == [])
+
+ action_with_pydeps(_unpack_target_name) {
+ script = "//build/android/gyp/aar.py" # Unzips the AAR
+ args = [
+ "extract",
+ rebase_path(invoker.aar_path, root_build_dir),
+ "--output-dir",
+ rebase_path(_output_path, root_build_dir),
+ "--assert-info-file",
+ rebase_path(_info_path, root_build_dir),
+ ]
+ inputs = [
+ invoker.aar_path,
+ ]
+ outputs = [
+ "${_output_path}/AndroidManifest.xml",
+ ]
+
+ if (_scanned_files.has_r_text_file) {
+ # Certain packages, in particular Play Services have no R.txt even
+ # though its presence is mandated by AAR spec. Such packages cause
+ # spurious rebuilds if this output is specified unconditionally.
+ outputs += [ "${_output_path}/R.txt" ]
+ }
+
+ if (_scanned_files.resources != []) {
+ outputs += get_path_info(
+ rebase_path(_scanned_files.resources, "", _output_path),
+ "abspath")
+ }
+ if (_scanned_files.has_classes_jar) {
+ outputs += [ "${_output_path}/classes.jar" ]
+ }
+ outputs +=
+ get_path_info(rebase_path(_scanned_files.subjars, "", _output_path),
+ "abspath")
+ if (_scanned_files.has_proguard_flags) {
+ outputs += [ "${_output_path}/proguard.txt" ]
+ }
+
+ if (_extract_native_libraries && _scanned_files.has_native_libraries) {
+ outputs += get_path_info(
+ rebase_path(_scanned_files.native_libraries, "", _output_path),
+ "abspath")
+ }
+ }
+
+ _strip_resources =
+ defined(invoker.strip_resources) && invoker.strip_resources
+ _has_unignored_resources =
+ !_strip_resources &&
+ (_scanned_files.resources != [] || _scanned_files.has_r_text_file)
+
+ # Create the android_resources target for resources.
+ if (_has_unignored_resources || !_scanned_files.is_manifest_empty) {
+ _res_target_name = "${target_name}__res"
+ android_resources(_res_target_name) {
+ forward_variables_from(invoker,
+ [
+ "create_srcjar",
+ "deps",
+ "testonly",
+ "strip_drawables",
+ ])
+ if (!defined(deps)) {
+ deps = []
+ }
+ deps += [ ":$_unpack_target_name" ]
+ android_manifest_dep = ":$_unpack_target_name"
+ android_manifest = "${_output_path}/AndroidManifest.xml"
+ resource_dirs = []
+ generated_resource_dirs = []
+ if (!_strip_resources && _scanned_files.resources != []) {
+ generated_resource_dirs += [ "${_output_path}/res" ]
+ }
+ generated_resource_files = []
+ if (!_strip_resources) {
+ generated_resource_files =
+ rebase_path(_scanned_files.resources, "", _output_path)
+ }
+ if (!_strip_resources && _scanned_files.has_r_text_file) {
+ r_text_file = "${_output_path}/R.txt"
+ }
+ v14_skip = true
+ }
+ } else if (defined(invoker.strip_drawables)) {
+ not_needed(invoker, [ "strip_drawables" ])
+ }
+
+ # Create android_java_prebuilt target for extra jars within jars/.
+ _subjar_targets = []
+ foreach(_tuple, _scanned_files.subjar_tuples) {
+ _current_target = "${target_name}__subjar_${_tuple[0]}"
+ _subjar_targets += [ ":$_current_target" ]
+ java_prebuilt(_current_target) {
+ forward_variables_from(invoker,
+ [
+ "jar_excluded_patterns",
+ "jar_included_patterns",
+ "requires_android",
+ ])
+ deps = [
+ ":$_unpack_target_name",
+ ]
+ if (!defined(requires_android)) {
+ requires_android = true
+ }
+ supports_android = true
+ jar_path = "$_output_path/${_tuple[1]}"
+ _base_output_name = get_path_info(jar_path, "name")
+ output_name = "${invoker.target_name}-$_base_output_name"
+ }
+ }
+
+ # Create android_java_prebuilt target for classes.jar.
+ if (_scanned_files.has_classes_jar) {
+ _jar_target_name = "${target_name}__classes"
+ java_prebuilt(_jar_target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "input_jars_paths",
+ "jar_excluded_patterns",
+ "jar_included_patterns",
+ "proguard_configs",
+ "requires_android",
+ "split_compat_class_names",
+ "testonly",
+ ])
+ if (!defined(deps)) {
+ deps = []
+ }
+ deps += _subjar_targets + [ ":$_unpack_target_name" ]
+ if (defined(_res_target_name)) {
+ deps += [ ":$_res_target_name" ]
+ }
+ if (!defined(requires_android)) {
+ requires_android = true
+ }
+ supports_android = true
+ jar_path = "$_output_path/classes.jar"
+ output_name = invoker.target_name
+
+ if (_scanned_files.has_proguard_flags) {
+ if (!defined(proguard_configs)) {
+ proguard_configs = []
+ }
+ proguard_configs += [ "$_output_path/proguard.txt" ]
+ }
+ }
+ }
+
+ java_group(target_name) {
+ forward_variables_from(invoker,
+ [
+ "testonly",
+ "visibility",
+ ])
+ public_deps = [
+ ":$_unpack_target_name",
+ ]
+ deps = []
+ if (defined(_jar_target_name)) {
+ deps += [ ":$_jar_target_name" ]
+
+ # Although subjars are meant to be private, we add them as deps here
+ # because in practice they seem to contain classes required to be in the
+ # classpath.
+ deps += _subjar_targets
+ }
+ if (defined(_res_target_name)) {
+ deps += [ ":$_res_target_name" ]
+ }
+ }
+ }
+
+ # Create an Android application bundle from one base android_apk target,
+ # and zero or more associated android_apk.
+ #
+ # Variables:
+ # base_module_target: Name of the android_app_bundle_module target
+ # corresponding to the base module for this application bundle. The
+ # bundle file will include the same content in its base module, though in
+ # a slightly different format.
+ #
+ # bundle_base_path: Optional. If set, the bundle will be output to this
+ # directory. Defaults to "$root_build_dir/apks".
+ #
+ # bundle_name: Optional. If set, the bundle will be output to the
+ # filename "${bundle_name}.aab".
+ #
+ # extra_modules: Optional list of scopes, one per extra module used by
+ # this bundle. Each scope must have a 'name' field that specifies the
+ # module name (which cannot be 'base', since this is reserved for the
+ # base module), and an 'apk_target' field that specified the
+ # corresponding android_apk target name the module is modeled on.
+ # A scope may have an additional field, 'proguard_async', that
+ # specifies whether or not the module is asynchronous. This field should
+ # be set to true if the module is asynchronous, and set to false or left
+ # undefined otherwise.
+ # Async modules are those that are proguarded in a separate build step.
+ # This ensures that changes to these modules do not change the base
+ # module.
+ #
+ # enable_language_splits: Optional. If true, enable APK splits based
+ # on languages.
+ #
+ # sign_bundle: Optional. If true, sign the bundle. Default is false
+ # because signing is very slow, and there is no reason to do it
+ # unless one wants to upload the bundle to the Play Store (e.g.
+ # for official builds).
+ #
+ # keystore_path: optional keystore path, used only when generating APKs.
+ # keystore_name: optional keystore name, used only when generating APKs.
+ # keystore_password: optional keystore password, used only when
+ # generating APKs.
+ #
+ # command_line_flags_file: Optional. If provided, named of the on-device
+ # file that will be used to store command-line arguments. The default
+ # is 'command_line_flags_file', but this is typically redefined to
+ # something more specific for certain bundles (e.g. the Chromium based
+ # APKs use 'chrome-command-line', the WebView one uses
+ # 'webview-command-line').
+ #
+ # proguard_enabled: Optional. True if proguarding is enabled for this
+ # bundle. Default is to enable this only for release builds. Note that
+ # this will always perform synchronized proguarding.
+ #
+ # proguard_jar_path: Optional. Path to custom proguard jar used for
+ # proguarding.
+ #
+ # enable_multidex: Optional. Enable multidexing of optimized modules jars
+ # when using synchronized proguarding. Only applies to base module.
+ #
+ # proguard_android_sdk_dep: Optional. android_system_java_prebuilt() target
+ # used as a library jar for synchronized proguarding.
+ #
+ # compress_shared_libraries: Optional. Whether to compress shared libraries
+ # such that they are extracted upon install. Libraries prefixed with
+ # "crazy." are never compressed.
+ #
+ # system_image_locale_whitelist: List of locales that should be included
+ # on system APKs generated from this bundle.
+ #
+ # Example:
+ # android_app_bundle("chrome_public_bundle") {
+ # base_module_target = "//chrome/android:chrome_public_apk"
+ # extra_modules = [
+ # { # NOTE: Scopes require one field per line, and no comma separators.
+ # name = "my_module"
+ # module_target = ":my_module"
+ # },
+ # ]
+ # }
+ #
+ template("android_app_bundle") {
+ _bundle_base_path = "$root_build_dir/apks"
+ if (defined(invoker.bundle_base_path)) {
+ _bundle_base_path = invoker.bundle_base_path
+ }
+
+ _bundle_name = target_name
+ if (defined(invoker.bundle_name)) {
+ _bundle_name = invoker.bundle_name
+ }
+ _bundle_path = "$_bundle_base_path/${_bundle_name}.aab"
+ _rebased_bundle_path = rebase_path(_bundle_path, root_build_dir)
+
+ _base_target_name = get_label_info(invoker.base_module_target, "name")
+ _base_target_gen_dir =
+ get_label_info(invoker.base_module_target, "target_gen_dir")
+ _base_module_build_config =
+ "$_base_target_gen_dir/${_base_target_name}.build_config"
+ _base_module_build_config_target =
+ "${invoker.base_module_target}$build_config_target_suffix"
+ _rebased_base_module_build_config =
+ rebase_path(_base_module_build_config, root_build_dir)
+
+ _sync_modules = [
+ {
+ name = "base"
+ module_target = invoker.base_module_target
+ build_config = _base_module_build_config
+ build_config_target = _base_module_build_config_target
+ },
+ ]
+
+ _async_modules = []
+
+ _proguard_enabled =
+ defined(invoker.proguard_enabled) && invoker.proguard_enabled
+ _enable_multidex =
+ !defined(invoker.enable_multidex) || invoker.enable_multidex
+
+ if (!_proguard_enabled && defined(invoker.min_sdk_version)) {
+ not_needed(invoker, [ "min_sdk_version" ])
+ }
+
+ # Prevent "unused variable".
+ not_needed([ "_enable_multidex" ])
+
+ assert(_proguard_enabled || !defined(invoker.enable_multidex),
+ "Bundle only adds dexing step if proguarding is enabled.")
+
+ if (defined(invoker.extra_modules)) {
+ _module_count = 0
+ not_needed([ "_module_count" ])
+
+ # Define unique package for each async proguarding run.
+ _async_package_number = 1
+
+ not_needed([ "_async_package_number" ])
+
+ foreach(_module, invoker.extra_modules) {
+ _module_count += 1
+ assert(defined(_module.name),
+ "Missing 'name' field for extra module #${_module_count}.")
+ assert(_module.name != "base",
+ "Module name 'base' is reserved for the main bundle module")
+ assert(
+ defined(_module.module_target),
+ "Missing 'module_target' field for extra module ${_module.name}.")
+ _module_target = _module.module_target
+ _module_target_name = get_label_info(_module_target, "name")
+ _module_target_gen_dir =
+ get_label_info(_module_target, "target_gen_dir")
+ _module.build_config =
+ "$_module_target_gen_dir/${_module_target_name}.build_config"
+ _module.build_config_target =
+ "$_module_target$build_config_target_suffix"
+
+ if (defined(_module.proguard_async) && _module.proguard_async) {
+ if (_proguard_enabled) {
+ # Use asynchronous proguarding for async modules.
+ # TODO(crbug.com/938635): Combine async module mapping paths with the sync one.
+ _async_proguard_mapping_path =
+ "${_bundle_path}_${_module.name}.mapping"
+
+ _dex_zip = "${target_out_dir}/${target_name}/${target_name}_${_module.name}_dex.zip"
+ _module.dex_path = _dex_zip
+
+ # Give unique name to each async dex target using module name.
+ _async_dex_target = "${target_name}_${_module.name}_dex"
+
+ dex(_async_dex_target) {
+ enable_multidex = _enable_multidex
+ proguard_enabled = true
+ proguard_mapping_path = _async_proguard_mapping_path
+ forward_variables_from(invoker,
+ [
+ "proguard_jar_path",
+ "min_sdk_version",
+ ])
+ build_config = _module.build_config
+ repackage_classes = "ap${_async_package_number}"
+
+ deps = [
+ _module.module_target,
+ ]
+
+ output = _dex_zip
+ }
+ _module.async_dex_target = _async_dex_target
+ _async_package_number += 1
+ }
+
+ _async_modules += [ _module ]
+ } else {
+ _sync_modules += [ _module ]
+ }
+ }
+ }
+
+ # Make build config, which is required for synchronized proguarding.
+ _sync_module_targets = []
+ foreach(_module, _sync_modules) {
+ _sync_module_targets += [ _module.module_target ]
+ }
+ _build_config = "$target_gen_dir/${target_name}.build_config"
+ _rebased_build_config = rebase_path(_build_config, root_build_dir)
+ _build_config_target = "$target_name$build_config_target_suffix"
+ if (defined(invoker.proguard_android_sdk_dep)) {
+ proguard_android_sdk_dep_ = invoker.proguard_android_sdk_dep
+ } else {
+ proguard_android_sdk_dep_ = "//third_party/android_sdk:android_sdk_java"
+ }
+ write_build_config(_build_config_target) {
+ # We don't want async modules to be proguarded synchronously, so we leave
+ # them out of possible_config_deps.
+ type = "android_app_bundle"
+ possible_config_deps =
+ _sync_module_targets + [ proguard_android_sdk_dep_ ]
+ build_config = _build_config
+ proguard_enabled = _proguard_enabled
+ }
+
+ if (_proguard_enabled) {
+ _proguard_mapping_path = "${_bundle_path}.mapping"
+ _unsplit_dex_zip =
+ "${target_gen_dir}/${target_name}/${target_name}__unsplit_dex.zip"
+ _unsplit_dex_target = "${target_name}__unsplit_dex"
+ dex(_unsplit_dex_target) {
+ enable_multidex = _enable_multidex
+ proguard_enabled = true
+ proguard_mapping_path = _proguard_mapping_path
+ forward_variables_from(invoker,
+ [
+ "proguard_jar_path",
+ "min_sdk_version",
+ ])
+ build_config = _build_config
+
+ deps = _sync_module_targets + [ ":$_build_config_target" ]
+ output = _unsplit_dex_zip
+ }
+
+ _dexsplitter_target = "${_unsplit_dex_target}__dexsplitter"
+ dexsplitter(_dexsplitter_target) {
+ input_dex_zip = _unsplit_dex_zip
+ proguard_mapping = _proguard_mapping_path
+ all_modules = _sync_modules
+ deps = [
+ ":${_unsplit_dex_target}",
+ ]
+ }
+ }
+
+ # Merge async and sync module scopes.
+ _all_modules = _sync_modules + _async_modules
+
+ _all_create_module_targets = []
+ _all_module_zip_paths = []
+ _all_module_build_configs = []
+ foreach(_module, _all_modules) {
+ _module_target = _module.module_target
+ _module_build_config = _module.build_config
+ _module_build_config_target = _module.build_config_target
+
+ if (!_proguard_enabled) {
+ _dex_target_for_module = "${_module_target}__final_dex"
+ } else if (defined(_module.dex_path)) {
+ _dex_target_for_module = ":${_module.async_dex_target}"
+ } else {
+ _dex_target_for_module = ":$_dexsplitter_target"
+ }
+
+ # Generate one module .zip file per bundle module.
+ #
+ # Important: the bundle tool uses the module's zip filename as
+ # the internal module name inside the final bundle, in other words,
+ # this file *must* be named ${_module.name}.zip
+ _create_module_target = "${target_name}__${_module.name}__create"
+ _module_zip_path = "$target_gen_dir/$target_name/${_module.name}.zip"
+
+ create_android_app_bundle_module(_create_module_target) {
+ build_config = _module_build_config
+ module_zip_path = _module_zip_path
+
+ # If module is async, use defined dex_path directly rather than
+ # build config FileArg.
+ if (defined(_module.dex_path)) {
+ dex_path = _module.dex_path
+ }
+
+ deps = [
+ _dex_target_for_module,
+ _module_build_config_target,
+ _module_target,
+ ]
+ }
+
+ _all_create_module_targets += [
+ ":$_create_module_target",
+ _module_build_config_target,
+ "${_module_target}__compile_resources",
+ ]
+ _all_module_zip_paths += [ _module_zip_path ]
+ _all_module_build_configs += [ _module_build_config ]
+ }
+
+ _all_rebased_module_zip_paths =
+ rebase_path(_all_module_zip_paths, root_build_dir)
+
+ _sign_bundle = defined(invoker.sign_bundle) && invoker.sign_bundle
+
+ _enable_language_splits = defined(invoker.enable_language_splits) &&
+ invoker.enable_language_splits
+
+ _split_dimensions = []
+ if (_enable_language_splits) {
+ _split_dimensions += [ "language" ]
+ }
+
+ _keystore_path = android_keystore_path
+ _keystore_password = android_keystore_password
+ _keystore_name = android_keystore_name
+
+ if (defined(invoker.keystore_path)) {
+ _keystore_path = invoker.keystore_path
+ _keystore_password = invoker.keystore_password
+ _keystore_name = invoker.keystore_name
+ }
+
+ _rebased_keystore_path = rebase_path(_keystore_path, root_build_dir)
+
+ if (_sign_bundle) {
+ # For now, the same keys are used to sign the bundle and the set of
+ # generated APKs. In the future, signing the bundle may require a
+ # different set of keys.
+ _bundle_keystore_name = _keystore_name
+ }
+
+ _bundle_target_name = "${target_name}__bundle"
+ action_with_pydeps(_bundle_target_name) {
+ script = "//build/android/gyp/create_app_bundle.py"
+ inputs = _all_module_zip_paths + _all_module_build_configs
+ outputs = [
+ _bundle_path,
+ ]
+ data = [
+ _bundle_path,
+ ]
+ deps = _all_create_module_targets + [ ":$_build_config_target" ]
+ args = [
+ "--out-bundle=$_rebased_bundle_path",
+ "--rtxt-out-path=$_rebased_bundle_path.R.txt",
+ "--module-zips=$_all_rebased_module_zip_paths",
+ ]
+ if (_sign_bundle) {
+ args += [
+ "--keystore-path",
+ _rebased_keystore_path,
+ "--keystore-password",
+ _keystore_password,
+ "--key-name",
+ _bundle_keystore_name,
+ ]
+ }
+ if (_split_dimensions != []) {
+ args += [ "--split-dimensions=$_split_dimensions" ]
+ }
+ if (defined(invoker.compress_shared_libraries) &&
+ invoker.compress_shared_libraries) {
+ args += [ "--compress-shared-libraries" ]
+ }
+
+ if (_enable_language_splits) {
+ args += [
+ "--base-whitelist-rtxt-path=@FileArg(" + "${_rebased_base_module_build_config}:deps_info:base_whitelist_rtxt_path)",
+ "--base-module-rtxt-path=@FileArg(" + "${_rebased_base_module_build_config}:deps_info:module_rtxt_path)",
+ ]
+ }
+
+ foreach(build_config, _all_module_build_configs) {
+ _rebased_build_config = rebase_path(build_config, root_build_dir)
+ args += [
+ "--uncompressed-assets=@FileArg(" +
+ "$_rebased_build_config:uncompressed_assets)",
+ "--rtxt-in-paths=@FileArg(" +
+ "$_rebased_build_config:deps_info:module_rtxt_path)",
+ ]
+ }
+ }
+
+ # Create size info files for targets that care about size
+ # (have proguard enabled).
+ if (_proguard_enabled) {
+ # Merge all module targets to obtain size info files for all targets.
+ _all_module_targets = _sync_module_targets
+ foreach(_async_module, _async_modules) {
+ _all_module_targets += [ _async_module.module_target ]
+ }
+
+ _size_info_target = "${target_name}__size_info"
+ create_size_info_files(_size_info_target) {
+ name = "$_bundle_name.aab"
+ deps = _all_module_targets + [ ":$_build_config_target" ]
+ module_build_configs = _all_module_build_configs
+ }
+ }
+
+ # Generate a wrapper script for the bundle.
+ _android_aapt2_path = android_sdk_tools_bundle_aapt2
+
+ _bundle_apks_path = "$_bundle_base_path/$_bundle_name.apks"
+ _bundle_wrapper_script_dir = "$root_build_dir/bin"
+ _bundle_wrapper_script_path = "$_bundle_wrapper_script_dir/$target_name"
+
+ action_with_pydeps("${target_name}__wrapper_script") {
+ script = "//build/android/gyp/create_bundle_wrapper_script.py"
+ inputs = [
+ _base_module_build_config,
+ ]
+ outputs = [
+ _bundle_wrapper_script_path,
+ ]
+
+ # Telemetry for bundles uses the wrapper script for installation.
+ data = [
+ _bundle_wrapper_script_path,
+ ]
+
+ deps = [
+ _base_module_build_config_target,
+ ]
+ args = [
+ "--script-output-path",
+ rebase_path(_bundle_wrapper_script_path, root_build_dir),
+ "--package-name=@FileArg(" +
+ "$_rebased_base_module_build_config:deps_info:package_name)",
+ "--aapt2",
+ rebase_path(_android_aapt2_path, root_build_dir),
+ "--bundle-path",
+ _rebased_bundle_path,
+ "--bundle-apks-path",
+ rebase_path(_bundle_apks_path, root_build_dir),
+ "--target-cpu=$target_cpu",
+ "--keystore-path",
+ _rebased_keystore_path,
+ "--keystore-password",
+ _keystore_password,
+ "--key-name",
+ _keystore_name,
+ ]
+ if (defined(invoker.system_image_locale_whitelist)) {
+ args += [
+ "--system-image-locales=${invoker.system_image_locale_whitelist}",
+ ]
+ }
+ if (defined(invoker.command_line_flags_file)) {
+ args += [
+ "--command-line-flags-file",
+ invoker.command_line_flags_file,
+ ]
+ }
+
+ # TODO(crbug.com/938635): Combine async module mapping paths with the sync one.
+ if (_proguard_enabled) {
+ args += [
+ "--proguard-mapping-path",
+ rebase_path(_proguard_mapping_path, root_build_dir),
+ ]
+ }
+ }
+
+ group(target_name) {
+ public_deps = [
+ ":${target_name}__bundle",
+ ":${target_name}__wrapper_script",
+ ]
+ if (defined(_size_info_target)) {
+ public_deps += [ ":$_size_info_target" ]
+ }
+ }
+ }
+
+ # Create an .apks file from an .aab file. The .apks file will contain the
+ # minimal set of .apk files needed for tracking binary size.
+ # The file will be created at "$bundle_path_without_extension.minimal.apks".
+ #
+ # Variables:
+ # bundle_path: Path to the input .aab file.
+ #
+ # Example:
+ # create_app_bundle_minimal_apks("minimal_apks") {
+ # deps = [
+ # ":bundle_target",
+ # ]
+ # bundle_path = "$root_build_dir/apks/Bundle.aab"
+ # }
+ template("create_app_bundle_minimal_apks") {
+ action_with_pydeps(target_name) {
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "testonly",
+ ])
+ script = "//build/android/gyp/create_app_bundle_minimal_apks.py"
+ _dir = get_path_info(invoker.bundle_path, "dir")
+ _name = get_path_info(invoker.bundle_path, "name")
+ _output_path = "$_dir/$_name.minimal.apks"
+ outputs = [
+ _output_path,
+ ]
+ inputs = [
+ invoker.bundle_path,
+ ]
+ args = [
+ "--bundle",
+ rebase_path(invoker.bundle_path, root_build_dir),
+ "--output",
+ rebase_path(_output_path, root_build_dir),
+ "--aapt2-path",
+ rebase_path(android_sdk_tools_bundle_aapt2, root_build_dir),
+ "--keystore-path",
+ rebase_path(android_keystore_path, root_build_dir),
+ "--keystore-name",
+ android_keystore_name,
+ "--keystore-password",
+ android_keystore_password,
+ ]
+ }
+ }
+}
+
+# Generate an Android resources target that contains localized strings
+# describing the current locale used by the Android framework to display
+# UI strings. These are used by
+# org.chromium.chrome.browser.ChromeLocalizationUtils.
+#
+# Variables:
+# ui_locales: List of Chromium locale names to generate resources for.
+#
+template("generate_ui_locale_resources") {
+ _generating_target_name = "${target_name}__generate"
+ _rebased_output_zip_path = rebase_path(target_gen_dir, root_gen_dir)
+ _output_zip = "${root_out_dir}/resource_zips/${_rebased_output_zip_path}/" +
+ "${target_name}.zip"
+
+ _locales = invoker.ui_locales
+ _depfile = "$target_gen_dir/$target_name.d"
+
+ action(_generating_target_name) {
+ script = "//build/android/gyp/create_ui_locale_resources.py"
+ depfile = _depfile
+ outputs = [
+ _output_zip,
+ ]
+ args = [
+ "--locale-list=$_locales",
+ "--depfile",
+ rebase_path(_depfile, root_build_dir),
+ "--output-zip",
+ rebase_path(_output_zip, root_build_dir),
+ ]
+ }
+
+ android_generated_resources(target_name) {
+ generating_target_name = ":$_generating_target_name"
+ generated_resources_zip = _output_zip
+ }
+}
diff --git a/deps/v8/build/config/android/sdk.gni b/deps/v8/build/config/android/sdk.gni
new file mode 100644
index 0000000000..1f1ebc5d3f
--- /dev/null
+++ b/deps/v8/build/config/android/sdk.gni
@@ -0,0 +1,10 @@
+# Copyright 2017 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.
+
+# The default SDK release used by public builds. Value may differ in
+# internal builds.
+default_android_sdk_release = "p"
+
+# SDK releases against which public builds are supported.
+public_sdk_releases = [ "p" ]