Skip to content

Commit

Permalink
[SNAP FORK][UPSTREAMED] fix aar_import rule
Browse files Browse the repository at this point in the history
- acls dont work with external dependencies (i.e @foo//)
  https://github.com/bazelbuild/rules_android/blob/pre-alpha/rules/acls.bzl#L293

- Propagate StarlarkAndroidResourcesInfo otherwise starlark rules
  wont be able to see those resources.

- Stop adding library R classes as runtime dependencies:
  This behavior is not correct- the only authoritive r class should be
  the final merged R class. Adding library R classes as runtime
  dependencies creates resources erasures in android_local_test targets
  where each individual R class is added to the test classpath and
  incorrect Ids are used to query the resource table.

- Merge aar library java_info with the resource java_info
  Libraries that directly depend on an AAR can depend as well on the AAR resource class
  so it is not enough to simply return the resource info as a dependency.
  see AarImport.java
  https://github.com/bazelbuild/bazel/blob/e0a9081f/src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java#L166
  • Loading branch information
Mauricio Galindo committed Jan 17, 2023
1 parent e364356 commit 86ed4c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
16 changes: 12 additions & 4 deletions rules/aar_import/impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _process_resources(
deps = ctx.attr.deps,
exports = ctx.attr.exports,
exports_manifest = getattr(ctx.attr, "exports_manifest", True),
propagate_resources = _acls.in_aar_propagate_resources(str(ctx.label)),
propagate_resources = True,

# Tool and Processing related inputs
aapt = _get_android_toolchain(ctx).aapt2.files_to_run,
Expand Down Expand Up @@ -351,7 +351,16 @@ def _process_jars(
# TODO(djwhang): AarImportTest is not expecting jdeps, enable or remove it completely
# jdeps = jdeps_artifact,
)
providers.append(java_info)

# Merge library java_info with the resource java_info
# Libraries that directly depend on an AAR can depend as well on the AAR resource class
# so it is not enough to simply return the resource info as a dependency.
# Note that adding r_java as an export is also not the correct behavior, since we only
# want to expose it as a direct dependency.
# see AarImport.java
# https://github.com/bazelbuild/bazel/blob/e0a9081f/src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java#L166
combined_java_info = java_common.merge([java_info] + r_java_info)
providers.append(combined_java_info)

return struct(
java_info = java_info,
Expand Down Expand Up @@ -493,8 +502,7 @@ def impl(ctx):
r_java = resources_ctx.r_java,
exports = _utils.collect_providers(JavaInfo, ctx.attr.exports),
enable_desugar_java8 = ctx.fragments.android.desugar_java8,
enable_imports_deps_check =
_acls.in_aar_import_deps_checker(str(ctx.label)),
enable_imports_deps_check = False,
aar_embedded_jars_extractor_tool =
_get_android_toolchain(ctx).aar_embedded_jars_extractor.files_to_run,
bootclasspath =
Expand Down
5 changes: 5 additions & 0 deletions rules/aar_import/rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

load(":attrs.bzl", _ATTRS = "ATTRS")
load(":impl.bzl", _impl = "impl")
load(
"//rules:providers.bzl",
"StarlarkAndroidResourcesInfo",
)

RULE_DOC = """
#### Examples
Expand All @@ -42,6 +46,7 @@ aar_import = rule(
AndroidLibraryResourceClassJarProvider,
AndroidNativeLibsInfo,
JavaInfo,
StarlarkAndroidResourcesInfo,
],
toolchains = ["//toolchains/android:toolchain_type"],
)
1 change: 1 addition & 0 deletions rules/resources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ def _process_starlark(
busybox = busybox,
host_javabase = host_javabase,
)
processed_manifest = None

# TODO(b/160907203): Remove this fix once the native resource processing pipeline is turned off.
if enable_data_binding:
Expand Down

0 comments on commit 86ed4c9

Please sign in to comment.