13
13
# limitations under the License.
14
14
"""Configures the UTP test environment."""
15
15
16
- load ("//tools/build_defs/android/public_api:android_sdk_info.bzl" , "AndroidSdkInfo" )
17
16
load (
18
17
":primitives.bzl" ,
19
18
"absolute_path_struct" ,
@@ -26,38 +25,37 @@ visibility([
26
25
"//test/launcher/..." ,
27
26
])
28
27
29
- def _android_sdk_to_message (target , dexdump , custom_adb ):
28
+ def _android_sdk_to_message (android_sdk , dexdump , custom_adb ):
30
29
"""Generates a google.testing.platform.proto.api.config.AndroidSdk message.
31
30
32
31
Args:
33
- target : (Target ) AndroidSdkInfo provider.
32
+ android_sdk : (Provider ) AndroidSdkInfo provider.
34
33
dexdump: (File) dexdump, since it's not available in the AndroidSdkInfo.
35
34
custom_adb: (File) overrides the adb specified in the Android SDK. Can be None
36
35
37
36
Returns:
38
37
(struct) An AndroidSdk message suitable for proto.encode_text().
39
38
"""
40
- info = target [AndroidSdkInfo ]
41
39
if custom_adb :
42
40
adb = custom_adb
43
41
else :
44
- adb = info .adb .executable
42
+ adb = android_sdk .adb .executable
45
43
return struct (
46
44
sdk_path = struct (
47
45
path = "/" .join (
48
46
[environment_variable ("PWD" )] +
49
- info .aapt .executable .dirname .split ("/" )[:- 1 ],
47
+ android_sdk .aapt .executable .dirname .split ("/" )[:- 1 ],
50
48
),
51
49
),
52
- aapt_path = absolute_path_struct (info .aapt2 .executable ),
50
+ aapt_path = absolute_path_struct (android_sdk .aapt2 .executable ),
53
51
adb_path = absolute_path_struct (adb ),
54
52
dexdump_path = absolute_path_struct (dexdump ),
55
53
)
56
54
57
55
AndroidEnvironmentInfo = provider (
58
56
doc = "Android-specific environment configuration" ,
59
57
fields = {
60
- "sdk " : "(Target ) Android SDK configuration" ,
58
+ "android_sdk " : "(Provider ) Android SDK configuration" ,
61
59
"custom_adb" : "(File) Custom ADB, overriding the one in sdk. Can be None." ,
62
60
"dexdump" : "(File) File for the dexdump binary" ,
63
61
"test_log_dir" : "(str) Relative path to output directory for Android instrumentation logs" ,
@@ -78,7 +76,7 @@ def android_environment_to_message(target):
78
76
"""
79
77
info = target [AndroidEnvironmentInfo ]
80
78
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 ),
82
80
test_log_dir = struct (path = info .test_log_dir ),
83
81
test_run_log = struct (path = info .test_run_log ),
84
82
)
@@ -96,9 +94,10 @@ def _android_environment_impl(ctx):
96
94
optional_deps = []
97
95
if ctx .attr .custom_adb :
98
96
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
99
98
return [
100
99
AndroidEnvironmentInfo (
101
- sdk = ctx . attr . _android_sdk ,
100
+ android_sdk = android_sdk ,
102
101
custom_adb = ctx .file .custom_adb ,
103
102
dexdump = ctx .file ._dexdump ,
104
103
test_log_dir = ctx .attr .test_log_dir ,
@@ -107,23 +106,15 @@ def _android_environment_impl(ctx):
107
106
logcat_options = ctx .attr .logcat_options ,
108
107
),
109
108
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 ,
112
111
ctx .file ._dexdump ,
113
112
] + optional_deps )),
114
113
]
115
114
116
115
android_environment = rule (
117
116
implementation = _android_environment_impl ,
118
117
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
- ),
127
118
_dexdump = attr .label (
128
119
default = "//tools/android:dexdump" ,
129
120
allow_single_file = True ,
@@ -143,6 +134,9 @@ android_environment = rule(
143
134
doc = "Command line options to pass to logcat when streaming logs, e.g. to the AndroidLogcatPlugin." ,
144
135
),
145
136
),
137
+ toolchains = [
138
+ "//third_party/bazel_rules/rules_android/toolchains/android_sdk:toolchain_type" ,
139
+ ],
146
140
)
147
141
148
142
EnvironmentInfo = provider (
0 commit comments