@@ -26,17 +26,22 @@ visibility([
26
26
"//test/launcher/..." ,
27
27
])
28
28
29
- def _android_sdk_to_message (target , dexdump ):
29
+ def _android_sdk_to_message (target , dexdump , custom_adb ):
30
30
"""Generates a google.testing.platform.proto.api.config.AndroidSdk message.
31
31
32
32
Args:
33
33
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
35
36
36
37
Returns:
37
38
(struct) An AndroidSdk message suitable for proto.encode_text().
38
39
"""
39
40
info = target [AndroidSdkInfo ]
41
+ if custom_adb :
42
+ adb = custom_adb
43
+ else :
44
+ adb = info .adb .executable
40
45
return struct (
41
46
sdk_path = struct (
42
47
path = "/" .join (
@@ -45,19 +50,20 @@ def _android_sdk_to_message(target, dexdump):
45
50
),
46
51
),
47
52
aapt_path = absolute_path_struct (info .aapt2 .executable ),
48
- adb_path = absolute_path_struct (info . adb . executable ),
53
+ adb_path = absolute_path_struct (adb ),
49
54
dexdump_path = absolute_path_struct (dexdump ),
50
55
)
51
56
52
57
AndroidEnvironmentInfo = provider (
53
58
doc = "Android-specific environment configuration" ,
54
59
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" ,
61
67
},
62
68
)
63
69
@@ -72,7 +78,7 @@ def android_environment_to_message(target):
72
78
"""
73
79
info = target [AndroidEnvironmentInfo ]
74
80
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 ),
76
82
test_log_dir = struct (path = info .test_log_dir ),
77
83
test_run_log = struct (path = info .test_run_log ),
78
84
)
@@ -87,9 +93,13 @@ def _android_environment_impl(ctx):
87
93
coverage_report_path = environment_variable ("JAVA_COVERAGE_FILE" )
88
94
else :
89
95
coverage_report_path = ""
96
+ optional_deps = []
97
+ if ctx .attr .custom_adb :
98
+ optional_deps .append (ctx .file .custom_adb )
90
99
return [
91
100
AndroidEnvironmentInfo (
92
101
sdk = ctx .attr ._android_sdk ,
102
+ custom_adb = ctx .file .custom_adb ,
93
103
dexdump = ctx .file ._dexdump ,
94
104
test_log_dir = ctx .attr .test_log_dir ,
95
105
test_run_log = ctx .attr .test_run_log ,
@@ -100,7 +110,7 @@ def _android_environment_impl(ctx):
100
110
ctx .attr ._android_sdk [AndroidSdkInfo ].aapt2 .executable ,
101
111
ctx .attr ._android_sdk [AndroidSdkInfo ].adb .executable ,
102
112
ctx .file ._dexdump ,
103
- ])),
113
+ ] + optional_deps )),
104
114
]
105
115
106
116
android_environment = rule (
@@ -118,6 +128,11 @@ android_environment = rule(
118
128
default = "//tools/android:dexdump" ,
119
129
allow_single_file = True ,
120
130
),
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
+ ),
121
136
test_log_dir = attr .string (
122
137
doc = "Relative path to output directory for Android instrumentation logs" ,
123
138
),
0 commit comments