Skip to content

Commit

Permalink
Adding support for filegroup data deps.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 610814901
Change-Id: I1d8072ca679c16af4bb1c0cedaf856aabba63cce
  • Loading branch information
A Googler authored and copybara-github committed Feb 27, 2024
1 parent 0b94a89 commit 81e178d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
12 changes: 9 additions & 3 deletions launcher/artifact.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,23 @@ def artifact_to_message(target):

def data_to_dep(target):
"""Generates a google.testing.platform.proto.api.core.Artifact for a data dep."""
if len(target.files.to_list()) == 0:
fail("//{}:{} has no files!".format(target.label.package, target.label.name))
return file_to_dep(target, target.files.to_list()[0])

def file_to_dep(target, file):
"""Generates a google.testing.platform.proto.api.core.Artifact for a file in a target."""
return struct(
label = struct(
label = target.label.name,
namespace = "//{}".format(target.label.package),
),
source_path = path_proto(target.files.to_list()[0]),
source_path = path_proto(file),
destination_path = struct(
path = "googletest/test_runfiles/google3/{}".format(target.files.to_list()[0].short_path),
path = "googletest/test_runfiles/google3/{}".format(file.short_path),
),
type = ARTIFACT_TYPE.TEST_DATA,
mime_type = get_mime_type(target.files.to_list()[0]),
mime_type = get_mime_type(file),
)

INSTALL_METHOD = struct(
Expand Down
18 changes: 12 additions & 6 deletions launcher/launcher.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

load("//provider:provider.bzl", "utp_provider", "utp_provider_tools")
load("@rules_android//rules:rules.bzl", "AndroidAppsInfo", "StarlarkApkInfo", "instrumented_app_info_aspect")
load(":artifact.bzl", "UTPArtifactInfo", "UTPArtifactsInfo", "apk_to_installable", "artifact_to_message", "data_to_dep")
load(":artifact.bzl", "UTPArtifactInfo", "UTPArtifactsInfo", "apk_to_installable", "artifact_to_message", "data_to_dep", "file_to_dep")
load(":entry_point.bzl", "UTPEntryPointInfo", "launcher_classpath")
load(":environment.bzl", "EnvironmentInfo", "environment_to_message")
load(":extension.bzl", "extension_config_proto", "extension_direct_deps", "extension_to_proto", "extension_transitive_deps")
Expand Down Expand Up @@ -78,11 +78,17 @@ def _utp_build_message(ctx):
artifact_to_message(a)
for a in t[UTPArtifactsInfo].artifacts
])
if ctx.attr.data:
test_fixture_setup["data_dep"].extend([
data_to_dep(target)
for target in ctx.attr.data
])
for target in ctx.attr.data:
# The target might be a filegroup, so generate one artifact per file.
if len(target.files.to_list()) == 0:
pass
elif len(target.files.to_list()) > 1:
test_fixture_setup["data_dep"].extend([
file_to_dep(target, f)
for f in target.files.to_list()
])
else:
test_fixture_setup["data_dep"].append(data_to_dep(target))
primary_test_fixture = dict(
test_fixture_id = primary_test_fixture_id,
setup = struct(**test_fixture_setup),
Expand Down
2 changes: 2 additions & 0 deletions launcher/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ load(
_apk_to_installable = "apk_to_installable",
_artifact_to_message = "artifact_to_message",
_data_to_dep = "data_to_dep",
_file_to_dep = "file_to_dep",
)
load(
":entry_point.bzl",
Expand Down Expand Up @@ -138,6 +139,7 @@ environment_variable = _environment_variable
environment_variable_direct = _environment_variable_direct
extension_config_proto = _extension_config_proto
extension_to_proto = _extension_to_proto
file_to_dep = _file_to_dep
path_proto = _path_proto
any_textproto = _any_textproto
instrumentation = _instrumentation
Expand Down

0 comments on commit 81e178d

Please sign in to comment.