From cae68a5fa32f9892c88bc490c3187fccb341a489 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 24 Mar 2017 23:02:00 +0000 Subject: Add "resources", "structured_resources" attrs to swift_library. -- PiperOrigin-RevId: 151183770 MOS_MIGRATED_REVID=151183770 --- tools/build_defs/apple/swift.bzl | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) 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", -- cgit v1.2.3