Skip to content

Commit

Permalink
Traverse Kotlin toolchain edge rather than _toolchain attr in mobile-…
Browse files Browse the repository at this point in the history
…install

PiperOrigin-RevId: 683399485
Change-Id: I0eb30241c490e05d5d3005a966233613833ce510
  • Loading branch information
nreid260 authored and copybara-github committed Oct 8, 2024
1 parent 21eea1c commit 3c559b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
14 changes: 13 additions & 1 deletion mobile_install/adapters/java_lite_grpc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def _adapt(target, ctx):
Returns:
A list of providers.
"""
if JavaInfo not in target:
return []

# TODO: This is needed as the adapter is shared between kt and java grpc library.
# Consider splitting this out into two separater adapters. Although this will need
# refactoring of the adapter test, which handles both.
is_java = (ctx.rule.kind == "_java_lite_grpc_library")

return [
providers.make_mi_android_dex_info(
dex_shards = dex(
Expand All @@ -45,7 +53,11 @@ def _adapt(target, ctx):
deps = providers.collect(
MIAndroidDexInfo,
ctx.rule.attr.deps,
[ctx.rule.attr._toolchain],
[
ctx.rule.attr._toolchain,
] if is_java else [
ctx.rule.toolchains["//third_party/bazel_rules/rules_kotlin/toolchains/kotlin_jvm"],
],
),
),
providers.make_mi_java_resources_info(
Expand Down
9 changes: 8 additions & 1 deletion mobile_install/mi.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ load("//rules/flags:flags.bzl", "flags")
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
load(":adapters.bzl", "adapters")
load(":debug.bzl", "debug")
load(":tools.bzl", "TOOL_ATTRS")
load(":tools.bzl", "TOOLCHAIN_TYPES", "TOOL_ATTRS")

visibility(PROJECT_VISIBILITY)

Expand Down Expand Up @@ -69,6 +69,12 @@ def make_aspect(
)
attrs.update(min_sdk_version.attrs)
attrs.update(tools)

# Optional args to pass to the aspect definition if Bazel supports them.
opt_kwargs = {}
if TOOLCHAIN_TYPES:
opt_kwargs["toolchains_aspects"] = TOOLCHAIN_TYPES

return aspect(
attr_aspects = adapters.get_all_aspect_attrs(),
attrs = attrs,
Expand All @@ -80,6 +86,7 @@ def make_aspect(
toolchains = [
ANDROID_SDK_TOOLCHAIN_TYPE,
],
**opt_kwargs
)

# MIASPECT allows you to run the aspect directly on a Blaze/Bazel command.
Expand Down
3 changes: 3 additions & 0 deletions mobile_install/tools.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,6 @@ TOOL_ATTRS = dict(
),

)

# Toolchains that will be traversed by the adapters.
TOOLCHAIN_TYPES = []

0 comments on commit 3c559b2

Please sign in to comment.