Skip to content

Commit

Permalink
Adding hints to the various textprotos emitted by UTP so tools that r…
Browse files Browse the repository at this point in the history
…ender textprotos know the specific one they're dealing with.

PiperOrigin-RevId: 606749309
Change-Id: I306b60b01c59a0aefe196cbce7c5024bd97655b5
  • Loading branch information
A Googler authored and copybara-github committed Feb 13, 2024
1 parent 8b14195 commit 0b94a89
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
4 changes: 4 additions & 0 deletions launcher/android_instrumentation_driver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def _android_instrumentation_driver_impl(ctx):
java_class = ctx.attr._class_name,
binary = deploy,
config_struct = struct(**configuration),
proto_type = ctx.attr._proto_type,
files = depset([deploy]),
),
]
Expand All @@ -65,6 +66,9 @@ android_instrumentation_driver = rule(
_class_name = attr.string(
default = "com.google.testing.platform.runtime.android.driver.AndroidInstrumentationDriver",
),
_proto_type = attr.string(
default = "google.testing.platform.proto.api.config.AndroidInstrumentationDriver",
),
utp_release = attr.label(
default = UTP_RELEASE,
providers = [[UTPReleaseInfo]],
Expand Down
28 changes: 26 additions & 2 deletions launcher/launcher.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,39 @@ def _utp_test_impl(ctx):
test_driver_config = ctx.actions.declare_file(ctx.attr.name + "_test_driver_config.proto")
direct_deps.append(test_driver_config)
ctx.actions.write(test_driver_config, extension_config_proto(ctx.attr.test_driver))
if ctx.attr.test_driver[utp_provider.UTPExtensionInfo].proto_type:
# If we know the type of the message, put that in the header to provide a hint for tools
# that display the textproto.
extra_setup_commands.append(
"echo '# proto-message: {}' > {}/test_driver_config.textproto".format(
ctx.attr.test_driver[utp_provider.UTPExtensionInfo].proto_type,
_UNDECLARED_OUTPUTS,
),
)
extra_setup_commands.append(
"{} {} > {}/test_driver_config.proto".format(_SED, test_driver_config.short_path, _UNDECLARED_OUTPUTS),
"{} {} >> {}/test_driver_config.textproto".format(
_SED,
test_driver_config.short_path,
_UNDECLARED_OUTPUTS,
),
)

device_provider_config = ctx.actions.declare_file(ctx.attr.name + "_device_provider_config.proto")
direct_deps.append(device_provider_config)
ctx.actions.write(device_provider_config, extension_config_proto(ctx.attr.device_provider))
if ctx.attr.device_provider[utp_provider.UTPExtensionInfo].proto_type:
extra_setup_commands.append(
"echo '# proto-message: {}' > {}/device_provider_config.textproto".format(
ctx.attr.device_provider[utp_provider.UTPExtensionInfo].proto_type,
_UNDECLARED_OUTPUTS,
),
)
extra_setup_commands.append(
"{} {} > {}/device_provider_config.proto".format(_SED, device_provider_config.short_path, _UNDECLARED_OUTPUTS),
"{} {} >> {}/device_provider_config.textproto".format(
_SED,
device_provider_config.short_path,
_UNDECLARED_OUTPUTS,
),
)

for target in [ctx.attr.device_provider] + ctx.attr.test_fixtures:
Expand Down
7 changes: 6 additions & 1 deletion launcher/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,15 @@ sed -r \
# not 4.8 from 2020! So use -r instead of -E to indicate extended regexps,
# and that -z is not available (which is why I used tr to quote newlines
# above).

# Put the message type in the header of the file, to make it easier for tools
# that display the textproto to know what they're working with.
echo '# proto-message: google.testing.platform.proto.api.config.RunnerConfig' \
> ${RUNNER_CONFIG}
sed -r \
-f ${SED_SCRIPT} \
${PWD}/%runner_config_short_path% \
> ${RUNNER_CONFIG}
>> ${RUNNER_CONFIG}

# Dump the config with line numbers, to make it easy to diagnose any error
# messages.
Expand Down
4 changes: 4 additions & 0 deletions launcher/local_android_device_provider.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def _local_android_device_provider_impl(ctx):
java_class = ctx.attr._class_name,
binary = deploy,
config_struct = struct(**configuration),
proto_type = ctx.attr._proto_type,
files = depset(),
),
DefaultInfo(
Expand All @@ -91,6 +92,9 @@ local_android_device_provider = rule(
_class_name = attr.string(
default = "com.google.testing.platform.runtime.android.provider.local.LocalAndroidDeviceProvider",
),
_proto_type = attr.string(
default = "google.testing.platform.proto.api.config.LocalAndroidDeviceProvider",
),
utp_release = attr.label(
default = UTP_RELEASE,
providers = [[UTPReleaseInfo]],
Expand Down
9 changes: 7 additions & 2 deletions provider/extension/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ UTPExtensionInfo = provider(
"java_class": "(string) The Extension's Java class.",
"binary": "(Label) The Java binary to load the Extension from.",
"text_proto": "(string) The textproto representation of this config.",
"proto_type": "(string or None) If specified, the type of the text_proto (protobuf package + name, not Java type name).",
"files": "(depset) Data dependencies to be made available at runtime. Deprecated; use DefaultInfo instead.",
},
)

def utp_extension_info(ctx, extension_rule, java_class, binary, config_struct, files):
def utp_extension_info(ctx, extension_rule, java_class, binary, config_struct, files, proto_type = None):
"""Wrapper for generating a UTPExtensionInfo provider.
Args:
Expand All @@ -36,6 +37,7 @@ def utp_extension_info(ctx, extension_rule, java_class, binary, config_struct, f
binary: The Java binary to load the Extension from.
config_struct: Struct representation of the configuration proto for this extension.
files: (depset) Data dependencies to be made available at runtime.
proto_type: (str) The type of the proto represented in config_struct (protobuf package + name, not Java type name).
Returns:
A UTPExtensionInfo provider containing information needed to create an extension proto.
"""
Expand All @@ -45,10 +47,11 @@ def utp_extension_info(ctx, extension_rule, java_class, binary, config_struct, f
java_class = java_class,
binary = binary,
text_proto = proto.encode_text(config_struct),
proto_type = proto_type,
files = files,
)

def utp_extension_info_from_textpb(ctx, extension_rule, java_class, binary, text_proto, files):
def utp_extension_info_from_textpb(ctx, extension_rule, java_class, binary, text_proto, files, proto_type = None):
"""Wrapper for generating a UTPExtensionInfo provider.
Args:
Expand All @@ -58,6 +61,7 @@ def utp_extension_info_from_textpb(ctx, extension_rule, java_class, binary, text
binary: The Java binary to load the Extension from.
text_proto: The string representation of the configuration proto for this extension.
files: (depset) Data dependencies to be made available at runtime.
proto_type: (str) The type of the proto in text_proto (protobuf package + name, not Java type name).
Returns:
A UTPExtensionInfo provider containing information needed to create an extension proto.
"""
Expand All @@ -68,5 +72,6 @@ def utp_extension_info_from_textpb(ctx, extension_rule, java_class, binary, text
java_class = java_class,
binary = binary,
text_proto = text_proto.strip(),
proto_type = proto_type,
files = depset([binary], transitive = [files]),
)

0 comments on commit 0b94a89

Please sign in to comment.