Skip to content

Commit

Permalink
Remove support to propagate frameworks via objc_library.runtime_deps
Browse files Browse the repository at this point in the history
f711be0 added support to propagate Apple frameworks using `data`
rule attribute for both objc_library and swift_library targets. This
change now removes support to propagate frameworks via `runtime_deps`.

PiperOrigin-RevId: 514762665
(cherry picked from commit 7d0ec13)
  • Loading branch information
keith committed Mar 21, 2023
1 parent ed5614f commit bb5b2bb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 96 deletions.
1 change: 0 additions & 1 deletion apple/internal/aspects/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ bzl_library(
],
deps = [
"//apple:providers",
"//apple/internal/providers:embeddable_info",
],
)

Expand Down
37 changes: 7 additions & 30 deletions apple/internal/aspects/framework_provider_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,38 @@ load(
"AppleFrameworkImportInfo",
"merge_apple_framework_import_info",
)
load(
"@build_bazel_rules_apple//apple/internal/providers:embeddable_info.bzl",
"AppleEmbeddableInfo",
"embeddable_info",
)

# List of attributes through which the aspect propagates. We include `runtime_deps` here as
# these are supported by `objc_library` for frameworks that should be present in the bundle, but not
# linked against.
# TODO(b/120205406): Remove `runtime_deps` support to use objc_library/swift_library `data` instead.
_FRAMEWORK_PROVIDERS_ASPECT_ATTRS = ["deps", "frameworks", "private_deps", "runtime_deps"]
# List of attributes through which the aspect propagates.
_FRAMEWORK_PROVIDERS_ASPECT_ATTRS = ["deps", "frameworks", "private_deps"]

def _framework_provider_aspect_impl(target, ctx):
"""Implementation of the framework provider propagation aspect."""
if AppleFrameworkImportInfo in target and ctx.rule.kind != "objc_library":
if AppleFrameworkImportInfo in target:
return []

apple_framework_infos = []
apple_embeddable_infos = []

for attribute in _FRAMEWORK_PROVIDERS_ASPECT_ATTRS:
if not hasattr(ctx.rule.attr, attribute):
continue
for dep_target in getattr(ctx.rule.attr, attribute):
# *_framework_import targets support
if AppleFrameworkImportInfo in dep_target:
apple_framework_infos.append(dep_target[AppleFrameworkImportInfo])

# *_framework targets support
if AppleEmbeddableInfo in dep_target and ctx.rule.kind == "objc_library":
apple_embeddable_infos.append(dep_target[AppleEmbeddableInfo])

apple_framework_info = merge_apple_framework_import_info(apple_framework_infos)
apple_embeddable_info = embeddable_info.merge_providers(apple_embeddable_infos)

providers = []
if apple_framework_info.framework_imports:
providers.append(apple_framework_info)
if apple_embeddable_info:
providers.append(apple_embeddable_info)

return providers
return [apple_framework_info]
return []

