Skip to content

Commit 748aa47

Browse files
A Googlercopybara-github
authored andcommitted
Adding support for the custom_adb field in the Android SDK.
PiperOrigin-RevId: 617225133 Change-Id: I67d35c2e5071db6e00f06e84e016b3f3aa9b4b4b
1 parent 26ec6c5 commit 748aa47

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

launcher/environment.bzl

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,22 @@ visibility([
2626
"//test/launcher/...",
2727
])
2828

29-
def _android_sdk_to_message(target, dexdump):
29+
def _android_sdk_to_message(target, dexdump, custom_adb):
3030
"""Generates a google.testing.platform.proto.api.config.AndroidSdk message.
3131
3232
Args:
3333
target: (Target) AndroidSdkInfo provider.
34-
dexdump: (Target) dexdump, since it's not available in the AndroidSdkInfo.
34+
dexdump: (File) dexdump, since it's not available in the AndroidSdkInfo.
35+
custom_adb: (File) overrides the adb specified in the Android SDK. Can be None
3536
3637
Returns:
3738
(struct) An AndroidSdk message suitable for proto.encode_text().
3839
"""
3940
info = target[AndroidSdkInfo]
41+
if custom_adb:
42+
adb = custom_adb
43+
else:
44+
adb = info.adb.executable
4045
return struct(
4146
sdk_path = struct(
4247
path = "/".join(
@@ -45,19 +50,20 @@ def _android_sdk_to_message(target, dexdump):
4550
),
4651
),
4752
aapt_path = absolute_path_struct(info.aapt2.executable),
48-
adb_path = absolute_path_struct(info.adb.executable),
53+
adb_path = absolute_path_struct(adb),
4954
dexdump_path = absolute_path_struct(dexdump),
5055
)
5156

5257
AndroidEnvironmentInfo = provider(
5358
doc = "Android-specific environment configuration",
5459
fields = {
55-
"sdk": "Android SDK configuration",
56-
"dexdump": "File for the dexdump binary",
57-
"test_log_dir": "Relative path to output directory for Android instrumentation logs",
58-
"test_run_log": "File name for test run logs",
59-
"coverage_report_path": "Path in which Jacoco coverage should be stored",
60-
"logcat_options": "Options to pass to logcat when streaming logs",
60+
"sdk": "(Target) Android SDK configuration",
61+
"custom_adb": "(File) Custom ADB, overriding the one in sdk. Can be None.",
62+
"dexdump": "(File) File for the dexdump binary",
63+
"test_log_dir": "(str) Relative path to output directory for Android instrumentation logs",
64+
"test_run_log": "(str) File name for test run logs",
65+
"coverage_report_path": "(str) Path in which Jacoco coverage should be stored",
66+
"logcat_options": "([str]) Options to pass to logcat when streaming logs",
6167
},
6268
)
6369

@@ -72,7 +78,7 @@ def android_environment_to_message(target):
7278
"""
7379
info = target[AndroidEnvironmentInfo]
7480
message = dict(
75-
android_sdk = _android_sdk_to_message(info.sdk, info.dexdump),
81+
android_sdk = _android_sdk_to_message(info.sdk, info.dexdump, info.custom_adb),
7682
test_log_dir = struct(path = info.test_log_dir),
7783
test_run_log = struct(path = info.test_run_log),
7884
)
@@ -87,9 +93,13 @@ def _android_environment_impl(ctx):
8793
coverage_report_path = environment_variable("JAVA_COVERAGE_FILE")
8894
else:
8995
coverage_report_path = ""
96+
optional_deps = []
97+
if ctx.attr.custom_adb:
98+
optional_deps.append(ctx.file.custom_adb)
9099
return [
91100
AndroidEnvironmentInfo(
92101
sdk = ctx.attr._android_sdk,
102+
custom_adb = ctx.file.custom_adb,
93103
dexdump = ctx.file._dexdump,
94104
test_log_dir = ctx.attr.test_log_dir,
95105
test_run_log = ctx.attr.test_run_log,
@@ -100,7 +110,7 @@ def _android_environment_impl(ctx):
100110
ctx.attr._android_sdk[AndroidSdkInfo].aapt2.executable,
101111
ctx.attr._android_sdk[AndroidSdkInfo].adb.executable,
102112
ctx.file._dexdump,
103-
])),
113+
] + optional_deps)),
104114
]
105115

106116
android_environment = rule(
@@ -118,6 +128,11 @@ android_environment = rule(
118128
default = "//tools/android:dexdump",
119129
allow_single_file = True,
120130
),
131+
custom_adb = attr.label(
132+
doc = "Custom ADB to use, overriding the one in the Android SDK.",
133+
allow_single_file = True,
134+
mandatory = False,
135+
),
121136
test_log_dir = attr.string(
122137
doc = "Relative path to output directory for Android instrumentation logs",
123138
),

0 commit comments

Comments
 (0)