From a4ff994d18a5b92419a6fc39b7defdbea0347dc4 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Mon, 20 Mar 2023 18:15:14 -0700 Subject: [PATCH] Remove support to propagate frameworks via objc_library.runtime_deps https://github.com/bazelbuild/rules_apple/commit/f711be032bd62fa13e866607bfb238e1988aca89 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 7d0ec138654c7009ca3fb00705d130d60ae50ee4) --- apple/internal/aspects/BUILD | 1 - .../aspects/framework_provider_aspect.bzl | 37 ++-------- apple/internal/ios_rules.bzl | 7 +- apple/internal/providers/embeddable_info.bzl | 68 +++++-------------- .../testing/apple_test_bundle_support.bzl | 4 +- apple/internal/tvos_rules.bzl | 2 +- apple/internal/watchos_rules.bzl | 4 +- 7 files changed, 27 insertions(+), 96 deletions(-) diff --git a/apple/internal/aspects/BUILD b/apple/internal/aspects/BUILD index 9db8b21da8..ea3b8f2b8a 100644 --- a/apple/internal/aspects/BUILD +++ b/apple/internal/aspects/BUILD @@ -15,7 +15,6 @@ bzl_library( ], deps = [ "//apple:providers", - "//apple/internal/providers:embeddable_info", ], ) diff --git a/apple/internal/aspects/framework_provider_aspect.bzl b/apple/internal/aspects/framework_provider_aspect.bzl index 3d180fc7cd..5be2aa5f41 100644 --- a/apple/internal/aspects/framework_provider_aspect.bzl +++ b/apple/internal/aspects/framework_provider_aspect.bzl @@ -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", "data"] +# List of attributes through which the aspect propagates. +_FRAMEWORK_PROVIDERS_ASPECT_ATTRS = ["deps", "frameworks", "private_deps", "data"] 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` """, ) diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index 86cd88293e..8f1a744d9d 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -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, diff --git a/apple/internal/providers/embeddable_info.bzl b/apple/internal/providers/embeddable_info.bzl index 0b9c9af2ff..7f69ad2fbf 100644 --- a/apple/internal/providers/embeddable_info.bzl +++ b/apple/internal/providers/embeddable_info.bzl @@ -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, + }, ) diff --git a/apple/internal/testing/apple_test_bundle_support.bzl b/apple/internal/testing/apple_test_bundle_support.bzl index d42aed97e2..52a5a32ab7 100644 --- a/apple/internal/testing/apple_test_bundle_support.bzl +++ b/apple/internal/testing/apple_test_bundle_support.bzl @@ -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, @@ -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( diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index 849ded7d21..d7c0bb8b80 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -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, diff --git a/apple/internal/watchos_rules.bzl b/apple/internal/watchos_rules.bzl index 39bbcbd000..7f0499c243 100644 --- a/apple/internal/watchos_rules.bzl +++ b/apple/internal/watchos_rules.bzl @@ -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,