Skip to content

Commit d1aebbc

Browse files
A Googlercopybara-github
authored andcommitted
Updating UTPExtensionInfo to represent a list of jars, matching the Extension proto, while maintaining compatibility with legacy usage.
PiperOrigin-RevId: 625141218 Change-Id: Idc31508b10529d4061d4f0d2ba9f3de377eac44a
1 parent ad6ba53 commit d1aebbc

File tree

6 files changed

+48
-18
lines changed

6 files changed

+48
-18
lines changed

launcher/extension.bzl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def extension_to_proto(target):
3939
label = target.label.name,
4040
),
4141
class_name = info.java_class,
42-
jar = [absolute_path_struct(info.binary)],
42+
jar = [absolute_path_struct(x) for x in info.binary],
4343
)
4444
if info.text_proto != None:
4545
message["resource"] = struct(
@@ -86,19 +86,20 @@ def extension_direct_deps(target):
8686
A list of Files.
8787
"""
8888
if utp_provider.UTPExtensionInfo in target:
89-
return [target[utp_provider.UTPExtensionInfo].binary]
89+
return target[utp_provider.UTPExtensionInfo].binary
9090
return []
9191

9292
def _utp_host_plugin_impl(ctx):
93-
deploy = ctx.file.binary
93+
deploy = [x.files.to_list()[0] for x in ctx.attr.shared_jars] + [ctx.file.binary]
94+
deps = depset(direct = [ctx.file.binary], transitive = [x.files for x in ctx.attr.shared_jars])
9495
return [
9596
extension.utp_extension_info(
9697
ctx = ctx,
9798
extension_rule = "{}:{}".format(ctx.label.package, ctx.label.name),
9899
java_class = ctx.attr.class_name,
99100
binary = deploy,
100101
config_struct = struct(),
101-
files = depset([deploy]),
102+
files = deps,
102103
),
103104
]
104105

@@ -112,6 +113,14 @@ utp_host_plugin = rule(
112113
mandatory = True,
113114
providers = [[JavaInfo]],
114115
allow_single_file = ["_deploy.jar"],
116+
# Use the host config so that it builds even with `--config=android_*`.
117+
cfg = "exec",
118+
),
119+
shared_jars = attr.label_list(
120+
doc = "Binary deploy jars shared by this host plugin.",
121+
providers = [[JavaInfo]],
122+
allow_files = ["_deploy.jar"],
123+
cfg = "exec",
115124
),
116125
class_name = attr.string(
117126
doc = "Class name of the host plugin.",

provider/extension/providers.bzl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
UTPExtensionInfo = provider(
1818
doc = "Unified Test Platform Extension classloading and configuration information.",
1919
fields = {
20-
"extension_rule": "(Label) The target for this extension rule.",
21-
"extension_target": "(Label) The target that configures this extension",
20+
"extension_rule": "(Target) The target for this extension rule.",
21+
"extension_target": "(Target) The target that configures this extension",
2222
"java_class": "(string) The Extension's Java class.",
23-
"binary": "(Label) The Java binary to load the Extension from.",
23+
"binary": "([File]) The Java binaries to load the Extension from.",
2424
"text_proto": "(string) The textproto representation of this config.",
2525
"proto_type": "(string or None) If specified, the type of the text_proto (protobuf package + name, not Java type name).",
2626
"files": "(depset) Data dependencies to be made available at runtime. Deprecated; use DefaultInfo instead.",
@@ -34,13 +34,15 @@ def utp_extension_info(ctx, extension_rule, java_class, binary, config_struct, f
3434
ctx: Starlark rule context.
3535
extension_rule: The target for this extension rule.
3636
java_class: The Extension's Java class.
37-
binary: The Java binary to load the Extension from.
37+
binary: (File or [File]) The Java binary to load the Extension from.
3838
config_struct: Struct representation of the configuration proto for this extension.
3939
files: (depset) Data dependencies to be made available at runtime.
4040
proto_type: (str) The type of the proto represented in config_struct (protobuf package + name, not Java type name).
4141
Returns:
4242
A UTPExtensionInfo provider containing information needed to create an extension proto.
4343
"""
44+
if type(binary) != type([]):
45+
binary = [binary]
4446
return utp_extension_info_from_textpb(
4547
ctx = ctx,
4648
extension_rule = extension_rule,
@@ -58,20 +60,21 @@ def utp_extension_info_from_textpb(ctx, extension_rule, java_class, binary, text
5860
ctx: Starlark rule context.
5961
extension_rule: The target for this extension rule.
6062
java_class: The Extension's Java class.
61-
binary: The Java binary to load the Extension from.
63+
binary: (File or [File]) The Java binary to load the Extension from.
6264
text_proto: The string representation of the configuration proto for this extension.
6365
files: (depset) Data dependencies to be made available at runtime.
6466
proto_type: (str) The type of the proto in text_proto (protobuf package + name, not Java type name).
6567
Returns:
6668
A UTPExtensionInfo provider containing information needed to create an extension proto.
6769
"""
68-
70+
if type(binary) != type([]):
71+
binary = [binary]
6972
return UTPExtensionInfo(
7073
extension_rule = extension_rule,
7174
extension_target = str(ctx.label),
7275
java_class = java_class,
7376
binary = binary,
7477
text_proto = text_proto.strip(),
7578
proto_type = proto_type,
76-
files = depset([binary], transitive = [files]),
79+
files = depset(binary, transitive = [files]),
7780
)

provider/extension/textproto.bzl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ _TEMPLATE = """label {
2222
namespace: "%s"
2323
}
2424
class_name: "%s"
25-
jar {
26-
path: "%s"
27-
}
25+
%s
2826
resource {
2927
encoding: TEXT
3028
raw: '%s'
@@ -48,7 +46,7 @@ def extension_to_textproto(ctx, extension):
4846
extension.extension_rule,
4947
extension.extension_target,
5048
extension.java_class,
51-
extension.binary.short_path,
49+
"\n".join(['jar {{\n path: "{}"\n}}'.format(x.short_path) for x in extension.binary]),
5250
extension.text_proto.replace("\n", "\\n"),
5351
)
5452
name = extension.extension_target.split(":")[-1] + "_extension.textproto"

test/launcher/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ java_binary(
3434
main_class = "EmptyJava",
3535
)
3636

37+
java_binary(
38+
name = "empty_shared_java_binary_deploy",
39+
main_class = "EmptySharedJava",
40+
)
41+
3742
bzl_library(
3843
name = "android_instrumentation_driver_test_bzl",
3944
srcs = ["android_instrumentation_driver_test.bzl"],

test/launcher/extension_test.bzl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616

1717
load("//launcher:extension.bzl", "extension_to_proto", "utp_host_plugin")
1818
load("//provider:provider.bzl", "utp_provider")
19-
load("//tools/utp:constants.bzl", "JAR_PATH_EMPTY_BINARY", "TARGET_EMPTY_BINARY")
19+
load(
20+
"//tools/utp:constants.bzl",
21+
"JAR_PATH_EMPTY_BINARY",
22+
"JAR_PATH_EMPTY_SHARED_BINARY",
23+
"TARGET_EMPTY_BINARY",
24+
"TARGET_EMPTY_SHARED_BINARY",
25+
)
2026
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
2127

2228
def _extension_to_proto_test(ctx):
@@ -39,9 +45,14 @@ def _extension_to_proto_test(ctx):
3945
)
4046
asserts.equals(
4147
env,
42-
"@@PWD@@/" + JAR_PATH_EMPTY_BINARY,
48+
"@@PWD@@/" + JAR_PATH_EMPTY_SHARED_BINARY,
4349
message.jar[0].path,
4450
)
51+
asserts.equals(
52+
env,
53+
"@@PWD@@/" + JAR_PATH_EMPTY_BINARY,
54+
message.jar[1].path,
55+
)
4556
return unittest.end(env)
4657

4758
extension_to_proto_test = unittest.make(
@@ -60,6 +71,7 @@ def extension_test_suite(name):
6071
testonly = True,
6172
class_name = "com.google.testing.platform.plugin.android.AndroidDevicePlugin",
6273
binary = TARGET_EMPTY_BINARY,
74+
shared_jars = [TARGET_EMPTY_SHARED_BINARY],
6375
)
6476

6577
unittest.suite(

tools/utp/constants.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ JAR_PATH_LOCAL_ANDROID_DEVICE_PROVIDER = "../rules_jvm_external~~maven~maven/com
2020
JAR_PATH_ANDROID_INSTRUMENTATION_DRIVER="../rules_jvm_external~~maven~maven/com/google/testing/platform/android-driver-instrumentation/0.0.9-alpha01/processed_android-driver-instrumentation-0.0.9-alpha01.jar"
2121

2222
TARGET_EMPTY_BINARY = "//test/launcher:empty_java_binary_deploy.jar"
23-
JAR_PATH_EMPTY_BINARY="test/launcher/empty_java_binary_deploy.jar"
23+
JAR_PATH_EMPTY_BINARY="test/launcher/empty_java_binary_deploy.jar"
24+
25+
TARGET_EMPTY_SHARED_BINARY = "//test/launcher:empty_java_shared_binary_deploy.jar"
26+
JAR_PATH_EMPTY_SHARED_BINARY = "test/launcher/empty_java_shared_binary_deploy.jar"

0 commit comments

Comments
 (0)