Add "resources", "structured_resources" attrs to swift_library.
MOS_MIGRATED_REVID=151183770
@@ -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",
