Skip to content

Commit

Permalink
Expose header files in AppleTestInfo
Browse files Browse the repository at this point in the history
This will allow Tulsi to properly add the header files to the xcodeproj.

RELNOTES: None.
PiperOrigin-RevId: 307811405
  • Loading branch information
DavidGoldman authored and swiple-rules-gardener committed Apr 22, 2020
1 parent 32ede96 commit 2c24d05
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
32 changes: 19 additions & 13 deletions apple/internal/testing/apple_test_bundle_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,18 @@ load(
# a bundle ID.
_DEFAULT_TEST_BUNDLE_ID = "com.bazelbuild.rulesapple.Tests"

def _collect_files(rule_attr, attr_name):
"""Collects files from attr_name (if present) into a depset."""
def _collect_files(rule_attr, attr_names):
"""Collects files from given attr_names (when present) into a depset."""
transitive_files = []

attr_val = getattr(rule_attr, attr_name, None)
if not attr_val:
return depset()
for attr_name in attr_names:
attr_val = getattr(rule_attr, attr_name, None)
if not attr_val:
continue
attr_val_as_list = attr_val if types.is_list(attr_val) else [attr_val]
transitive_files.extend([f.files for f in attr_val_as_list])

attr_val_as_list = attr_val if types.is_list(attr_val) else [attr_val]
return depset(transitive = [f.files for f in attr_val_as_list])
return depset(transitive = transitive_files)

def _apple_test_info_aspect_impl(target, ctx):
"""See `test_info_aspect` for full documentation."""
Expand Down Expand Up @@ -107,12 +110,15 @@ def _apple_test_info_aspect_impl(target, ctx):
hasattr(target[SwiftInfo], "transitive_swiftmodules")):
swift_modules.append(target[SwiftInfo].transitive_swiftmodules)

# Collect sources from the current target and add any relevant transitive
# information. Note that we do not propagate sources transitively as we
# intentionally only show test sources from the test's first-level of
# dependencies instead of all transitive dependencies.
non_arc_sources = _collect_files(ctx.rule.attr, "non_arc_srcs")
sources = _collect_files(ctx.rule.attr, "srcs")
# Collect sources from the current target. Note that we do not propagate
# sources transitively as we intentionally only show test sources from the
# test's first-level of dependencies instead of all transitive dependencies.
#
# Group the transitively exported headers into `sources` since we have no
# need to differentiate between internal headers and transitively exported
# headers.
non_arc_sources = _collect_files(ctx.rule.attr, ["non_arc_srcs"])
sources = _collect_files(ctx.rule.attr, ["srcs", "hdrs", "textual_hdrs"])

return [AppleTestInfo(
includes = depset(transitive = includes),
Expand Down
2 changes: 1 addition & 1 deletion apple/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ used by an IDE to identify the Swift module (if any) used by the test's sources.
deps.
""",
"sources": """
`depset` of `File`s containing sources from the test's immediate deps.
`depset` of `File`s containing sources and headers from the test's immediate deps.
""",
"swift_modules": """
`depset` of `File`s representing transitive swift modules which are needed by
Expand Down

0 comments on commit 2c24d05

Please sign in to comment.