Skip to content

Commit

Permalink
Add custom_umbrella_header to ios_static_framework
Browse files Browse the repository at this point in the history
This attribute allows users to specify an umbrella header to use for the
framework in place of generating a default one. This is useful for
frameworks that have multiple headers, including a natural umbrella
header, that has a conflicting name with the one that would be
generated.
  • Loading branch information
keith committed May 20, 2019
1 parent f8b1da5 commit b640133
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions apple/internal/ios_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def _ios_static_framework_impl(ctx):
partials.binary_partial(binary_artifact = binary_artifact),
partials.static_framework_header_modulemap_partial(
hdrs = ctx.files.hdrs,
umbrella_header = ctx.file.umbrella_header,
binary_objc_provider = binary_target[apple_common.Objc],
),
]
Expand Down
13 changes: 10 additions & 3 deletions apple/internal/partials/static_framework_header_modulemap.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,19 @@ def _create_umbrella_header(actions, output, headers):
content = "\n".join(import_lines) + "\n"
actions.write(output = output, content = content)

def _static_framework_header_modulemap_partial_impl(ctx, hdrs, binary_objc_provider):
def _static_framework_header_modulemap_partial_impl(ctx, hdrs, umbrella_header, binary_objc_provider):
"""Implementation for the static framework headers and modulemaps partial."""
bundle_name = bundling_support.bundle_name(ctx)

bundle_files = []

umbrella_header_name = None
if hdrs:
if umbrella_header:
umbrella_header_name = umbrella_header.basename
bundle_files.append(
(processor.location.bundle, "Headers", depset(hdrs + [umbrella_header])),
)
elif hdrs:
umbrella_header_name = "{}.h".format(bundle_name)
umbrella_header_file = intermediates.file(ctx.actions, ctx.label.name, umbrella_header_name)
_create_umbrella_header(
Expand Down Expand Up @@ -165,13 +170,14 @@ def _static_framework_header_modulemap_partial_impl(ctx, hdrs, binary_objc_provi
bundle_files = bundle_files,
)

def static_framework_header_modulemap_partial(hdrs, binary_objc_provider):
def static_framework_header_modulemap_partial(hdrs, umbrella_header, binary_objc_provider):
"""Constructor for the static framework headers and modulemaps partial.
This partial bundles the headers and modulemaps for static frameworks.
Args:
hdrs: The list of headers to bundle.
umbrella_header: An umbrella header to use instead of generating one
binary_objc_provider: The ObjC provider for the binary target.
Returns:
Expand All @@ -181,5 +187,6 @@ def static_framework_header_modulemap_partial(hdrs, binary_objc_provider):
return partial.make(
_static_framework_header_modulemap_partial_impl,
hdrs = hdrs,
umbrella_header = umbrella_header,
binary_objc_provider = binary_objc_provider,
)
9 changes: 9 additions & 0 deletions apple/internal/rule_factory.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,15 @@ use only extension-safe APIs.
A list of `.h` files that will be publicly exposed by this framework. These headers should have
framework-relative imports, and if non-empty, an umbrella header named `%{bundle_name}.h` will also
be generated that imports all of the headers listed here.
""",
),
"umbrella_header": attr.label(
allow_single_file = [".h"],
doc = """
A single .h file to use as the umbrella header for this framework. Usually, this header will have the
same name as this target, so that clients can load the header using the #import <MyFramework/MyFramework.h>
format. If this attribute is not specified, an umbrella header will be generated under the same name as this
target.
""",
),
"avoid_deps": attr.label_list(
Expand Down

0 comments on commit b640133

Please sign in to comment.