Commit 81f95977 authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android: Improve type filtering, add __assetres (reland)

Add _java_resource_types, _java_library_types, and _java_leaf_types.
These types, together with "group", define all existing invoker.type
values for all java targets. Since leaf types like android_apk are not
used as dependencies for other java targets, all java targets in deps
trees can be defined as either resources, libraries, or groups.

Naming conventions have also been improved. Now java targets must match
_java_resource_patterns if the target is a resource target. Otherwise,
it must match _java_library_patterns if the target is a library target.
Group targets can match either of those, but should prefer matching
_java_library_patterns since they are treated as library targets in the
java_group template.

Thus, target filtering is now simplified. To filter for resource targets
, simply use _java_resource_patterns. To filter for library targets, use
_java_library_patterns and ignore the ones that also match
_java_resource_patterns. To filter for any java target, use
_java_target_patterns, which is a simple concatenation of the other two
lists of patterns.

The assert in write_build_config has been updated to enforce naming
schemes accordingly. This enables assumptions about library and resource
targets such as __header, __impl, and the newly added __assetres, which
is defined on library targets to be its transitive list of all resource
target deps.

Now compile_resources targets can filter their deps so that they only
depend on transitive resource deps. This allows compile_resources to
not depend on java library targets, and unblocks header generation for
apk targets. Previously an apk's __header target would depend on
compile_resources to finish, while the compile_resources target would
depend on the rest of the java library dependencies (not headers),
completely removing any benefit of header compilation for apk targets.

Original CL: https://crrev.com/c/2220585

Fixed:
- Turns out compile_resources depends on the android sdk, and that was
  either supplied directly (in the case of android_apk_or_module) or it
  was supplied by its java dependencies (in the case of junit_binary).
- This dependency was broken by replacing java library deps with their
  corresponding __assetres deps.
- Fixed by explicitly specifying android_sdk_dep just like
  build_config_dep.
- Added comments for both of these explicit *_dep variables.

Bug: 1090812
Change-Id: I57c63ff805c4e27ff6b47bc69c0a6954b0b681c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2231178
Commit-Queue: Peter Wen <wnwen@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Auto-Submit: Peter Wen <wnwen@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775105}
parent 66bfc24c
This diff is collapsed.
......@@ -1123,12 +1123,9 @@ if (enable_java_templates) {
# }
# }
template("java_group") {
forward_variables_from(invoker,
[
"testonly",
"input_jars_paths",
])
forward_variables_from(invoker, [ "testonly" ])
write_build_config("$target_name$build_config_target_suffix") {
forward_variables_from(invoker, [ "input_jars_paths" ])
type = "group"
build_config = "$target_gen_dir/${invoker.target_name}.build_config"
supports_android = true
......@@ -1140,6 +1137,7 @@ if (enable_java_templates) {
[
"header",
"impl",
"assetres",
]) {
java_lib_group("${target_name}__${_group_name}") {
forward_variables_from(invoker, [ "deps" ])
......@@ -1346,6 +1344,11 @@ if (enable_java_templates) {
if (defined(invoker.deps)) {
_deps += invoker.deps
}
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"
}
# 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
......@@ -1360,7 +1363,9 @@ if (enable_java_templates) {
_compile_resources_target = "${target_name}__compile_resources"
compile_resources(_compile_resources_target) {
forward_variables_from(invoker, [ "android_manifest" ])
deps = _deps + [ ":$_build_config_target_name" ]
deps = _deps
android_sdk_dep = _android_sdk_dep
build_config_dep = ":$_build_config_target_name"
build_config = _build_config
if (defined(_package_name)) {
rename_manifest_package = _package_name
......@@ -2491,6 +2496,7 @@ if (enable_java_templates) {
short_resource_paths = _short_resource_paths
strip_resource_names = _strip_resource_names
android_manifest = _android_manifest
android_manifest_dep = ":$_merge_manifest_target"
version_code = _version_code
version_name = _version_name
min_sdk_version = _min_sdk_version
......@@ -2498,8 +2504,6 @@ if (enable_java_templates) {
if (defined(invoker.verify_manifest) && invoker.verify_manifest &&
!is_java_debug) {
verify_manifest_target_name = _template_name
build_config_dep = ":$_build_config_target"
android_manifest_dep = ":$_merge_manifest_target"
forward_variables_from(invoker,
[ "expected_manifest_base_expectation" ])
}
......@@ -2523,11 +2527,9 @@ if (enable_java_templates) {
}
build_config = _build_config
deps = _deps + [
":$_merge_manifest_target",
":$_build_config_target",
_android_sdk_dep,
]
build_config_dep = ":$_build_config_target"
android_sdk_dep = _android_sdk_dep
deps = _deps
# The static library uses the R.txt files generated by the
# static_library_dependent_targets when generating the final R.java file.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment