summaryrefslogtreecommitdiff
path: root/chromium/build/config/android/internal_rules.gni
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/build/config/android/internal_rules.gni')
-rw-r--r--chromium/build/config/android/internal_rules.gni1541
1 files changed, 757 insertions, 784 deletions
diff --git a/chromium/build/config/android/internal_rules.gni b/chromium/build/config/android/internal_rules.gni
index 1494124a991..b6b7627dda3 100644
--- a/chromium/build/config/android/internal_rules.gni
+++ b/chromium/build/config/android/internal_rules.gni
@@ -16,47 +16,69 @@ import("//build/util/generate_wrapper.gni")
import("//build_overrides/build.gni")
assert(is_android)
-# These filters identify most targets that eventually use the java_library_impl
-# template.
-_java_lib_patterns = [
+# The following _java_*_types variables capture all the existing target types.
+# If a new type is introduced, please add it to one of these categories,
+# preferring the more specific resource/library types.
+_java_resource_types = [
+ "android_assets",
+ "android_resources",
+]
+
+_java_library_types = [
+ "java_library",
+ "system_java_library",
+ "android_app_bundle_module",
+]
+
+# These are leaf java target types. They cannot be passed as deps to other
+# targets. Thus their naming schemes are not enforced.
+_java_leaf_types = [
+ "android_apk",
+ "android_app_bundle",
+ "dist_aar",
+ "dist_jar",
+ "java_annotation_processor",
+ "java_binary",
+ "junit_binary",
+]
+
+# All _java_resource_types targets must conform to these patterns.
+_java_resource_patterns = [
+ "*:*_assets",
+ "*android*:assets",
+ "*:*_apk_*resources",
+ "*android*:resources",
+ "*:*_resources",
+ "*:*_grd",
+ "*:*locale_paks",
+ "*:*_java_strings",
+ "*:*strings_java",
+]
+
+# All _java_library_types targets must conform to these patterns. This includes
+# all non-leaf targets that use java_library_impl.
+_java_library_patterns = [
"*:*_java",
"*:*_javalib",
- "*:*_java_*", # e.g. java_test_support
+ "*:*_java_*", # e.g. chrome_java_test_support
"*:java",
"*:junit",
"*:junit_*",
"*:*_junit_*",
"*:*javatests",
+ "*:*_bundle_module",
# TODO(agrieve): Rename targets below to match above patterns.
- "*android_webview/glue*:glue",
+ "//android_webview/glue:glue",
]
-# These identify targets that have .build_config files (except for android_apk,
-# java_binary, android_app_bundle since we never need to depend on these).
-_java_target_patterns = _java_lib_patterns + [
- "*:*_assets",
- "*android*:assets",
- "*:*_apk_*resources",
- "*android*:resources",
- "*:*_resources",
- "*:*_grd",
- "*:*locale_paks",
- "*_bundle_module",
- ]
-
-# Targets that match _java_target_patterns but are not actually java targets.
-_java_target_exceptions = [ "*:*_unpack_aar" ]
-
-# These targets match _java_lib_patterns but do not use java_library_impl.
-_java_lib_exceptions =
- _java_target_patterns - _java_lib_patterns + _java_target_exceptions + [
- "*:*__res", # TODO(wnwen): Rename these to the standard ones.
- ]
+# These identify all non-leaf targets that have .build_config files.
+_java_target_patterns = _java_library_patterns + _java_resource_patterns
_r8_path = "//third_party/r8/lib/r8.jar"
_desugar_jdk_libs_json = "//third_party/r8/desugar_jdk_libs.json"
_desugar_jdk_libs_jar = "//third_party/android_deps/libs/com_android_tools_desugar_jdk_libs/desugar_jdk_libs-1.0.5.jar"
+_desugar_runtime_jar = "$root_build_dir/obj/third_party/bazel/desugar/Desugar_runtime.processed.jar"
_dexdump_path = "$android_sdk_build_tools/dexdump"
_dexlayout_path = "//third_party/android_build_tools/art/dexlayout"
@@ -120,19 +142,32 @@ build_config_target_suffix = "__build_config_crbug_908819"
# 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 != "dist_jar" &&
- _type != "java_annotation_processor" && _type != "dist_aar" &&
- _type != "android_app_bundle") {
- _parent_invoker = invoker.invoker
- _target_label =
- get_label_info(":${_parent_invoker.target_name}", "label_no_toolchain")
- if (filter_exclude([ _target_label ], _java_target_patterns) != [] &&
- filter_exclude([ _target_label ], _java_target_exceptions) != []) {
+ _parent_invoker = invoker.invoker
+ _target_label =
+ get_label_info(":${_parent_invoker.target_name}", "label_no_toolchain")
+
+ # Ensure targets match naming patterns so that __assetres, __header, __impl
+ # targets work properly. Those generated targets allow for effective deps
+ # filtering.
+ if (filter_exclude([ _type ], _java_resource_types) == []) {
+ if (filter_exclude([ _target_label ], _java_resource_patterns) != []) {
+ assert(false, "Invalid java resource target name: $_target_label")
+ }
+ } else if (filter_exclude([ _type ], _java_library_types) == []) {
+ if (filter_exclude([ _target_label ], _java_library_patterns) != [] ||
+ filter_exclude([ _target_label ], _java_resource_patterns) == []) {
+ assert(false, "Invalid java library target name: $_target_label")
+ }
+ } else if (_type == "group") {
+ if (filter_exclude([ _target_label ], _java_target_patterns) != []) {
assert(false, "Invalid java target name: $_target_label")
}
+ } else if (filter_exclude([ _type ], _java_leaf_types) != []) {
+ assert(false, "This java type needs a category: $_type")
+ }
+
+ if (defined(invoker.public_target_label)) {
+ _target_label = invoker.public_target_label
}
action_with_pydeps(target_name) {
@@ -156,12 +191,11 @@ template("write_build_config") {
_deps_configs = []
if (defined(invoker.possible_config_deps)) {
foreach(_possible_dep, invoker.possible_config_deps) {
- _target_label = get_label_info(_possible_dep, "label_no_toolchain")
- if (filter_exclude([ _target_label ], _java_target_patterns) == [] &&
- filter_exclude([ _target_label ], _java_target_exceptions) != []) {
+ _dep_label = get_label_info(_possible_dep, "label_no_toolchain")
+ if (filter_exclude([ _dep_label ], _java_target_patterns) == []) {
# Put the bug number in the target name so that false-positives
# have a hint in the error message about non-existent dependencies.
- deps += [ "$_target_label$build_config_target_suffix" ]
+ deps += [ "$_dep_label$build_config_target_suffix" ]
_dep_gen_dir = get_label_info(_possible_dep, "target_gen_dir")
_dep_name = get_label_info(_possible_dep, "name")
_deps_configs += [ "$_dep_gen_dir/$_dep_name.build_config" ]
@@ -177,6 +211,8 @@ template("write_build_config") {
"--deps-configs=$_rebased_deps_configs",
"--build-config",
rebase_path(invoker.build_config, root_build_dir),
+ "--gn-target",
+ _target_label,
]
if (defined(invoker.chromium_code) && !invoker.chromium_code) {
@@ -184,10 +220,16 @@ template("write_build_config") {
args += [ "--non-chromium-code" ]
}
- if (defined(invoker.jar_path)) {
+ if (defined(invoker.device_jar_path)) {
args += [
- "--jar-path",
- rebase_path(invoker.jar_path, root_build_dir),
+ "--device-jar-path",
+ rebase_path(invoker.device_jar_path, root_build_dir),
+ ]
+ }
+ if (defined(invoker.host_jar_path)) {
+ args += [
+ "--host-jar-path",
+ rebase_path(invoker.host_jar_path, root_build_dir),
]
}
if (defined(invoker.unprocessed_jar_path)) {
@@ -208,22 +250,20 @@ template("write_build_config") {
rebase_path(invoker.java_resources_jar, root_build_dir),
]
}
- if (defined(invoker.skip_jetify) && invoker.skip_jetify) {
- args += [ "--skip-jetify" ]
- }
if (defined(invoker.jetified_jar_path)) {
args += [
"--jetified-jar-path",
rebase_path(invoker.jetified_jar_path, root_build_dir),
]
}
- if (defined(invoker.annotation_processor_deps)) {
+ if (defined(invoker.annotation_processor_deps) &&
+ invoker.annotation_processor_deps != []) {
_processor_configs = []
foreach(_processor_dep, invoker.annotation_processor_deps) {
- _target_label = get_label_info(_processor_dep, "label_no_toolchain")
+ _dep_label = get_label_info(_processor_dep, "label_no_toolchain")
_dep_gen_dir = get_label_info(_processor_dep, "target_gen_dir")
_dep_name = get_label_info(_processor_dep, "name")
- deps += [ "$_target_label$build_config_target_suffix" ]
+ deps += [ "$_dep_label$build_config_target_suffix" ]
_processor_configs += [ "$_dep_gen_dir/$_dep_name.build_config" ]
}
_rebased_processor_configs =
@@ -471,12 +511,12 @@ template("write_build_config") {
}
if (defined(invoker.static_library_dependent_targets)) {
_dependent_configs = []
- foreach(_target, invoker.static_library_dependent_targets) {
- _target_name = _target.name
- _target_label = get_label_info(_target_name, "label_no_toolchain")
- deps += [ "$_target_label$build_config_target_suffix" ]
- _dep_gen_dir = get_label_info(_target_name, "target_gen_dir")
- _dep_name = get_label_info(_target_name, "name")
+ foreach(_dep, invoker.static_library_dependent_targets) {
+ _dep_name = _dep.name
+ _dep_label = get_label_info(_dep_name, "label_no_toolchain")
+ deps += [ "$_dep_label$build_config_target_suffix" ]
+ _dep_gen_dir = get_label_info(_dep_name, "target_gen_dir")
+ _dep_name = get_label_info(_dep_name, "name")
_config =
rebase_path("$_dep_gen_dir/$_dep_name.build_config", root_build_dir)
_dependent_configs += [ _config ]
@@ -494,11 +534,11 @@ template("write_build_config") {
]
}
if (defined(invoker.base_module_target)) {
- _target_label =
+ _base_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" ]
+ _dep_gen_dir = get_label_info(_base_label, "target_gen_dir")
+ _dep_name = get_label_info(_base_label, "name")
+ deps += [ "$_base_label$build_config_target_suffix" ]
args += [
"--base-module-build-config",
rebase_path("$_dep_gen_dir/$_dep_name.build_config", root_build_dir),
@@ -523,7 +563,8 @@ template("write_build_config") {
# }
_msg = [
"Tried to build an Android target in a non-default toolchain.",
- "target: " + get_label_info(":$target_name", "label_with_toolchain"),
+ "target: $_target_label",
+ "current_toolchain: $current_toolchain",
"default_toolchain: $default_toolchain",
]
args += [ "--fail=$_msg" ]
@@ -859,70 +900,89 @@ template("test_runner_script") {
}
if (enable_java_templates) {
- android_sdk_jar = "$android_sdk/android.jar"
-
template("android_lint") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
- "deps",
"data_deps",
"public_deps",
"testonly",
])
+ if (!defined(deps)) {
+ deps = []
+ }
+
+ # https://crbug.com/1098752 Fix for bot OOM (https://crbug.com/1098333).
+ pool = "//build/toolchain:link_pool($default_toolchain)"
+
+ # Lint only requires generated sources and generated resources from the
+ # build. Since turbine __header targets already depend on and generate all
+ # the generated sources, and the __assetres targets include all generated
+ # resources, lint only needs to depend on the header and assetres targets
+ # rather than the top level java targets.
+ if (defined(invoker.deps)) {
+ foreach(_dep, invoker.deps) {
+ _target_label = get_label_info(_dep, "label_no_toolchain")
+ if (filter_exclude([ _target_label ], _java_library_patterns) == [] &&
+ filter_exclude([ _target_label ], _java_resource_patterns) !=
+ []) {
+ deps += [
+ # Strictly speaking the __header target is sufficient, since they
+ # already depend on resources (due to srcjar deps), but prefer to
+ # be more explicit here since if/when __header targets stop
+ # depending on resources (e.g. if R.java generation moves to java
+ # targets), lint will not be affected.
+ "${_target_label}__assetres",
+ "${_target_label}__header",
+ ]
+ } else {
+ deps += [ _dep ]
+ }
+ }
+ }
+
if (defined(invoker.lint_suppressions_file)) {
- lint_suppressions_file = invoker.lint_suppressions_file
- } else if (!defined(lint_suppressions_file)) {
- # WebRTC defines its own lint_suppressions_file:
- # //tools_webrtc/android/suppressions.xml
- lint_suppressions_file = "//build/android/lint/suppressions.xml"
+ _suppressions_file = invoker.lint_suppressions_file
+
+ # The custom suppressions file might be a generated file needing a dep.
+ # e.g. generating it by appending to the default suppressions.xml file.
+ if (defined(invoker.lint_suppressions_dep)) {
+ deps += [ invoker.lint_suppressions_dep ]
+ }
+ } else {
+ _suppressions_file = "//build/android/lint/suppressions.xml"
}
_min_sdk_version = default_min_sdk_version
if (defined(invoker.min_sdk_version)) {
_min_sdk_version = invoker.min_sdk_version
}
- _lint_path = "$lint_android_sdk_root/cmdline-tools/latest/bin/lint"
+
+ _lint_binary_path = "$lint_android_sdk_root/cmdline-tools/latest/bin/lint"
_cache_dir = "$root_build_dir/android_lint_cache"
- _result_path = "$target_out_dir/$target_name/result.xml"
- _config_path = "$target_out_dir/$target_name/config.xml"
- _stamp_path = "$target_out_dir/$target_name/build.lint.stamp"
- _suppressions_file = lint_suppressions_file
- _platform_xml_path =
- "$lint_android_sdk_root/platform-tools/api/api-versions.xml"
+
+ # Save these generated xml files in a consistent location for debugging.
+ _lint_gen_dir = "$target_gen_dir/$target_name"
script = "//build/android/gyp/lint.py"
depfile = "$target_gen_dir/$target_name.d"
inputs = [
- _lint_path,
- _platform_xml_path,
+ _lint_binary_path,
_suppressions_file,
]
- # _result_path is also an output, but do not list it in order to avoid it
- # being uploaded to swarming as part of isolates. This happens as a
- # side-effect of lint targets being listed as "data_deps" in order to
- # have them run concurrently with other targets.
- outputs = [ _stamp_path ]
-
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
- "--lint-path",
- rebase_path(_lint_path, root_build_dir),
+ "--lint-binary-path",
+ rebase_path(_lint_binary_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}",
"--config-path",
rebase_path(_suppressions_file, root_build_dir),
- "--product-dir=.",
- "--result-path",
- rebase_path(_result_path, root_build_dir),
- "--stamp",
- rebase_path(_stamp_path, root_build_dir),
- "--include-unexpected-failures",
+ "--lint-gen-dir",
+ rebase_path(_lint_gen_dir, root_build_dir),
+ "--android-sdk-version=${lint_android_sdk_version}",
"--min-sdk-version=$_min_sdk_version",
"--android-sdk-root",
rebase_path(lint_android_sdk_root, root_build_dir),
@@ -933,11 +993,27 @@ if (enable_java_templates) {
args += [ "--testonly" ]
}
+ if (defined(invoker.manifest_package)) {
+ args += [ "--manifest-package=${invoker.manifest_package}" ]
+ }
+
+ if (java_warnings_as_errors) {
+ args += [ "--can-fail-build" ]
+ }
+
+ _stamp_path = "$target_out_dir/$target_name/build.lint.stamp"
if (defined(invoker.create_cache) && invoker.create_cache) {
args += [ "--silent" ]
+
+ # Putting the stamp file in the cache dir allows us to depend on ninja
+ # to create the cache dir for us.
+ _stamp_path = "$_cache_dir/build.lint.stamp"
} else {
+ deps += [
+ "//build/android:prepare_android_lint_cache",
+ invoker.build_config_dep,
+ ]
inputs += [ invoker.build_config ]
- deps += [ "//build/android:prepare_android_lint_cache" ]
_rebased_build_config =
rebase_path(invoker.build_config, root_build_dir)
args += [
@@ -947,14 +1023,13 @@ if (enable_java_templates) {
"--resource-sources=@FileArg($_rebased_build_config:deps_info:lint_resource_sources)",
"--resource-zips=@FileArg($_rebased_build_config:deps_info:lint_resource_zips)",
]
- if (java_warnings_as_errors) {
- args += [ "--can-fail-build" ]
- }
}
- if (defined(invoker.manifest_package)) {
- args += [ "--manifest-package=${invoker.manifest_package}" ]
- }
+ outputs = [ _stamp_path ]
+ args += [
+ "--stamp",
+ rebase_path(_stamp_path, root_build_dir),
+ ]
}
}
@@ -973,7 +1048,10 @@ if (enable_java_templates) {
# http://crbug.com/725224. Fix for bots running out of memory.
_pool = "//build/toolchain:link_pool($default_toolchain)"
- _inputs = [ invoker.build_config ]
+ _inputs = [
+ invoker.build_config,
+ _r8_path,
+ ]
if (defined(invoker.inputs)) {
_inputs += invoker.inputs
}
@@ -986,6 +1064,11 @@ if (enable_java_templates) {
_mapping_path = invoker.proguard_mapping_path
}
+ _enable_jdk_library_desugaring = enable_jdk_library_desugaring
+ if (defined(invoker.supports_jdk_library_desugaring) &&
+ !invoker.supports_jdk_library_desugaring) {
+ _enable_jdk_library_desugaring = false
+ }
_proguard_sourcefile_suffix = ""
if (defined(invoker.proguard_sourcefile_suffix)) {
_proguard_sourcefile_suffix = "-${invoker.proguard_sourcefile_suffix}"
@@ -999,6 +1082,8 @@ if (enable_java_templates) {
"@FileArg($_rebased_build_config:deps_info:proguard_classpath_jars)",
"--classpath",
"@FileArg($_rebased_build_config:android:sdk_jars)",
+ "--r8-path",
+ rebase_path(_r8_path, root_build_dir),
]
if (enable_proguard_obfuscation) {
@@ -1020,7 +1105,7 @@ if (enable_java_templates) {
_args += [
"--feature-name=${_feature_module.name}",
"--dex-dest=@FileArg($_rebased_module_build_config:final_dex:path)",
- "--feature-jars=@FileArg($_rebased_module_build_config:deps_info:java_runtime_classpath)",
+ "--feature-jars=@FileArg($_rebased_module_build_config:deps_info:device_classpath)",
]
_deps += [ _feature_module.build_config_target ]
}
@@ -1066,26 +1151,25 @@ if (enable_java_templates) {
]
}
- if (!defined(invoker.proguard_jar_path)) {
+ if (_enable_jdk_library_desugaring) {
_args += [
- "--r8-path",
- rebase_path(_r8_path, root_build_dir),
+ "--desugar-jdk-libs-json",
+ rebase_path(_desugar_jdk_libs_json, root_build_dir),
]
- _inputs += [ _r8_path ]
- if (enable_jdk_library_desugaring) {
- _args += [
- "--desugar-jdk-libs-json",
- rebase_path(_desugar_jdk_libs_json, root_build_dir),
- ]
- _inputs += [ _desugar_jdk_libs_json ]
- }
- } else {
- _proguard_jar_path = invoker.proguard_jar_path
+ _inputs += [ _desugar_jdk_libs_json ]
+
+ _args += [
+ "--desugar-jdk-libs-jar",
+ rebase_path(_desugar_jdk_libs_jar, root_build_dir),
+ ]
+ _inputs += [ _desugar_jdk_libs_jar ]
+
+ _desugared_library_keep_rule_output_path =
+ "$target_gen_dir/$target_name.desugared_library_keep_rules.flags"
_args += [
- "--proguard-path",
- rebase_path(_proguard_jar_path, root_build_dir),
+ "--desugared-library-keep-rule-output",
+ rebase_path(_desugared_library_keep_rule_output_path, root_build_dir),
]
- _inputs += [ _proguard_jar_path ]
}
_enable_assert = is_java_debug || dcheck_always_on
@@ -1099,45 +1183,39 @@ if (enable_java_templates) {
_args += invoker.args
}
- if (defined(invoker.verify_proguard_flags_target_name)) {
- _expectations_target = "${invoker.verify_proguard_flags_target_name}" +
- "_proguard_expectations"
+ if (defined(invoker.expected_proguard_config)) {
+ _expectations_target =
+ "${invoker.top_target_name}_validate_proguard_config"
action_with_pydeps(_expectations_target) {
- _expected_configs_file =
- get_label_info(":${invoker.verify_proguard_flags_target_name}",
- "dir") +
- "/java/${invoker.verify_proguard_flags_target_name}" +
- ".proguard_flags.expected"
- _failed_proguard_expectation_file =
- "$android_configuration_failure_dir/" +
- string_replace(_expected_configs_file, "/", "_")
- _expectation_stamp = "${target_gen_dir}/${_expectations_target}.stamp"
- if (fail_on_android_expectations) {
- args += [ "--fail-on-expectations" ]
- }
script = _script
# Need to depend on all deps so that proguard.txt within .aar files get
# extracted.
deps = _deps
- pool = _pool
depfile = "${target_gen_dir}/${target_name}.d"
inputs = [
invoker.build_config,
- _expected_configs_file,
+ invoker.expected_proguard_config,
]
+ _failure_file =
+ "$android_configuration_failure_dir/" +
+ string_replace(invoker.expected_proguard_config, "/", "_")
+ _expectation_stamp = "$target_gen_dir/$target_name.stamp"
outputs = [ _expectation_stamp ]
args = _args + [
"--depfile",
rebase_path(depfile, root_build_dir),
"--proguard-expectations-failure-file",
- rebase_path(_failed_proguard_expectation_file, root_build_dir),
+ rebase_path(_failure_file, root_build_dir),
"--expected-configs-file",
- rebase_path(_expected_configs_file, root_build_dir),
+ rebase_path(invoker.expected_proguard_config, root_build_dir),
"--stamp",
rebase_path(_expectation_stamp, root_build_dir),
"--only-verify-expectations",
]
+ if (fail_on_android_expectations) {
+ args += [ "--fail-on-expectations" ]
+ }
}
_deps += [ ":$_expectations_target" ]
}
@@ -1186,7 +1264,9 @@ if (enable_java_templates) {
"--main-class",
_main_class,
]
- args += [ "--classpath=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)" ]
+ args += [
+ "--classpath=@FileArg($_rebased_build_config:deps_info:host_classpath)",
+ ]
if (use_jacoco_coverage) {
args += [
@@ -1214,8 +1294,6 @@ if (enable_java_templates) {
_proguard_enabled =
defined(invoker.proguard_enabled) && invoker.proguard_enabled
_is_dex_merging = defined(invoker.input_dex_filearg)
- _proguarding_with_r8 =
- _proguard_enabled && !defined(invoker.proguard_jar_path)
_enable_multidex =
!defined(invoker.enable_multidex) || invoker.enable_multidex
_enable_main_dex_list = _enable_multidex && _min_sdk_version < 21
@@ -1228,6 +1306,9 @@ if (enable_java_templates) {
}
}
+ # It's not safe to dex merge with libraries dex'ed at higher api versions.
+ assert(!_is_dex_merging || _min_sdk_version >= default_min_sdk_version)
+
# For D8's backported method desugaring to work properly, the dex merge step
# must not be set to a higher minSdkVersion than it was for the libraries.
if (_enable_desugar && _is_dex_merging) {
@@ -1235,7 +1316,7 @@ if (enable_java_templates) {
}
assert(defined(invoker.output) ||
- (_proguarding_with_r8 && defined(invoker.modules)))
+ (_proguard_enabled && defined(invoker.modules)))
assert(!_proguard_enabled || !(defined(invoker.input_dex_filearg) ||
defined(invoker.input_classes_filearg) ||
defined(invoker.input_class_jars)),
@@ -1257,30 +1338,29 @@ if (enable_java_templates) {
}
if (_proguard_enabled) {
- if (_proguarding_with_r8) {
- if (defined(invoker.output)) {
- _proguard_output_path = invoker.output
- }
- _proguard_target_name = target_name
- } else {
- _proguard_output_path = invoker.output + ".proguard.jar"
- _proguard_target_name = "${target_name}__proguard"
+ if (defined(invoker.output)) {
+ _proguard_output_path = invoker.output
}
+ _proguard_target_name = target_name
proguard(_proguard_target_name) {
forward_variables_from(invoker,
[
"build_config",
+ "data",
+ "data_deps",
+ "deps",
"disable_checkdiscard",
"disable_r8_outlining",
- "deps",
+ "expected_proguard_config",
+ "is_static_library",
"modules",
- "verify_proguard_flags_target_name",
- "proguard_jar_path",
"proguard_mapping_path",
"proguard_sourcefile_suffix",
- "is_static_library",
+ "supports_jdk_library_desugaring",
"testonly",
+ "top_target_name",
+ "visibiity",
])
inputs = []
if (defined(invoker.inputs)) {
@@ -1292,13 +1372,20 @@ if (enable_java_templates) {
args = [
"--proguard-configs=@FileArg($_rebased_build_config:deps_info:proguard_all_configs)",
- "--input-paths=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)",
"--min-api=$_min_sdk_version",
]
+ if (defined(invoker.has_apk_under_test) && invoker.has_apk_under_test) {
+ args += [ "--input-paths=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath_extended)" ]
+ } else {
+ args += [ "--input-paths=@FileArg($_rebased_build_config:deps_info:device_classpath)" ]
+ }
if (enable_bazel_desugar) {
deps += [ "//third_party/bazel/desugar:desugar_runtime_java" ]
- inputs += [ "$root_build_dir/lib.java/third_party/bazel/desugar/Desugar_runtime.jar" ]
- args += [ "--input-paths=lib.java/third_party/bazel/desugar/Desugar_runtime.jar" ]
+ inputs += [ _desugar_runtime_jar ]
+ args += [
+ "--input-paths",
+ rebase_path(_desugar_runtime_jar, root_build_dir),
+ ]
}
if (defined(invoker.proguard_args)) {
args += invoker.proguard_args
@@ -1317,7 +1404,7 @@ if (enable_java_templates) {
args += [ "--apply-mapping=$_rebased_apply_mapping_path" ]
}
- if (_proguarding_with_r8 && _enable_main_dex_list) {
+ if (_enable_main_dex_list) {
if (defined(invoker.extra_main_dex_proguard_config)) {
args += [
"--main-dex-rules-path",
@@ -1335,36 +1422,25 @@ if (enable_java_templates) {
if (defined(_proguard_output_path)) {
output_path = _proguard_output_path
- if (_proguarding_with_r8) {
- config_output_path = "$_proguard_output_path.proguard_flags"
- }
+ config_output_path = "$_proguard_output_path.proguard_flags"
} else {
mapping_path = "$target_out_dir/$target_name.mapping"
- if (_proguarding_with_r8) {
- config_output_path = "$target_out_dir/$target_name.proguard_flags"
- }
+ config_output_path = "$target_out_dir/$target_name.proguard_flags"
}
}
- }
-
- if (!_proguarding_with_r8) {
+ } else { # !_proguard_enabled
+ _is_library = defined(invoker.is_library) && invoker.is_library
_input_class_jars = []
if (defined(invoker.input_class_jars)) {
_input_class_jars = invoker.input_class_jars
}
- if (_proguard_enabled) {
- _input_class_jars += [ _proguard_output_path ]
- }
_deps = invoker.deps
- if (_proguard_enabled) {
- _deps += [ ":${_proguard_target_name}" ]
- }
- if (_is_dex_merging && enable_bazel_desugar) {
+ if (!_is_library && enable_bazel_desugar) {
# It would be more efficient to use the pre-dex'ed copy of the runtime,
# but it's easier to add it in this way.
_deps += [ "//third_party/bazel/desugar:desugar_runtime_java" ]
- _input_class_jars += [ "$root_build_dir/lib.java/third_party/bazel/desugar/Desugar_runtime.jar" ]
+ _input_class_jars += [ _desugar_runtime_jar ]
}
if (_input_class_jars != []) {
_rebased_input_class_jars =
@@ -1442,7 +1518,13 @@ if (enable_java_templates) {
}
action_with_pydeps(target_name) {
- forward_variables_from(invoker, [ "testonly" ])
+ forward_variables_from(invoker,
+ [
+ "data",
+ "data_deps",
+ "testonly",
+ "visibility",
+ ])
script = "//build/android/gyp/dex.py"
deps = _deps
depfile = "$target_gen_dir/$target_name.d"
@@ -1459,9 +1541,8 @@ if (enable_java_templates) {
rebase_path(_r8_path, root_build_dir),
]
- if (!_proguard_enabled && enable_incremental_d8 &&
- !(defined(invoker.disable_incremental) &&
- invoker.disable_incremental)) {
+ if (enable_incremental_d8 && !(defined(invoker.disable_incremental) &&
+ invoker.disable_incremental)) {
# Don't use incremental dexing for ProGuarded inputs as a precaution.
args += [
"--incremental-dir",
@@ -1479,11 +1560,10 @@ if (enable_java_templates) {
deps += [ ":${_main_dex_list_target_name}" ]
inputs += [ _main_dex_list_path ]
}
- } else if (defined(invoker.enable_library_multidex) &&
- invoker.enable_library_multidex) {
- args += [ "--multi-dex" ]
}
-
+ if (_is_library) {
+ args += [ "--library" ]
+ }
if (defined(invoker.input_dex_filearg)) {
inputs += [ invoker.build_config ]
args += [ "--dex-inputs-filearg=${invoker.input_dex_filearg}" ]
@@ -1515,20 +1595,13 @@ if (enable_java_templates) {
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 ]
- }
}
# Never compile intemediates with --release in order to:
# 1) not require recompiles when toggling is_java_debug,
# 2) allow incremental_install=1 to still have local variable
# information even when is_java_debug=false.
- if (!is_java_debug && _is_dex_merging) {
+ if (!is_java_debug && !_is_library) {
args += [ "--release" ]
}
@@ -1605,7 +1678,9 @@ if (enable_java_templates) {
"testonly",
])
- _sources_json_file = "$target_out_dir/${target_name}_sources.json"
+ # The name needs to match the SOURCES_JSON_FILES_SUFFIX in
+ # generate_coverage_metadata_for_java.py.
+ _sources_json_file = "$target_out_dir/${target_name}__jacoco_sources.json"
_jacococli_jar = "//third_party/jacoco/lib/jacococli.jar"
script = "//build/android/gyp/jacoco_instr.py"
@@ -1638,115 +1713,78 @@ if (enable_java_templates) {
}
}
- # TODO(digit): Document this!
- #
- # Variables:
- # testonly:
- # build_config:
- # input_jar_path:
- # output_jar_path:
- # supports_android:
- # jacoco_instrument: Use Jacoco-instrumented classes to generate Java
- # coverage data.
- # jar_excluded_patterns: Optional list of .class file patterns to exclude
- # from the final .jar file.
- # jar_included_patterns: Optional list of .class file patterns to include
- # in the final .jar file. jar_excluded_patterns take precedence over this.
- # skip_jetify: A boolean on whether to skip jetifying or not.
- # 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
-
- # Turned off because of existing code which fails the assertion
- _enable_thread_annotations = false
-
- _jacoco_instrument = invoker.jacoco_instrument
- _skip_jetify = defined(invoker.skip_jetify) && invoker.skip_jetify
+ template("filter_jar") {
+ action_with_pydeps(target_name) {
+ script = "//build/android/gyp/filter_zip.py"
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "testonly",
+ ])
+ inputs = [ invoker.input_jar ]
+ if (defined(invoker.inputs)) {
+ inputs += invoker.inputs
+ }
+ outputs = [ invoker.output_jar ]
- _enable_bytecode_rewriter = _enable_thread_annotations
- _is_prebuilt = defined(invoker.is_prebuilt) && invoker.is_prebuilt
- _enable_bytecode_checks = !defined(invoker.enable_bytecode_checks) ||
- invoker.enable_bytecode_checks
- _missing_classes_allowlist = []
- if (defined(invoker.missing_classes_allowlist)) {
- _missing_classes_allowlist = invoker.missing_classes_allowlist
+ _jar_excluded_patterns = []
+ if (defined(invoker.jar_excluded_patterns)) {
+ _jar_excluded_patterns = invoker.jar_excluded_patterns
+ }
+ _jar_included_patterns = []
+ if (defined(invoker.jar_included_patterns)) {
+ _jar_included_patterns = invoker.jar_included_patterns
+ }
+ _strip_resource_classes = defined(invoker.strip_resource_classes) &&
+ invoker.strip_resource_classes
+ args = [
+ "--input",
+ rebase_path(invoker.input_jar, root_build_dir),
+ "--output",
+ rebase_path(invoker.output_jar, root_build_dir),
+ "--exclude-globs=${_jar_excluded_patterns}",
+ "--include-globs=${_jar_included_patterns}",
+ ]
+ if (_strip_resource_classes) {
+ inputs += [ invoker.build_config ]
+ _rebased_build_config =
+ rebase_path(invoker.build_config, root_build_dir)
+ args += [ "--strip-resource-classes-for=@FileArg($_rebased_build_config:javac:resource_packages)" ]
+ }
}
+ }
- # 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",
- "_missing_classes_allowlist",
- ])
- if (defined(invoker.enable_bytecode_rewriter)) {
- not_needed([
- "_enable_custom_resources",
- "_enable_thread_annotations",
- ])
- _enable_bytecode_rewriter = invoker.enable_bytecode_rewriter
- }
+ template("process_java_prebuilt") {
+ forward_variables_from(invoker, [ "testonly" ])
- _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
+ _rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
+ not_needed([ "_rebased_build_config" ])
+ not_needed(invoker, [ "build_config_dep" ])
- _deps = []
- _previous_output_jar = _input_jar_path
+ _deps = invoker.jar_deps
+ _previous_output_jar = invoker.input_jar_path
- if (!_skip_jetify) {
+ if (defined(invoker.jetified_jar_path)) {
_jetify_target = "${target_name}__jetify"
- _jetify_input_jar = _previous_output_jar
- _jetify_output_jar = "$target_out_dir/$target_name.jetified.jar"
action_with_pydeps(_jetify_target) {
script = "//build/android/gyp/jetify_jar.py"
deps = _deps
- if (defined(invoker.deps)) {
- deps += invoker.deps
- }
_jetify_jar_path =
"//third_party/jetifier_standalone/bin/jetifier-standalone"
_jetify_config_path =
"//third_party/jetifier_standalone/config/ignore_R.config"
inputs = [
- _jetify_input_jar,
+ _previous_output_jar,
_jetify_jar_path,
]
- outputs = [ _jetify_output_jar ]
+ outputs = [ invoker.jetified_jar_path ]
args = [
"--input-path",
rebase_path(invoker.input_jar_path, root_build_dir),
"--output-path",
- rebase_path(_jetify_output_jar, root_build_dir),
+ rebase_path(invoker.jetified_jar_path, root_build_dir),
"--jetify-path",
rebase_path(_jetify_jar_path, root_build_dir),
"--jetify-config-path",
@@ -1756,192 +1794,159 @@ if (enable_java_templates) {
_deps = []
_deps = [ ":$_jetify_target" ]
- _previous_output_jar = _jetify_output_jar
- }
-
- 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 (defined(_enable_custom_resources) && _enable_custom_resources) {
- args += [ "--enable-custom-resources" ]
- }
- if (_enable_thread_annotations) {
- args += [ "--enable-thread-annotations" ]
+ _previous_output_jar = invoker.jetified_jar_path
+ }
+
+ # Create the .jar in lib.java for use by java_binary.
+ if (defined(invoker.host_jar_path)) {
+ filter_jar("${target_name}_host") {
+ forward_variables_from(invoker,
+ [
+ "jar_excluded_patterns",
+ "jar_included_patterns",
+ "strip_resource_classes",
+ ])
+ deps = _deps
+ input_jar = _previous_output_jar
+ output_jar = invoker.host_jar_path
+ inputs = []
+ if (defined(strip_resource_classes) && strip_resource_classes) {
+ inputs += [ invoker.build_config ]
+ deps += [ invoker.build_config_dep ]
+ args += [ "--strip-resource-classes-for=@FileArg($_rebased_build_config:javac:resource_packages)" ]
}
- if (_enable_bytecode_checks) {
- args += [ "--enable-check-class-path" ]
+ if (defined(invoker.inputs)) {
+ inputs += invoker.inputs
+ deps += invoker.input_deps
}
- args += [
- "--missing-classes-allowlist",
- "${_missing_classes_allowlist}",
- "--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 (invoker.enable_desugar) {
- _desugar_target = "${target_name}__desugar"
- _desugar_input_jar = _previous_output_jar
- _desugar_output_jar = "$target_out_dir/$target_name.desugar.jar"
+ if (defined(invoker.device_jar_path)) {
+ if (invoker.enable_desugar) {
+ _desugar_target = "${target_name}_device__desugar"
+ _desugar_output_jar = "$target_out_dir/$target_name.desugar.jar"
- action_with_pydeps(_desugar_target) {
- script = "//build/android/gyp/desugar.py"
- deps = _deps
- depfile = "$target_gen_dir/$target_name.d"
- if (defined(invoker.deps)) {
- deps += invoker.deps
+ action_with_pydeps(_desugar_target) {
+ script = "//build/android/gyp/desugar.py"
+ deps = _deps + invoker.classpath_deps
+ depfile = "$target_gen_dir/$target_name.d"
+ _desugar_jar = "//third_party/bazel/desugar/Desugar.jar"
+
+ inputs = [
+ invoker.build_config,
+ _previous_output_jar,
+ _desugar_jar,
+ ]
+ outputs = [ _desugar_output_jar ]
+ args = [
+ "--desugar-jar",
+ rebase_path(_desugar_jar, root_build_dir),
+ "--input-jar",
+ rebase_path(_previous_output_jar, root_build_dir),
+ "--output-jar",
+ rebase_path(_desugar_output_jar, root_build_dir),
+
+ # Temporarily using java_full_interface_classpath until classpath validation of targets
+ # is implemented, see http://crbug.com/885273
+ "--classpath=@FileArg($_rebased_build_config:deps_info:jetified_full_jar_classpath)",
+ "--bootclasspath=@FileArg($_rebased_build_config:android:sdk_interface_jars)",
+ "--depfile",
+ rebase_path(depfile, root_build_dir),
+ ]
}
- _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:jetified_full_jar_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
}
- _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"
+ if (invoker.jacoco_instrument) {
+ _filter_jar_target_name = "${target_name}_device__filter_jar"
+ _filter_jar_output_jar = "$target_out_dir/$target_name.filter.jar"
+ } else {
+ _filter_jar_target_name = "${target_name}_device"
+ _filter_jar_output_jar = invoker.device_jar_path
+ }
+ filter_jar(_filter_jar_target_name) {
+ forward_variables_from(invoker,
+ [
+ "jar_excluded_patterns",
+ "jar_included_patterns",
+ "strip_resource_classes",
+ ])
deps = _deps
- 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) {
+ input_jar = _previous_output_jar
+ output_jar = _filter_jar_output_jar
+ inputs = []
+ if (defined(strip_resource_classes) && strip_resource_classes) {
+ inputs += [ invoker.build_config ]
+ deps += [ invoker.build_config_dep ]
args += [ "--strip-resource-classes-for=@FileArg($_rebased_build_config:javac:resource_packages)" ]
}
+ if (!defined(invoker.host_jar_path) && defined(invoker.inputs)) {
+ inputs += invoker.inputs
+ deps += invoker.input_deps
+ }
}
- _deps = []
- _deps = [ ":$_filter_target" ]
- _previous_output_jar = _filter_output_jar
- }
-
- if (_jacoco_instrument) {
- # Jacoco must run after desugar (or else desugar sometimes fails).
- _jacoco_target = "${target_name}__jacoco"
- _jacoco_input_jar = _previous_output_jar
- _jacoco_output_jar = "$target_out_dir/$target_name.instrumented.jar"
+ if (invoker.jacoco_instrument) {
+ # Jacoco must run after desugar (or else desugar sometimes fails).
+ # It must run after filtering to avoid the same (filtered) class mapping
+ # to multiple .jar files.
+ jacoco_instr("${target_name}_device") {
+ deps = [ ":$_filter_jar_target_name" ] + invoker.jar_deps
+ forward_variables_from(invoker,
+ [
+ "java_files",
+ "java_sources_file",
+ ])
- jacoco_instr(_jacoco_target) {
- deps = _deps
- if (defined(invoker.deps)) {
- deps += invoker.deps
+ input_jar_path = _filter_jar_output_jar
+ output_jar_path = invoker.device_jar_path
}
-
- forward_variables_from(invoker,
- [
- "java_files",
- "java_sources_file",
- ])
-
- input_jar_path = _jacoco_input_jar
- output_jar_path = _jacoco_output_jar
}
-
- _deps = []
- _deps = [ ":$_jacoco_target" ]
- _previous_output_jar = _jacoco_output_jar
}
+ }
- _output_jar_target = "${target_name}__copy"
-
- # This is copy_ex rather than copy to ensure that JARs (rather than
- # possibly broken symlinks to them) get copied into the output
- # directory.
- copy_ex(_output_jar_target) {
- forward_variables_from(invoker, [ "inputs" ])
- deps = _deps
- if (defined(invoker.deps)) {
- deps += invoker.deps
+ template("bytecode_processor") {
+ action_with_pydeps(target_name) {
+ forward_variables_from(invoker, [ "testonly" ])
+ _bytecode_checker_script = "$root_build_dir/bin/helper/bytecode_processor"
+ script = "//build/android/gyp/bytecode_processor.py"
+ inputs = [
+ invoker.build_config,
+ invoker.input_jar,
+ _bytecode_checker_script,
+ ]
+ outputs = [ "$target_out_dir/$target_name.bytecode.stamp" ]
+ deps =
+ invoker.deps +
+ [ "//build/android/bytecode:bytecode_processor($default_toolchain)" ]
+ _rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
+ args = [
+ "--script",
+ rebase_path(_bytecode_checker_script, root_build_dir),
+ "--gn-target=${invoker.target_label}",
+ "--input-jar",
+ rebase_path(invoker.input_jar, root_build_dir),
+ "--stamp",
+ rebase_path(outputs[0], root_build_dir),
+ "--direct-classpath-jars=@FileArg($_rebased_build_config:javac:classpath)",
+ "--full-classpath-jars=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)",
+ "--full-classpath-gn-targets=@FileArg($_rebased_build_config:deps_info:javac_full_classpath_targets)",
+ ]
+ if (invoker.is_prebuilt) {
+ args += [ "--is-prebuilt" ]
+ }
+ if (invoker.requires_android) {
+ args += [ "--sdk-classpath-jars=@FileArg($_rebased_build_config:android:sdk_jars)" ]
+ }
+ if (defined(invoker.missing_classes_allowlist)) {
+ args += [
+ "--missing-classes-allowlist=${invoker.missing_classes_allowlist}",
+ ]
}
- 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" ]
}
}
@@ -2125,10 +2130,14 @@ if (enable_java_templates) {
# final R.java sources for all resource packages the binary depends on.
#
# Input variables:
+ # android_sdk_dep: The sdk dep that these resources should compile against.
+ #
# deps: Specifies the input dependencies for this target.
#
# build_config: Path to the .build_config file corresponding to the target.
#
+ # build_config_dep: Dep target to generate the .build_config file.
+ #
# android_manifest: Path to root manifest for the binary.
#
# version_code: (optional)
@@ -2238,7 +2247,23 @@ if (enable_java_templates) {
"visibility",
])
- _deps = invoker.deps
+ _deps = [
+ invoker.android_sdk_dep,
+ invoker.build_config_dep,
+ ]
+ if (defined(invoker.android_manifest_dep)) {
+ _deps += [ invoker.android_manifest_dep ]
+ }
+ foreach(_dep, invoker.deps) {
+ _target_label = get_label_info(_dep, "label_no_toolchain")
+ if (filter_exclude([ _target_label ], _java_library_patterns) == [] &&
+ filter_exclude([ _target_label ], _java_resource_patterns) != []) {
+ # Depend on the java libraries' transitive __assetres target instead.
+ _deps += [ "${_target_label}__assetres" ]
+ } else {
+ _deps += [ _dep ]
+ }
+ }
if (defined(invoker.arsc_output)) {
_arsc_output = invoker.arsc_output
@@ -2506,43 +2531,26 @@ if (enable_java_templates) {
_args += [ "--is-bundle-module" ]
}
- if (defined(invoker.verify_manifest_target_name)) {
+ if (defined(invoker.expected_android_manifest)) {
_expectations_target =
- "${invoker.verify_manifest_target_name}_manifest_expectations"
+ "${invoker.top_target_name}_validate_android_manifest"
action_with_pydeps(_expectations_target) {
- _target_src_dir = get_label_info(":$target_name", "dir")
_normalized_output = "${invoker.android_manifest}.normalized"
- _manifest_expectations_failure_filepath =
+ _failure_file =
"$android_configuration_failure_dir/" +
- "${invoker.verify_manifest_target_name}.AndroidManifest.failed"
+ string_replace(invoker.expected_android_manifest, "/", "_")
inputs = [
invoker.android_manifest,
invoker.build_config,
+ invoker.expected_android_manifest,
]
- if (defined(invoker.expected_manifest_base_expectation)) {
+ if (defined(invoker.expected_android_manifest_base)) {
_args += [
"--expected-manifest-base-expectation",
- rebase_path(invoker.expected_manifest_base_expectation,
- root_build_dir),
+ rebase_path(invoker.expected_android_manifest_base, root_build_dir),
]
- inputs += [ invoker.expected_manifest_base_expectation ]
-
- # When invoker.expected_manifest_base_expectation is defined, we use
- # a different file extension to indicate that the expected file is a
- # diff file.
- # In addition, we set expected_manifest_base_expectation only for
- # internal targets, therefore, the expected file is in a different
- # directory.
- _expected_file =
- "$_target_src_dir/" +
- "${invoker.verify_manifest_target_name}.AndroidManifest" +
- ".diff.expected"
- } else {
- _expected_file =
- "$_target_src_dir/java/" +
- "${invoker.verify_manifest_target_name}.AndroidManifest.expected"
+ inputs += [ invoker.expected_android_manifest_base ]
}
- inputs += [ _expected_file ]
if (fail_on_android_expectations) {
_args += [ "--fail-on-expectations" ]
}
@@ -2555,12 +2563,11 @@ if (enable_java_templates) {
script = _script
args = _args + [
"--expected-file",
- rebase_path(_expected_file, root_build_dir),
+ rebase_path(invoker.expected_android_manifest, root_build_dir),
"--android-manifest-normalized",
rebase_path(_normalized_output, root_build_dir),
"--android-manifest-expectations-failure-file",
- rebase_path(_manifest_expectations_failure_filepath,
- root_build_dir),
+ rebase_path(_failure_file, root_build_dir),
"--only-verify-expectations",
]
}
@@ -2636,7 +2643,7 @@ if (enable_java_templates) {
_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:unprocessed_jar_path)",
"--jar-files=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)",
"--in-res-info-path",
rebase_path(invoker.res_size_info_path, root_build_dir),
@@ -2675,9 +2682,8 @@ if (enable_java_templates) {
# keystore_password: Keystore password.
# uncompress_shared_libraries: (optional, default false) Whether to store
# native libraries inside the APK uncompressed and page-aligned.
- # verify_native_libs_and_assets_target_name: (optional): If set, will verify
- # the list of included native libraries and assets is consistent with an
- # expectation file.
+ # expected_libs_and_assets: (optional): Verify the list of included native
+ # libraries and assets is consistent with the given expectation file.
template("package_apk") {
forward_variables_from(invoker,
[
@@ -2803,43 +2809,33 @@ if (enable_java_templates) {
_args += [ "--secondary-native-lib-placeholders=$_secondary_native_lib_placeholders" ]
}
- if (defined(invoker.verify_native_libs_and_assets_target_name)) {
+ if (defined(invoker.expected_libs_and_assets)) {
_expectations_target =
- "${invoker.verify_native_libs_and_assets_target_name}" +
- "_libs_and_assets_expectations"
+ "${invoker.top_target_name}_validate_libs_and_assets"
action_with_pydeps(_expectations_target) {
_stamp = "$target_gen_dir/$target_name.stamp"
- _target_src_dir = get_label_info(":$target_name", "dir")
- _expected_native_libs_and_assets =
- "$_target_src_dir/java/" +
- "${invoker.verify_native_libs_and_assets_target_name}." +
- "${target_cpu}.native_libs_and_assets.expected"
- _native_libs_and_assets_expectation_failure_filepath =
+ _failure_file =
"$android_configuration_failure_dir/" +
- "${invoker.verify_native_libs_and_assets_target_name}." +
- "${target_cpu}.native_libs_and_assets.failed"
- if (fail_on_android_expectations) {
- _args += [ "--fail-on-expectations" ]
- }
-
+ string_replace(invoker.expected_libs_and_assets, "/", "_")
inputs = [
invoker.build_config,
- _expected_native_libs_and_assets,
+ invoker.expected_libs_and_assets,
]
deps = [ invoker.build_config_dep ]
outputs = [ _stamp ]
script = _script
- args =
- _args + [
- "--expected-native-libs-and-assets",
- rebase_path(_expected_native_libs_and_assets, root_build_dir),
- "--native-libs-and-assets-expectation-failure-file",
- rebase_path(_native_libs_and_assets_expectation_failure_filepath,
- root_build_dir),
- "--stamp",
- rebase_path(_stamp, root_build_dir),
- "--only-verify-expectations",
- ]
+ args = _args + [
+ "--expected-native-libs-and-assets",
+ rebase_path(invoker.expected_libs_and_assets, root_build_dir),
+ "--native-libs-and-assets-expectation-failure-file",
+ rebase_path(_failure_file, root_build_dir),
+ "--stamp",
+ rebase_path(_stamp, root_build_dir),
+ "--only-verify-expectations",
+ ]
+ if (fail_on_android_expectations) {
+ args += [ "--fail-on-expectations" ]
+ }
}
_deps += [ ":$_expectations_target" ]
}
@@ -2889,7 +2885,6 @@ if (enable_java_templates) {
# javac:processor_classes
# javac_jar_path: Path to the final output .jar file.
# javac_args: Optional list of extra arguments to pass to javac.
- # never_goma: When true, ignore the value of use_java_goma.
# 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
@@ -3016,8 +3011,7 @@ if (enable_java_templates) {
if (invoker.supports_android || invoker.use_turbine) {
args += [ "--java-version=1.8" ]
}
- if ((!defined(invoker.never_goma) || !invoker.never_goma) &&
- use_java_goma) {
+ if (use_java_goma) {
args += [ "--gomacc-path=$goma_dir/gomacc" ]
# Override the default action_pool when goma is enabled.
@@ -3047,16 +3041,14 @@ if (enable_java_templates) {
if (invoker.enable_errorprone) {
# Our custom plugin pulls in the main errorprone dep transitively.
- _errorprone_dep =
- "//tools/android/errorprone_plugin:errorprone_plugin_java"
+ _errorprone_dep = "//tools/android/errorprone_plugin:errorprone_plugin"
deps += [ _errorprone_dep ]
_dep_gen_dir = get_label_info(_errorprone_dep, "target_gen_dir")
_dep_name = get_label_info(_errorprone_dep, "name")
_rebased_errorprone_buildconfig =
rebase_path("$_dep_gen_dir/$_dep_name.build_config", root_build_dir)
args += [
- "--processorpath=@FileArg($_rebased_errorprone_buildconfig:deps_info:jar_path)",
- "--processorpath=@FileArg($_rebased_errorprone_buildconfig:deps_info:javac_full_classpath)",
+ "--processorpath=@FileArg($_rebased_errorprone_buildconfig:deps_info:host_classpath)",
"--enable-errorprone",
]
}
@@ -3083,37 +3075,22 @@ if (enable_java_templates) {
}
}
- template("java_header_group") {
+ template("java_lib_group") {
forward_variables_from(invoker, [ "testonly" ])
+ _group_name = invoker.group_name
+ not_needed([ "_group_name" ])
group(target_name) {
if (defined(invoker.deps)) {
deps = []
foreach(_dep, invoker.deps) {
_target_label = get_label_info(_dep, "label_no_toolchain")
- if (filter_exclude([ _target_label ], _java_lib_patterns) == [] &&
- filter_exclude([ _target_label ], _java_lib_exceptions) != []) {
- # This is a java dep, so replace it.
- deps += [ "${_target_label}__header" ]
- } else {
- deps += [ _dep ]
- }
- }
- }
- }
- }
-
- template("java_impl_group") {
- forward_variables_from(invoker, [ "testonly" ])
- group(target_name) {
- if (defined(invoker.deps)) {
- deps = []
- foreach(_dep, invoker.deps) {
- _target_label = get_label_info(_dep, "label_no_toolchain")
- if (filter_exclude([ _target_label ], _java_lib_patterns) == [] &&
- filter_exclude([ _target_label ], _java_lib_exceptions) != []) {
- # This is a java dep, so replace it.
- deps += [ "${_target_label}__impl" ]
+ if (filter_exclude([ _target_label ], _java_library_patterns) == [] &&
+ filter_exclude([ _target_label ], _java_resource_patterns) !=
+ []) {
+ # This is a java library dep, so replace it.
+ deps += [ "${_target_label}__${_group_name}" ]
} else {
+ # Transitive java group targets should also include direct deps.
deps += [ _dep ]
}
}
@@ -3184,7 +3161,6 @@ if (enable_java_templates) {
# 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.
- # never_goma: When true, ignore the value of use_java_goma.
# 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.
@@ -3194,23 +3170,14 @@ if (enable_java_templates) {
# 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
+ # output_name: Optional output name for the final jar path. Used to
+ # determine the name of the final jar. 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.
- # enable_turbine: If exists then will be used to determine whether to run
- # turbine or not. Useful for disabling turbine headers for problematic
- # targets.
# 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
@@ -3244,8 +3211,6 @@ if (enable_java_templates) {
# 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.
- # min_sdk_version: Optional. The minimum Android SDK version this target
- # supports.
#
# For 'android_apk' and 'android_app_bundle_module' targets only:
#
@@ -3293,15 +3258,12 @@ if (enable_java_templates) {
# TODO(crbug.com/1042017): Remove.
not_needed(invoker, [ "no_build_hooks" ])
- # TODO(bjoyce): Remove when able to use.
- not_needed(invoker, [ "enable_jetify" ])
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 =
@@ -3341,8 +3303,6 @@ if (enable_java_templates) {
"main_class cannot be used for target of type ${invoker.type}")
}
- # 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 {
@@ -3357,7 +3317,15 @@ if (enable_java_templates) {
}
}
+ # 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"
+
# The only target that might have no prebuilt and no sources is a java_binary.
+ _build_host_jar = false
+ _build_device_jar = false
if (_is_prebuilt || _has_sources) {
if (defined(invoker.output_name)) {
_output_name = invoker.output_name
@@ -3367,20 +3335,25 @@ if (enable_java_templates) {
_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
+ _build_host_jar = _is_java_binary || _is_annotation_processor ||
+ invoker.type == "java_library"
+ _build_device_jar =
+ invoker.type != "system_java_library" && _supports_android
+ if (_build_host_jar) {
+ # Jar files can be needed at runtime (by Robolectric tests or java binaries),
+ # so do not put them under obj/.
+ # TODO(agrieve): I suspect it would be better to use dist_jar for java_binary
+ # rather than archiving unnecessary .jar files within lib.java.
+ _target_dir_name = get_label_info(":$_main_target_name", "dir")
+ _host_processed_jar_path =
+ "$root_out_dir/lib.java$_target_dir_name/$_output_name.jar"
}
-
- # TODO(wnwen): Enable turbine for non-chromium code when r8 optimizes out
- # bridge methods.
- _enable_turbine = _has_sources && _chromium_code
- if (defined(invoker.enable_turbine)) {
- _enable_turbine = invoker.enable_turbine
+ if (_build_device_jar) {
+ _device_processed_jar_path =
+ "$target_out_dir/$_output_name.processed.jar"
+ _dex_path = "$target_out_dir/$_main_target_name.dex.jar"
+ _enable_desugar =
+ !defined(invoker.enable_desugar) || !invoker.enable_desugar
}
# For static libraries, the javac jar output is created at the intermediate
@@ -3388,13 +3361,10 @@ if (enable_java_templates) {
# spot that the .build_config knows about. Technically this should be done
# for the ijar as well, but this is only used for APK targets where
# the ijar path isn't actually used.
- _build_config_jar_path = _final_jar_path
- _final_ijar_path = get_path_info(_final_jar_path, "dir") + "/" +
- get_path_info(_final_jar_path, "name")
- if (_enable_turbine) {
- _final_ijar_path += ".turbine.jar"
+ if (_has_sources) {
+ _final_ijar_path = "$target_out_dir/$_output_name.turbine.jar"
} else {
- _final_ijar_path += ".ijar.jar"
+ _final_ijar_path = "$target_out_dir/$_output_name.ijar.jar"
}
if (_has_sources) {
@@ -3408,58 +3378,77 @@ if (enable_java_templates) {
} else {
_unprocessed_jar_path = _javac_jar_path
}
-
- if (_supports_android) {
- _dex_path = "$target_out_dir/$_main_target_name.dex.jar"
- if (defined(invoker.dex_path)) {
- _dex_path = invoker.dex_path
- }
+ }
+ if (_build_host_jar || _build_device_jar) {
+ if (defined(invoker.enable_jetify) && invoker.enable_jetify) {
+ _jetified_jar_path = "$target_out_dir/${_main_target_name}.jetified.jar"
}
}
- _public_deps = []
- _accumulated_deps = []
- _java_header_deps = []
- _java_impl_deps = []
- _java_full_deps = []
- if (defined(invoker.deps)) {
- foreach(_dep, invoker.deps) {
- _target_label = get_label_info(_dep, "label_no_toolchain")
- if (filter_exclude([ _target_label ], _java_lib_patterns) == [] &&
- filter_exclude([ _target_label ], _java_lib_exceptions) != []) {
- # This is a java dep, so replace it with its header.
- _java_header_deps += [ "${_target_label}__header" ]
- _java_impl_deps += [ "${_target_label}__impl" ]
- _java_full_deps += [ _dep ]
- } else {
- # Not a java header dep, so no need to replace it with its header.
- _accumulated_deps += [ _dep ]
+ if (_is_prebuilt || _has_sources) {
+ _java_header_deps = []
+ _java_impl_deps = []
+ _non_java_deps = []
+ if (defined(invoker.deps)) {
+ foreach(_dep, invoker.deps) {
+ _target_label = get_label_info(_dep, "label_no_toolchain")
+ if (filter_exclude([ _target_label ], _java_library_patterns) == [] &&
+ filter_exclude([ _target_label ], _java_resource_patterns) !=
+ []) {
+ # This is a java dep, so replace it with its header.
+ _java_header_deps += [ "${_target_label}__header" ]
+ _java_impl_deps += [ "${_target_label}__impl" ]
+ } else {
+ _non_java_deps += [ _dep ]
+ }
}
}
- }
- # TODO(crbug.com/1078484): Don't use desugared .jar files for java binaries.
- if (_is_java_binary && enable_bazel_desugar) {
- _accumulated_deps +=
- [ "//third_party/bazel/desugar:desugar_runtime_java" ]
- }
+ # Don't need to depend on the apk-under-test to be packaged.
+ if (defined(invoker.apk_under_test)) {
+ _java_header_deps += [ "${invoker.apk_under_test}__java__header" ]
+ _java_impl_deps += [ "${invoker.apk_under_test}__java__impl" ]
+ }
- if (defined(_final_jar_path)) {
+ _extra_java_deps = []
_jacoco_instrument =
use_jacoco_coverage && _chromium_code && _java_files != [] &&
- !_is_java_binary && !_is_annotation_processor &&
- (!defined(invoker.testonly) || !invoker.testonly)
+ _build_device_jar && (!defined(invoker.testonly) || !invoker.testonly)
if (defined(invoker.jacoco_never_instrument)) {
_jacoco_instrument =
!invoker.jacoco_never_instrument && _jacoco_instrument
}
if (_jacoco_instrument) {
- _java_full_deps += [ "//third_party/jacoco:jacocoagent_java" ]
- _java_header_deps += [ "//third_party/jacoco:jacocoagent_java__header" ]
- _java_impl_deps += [ "//third_party/jacoco:jacocoagent_java__impl" ]
+ _extra_java_deps += [ "//third_party/jacoco:jacocoagent_java" ]
+ }
+
+ _include_android_sdk = _build_device_jar
+ if (defined(invoker.include_android_sdk)) {
+ _include_android_sdk = invoker.include_android_sdk
+ }
+ if (_include_android_sdk) {
+ _sdk_java_dep = "//third_party/android_sdk:android_sdk_java"
+ if (defined(invoker.alternative_android_sdk_dep)) {
+ _sdk_java_dep = invoker.alternative_android_sdk_dep
+ }
+
+ # This is an android_system_java_prebuilt target, so no headers.
+ _extra_java_deps += [ _sdk_java_dep ]
}
+
+ _classpath_deps = _java_header_deps + _non_java_deps + _extra_java_deps +
+ [ ":$_build_config_target_name" ]
+ _full_classpath_deps =
+ _java_impl_deps + _non_java_deps + _extra_java_deps +
+ [ ":$_build_config_target_name" ]
}
+ # Often needed, but too hard to figure out when ahead of time.
+ not_needed([
+ "_classpath_deps",
+ "_full_classpath_deps",
+ ])
+
if (_java_files != []) {
_java_sources_file = "$target_gen_dir/$_main_target_name.sources"
if (defined(invoker.java_sources_file)) {
@@ -3468,28 +3457,6 @@ if (enable_java_templates) {
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) {
- _sdk_java_dep = "//third_party/android_sdk:android_sdk_java"
- if (defined(invoker.alternative_android_sdk_dep)) {
- _sdk_java_dep = invoker.alternative_android_sdk_dep
- }
-
- # This is an android_system_java_prebuilt target, so no headers.
- _accumulated_deps += [ _sdk_java_dep ]
- }
- _jetified_jar_path =
- "$target_out_dir/${target_name}__process_prebuilt.jetified.jar"
-
- # 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,
[
@@ -3498,6 +3465,7 @@ if (enable_java_templates) {
"gradle_treat_as_prebuilt",
"input_jars_paths",
"main_class",
+ "public_target_label",
"proguard_configs",
"proguard_enabled",
"proguard_mapping_path",
@@ -3545,9 +3513,17 @@ if (enable_java_templates) {
chromium_code = _chromium_code
build_config = _build_config
is_prebuilt = _is_prebuilt
- jetified_jar_path = _jetified_jar_path
- possible_config_deps = _java_full_deps + _accumulated_deps
- skip_jetify = defined(invoker.skip_jetify) && invoker.skip_jetify
+ if (defined(invoker.enable_jetify) && invoker.enable_jetify) {
+ jetified_jar_path = _jetified_jar_path
+ }
+
+ possible_config_deps = []
+ if (defined(_extra_java_deps)) {
+ possible_config_deps = _extra_java_deps
+ }
+ if (defined(invoker.deps)) {
+ possible_config_deps += invoker.deps
+ }
if (defined(apk_under_test)) {
possible_config_deps += [ apk_under_test ]
}
@@ -3556,12 +3532,15 @@ if (enable_java_templates) {
bypass_platform_checks = defined(invoker.bypass_platform_checks) &&
invoker.bypass_platform_checks
- if (defined(_final_jar_path)) {
- jar_path = _build_config_jar_path
+ if (_is_prebuilt || _has_sources) {
ijar_path = _final_ijar_path
unprocessed_jar_path = _unprocessed_jar_path
}
- if (defined(_dex_path)) {
+ if (_build_host_jar) {
+ host_jar_path = _host_processed_jar_path
+ }
+ if (_build_device_jar) {
+ device_jar_path = _device_processed_jar_path
dex_path = _dex_path
}
if (_java_files != []) {
@@ -3576,35 +3555,22 @@ if (enable_java_templates) {
}
if (defined(invoker.include_java_resources) &&
invoker.include_java_resources) {
+ java_resources_jar = _unprocessed_jar_path
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
+ java_resources_jar = _device_processed_jar_path
}
}
}
- # Don't need to depend on the apk-under-test to be packaged.
- if (defined(invoker.apk_under_test)) {
- # No need to add to _java_full_deps since that is only used for
- # write_build_config.
- _java_header_deps += [ "${invoker.apk_under_test}__java__header" ]
- _java_impl_deps += [ "${invoker.apk_under_test}__java__impl" ]
- }
- if (defined(invoker.android_manifest_dep)) {
- _accumulated_deps += [ invoker.android_manifest_dep ]
- }
- if (defined(invoker.annotation_processor_deps)) {
- # We need the full annotation processors rather than just the headers.
- _accumulated_deps += invoker.annotation_processor_deps
- }
-
- if (_has_sources || _is_prebuilt) {
+ if (_is_prebuilt || _has_sources) {
_header_target_name = "${target_name}__header"
}
+ _public_deps = []
+ _analysis_public_deps = []
if (_has_sources) {
if (defined(invoker.enable_errorprone)) {
_enable_errorprone = invoker.enable_errorprone
@@ -3635,8 +3601,7 @@ if (enable_java_templates) {
if (!defined(deps)) {
deps = []
}
- deps += _java_header_deps + _accumulated_deps +
- [ ":$_build_config_target_name" ]
+ deps += _classpath_deps
# android_apk and junit_binary pass R.java srcjars via srcjar_deps.
if (_type == "java_library" && _requires_android) {
@@ -3652,27 +3617,27 @@ if (enable_java_templates) {
"provider_configurations",
"javac_args",
"jar_excluded_patterns",
- "never_goma",
]
+ _annotation_processor_deps = []
+ if (defined(invoker.annotation_processor_deps)) {
+ _annotation_processor_deps = invoker.annotation_processor_deps
+ }
- if (_enable_turbine) {
- compile_java_helper(_header_target_name) {
- forward_variables_from(invoker, _compile_java_forward_variables)
- use_turbine = true
- output_jar_path = _final_ijar_path
- generated_jar_path = _generated_jar_path
- }
+ compile_java_helper(_header_target_name) {
+ forward_variables_from(invoker, _compile_java_forward_variables)
+ use_turbine = true
+ output_jar_path = _final_ijar_path
+ generated_jar_path = _generated_jar_path
+ deps = _annotation_processor_deps
}
+ _public_deps += [ ":$_header_target_name" ]
- _analysis_public_deps = []
_compile_java_target = "${_main_target_name}__compile_java"
compile_java_helper(_compile_java_target) {
forward_variables_from(invoker, _compile_java_forward_variables)
output_jar_path = _javac_jar_path
- if (_enable_turbine) {
- deps = [ ":$_header_target_name" ]
- generated_jar_path = _generated_jar_path
- }
+ deps = [ ":$_header_target_name" ]
+ generated_jar_path = _generated_jar_path
}
if (_enable_errorprone) {
_compile_java_errorprone_target = "${_main_target_name}__errorprone"
@@ -3685,121 +3650,129 @@ if (enable_java_templates) {
}
javac_args += invoker.errorprone_args
}
- if (_enable_turbine) {
- deps = [ ":$_header_target_name" ]
- generated_jar_path = _generated_jar_path
- }
+ deps = [ ":$_header_target_name" ]
+ generated_jar_path = _generated_jar_path
output_jar_path = "$target_out_dir/$target_name.errorprone.stamp"
}
_analysis_public_deps += [ ":$_compile_java_errorprone_target" ]
}
} # _has_sources
- if (_has_sources || _is_prebuilt) {
- if (!_enable_turbine) {
- generate_interface_jar(_header_target_name) {
- # 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
-
- # Some prebuilts have java deps (e.g. //third_party/proguard:retrace_java).
- deps = _java_header_deps + _accumulated_deps
- if (_has_sources) {
- deps += [ ":$_compile_java_target" ]
- }
+ if (_is_prebuilt) {
+ generate_interface_jar(_header_target_name) {
+ # 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
+
+ # ijar does not require classpath, but must declare these as deps so
+ # that they are transitive deps for targets that depend on this
+ # target. If we can change compile & desugar steps to use direct
+ # interface classpath rather than full interface classpath, then this
+ # could just be _non_java_deps.
+ deps = _classpath_deps
+ if (_has_sources) {
+ deps += [ ":$_compile_java_target" ]
}
}
_public_deps += [ ":$_header_target_name" ]
}
- if (defined(_final_jar_path)) {
- if (_is_system_library) {
- # These deps are only needed for the process_java_prebuilt template.
- not_needed([ "_java_impl_deps" ])
-
- _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 ]
+ if (_build_host_jar || _build_device_jar) {
+ _process_prebuilt_target_name = "${target_name}_process"
+ process_java_prebuilt(_process_prebuilt_target_name) {
+ forward_variables_from(invoker,
+ [
+ "jar_excluded_patterns",
+ "jar_included_patterns",
+ ])
+ build_config = _build_config
+ build_config_dep = ":$_build_config_target_name"
+ input_jar_path = _unprocessed_jar_path
+ jar_deps = _non_java_deps
+ if (_has_sources) {
+ jar_deps += [ ":$_compile_java_target" ]
}
- _public_deps += [ ":$_copy_system_library_target_name" ]
- } else {
- _enable_desugar = (!defined(invoker.enable_desugar) ||
- !invoker.enable_desugar) && _supports_android
- _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",
- "missing_classes_allowlist",
- "jar_excluded_patterns",
- "jar_included_patterns",
- "skip_jetify",
- ])
- enable_desugar = _enable_desugar && enable_bazel_desugar
- is_prebuilt = _is_prebuilt
- build_config = _build_config
- input_jar_path = _unprocessed_jar_path
+ if (_build_host_jar) {
+ host_jar_path = _host_processed_jar_path
+ }
+ if (_build_device_jar) {
+ device_jar_path = _device_processed_jar_path
jacoco_instrument = _jacoco_instrument
if (_jacoco_instrument) {
java_files = _java_files
java_sources_file = _java_sources_file
}
- output_jar_path = _final_jar_path
- deps = _java_impl_deps + _accumulated_deps +
- [ ":$_build_config_target_name" ]
- if (_has_sources) {
- deps += [ ":$_compile_java_target" ]
- }
-
- # 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.
+ enable_desugar = _enable_desugar && enable_bazel_desugar
+ if (enable_desugar) {
+ classpath_deps = _full_classpath_deps
}
}
- _public_deps += [ ":$_process_prebuilt_target_name" ]
+ if (defined(invoker.enable_jetify) && invoker.enable_jetify) {
+ jetified_jar_path = _jetified_jar_path
+ }
- if (defined(_dex_path)) {
- dex("${target_name}__dex") {
- input_class_jars = [ _final_jar_path ]
+ # 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
+ input_deps = _non_java_deps + _srcjar_deps # For the aapt-generated
+ # proguard rules.
+ }
+ }
+ if (_build_host_jar) {
+ _public_deps += [ ":${_process_prebuilt_target_name}_host" ]
+ }
+ if (_build_device_jar) {
+ _public_deps += [ ":${_process_prebuilt_target_name}_device" ]
+ }
- enable_desugar = _enable_desugar
+ if (!defined(invoker.enable_bytecode_checks) ||
+ invoker.enable_bytecode_checks) {
+ _bytecode_checks_target = "${target_name}__validate_classpath"
+ bytecode_processor(_bytecode_checks_target) {
+ forward_variables_from(invoker, [ "missing_classes_allowlist" ])
+ deps = _full_classpath_deps
+ if (_has_sources) {
+ deps += [ ":$_compile_java_target" ]
+ }
+ requires_android = _requires_android
+ target_label =
+ get_label_info(":${invoker.target_name}", "label_no_toolchain")
+ input_jar = _unprocessed_jar_path
+ build_config = _build_config
+ is_prebuilt = _is_prebuilt
+ }
+ _analysis_public_deps += [ ":$_bytecode_checks_target" ]
+ }
+ }
- # There's no value in per-class dexing prebuilts since they never
- # change just one class at a time.
- disable_incremental = _is_prebuilt
- output = _dex_path
- deps = [ ":$_process_prebuilt_target_name" ]
+ if (_build_device_jar) {
+ dex("${target_name}__dex") {
+ input_class_jars = [ _device_processed_jar_path ]
+ enable_desugar = _enable_desugar
- if (enable_desugar && !enable_bazel_desugar) {
- build_config = _build_config
- final_ijar_path = _final_ijar_path
- deps += _java_header_deps + [ ":$_header_target_name" ]
- }
+ # There's no value in per-class dexing prebuilts since they never
+ # change just one class at a time.
+ disable_incremental = _is_prebuilt
+ output = _dex_path
+ deps = [ ":${_process_prebuilt_target_name}_device" ]
- # For library targets, we do not need a proper main dex list, but do
- # need to allow multiple dex files.
- enable_multidex = false
- enable_library_multidex = true
- }
- _public_deps += [ ":${target_name}__dex" ]
+ if (enable_desugar && !enable_bazel_desugar) {
+ # Desugaring with D8 requires full classpath.
+ build_config = _build_config
+ final_ijar_path = _final_ijar_path
+ deps += _classpath_deps + [ ":$_header_target_name" ]
}
+
+ enable_multidex = false
+ is_library = true
}
+ _public_deps += [ ":${target_name}__dex" ]
}
if (_is_java_binary) {
@@ -3829,6 +3802,11 @@ if (enable_java_templates) {
public_deps = _public_deps
}
+ java_lib_group("${target_name}__assetres") {
+ forward_variables_from(invoker, [ "deps" ])
+ group_name = "assetres"
+ }
+
group(target_name) {
forward_variables_from(invoker,
[
@@ -3873,13 +3851,17 @@ if (enable_java_templates) {
# packaged into each module.
# is_multi_abi: If true will add a library placeholder for the missing ABI if
# either the primary or the secondary ABI has no native libraries set.
-# verify_native_libs_and_assets_target_name: (optional): If set, will verify
-# the list of included native libraries and assets is consistent with an
-# expectation file.
+# expected_libs_and_assets: (optional): Verify the list of included native
+# libraries and assets is consistent with the given expectation file.
+# 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.
template("create_android_app_bundle_module") {
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
_rebased_native_libraries_config =
rebase_path(invoker.native_libraries_config, root_build_dir)
+ _proguard_enabled =
+ defined(invoker.proguard_enabled) && invoker.proguard_enabled
forward_variables_from(invoker,
[
@@ -3950,8 +3932,9 @@ template("create_android_app_bundle_module") {
_args += [ "--dex-file=@FileArg($_rebased_build_config:final_dex:path)" ]
}
- # TODO(https://crbug.com/1056751): Add support for proguarding jdk libs.
- if (enable_jdk_library_desugaring && invoker.module_name == "base") {
+ # The library is imported via proguard when proguard is enabled.
+ if (!_proguard_enabled && enable_jdk_library_desugaring &&
+ invoker.module_name == "base") {
_all_jdk_libs = "//build/android:all_jdk_libs"
_deps += [ _all_jdk_libs ]
_jdk_libs_dex =
@@ -3963,26 +3946,14 @@ template("create_android_app_bundle_module") {
]
}
- if (defined(invoker.verify_native_libs_and_assets_target_name)) {
- _expectations_target =
- "${invoker.verify_native_libs_and_assets_target_name}" +
- "_libs_and_assets_expectations"
+ if (defined(invoker.expected_libs_and_assets)) {
+ _expectations_target = "${invoker.top_target_name}_validate_libs_and_assets"
action_with_pydeps(_expectations_target) {
_stamp = "$target_gen_dir/$target_name.stamp"
- _target_src_dir = get_label_info(":$target_name", "dir")
- _expected_native_libs_and_assets =
- "$_target_src_dir/java/" +
- "${invoker.verify_native_libs_and_assets_target_name}." +
- "${target_cpu}.native_libs_and_assets.expected"
- _native_libs_and_assets_expectation_failure_filepath =
- "$android_configuration_failure_dir/" +
- "${invoker.verify_native_libs_and_assets_target_name}." +
- "${target_cpu}.native_libs_and_assets.failed"
- if (fail_on_android_expectations) {
- _args += [ "--fail-on-expectations" ]
- }
+ _failure_file = "$android_configuration_failure_dir/" +
+ string_replace(invoker.expected_libs_and_assets, "/", "_")
inputs = [
- _expected_native_libs_and_assets,
+ invoker.expected_libs_and_assets,
invoker.build_config,
invoker.native_libraries_config,
]
@@ -3998,14 +3969,16 @@ template("create_android_app_bundle_module") {
script = _script
args = _args + [
"--expected-native-libs-and-assets",
- rebase_path(_expected_native_libs_and_assets, root_build_dir),
+ rebase_path(invoker.expected_libs_and_assets, root_build_dir),
"--native-libs-and-assets-expectation-failure-file",
- rebase_path(_native_libs_and_assets_expectation_failure_filepath,
- root_build_dir),
+ rebase_path(_failure_file, root_build_dir),
"--stamp",
rebase_path(_stamp, root_build_dir),
"--only-verify-expectations",
]
+ if (fail_on_android_expectations) {
+ args += [ "--fail-on-expectations" ]
+ }
}
_deps += [ ":$_expectations_target" ]
}
@@ -4066,7 +4039,7 @@ template("dexsplitter") {
"--dex-dest=@FileArg($_rebased_module_build_config:final_dex:path)",
]
if (!defined(invoker.feature_jars_args)) {
- args += [ "--feature-jars=@FileArg($_rebased_module_build_config:deps_info:java_runtime_classpath)" ]
+ args += [ "--feature-jars=@FileArg($_rebased_module_build_config:deps_info:device_classpath)" ]
}
deps += [ _feature_module.build_config_target ]
}