Skip to content

Commit d76787e

Browse files
katrecopybara-github
authored andcommitted
Get the Android SDK from the toolchain, not the deprecated late-bound attribute.
PiperOrigin-RevId: 676886675 Change-Id: I5a5b88d24eb86177ed169d23144e4954381adb7b
1 parent 9fc3f4c commit d76787e

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

launcher/environment.bzl

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414
"""Configures the UTP test environment."""
1515

16-
load("//tools/build_defs/android/public_api:android_sdk_info.bzl", "AndroidSdkInfo")
1716
load(
1817
":primitives.bzl",
1918
"absolute_path_struct",
@@ -26,38 +25,37 @@ visibility([
2625
"//test/launcher/...",
2726
])
2827

29-
def _android_sdk_to_message(target, dexdump, custom_adb):
28+
def _android_sdk_to_message(android_sdk, dexdump, custom_adb):
3029
"""Generates a google.testing.platform.proto.api.config.AndroidSdk message.
3130
3231
Args:
33-
target: (Target) AndroidSdkInfo provider.
32+
android_sdk: (Provider) AndroidSdkInfo provider.
3433
dexdump: (File) dexdump, since it's not available in the AndroidSdkInfo.
3534
custom_adb: (File) overrides the adb specified in the Android SDK. Can be None
3635
3736
Returns:
3837
(struct) An AndroidSdk message suitable for proto.encode_text().
3938
"""
40-
info = target[AndroidSdkInfo]
4139
if custom_adb:
4240
adb = custom_adb
4341
else:
44-
adb = info.adb.executable
42+
adb = android_sdk.adb.executable
4543
return struct(
4644
sdk_path = struct(
4745
path = "/".join(
4846
[environment_variable("PWD")] +
49-
info.aapt.executable.dirname.split("/")[:-1],
47+
android_sdk.aapt.executable.dirname.split("/")[:-1],
5048
),
5149
),
52-
aapt_path = absolute_path_struct(info.aapt2.executable),
50+
aapt_path = absolute_path_struct(android_sdk.aapt2.executable),
5351
adb_path = absolute_path_struct(adb),
5452
dexdump_path = absolute_path_struct(dexdump),
5553
)
5654

5755
AndroidEnvironmentInfo = provider(
5856
doc = "Android-specific environment configuration",
5957
fields = {
60-
"sdk": "(Target) Android SDK configuration",
58+
"android_sdk": "(Provider) Android SDK configuration",
6159
"custom_adb": "(File) Custom ADB, overriding the one in sdk. Can be None.",
6260
"dexdump": "(File) File for the dexdump binary",
6361
"test_log_dir": "(str) Relative path to output directory for Android instrumentation logs",
@@ -78,7 +76,7 @@ def android_environment_to_message(target):
7876
"""
7977
info = target[AndroidEnvironmentInfo]
8078
message = dict(
81-
android_sdk = _android_sdk_to_message(info.sdk, info.dexdump, info.custom_adb),
79+
android_sdk = _android_sdk_to_message(info.android_sdk, info.dexdump, info.custom_adb),
8280
test_log_dir = struct(path = info.test_log_dir),
8381
test_run_log = struct(path = info.test_run_log),
8482
)
@@ -96,9 +94,10 @@ def _android_environment_impl(ctx):
9694
optional_deps = []
9795
if ctx.attr.custom_adb:
9896
optional_deps.append(ctx.file.custom_adb)
97+
android_sdk = ctx.toolchains["//third_party/bazel_rules/rules_android/toolchains/android_sdk:toolchain_type"].android_sdk_info
9998
return [
10099
AndroidEnvironmentInfo(
101-
sdk = ctx.attr._android_sdk,
100+
android_sdk = android_sdk,
102101
custom_adb = ctx.file.custom_adb,
103102
dexdump = ctx.file._dexdump,
104103
test_log_dir = ctx.attr.test_log_dir,
@@ -107,23 +106,15 @@ def _android_environment_impl(ctx):
107106
logcat_options = ctx.attr.logcat_options,
108107
),
109108
DefaultInfo(files = depset([
110-
ctx.attr._android_sdk[AndroidSdkInfo].aapt2.executable,
111-
ctx.attr._android_sdk[AndroidSdkInfo].adb.executable,
109+
android_sdk.aapt2.executable,
110+
android_sdk.adb.executable,
112111
ctx.file._dexdump,
113112
] + optional_deps)),
114113
]
115114

116115
android_environment = rule(
117116
implementation = _android_environment_impl,
118117
attrs = dict(
119-
_android_sdk = attr.label(
120-
allow_rules = ["android_sdk"],
121-
default = configuration_field(
122-
fragment = "android",
123-
name = "android_sdk_label",
124-
),
125-
providers = [[AndroidSdkInfo]],
126-
),
127118
_dexdump = attr.label(
128119
default = "//tools/android:dexdump",
129120
allow_single_file = True,
@@ -143,6 +134,9 @@ android_environment = rule(
143134
doc = "Command line options to pass to logcat when streaming logs, e.g. to the AndroidLogcatPlugin.",
144135
),
145136
),
137+
toolchains = [
138+
"//third_party/bazel_rules/rules_android/toolchains/android_sdk:toolchain_type",
139+
],
146140
)
147141

148142
EnvironmentInfo = provider(

0 commit comments

Comments
 (0)