aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-03-24 23:02:00 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2017-03-27 11:36:49 +0000
commitcae68a5fa32f9892c88bc490c3187fccb341a489 (patch)
treea39ee887792c12c178ab66cc8f965340161123ad
parent33bc4b53684292dd3871e165a35a96d113c63f55 (diff)
Add "resources", "structured_resources" attrs to swift_library.
-- PiperOrigin-RevId: 151183770 MOS_MIGRATED_REVID=151183770
-rw-r--r--tools/build_defs/apple/swift.bzl47
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/build_defs/apple/swift.bzl b/tools/build_defs/apple/swift.bzl
index 12fdf6533b..41fb4d226d 100644
--- a/tools/build_defs/apple/swift.bzl
+++ b/tools/build_defs/apple/swift.bzl
@@ -328,6 +328,40 @@ def swiftc_args(ctx):
return args
+def _collect_resource_sets(ctx, module_name):
+ """Collects resource sets from the target and its dependencies.
+
+ Args:
+ ctx: The Skylark context.
+ module_name: The name of the Swift module associated with the resources
+ (either the user-provided name, or the auto-generated one).
+ Returns:
+ A list of structs representing the transitive resources to propagate to the
+ bundling rules.
+ """
+ resource_sets = []
+
+ # Create a resource set from the resources attached directly to this target.
+ if ctx.files.resources or ctx.files.structured_resources:
+ resource_sets.append(struct(
+ bundle_dir=None,
+ infoplists=depset(),
+ objc_bundle_imports=depset(),
+ resources=depset(ctx.files.resources),
+ structured_resources=depset(ctx.files.structured_resources),
+ structured_resource_zips=depset(),
+ swift_module=module_name,
+ ))
+
+ # Collect transitive resource sets from dependencies.
+ for dep in ctx.attr.deps:
+ apple_resource = getattr(dep, "AppleResource", None)
+ if apple_resource:
+ resource_sets.extend(apple_resource.resource_sets)
+
+ return resource_sets
+
+
def _swift_library_impl(ctx):
"""Implementation for swift_library Skylark rule."""
@@ -450,12 +484,17 @@ def _swift_library_impl(ctx):
link_inputs=set([output_module]),
uses_swift=True,)
+ apple_resource_provider = struct(
+ resource_sets=_collect_resource_sets(ctx, module_name)
+ )
+
return struct(
swift=struct(
transitive_libs=[output_lib] + dep_libs,
transitive_modules=[output_module] + dep_modules,
transitive_defines=swiftc_defines),
objc=objc_provider,
+ AppleResource=apple_resource_provider,
files=set([output_lib, output_module, output_header]))
SWIFT_LIBRARY_ATTRS = {
@@ -464,6 +503,14 @@ SWIFT_LIBRARY_ATTRS = {
"module_name": attr.string(mandatory=False),
"defines": attr.string_list(mandatory=False, allow_empty=True),
"copts": attr.string_list(mandatory=False, allow_empty=True),
+ "resources": attr.label_list(
+ mandatory=False,
+ allow_empty=True,
+ allow_files=True),
+ "structured_resources": attr.label_list(
+ mandatory=False,
+ allow_empty=True,
+ allow_files=True),
"_xcrunwrapper": attr.label(
executable=True,
cfg="host",