framework_provider_aspect = aspect(
implementation = _framework_provider_aspect_impl,
attr_aspects = _FRAMEWORK_PROVIDERS_ASPECT_ATTRS,
doc = """
Aspect that collects frameworks providers from non-Apple rules targets
(e.g. objc_library) to be packaged within the top-level application bundle .
Aspect that collects frameworks providers from non-Apple rules targets (e.g. objc_library
or swift_library) to be packaged within the top-level application bundle.
Framework targets supported are:
- `apple_static_framework_import`
- `apple_dynamic_framework_import`
- `ios_framework`
- `tvos_framework`
- `watchos_framework`
""",
)
7 changes: 1 addition & 6 deletions apple/internal/ios_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,7 @@ def _ios_application_impl(ctx):
bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx)
executable_name = bundling_support.executable_name(ctx)
bundle_verification_targets = [struct(target = ext) for ext in ctx.attr.extensions]
embeddable_targets = (
ctx.attr.frameworks +
ctx.attr.extensions +
ctx.attr.app_clips +
ctx.attr.deps
)
embeddable_targets = ctx.attr.frameworks + ctx.attr.extensions + ctx.attr.app_clips
features = features_support.compute_enabled_features(
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
Expand Down
68 changes: 16 additions & 52 deletions apple/internal/providers/embeddable_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,31 @@

"""AppleEmbeddableInfo provider implementation for embeddable bundles propagation."""

_APPLE_EMBEDDABLE_INFO_FIELDS = {
"app_clips": """
AppleEmbeddableInfo = provider(
doc = """
Internal provider used to propagate the different embeddable bundles that a
top-level bundling rule will need to package. For non Apple targets (e.g.
objc_library) this provider is propagated with by the embeddable_info_aspect.
Do not depend on this provider for non Apple rules.
""",
fields = {
"app_clips": """
A depset with the zipped archives of bundles that need to be expanded into the
AppClips section of the packaging bundle.""",
"frameworks": """
"frameworks": """
A depset with the zipped archives of bundles that need to be expanded into the
Frameworks section of the packaging bundle.""",
"plugins": """
"plugins": """
A depset with the zipped archives of bundles that need to be expanded into the
PlugIns section of the packaging bundle.""",
"signed_frameworks": """
"signed_frameworks": """
A depset of strings referencing frameworks that have already been codesigned.""",
"watch_bundles": """
"watch_bundles": """
A depset with the zipped archives of bundles that need to be expanded into the Watch section of
the packaging bundle. Only applicable for iOS applications.""",
"xpc_services": """
"xpc_services": """
A depset with the zipped archives of bundles that need to be expanded into the XPCServices section
of the packaging bundle. Only applicable for macOS applications.""",
}

AppleEmbeddableInfo = provider(
doc = """
Internal provider used to propagate the different embeddable bundles that a
top-level bundling rule will need to package. For non Apple targets (e.g.
objc_library) this provider is propagated with by the embeddable_info_aspect.
Do not depend on this provider for non Apple rules.
""",
fields = _APPLE_EMBEDDABLE_INFO_FIELDS,
)

def _merge_providers(apple_embeddable_infos):
"""Merges multiple `AppleEmbeddableInfo` providers into one.
Merging multiple providers into one is needed to collect multiple
framework providers from `framework_provider_aspect`.
Args:
apple_embeddable_infos: List of `AppleEmbeddableInfo` to be merged.
Returns:
Merged `AppleEmbeddableInfo` provider.
"""
if not apple_embeddable_infos:
return None

embeddable_info_fields = {}
for field in _APPLE_EMBEDDABLE_INFO_FIELDS:
field_embeddable_infos = []
for apple_embeddable_info in apple_embeddable_infos:
if hasattr(apple_embeddable_info, field):
field_embeddable_infos.append(
getattr(apple_embeddable_info, field),
)

if field_embeddable_infos:
embeddable_info_fields[field] = depset(
transitive = field_embeddable_infos,
)

return AppleEmbeddableInfo(**embeddable_info_fields)

embeddable_info = struct(
merge_providers = _merge_providers,
},
)
4 changes: 1 addition & 3 deletions apple/internal/testing/apple_test_bundle_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,6 @@ def _apple_test_bundle_impl(ctx):
if bundle_loader:
targets_to_avoid.append(bundle_loader)

embeddable_targets = ctx.attr.deps + getattr(ctx.attr, "frameworks", [])

processor_partials = [
partials.apple_bundle_info_partial(
actions = actions,
Expand Down Expand Up @@ -399,7 +397,7 @@ def _apple_test_bundle_impl(ctx):
),
partials.embedded_bundles_partial(
bundle_embedded_bundles = True,
embeddable_targets = embeddable_targets,
embeddable_targets = getattr(ctx.attr, "frameworks", []),
platform_prerequisites = platform_prerequisites,
),
partials.framework_import_partial(
Expand Down
2 changes: 1 addition & 1 deletion apple/internal/tvos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _tvos_application_impl(ctx):
unsupported_features = ctx.disabled_features,
)
bundle_verification_targets = [struct(target = ext) for ext in ctx.attr.extensions]
embeddable_targets = ctx.attr.extensions + ctx.attr.frameworks + ctx.attr.deps
embeddable_targets = ctx.attr.extensions + ctx.attr.frameworks
features = features_support.compute_enabled_features(
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
Expand Down
4 changes: 1 addition & 3 deletions apple/internal/watchos_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,7 @@ def _watchos_extension_impl(ctx):
apple_xplat_toolchain_info = ctx.attr._xplat_toolchain[AppleXPlatToolsToolchainInfo]
bundle_id = ctx.attr.bundle_id
bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx)
embeddable_targets = (
ctx.attr.extensions + ctx.attr.frameworks + ctx.attr.deps
)
embeddable_targets = ctx.attr.extensions + ctx.attr.frameworks
executable_name = bundling_support.executable_name(ctx)
features = features_support.compute_enabled_features(
requested_features = ctx.features,
Expand Down

0 comments on commit bb5b2bb

Please sign in to comment.