From f953a1aa3c2873cd14164b20f9325bc0ae0eb60d Mon Sep 17 00:00:00 2001 From: mccorkill1 <69316216+mccorkill1@users.noreply.github.com> Date: Tue, 29 Sep 2020 11:48:35 -0400 Subject: [PATCH 01/26] Add ability to package an iOS dynamic framework into a format Xcode can consume --- .../swift_dynamic_framework_aspect.bzl | 137 +++++++++ apple/internal/ios_rules.bzl | 162 +++++++++++ apple/internal/partials.bzl | 5 + .../partials/swift_dynamic_framework.bzl | 129 +++++++++ apple/internal/rule_factory.bzl | 45 ++- apple/internal/rule_support.bzl | 14 + apple/internal/watchos_rules.bzl | 125 ++++++++ apple/ios.bzl | 34 +++ apple/watchos.bzl | 41 +++ test/starlark_tests/BUILD | 3 + .../ios_dynamic_framework_tests.bzl | 164 +++++++++++ test/starlark_tests/resources/BUILD | 52 ++++ .../resources/BasicFramework.swift | 19 ++ test/starlark_tests/resources/Common.swift | 23 ++ .../resources/DirectDependencyTest.swift | 24 ++ test/starlark_tests/resources/Shared.swift | 35 +++ .../resources/TransitiveDependencyTest.swift | 27 ++ .../resources/Transitives.swift | 37 +++ .../targets_under_test/ios/BUILD | 268 ++++++++++++++++++ 19 files changed, 1341 insertions(+), 3 deletions(-) create mode 100644 apple/internal/aspects/swift_dynamic_framework_aspect.bzl create mode 100644 apple/internal/partials/swift_dynamic_framework.bzl create mode 100644 test/starlark_tests/ios_dynamic_framework_tests.bzl create mode 100644 test/starlark_tests/resources/BasicFramework.swift create mode 100644 test/starlark_tests/resources/Common.swift create mode 100644 test/starlark_tests/resources/DirectDependencyTest.swift create mode 100644 test/starlark_tests/resources/Shared.swift create mode 100644 test/starlark_tests/resources/TransitiveDependencyTest.swift create mode 100644 test/starlark_tests/resources/Transitives.swift diff --git a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl new file mode 100644 index 0000000000..84ee5159ad --- /dev/null +++ b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl @@ -0,0 +1,137 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Aspect implementation for Swift dynamic framework support.""" + +load( + "@build_bazel_rules_swift//swift:swift.bzl", + "SwiftInfo", +) + +SwiftDynamicFrameworkInfo = provider( + fields = { + "module_name": "The module name for the single swift_library dependency.", + "swiftinterfaces": """ +Dictionary of architecture to the generated swiftinterface file for that architecture. +""", + "swiftdocs": """ +Dictionary of architecture to the generated swiftdoc file for that architecture. +""", + "generated_header": """ +The generated Objective-C header for the single swift_library dependency. +""", + "swiftmodules": """ +Dictionary of architecture to the generated swiftmodule file for that architecture. +""", + "modulemap": """ +Generated modulemap for that architecture. +""", + }, + doc = """ +Provider that collects artifacts required to build a Swift-based dynamic framework. +""", +) + +def _swift_target_for_dep(dep): + """Returns the target for which the dependency was compiled. + + This is really hacky, but there's no easy way to acquire the Apple CPU for which the target was + built. One option would be to let this aspect propagate transitively through deps and have + another provider that propagates the CPU, but the model there gets a bit more complicated to + follow. With this approach, we avoid propagating the aspect transitively as well. + + This should be cleaned up when b/141931700 is fixed (adding support for ctx.rule.split_attr). + """ + for action in dep.actions: + if action.mnemonic == "SwiftCompile": + target_found = False + for arg in action.argv: + if target_found: + return arg + if arg == "-target": + target_found = True + fail("error: Expected at least one Swift compilation action for target {}.".format(dep.label)) + +def _swift_arch_for_dep(dep): + """Returns the architecture for which the dependency was built.""" + target = _swift_target_for_dep(dep) + return target.split("-", 1)[0] + +def _modulemap_contents(module_name): + """Returns the contents for the modulemap file for the framework.""" + return """\ +framework module {module_name} {{ + header "{module_name}.h" + requires objc +}} +""".format(module_name = module_name) + +def _swift_dynamic_framework_aspect_impl(target, ctx): + """Aspect implementation for Swift dynamic framework support.""" + + swiftdeps = [x for x in ctx.rule.attr.deps if SwiftInfo in x] + + # If there are no Swift dependencies, return nothing. + if not swiftdeps: + return [] + + # Collect all relevant artifacts for Swift dynamic framework generation. + module_name = None + generated_header = None + swiftdocs = {} + swiftmodules = {} + for dep in swiftdeps: + swiftinfo = dep[SwiftInfo] + + if not module_name: + module_name = swiftinfo.module_name + + arch = _swift_arch_for_dep(dep) + + # Collect the interface artifacts. + if swiftinfo.transitive_generated_headers: + if not generated_header: + generated_header = swiftinfo.transitive_generated_headers.to_list().pop() + + swiftdocs[arch] = swiftinfo.transitive_swiftdocs.to_list().pop() + swiftmodules[arch] = swiftinfo.transitive_swiftmodules.to_list().pop() + + modulemapFile = ctx.actions.declare_file("{}File.modulemap".format(module_name)) + ctx.actions.write(modulemapFile, _modulemap_contents(module_name)) + + # Make sure that all dictionaries contain at least one module before returning the provider. + if all([module_name, generated_header, swiftdocs, swiftmodules, modulemapFile]): + return [ + SwiftDynamicFrameworkInfo( + module_name = module_name, + generated_header = generated_header, + swiftdocs = swiftdocs, + swiftmodules = swiftmodules, + modulemap = modulemapFile, + ), + ] + else: + fail( + """\ +error: Could not find all required artifacts and information to build a Swift dynamic framework. \ +Please file an issue with a reproducible error case.\ +""", + ) + +swift_dynamic_framework_aspect = aspect( + implementation = _swift_dynamic_framework_aspect_impl, + doc = """ +Aspect that collects Swift information to construct a dynamic framework that supports Swift. +""", +) diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index ec700217bc..828dc1ea58 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -62,6 +62,10 @@ load( "@build_bazel_rules_apple//apple/internal/aspects:swift_static_framework_aspect.bzl", "SwiftStaticFrameworkInfo", ) +load( + "@build_bazel_rules_apple//apple/internal/aspects:swift_dynamic_framework_aspect.bzl", + "SwiftDynamicFrameworkInfo", +) load( "@build_bazel_rules_apple//apple:providers.bzl", "IosAppClipBundleInfo", @@ -576,6 +580,157 @@ def _ios_extension_impl(ctx): binary_target[apple_common.AppleExecutableBinary], ] + processor_result.providers +def _ios_dynamic_framework_impl(ctx): + """Experimental implementation of ios_dynamic_framework.""" + + binary_target = ctx.attr.deps[0] + binary_artifact = binary_target[apple_common.AppleDylibBinary].binary + + actions = ctx.actions + bundle_id = ctx.attr.bundle_id + bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) + entitlements = getattr(ctx.attr, "entitlements", None) + executable_name = bundling_support.executable_name(ctx) + label = ctx.label + platform_prerequisites = platform_support.platform_prerequisites_from_rule_ctx(ctx) + predeclared_outputs = ctx.outputs + product_type = ctx.attr._product_type + rule_descriptor = rule_support.rule_descriptor(ctx) + + signed_frameworks = [] + if getattr(ctx.file, "provisioning_profile", None): + signed_frameworks = [ + bundle_name + rule_descriptor.bundle_extension, + ] + + archive_for_embedding = outputs.archive_for_embedding( + actions = actions, + bundle_name = bundle_name, + bundle_extension = bundle_extension, + executable_name = executable_name, + label_name = label.name, + rule_descriptor = rule_descriptor, + platform_prerequisites = platform_prerequisites, + predeclared_outputs = predeclared_outputs, + ) + + processor_partials = [ + partials.apple_bundle_info_partial( + actions = actions, + bundle_extension = bundle_extension, + bundle_id = bundle_id, + bundle_name = bundle_name, + executable_name = executable_name, + entitlements = entitlements, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + predeclared_outputs = predeclared_outputs, + product_type = product_type, + ), + + + partials.binary_partial( + actions = actions, + binary_artifact = binary_artifact, + executable_name = executable_name, + label_name = label.name, + ), + partials.bitcode_symbols_partial( + actions = actions, + binary_artifact = binary_artifact, + debug_outputs_provider = binary_target[apple_common.AppleDebugOutputs], + dependency_targets = ctx.attr.frameworks, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + ), + # TODO(kaipi): Check if clang_rt dylibs are needed in Frameworks, or if + # the can be skipped. + partials.clang_rt_dylibs_partial(binary_artifact = binary_artifact), + partials.debug_symbols_partial( + debug_dependencies = ctx.attr.frameworks, + debug_outputs_provider = binary_target[apple_common.AppleDebugOutputs], + ), + partials.embedded_bundles_partial( + frameworks = [archive_for_embedding], + embeddable_targets = ctx.attr.frameworks, + signed_frameworks = depset(signed_frameworks), + ), + partials.extension_safe_validation_partial(is_extension_safe = ctx.attr.extension_safe), + partials.framework_headers_partial(hdrs = ctx.files.hdrs), + partials.framework_provider_partial( + binary_provider = binary_target[apple_common.AppleDylibBinary], + ), + partials.resources_partial( + bundle_id = bundle_id, + plist_attrs = ["infoplists"], + targets_to_avoid = ctx.attr.frameworks, + version_keys_required = False, + top_level_attrs = ["resources"], + ), + partials.swift_dylibs_partial( + binary_artifact = binary_artifact, + dependency_targets = ctx.attr.frameworks, + ), + partials.swift_dynamic_framework_partial( + swift_dynamic_framework_info = binary_target[SwiftDynamicFrameworkInfo], + ), + ] + + processor_result = processor.process(ctx, processor_partials) + providers = processor_result.providers + + framework_dir = depset() + framework_files = depset() + desired_path = "" + for provider in providers: + if type(provider) == "AppleDynamicFramework": + framework_dir = provider.framework_dirs + framework_files = provider.framework_files + full_path = framework_dir.to_list()[0] + path_parts = full_path.split("/") + for part in path_parts: + if part != path_parts[len(path_parts)-1]: + desired_path = desired_path + part + "/" + else: + desired_path = desired_path[0:len(desired_path)-1] + desired_framework_dir = depset([desired_path]) + + #=========================================================================================================== + # TODO: Create the complete CcInfo in a partial, OR just do it here like so (feels hacky) + # As of right now we have a parital CcInfo being created in the dynamic_framework_partial + # But we need the framework_dir from the AppleDynamicFramework returned by the framework_provider_partial + # To be included so the transitive dependencies will work properly + # This feels like the wrong place to do this logic, but it's the only place we had access to all the data + #=========================================================================================================== + + # Make the ObjC provider + objc_provider_fields = {} + objc_provider_fields["dynamic_framework_file"] = framework_files + objc_provider = apple_common.new_objc_provider(**objc_provider_fields) + + # Add everything but CcInfo provider so we can make a new one + new_providers = [] + for provider in providers: + if type(provider) != "CcInfo": + new_providers.append(provider) + else: + cc_info = CcInfo( + compilation_context = cc_common.create_compilation_context( + headers = provider.compilation_context.headers, + framework_includes = desired_framework_dir, + ), + ) + new_providers.append(cc_info) + + new_providers.append(objc_provider) + + providers = [ + DefaultInfo(files = processor_result.output_files), + IosFrameworkBundleInfo(), + ] + new_providers + + return providers + def _ios_static_framework_impl(ctx): """Experimental implementation of ios_static_framework.""" @@ -949,6 +1104,13 @@ ios_framework = rule_factory.create_apple_bundling_rule( doc = "Builds and bundles an iOS Dynamic Framework.", ) +ios_dynamic_framework = rule_factory.create_apple_bundling_rule( + implementation = _ios_dynamic_framework_impl, + platform_type = "ios", + product_type = apple_product_type.framework, + doc = "Builds and bundles an iOS Dynamic Framework consumable in Xcode.", +) + ios_static_framework = rule_factory.create_apple_bundling_rule( implementation = _ios_static_framework_impl, platform_type = "ios", diff --git a/apple/internal/partials.bzl b/apple/internal/partials.bzl index 3d3c47a8f5..3350950698 100644 --- a/apple/internal/partials.bzl +++ b/apple/internal/partials.bzl @@ -86,6 +86,10 @@ load( "@build_bazel_rules_apple//apple/internal/partials:swift_dylibs.bzl", _swift_dylibs_partial = "swift_dylibs_partial", ) +load( + "@build_bazel_rules_apple//apple/internal/partials:swift_dynamic_framework.bzl", + _swift_dynamic_framework_partial = "swift_dynamic_framework_partial", +) load( "@build_bazel_rules_apple//apple/internal/partials:swift_static_framework.bzl", _swift_static_framework_partial = "swift_static_framework_partial", @@ -114,6 +118,7 @@ partials = struct( settings_bundle_partial = _settings_bundle_partial, static_framework_header_modulemap_partial = _static_framework_header_modulemap_partial, swift_dylibs_partial = _swift_dylibs_partial, + swift_dynamic_framework_partial = _swift_dynamic_framework_partial, swift_static_framework_partial = _swift_static_framework_partial, watchos_stub_partial = _watchos_stub_partial, ) diff --git a/apple/internal/partials/swift_dynamic_framework.bzl b/apple/internal/partials/swift_dynamic_framework.bzl new file mode 100644 index 0000000000..1af1e585c7 --- /dev/null +++ b/apple/internal/partials/swift_dynamic_framework.bzl @@ -0,0 +1,129 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Partial implementation for Swift dynamic frameworks.""" + +load( + "@build_bazel_rules_apple//apple/internal:bundling_support.bzl", + "bundling_support", +) +load( + "@build_bazel_rules_apple//apple/internal:intermediates.bzl", + "intermediates", +) +load( + "@build_bazel_rules_apple//apple/internal:processor.bzl", + "processor", +) +load( + "@bazel_skylib//lib:partial.bzl", + "partial", +) +load( + "@bazel_skylib//lib:paths.bzl", + "paths", +) + +def _get_header_imports(framework_imports): + """Get the header files from the list of framework imports""" + + header_imports = [] + for file in framework_imports: + file_short_path = file.short_path + if file_short_path.endswith(".h"): + header_imports.append(file) + + return header_imports + +def _swift_dynamic_framework_partial_impl(ctx, swift_dynamic_framework_info): + """Implementation for the Swift static framework processing partial.""" + + expected_module_name = bundling_support.bundle_name(ctx) + if expected_module_name != swift_dynamic_framework_info.module_name: + fail(""" +error: Found swift_library with module name {} but expected {}. Swift dynamic \ +frameworks expect a single swift_library dependency with `module_name` set to the same \ +`bundle_name` as the dynamic framework target.\ +""".format(swift_dynamic_framework_info.module_name, expected_module_name)) + + generated_header = swift_dynamic_framework_info.generated_header + swiftdocs = swift_dynamic_framework_info.swiftdocs + swiftmodules = swift_dynamic_framework_info.swiftmodules + modulemapFile = swift_dynamic_framework_info.modulemap + + bundle_files = [] + modules_parent = paths.join("Modules", "{}.swiftmodule".format(expected_module_name)) + + for arch, swiftdoc in swiftdocs.items(): + bundle_doc = intermediates.file(ctx.actions, ctx.label.name, "{}.swiftdoc".format(arch)) + ctx.actions.symlink(target_file = swiftdoc, output = bundle_doc) + bundle_files.append((processor.location.bundle, modules_parent, depset([bundle_doc]))) + + for arch, swiftmodule in swiftmodules.items(): + bundle_doc = intermediates.file(ctx.actions, ctx.label.name, "{}.swiftmodule".format(arch)) + ctx.actions.symlink(target_file = swiftmodule, output = bundle_doc) + bundle_files.append((processor.location.bundle, modules_parent, depset([bundle_doc]))) + + if generated_header: + bundle_header = intermediates.file( + ctx.actions, + ctx.label.name, + "{}.h".format(expected_module_name), + ) + ctx.actions.symlink(target_file = generated_header, output = bundle_header) + bundle_files.append((processor.location.bundle, "Headers", depset([bundle_header]))) + + if modulemapFile: + modulemap = intermediates.file(ctx.actions, ctx.label.name, "module.modulemap") + ctx.actions.symlink(target_file = modulemapFile, output = modulemap) + bundle_files.append((processor.location.bundle, "Modules", depset([modulemap]))) + + providers = [] + all_files = [] + for bundle, path, files in bundle_files: + all_files += files.to_list() + + header_imports = _get_header_imports(all_files) + + cc_info_provider = CcInfo( + compilation_context = cc_common.create_compilation_context( + headers = depset(header_imports), + ), + ) + + providers.append(cc_info_provider) + + return struct( + bundle_files = bundle_files, + providers = providers + ) + +def swift_dynamic_framework_partial(swift_dynamic_framework_info): + """Constructor for the Swift dynamic framework processing partial. + + This partial collects and bundles the necessary files to construct a Swift based dynamic + framework. + + Args: + swift_dynamic_framework_info: The SwiftDynamicFrameworkInfo provider containing the required + artifacts. + + Returns: + A partial that returns the bundle location of the supporting Swift artifacts needed in a + Swift based static framework. + """ + return partial.make( + _swift_dynamic_framework_partial_impl, + swift_dynamic_framework_info = swift_dynamic_framework_info, + ) diff --git a/apple/internal/rule_factory.bzl b/apple/internal/rule_factory.bzl index 191bc66e0f..30212efc61 100644 --- a/apple/internal/rule_factory.bzl +++ b/apple/internal/rule_factory.bzl @@ -38,6 +38,10 @@ load( "@build_bazel_rules_apple//apple/internal/aspects:swift_static_framework_aspect.bzl", "swift_static_framework_aspect", ) +load( + "@build_bazel_rules_apple//apple/internal/aspects:swift_dynamic_framework_aspect.bzl", + "swift_dynamic_framework_aspect", +) load( "@build_bazel_rules_apple//apple/internal:transition_support.bzl", "transition_support", @@ -233,7 +237,7 @@ true. ), } -def _common_binary_linking_attrs(rule_descriptor): +def _common_binary_linking_attrs(rule_descriptor, platform_type): deps_aspects = [ apple_common.objc_proto_aspect, apple_resource_aspect, @@ -245,6 +249,8 @@ def _common_binary_linking_attrs(rule_descriptor): if rule_descriptor.product_type == apple_product_type.static_framework: deps_aspects.append(swift_static_framework_aspect) + if rule_descriptor.product_type == apple_product_type.framework and (platform_type == "ios" or platform_type == "watchos"): + deps_aspects.append(swift_dynamic_framework_aspect) return { "binary_type": attr.string( @@ -876,6 +882,39 @@ ignored. """, ), }) + elif rule_descriptor.product_type == apple_product_type.framework: + attrs.append({ + # TODO: This attribute is not publicly documented, but it is tested in + # http://github.com/bazelbuild/rules_apple/test/ios_framework_test.sh?l=79. Figure out + # what to do with this. + "hdrs": attr.label_list( + allow_files = [".h"], + ), + "extension_safe": attr.bool( + default = False, + doc = """ + If true, compiles and links this framework with `-application-extension`, restricting the binary to + use only extension-safe APIs. + """, + ), + }) + + if rule_descriptor.requires_deps: + extra_args = {} + if rule_descriptor.product_type == apple_product_type.application: + extra_args["aspects"] = [framework_import_aspect] + + attrs.append({ + "frameworks": attr.label_list( + providers = [[AppleBundleInfo, IosFrameworkBundleInfo]], + doc = """ + A list of framework targets (see + [`ios_framework`](https://github.com/bazelbuild/rules_apple/blob/master/doc/rules-ios.md#ios_framework)) + that this target depends on. + """, + **extra_args + ), + }) return attrs @@ -956,7 +995,7 @@ def _create_apple_binary_rule(implementation, platform_type, product_type, doc): rule_attrs.append(_COMMON_PRIVATE_TOOL_ATTRS) if rule_descriptor.requires_deps: - rule_attrs.append(_common_binary_linking_attrs(rule_descriptor)) + rule_attrs.append(_common_binary_linking_attrs(rule_descriptor, platform_type)) rule_attrs.extend(_get_macos_binary_attrs(rule_descriptor)) @@ -997,7 +1036,7 @@ def _create_apple_bundling_rule(implementation, platform_type, product_type, doc rule_attrs.extend(_get_common_bundling_attributes(rule_descriptor)) if rule_descriptor.requires_deps: - rule_attrs.append(_common_binary_linking_attrs(rule_descriptor)) + rule_attrs.append(_common_binary_linking_attrs(rule_descriptor, platform_type)) is_test_product_type = _is_test_product_type(rule_descriptor.product_type) if is_test_product_type: diff --git a/apple/internal/rule_support.bzl b/apple/internal/rule_support.bzl index 4cca2a7de3..752e724aae 100644 --- a/apple/internal/rule_support.bzl +++ b/apple/internal/rule_support.bzl @@ -756,6 +756,20 @@ _RULE_TYPE_DESCRIPTORS = { "@executable_path/../../Frameworks", ], ), + # watchos_framework + apple_product_type.framework: _describe_rule_type( + allowed_device_families = ["watch"], + bundle_extension = ".framework", + codesigning_exceptions = _CODESIGNING_EXCEPTIONS.sign_with_provisioning_profile, + mandatory_families = True, + product_type = apple_product_type.framework, + rpaths = [ + # Framework binaries live in + # Application.app/Frameworks/Framework.framework/Framework + # Frameworks are packaged in Application.app/Frameworks + "@executable_path/Frameworks", + ], + ), }, } diff --git a/apple/internal/watchos_rules.bzl b/apple/internal/watchos_rules.bzl index fbd4ab6ac6..5db5320a26 100644 --- a/apple/internal/watchos_rules.bzl +++ b/apple/internal/watchos_rules.bzl @@ -63,6 +63,124 @@ load( "WatchosApplicationBundleInfo", "WatchosExtensionBundleInfo", ) +load( + "@build_bazel_rules_apple//apple/internal:bundling_support.bzl", + "bundling_support", +) +load( + "@build_bazel_rules_apple//apple/internal/aspects:swift_dynamic_framework_aspect.bzl", + "SwiftDynamicFrameworkInfo", +) +load( + "@build_bazel_rules_apple//apple:providers.bzl", + "IosFrameworkBundleInfo", +) + +def _watchos_dynamic_framework_impl(ctx): + """Experimental implementation of watchos_dynamic_framework.""" + platform_prerequisites = platform_support.platform_prerequisites_from_rule_ctx(ctx) + + binary_target = ctx.attr.deps[0] + binary_artifact = binary_target[apple_common.AppleDylibBinary].binary + + bundle_id = ctx.attr.bundle_id + + signed_frameworks = [] + if getattr(ctx.file, "provisioning_profile", None): + rule_descriptor = rule_support.rule_descriptor(ctx) + signed_frameworks = [ + bundling_support.bundle_name(ctx) + rule_descriptor.bundle_extension, + ] + + dynamic_framework_partial = partials.swift_dynamic_framework_partial( + swift_dynamic_framework_info = binary_target[SwiftDynamicFrameworkInfo], + ) + processor_partials = [ + partials.apple_bundle_info_partial(bundle_id = bundle_id), + partials.binary_partial(binary_artifact = binary_artifact), + partials.bitcode_symbols_partial( + actions = ctx.actions, + binary_artifact = binary_artifact, + debug_outputs_provider = binary_target[apple_common.AppleDebugOutputs], + label_name = ctx.label.name, + platform_prerequisites = platform_prerequisites, + dependency_targets = ctx.attr.frameworks, + ), + # TODO: Check if clang_rt dylibs are needed in Frameworks, or if + # the can be skipped. + partials.clang_rt_dylibs_partial(binary_artifact = binary_artifact), + partials.debug_symbols_partial( + debug_dependencies = ctx.attr.frameworks, + debug_outputs_provider = binary_target[apple_common.AppleDebugOutputs], + ), + partials.embedded_bundles_partial( + frameworks = [outputs.archive(ctx)], + embeddable_targets = ctx.attr.frameworks, + signed_frameworks = depset(signed_frameworks), + ), + partials.extension_safe_validation_partial(is_extension_safe = ctx.attr.extension_safe), + partials.framework_provider_partial( + binary_provider = binary_target[apple_common.AppleDylibBinary], + ), + partials.resources_partial( + bundle_id = bundle_id, + plist_attrs = ["infoplists"], + targets_to_avoid = ctx.attr.frameworks, + version_keys_required = False, + top_level_attrs = ["resources"], + ), + partials.swift_dylibs_partial( + binary_artifact = binary_artifact, + dependency_targets = ctx.attr.frameworks, + ), + dynamic_framework_partial, + ] + + processor_result = processor.process(ctx, processor_partials) + providers = processor_result.providers + + framework_dir = depset() + framework_files = depset() + for provider in providers: + if type(provider) == "AppleDynamicFramework": + framework_dir = provider.framework_dirs + framework_files = provider.framework_files + + #=========================================================================================================== + # TODO: Create the complete CcInfo in a partial, OR just do it here like so (feels hacky) + # As of right now we have a parital CcInfo being created in the dynamic_framework_partial + # But we need the framework_dir from the AppleDynamicFramework returned by the framework_provider_partial + # To be included so the transitive dependencies will work properly + # This feels like the wrong place to do this logic, but it's the only place we had access to all the data + #=========================================================================================================== + + # Make the ObjC provider + objc_provider_fields = {} + objc_provider_fields["dynamic_framework_file"] = framework_files + objc_provider = apple_common.new_objc_provider(**objc_provider_fields) + + # Add everything but CcInfo provider so we can make a new one + new_providers = [] + for provider in providers: + if type(provider) != "CcInfo": + new_providers.append(provider) + else: + cc_info = CcInfo( + compilation_context = cc_common.create_compilation_context( + headers = provider.compilation_context.headers, + framework_includes = framework_dir, + ), + ) + new_providers.append(cc_info) + + new_providers.append(objc_provider) + + providers = [ + DefaultInfo(files = processor_result.output_files), + IosFrameworkBundleInfo(), + ] + new_providers + + return providers def _watchos_application_impl(ctx): """Implementation of watchos_application.""" @@ -297,3 +415,10 @@ watchos_extension = rule_factory.create_apple_bundling_rule( product_type = apple_product_type.watch2_extension, doc = "Builds and bundles an watchOS Extension.", ) + +watchos_dynamic_framework = rule_factory.create_apple_bundling_rule( + implementation = _watchos_dynamic_framework_impl, + platform_type = "watchos", + product_type = apple_product_type.framework, + doc = "Builds and bundles an iOS Dynamic Framework consumable in Xcode.", +) diff --git a/apple/ios.bzl b/apple/ios.bzl index 82e5d98dc5..0b2d305438 100644 --- a/apple/ios.bzl +++ b/apple/ios.bzl @@ -46,6 +46,7 @@ load( _ios_imessage_application = "ios_imessage_application", _ios_imessage_extension = "ios_imessage_extension", _ios_static_framework = "ios_static_framework", + _ios_dynamic_framework = "ios_dynamic_framework", _ios_sticker_pack_extension = "ios_sticker_pack_extension", ) @@ -125,6 +126,39 @@ def ios_framework(name, **kwargs): **bundling_args ) +def ios_dynamic_framework(name, **kwargs): + # buildifier: disable=function-docstring-args + """Builds and bundles an iOS dynamic framework.""" + linkopts = kwargs.get("linkopts", []) + + # Can't read this from the descriptor, since it requires the bundle name as argument. Once this + # is migrated to be a rule, we can move this to the rule implementation. + bundle_name = kwargs.get("bundle_name", name) + linkopts += [ + "-install_name", + "@rpath/%s.framework/%s" % (bundle_name, bundle_name), + ] + kwargs["linkopts"] = linkopts + + # Link the executable from any library deps and sources provided. + bundling_args = binary_support.create_binary( + name, + str(apple_common.platform_type.ios), + apple_product_type.framework, + binary_type = "dylib", + suppress_entitlements = True, + **kwargs + ) + + # Remove any kwargs that shouldn't be passed to the underlying rule. + bundling_args.pop("entitlements", None) + + _ios_dynamic_framework( + name = name, + extension_safe = kwargs.get("extension_safe"), + **bundling_args + ) + def ios_static_framework(name, **kwargs): # buildifier: disable=function-docstring-args """Builds and bundles an iOS static framework for third-party distribution.""" diff --git a/apple/watchos.bzl b/apple/watchos.bzl index 742253f689..d8a18e2904 100644 --- a/apple/watchos.bzl +++ b/apple/watchos.bzl @@ -26,6 +26,14 @@ load( "@build_bazel_rules_apple//apple/internal:binary_support.bzl", "binary_support", ) +load( + "@build_bazel_rules_apple//apple/internal:watchos_rules.bzl", + _watchos_dynamic_framework = "watchos_dynamic_framework", +) +load( + "@build_bazel_rules_apple//apple/internal:apple_product_type.bzl", + "apple_product_type", +) # Alias the internal rules when we load them. This lets the rules keep their # original name in queries and logs since they collide with the wrapper macros. @@ -65,6 +73,39 @@ def watchos_extension(name, **kwargs): **bundling_args ) +def watchos_dynamic_framework(name, **kwargs): + # buildifier: disable=function-docstring-args + """Builds and bundles a watchOS dynamic framework.""" + linkopts = kwargs.get("linkopts", []) + + # Can't read this from the descriptor, since it requires the bundle name as argument. Once this + # is migrated to be a rule, we can move this to the rule implementation. + bundle_name = kwargs.get("bundle_name", name) + linkopts += [ + "-install_name", + "@rpath/%s.framework/%s" % (bundle_name, bundle_name), + ] + kwargs["linkopts"] = linkopts + + # Link the executable from any library deps and sources provided. + bundling_args = binary_support.create_binary( + name, + str(apple_common.platform_type.watchos), + apple_product_type.framework, + binary_type = "dylib", + suppress_entitlements = True, + **kwargs + ) + + # Remove any kwargs that shouldn't be passed to the underlying rule. + bundling_args.pop("entitlements", None) + + _watchos_dynamic_framework( + name = name, + extension_safe = kwargs.get("extension_safe"), + **bundling_args + ) + watchos_build_test = apple_build_test_rule( doc = """\ Test rule to check that the given library targets (Swift, Objective-C, C++) diff --git a/test/starlark_tests/BUILD b/test/starlark_tests/BUILD index 330742bce4..391da44cc5 100644 --- a/test/starlark_tests/BUILD +++ b/test/starlark_tests/BUILD @@ -6,6 +6,7 @@ load(":ios_application_tests.bzl", "ios_application_test_suite") load(":ios_app_clip_tests.bzl", "ios_app_clip_test_suite") load(":ios_extension_tests.bzl", "ios_extension_test_suite") load(":ios_framework_tests.bzl", "ios_framework_test_suite") +load(":ios_dynamic_framework_tests.bzl", "ios_dynamic_framework_test_suite") load(":ios_imessage_application_tests.bzl", "ios_imessage_application_test_suite") load(":ios_sticker_pack_extension_tests.bzl", "ios_sticker_pack_extension_test_suite") load(":ios_ui_test_tests.bzl", "ios_ui_test_test_suite") @@ -47,6 +48,8 @@ ios_extension_test_suite() ios_framework_test_suite() +ios_dynamic_framework_test_suite() + ios_imessage_application_test_suite() ios_sticker_pack_extension_test_suite() diff --git a/test/starlark_tests/ios_dynamic_framework_tests.bzl b/test/starlark_tests/ios_dynamic_framework_tests.bzl new file mode 100644 index 0000000000..9fa133fd35 --- /dev/null +++ b/test/starlark_tests/ios_dynamic_framework_tests.bzl @@ -0,0 +1,164 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""ios_framework Starlark tests.""" + +load( + ":rules/common_verification_tests.bzl", + "archive_contents_test", +) +load( + ":rules/infoplist_contents_test.bzl", + "infoplist_contents_test", +) + +def ios_dynamic_framework_test_suite(): + """Test suite for ios_framework.""" + name = "ios_dynamic_framework" + + archive_contents_test( + name = "{}_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/ios:basic_framework", + binary_test_file = "$BUNDLE_ROOT/BasicFramework", + binary_test_architecture = "x86_64", + macho_load_commands_contain = ["name @rpath/BasicFramework.framework/BasicFramework (offset 24)"], + contains = [ + "$BUNDLE_ROOT/BasicFramework", + "$BUNDLE_ROOT/Headers/BasicFramework.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/BasicFramework.swiftmodule/x86_64.swiftdoc", + "$BUNDLE_ROOT/Modules/BasicFramework.swiftmodule/x86_64.swiftmodule" + ], + tags = [name], + ) + + infoplist_contents_test( + name = "{}_plist_test".format(name), + target_under_test = "//test/starlark_tests/targets_under_test/ios:basic_framework", + expected_values = { + "BuildMachineOSBuild": "*", + "CFBundleExecutable": "BasicFramework", + "CFBundleIdentifier": "com.google.example.framework", + "CFBundleName": "BasicFramework", + "CFBundleSupportedPlatforms:0": "iPhone*", + "DTCompiler": "com.apple.compilers.llvm.clang.1_0", + "DTPlatformBuild": "*", + "DTPlatformName": "iphone*", + "DTPlatformVersion": "*", + "DTSDKBuild": "*", + "DTSDKName": "iphone*", + "DTXcode": "*", + "DTXcodeBuild": "*", + "MinimumOSVersion": "8.0", + "UIDeviceFamily:0": "1", + }, + tags = [name], + ) + + archive_contents_test( + name = "{}_direct_dependency_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/ios:basic_framework_with_direct_dependency", + binary_test_file = "$BUNDLE_ROOT/DirectDependencyTest", + binary_test_architecture = "x86_64", + macho_load_commands_contain = ["name @rpath/DirectDependencyTest.framework/DirectDependencyTest (offset 24)"], + contains = [ + "$BUNDLE_ROOT/DirectDependencyTest", + "$BUNDLE_ROOT/Headers/DirectDependencyTest.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/DirectDependencyTest.swiftmodule/x86_64.swiftdoc", + "$BUNDLE_ROOT/Modules/DirectDependencyTest.swiftmodule/x86_64.swiftmodule" + ], + tags = [name], + ) + + archive_contents_test( + name = "{}_transitive_dependency_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/ios:basic_framework_with_transitive_dependency", + binary_test_file = "$BUNDLE_ROOT/TransitiveDependencyTest", + binary_test_architecture = "x86_64", + macho_load_commands_contain = ["name @rpath/TransitiveDependencyTest.framework/TransitiveDependencyTest (offset 24)"], + contains = [ + "$BUNDLE_ROOT/TransitiveDependencyTest", + "$BUNDLE_ROOT/Headers/TransitiveDependencyTest.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/TransitiveDependencyTest.swiftmodule/x86_64.swiftdoc", + "$BUNDLE_ROOT/Modules/TransitiveDependencyTest.swiftmodule/x86_64.swiftmodule" + ], + tags = [name], + ) + + # Tests that libraries that both apps and frameworks depend only have symbols + # present in the framework. + archive_contents_test( + name = "{}_symbols_from_shared_library_in_framework".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/ios:app_with_dynamic_framework_and_resources", + binary_test_architecture = "x86_64", + binary_test_file = "$BUNDLE_ROOT/Frameworks/swift_lib_with_resources.framework/swift_lib_with_resources", + binary_contains_symbols = ["_$s24swift_lib_with_resources16dontCallMeSharedyyF"], + tags = [name], + ) + + archive_contents_test( + name = "{}_symbols_from_shared_library_not_in_application".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/ios:app_with_dynamic_framework_and_resources", + binary_test_file = "$BUNDLE_ROOT/app_with_dynamic_framework_and_resources", + binary_test_architecture = "x86_64", + binary_not_contains_symbols = ["_$s24swift_lib_with_resources16dontCallMeSharedyyF"], + tags = [name], + ) + + archive_contents_test( + name = "{}_app_includes_transitive_framework_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/ios:app_with_dynamic_framework_with_dynamic_framework", + binary_test_file = "$BUNDLE_ROOT/Frameworks/swift_transitive_lib.framework/swift_transitive_lib", + binary_test_architecture = "x86_64", + contains = [ + "$BUNDLE_ROOT/Frameworks/swift_transitive_lib.framework/swift_transitive_lib", + "$BUNDLE_ROOT/Frameworks/swift_transitive_lib.framework/Info.plist", + "$BUNDLE_ROOT/Frameworks/swift_shared_lib.framework/nonlocalized.plist", + "$BUNDLE_ROOT/Frameworks/swift_shared_lib.framework/swift_shared_lib", + "$BUNDLE_ROOT/Frameworks/swift_shared_lib.framework/Info.plist", + ], + not_contains = [ + "$BUNDLE_ROOT/Frameworks/swift_transitive_lib.framework/Frameworks/", + "$BUNDLE_ROOT/Frameworks/swift_transitive_lib.framework/nonlocalized.plist", + "$BUNDLE_ROOT/framework_resources/nonlocalized.plist", + ], + binary_contains_symbols = ["_$s20swift_transitive_lib21anotherFunctionSharedyyF"], + tags = [name], + ) + + archive_contents_test( + name = "{}_app_includes_transitive_framework_symbols_not_in_app".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/ios:app_with_dynamic_framework_with_dynamic_framework", + binary_test_file = "$BUNDLE_ROOT/app_with_dynamic_framework_with_dynamic_framework", + binary_test_architecture = "x86_64", + binary_not_contains_symbols = ["_$s20swift_transitive_lib21anotherFunctionSharedyyF"], + tags = [name], + ) + + native.test_suite( + name = name, + tags = [name], + ) \ No newline at end of file diff --git a/test/starlark_tests/resources/BUILD b/test/starlark_tests/resources/BUILD index 2594dc6e3f..74f9d79f1d 100644 --- a/test/starlark_tests/resources/BUILD +++ b/test/starlark_tests/resources/BUILD @@ -1,3 +1,4 @@ +test/starlark_tests/resources/BUILD load("@rules_cc//cc:defs.bzl", "objc_library") load( "//apple:resources.bzl", @@ -70,6 +71,57 @@ swift_library( ], ) +swift_library( + name = "swift_lib_with_resources", + module_name = "swift_lib_with_resources", + srcs = [ + "Shared.swift", + ], + data = [ + ":structured_resources", + ], + testonly = True, +) + +swift_library( + name = "swift_common_lib", + module_name = "swift_common_lib", + srcs = ["Common.swift"], + testonly = True, +) + +swift_library( + name = "swift_shared_lib", + module_name = "swift_shared_lib", + srcs = ["Shared.swift"], + deps = [ + "//test/starlark_tests/targets_under_test/ios:swift_common_lib_framework", + ], + testonly = True, +) + +swift_library( + name = "swift_transitive_lib", + module_name = "swift_transitive_lib", + srcs = ["Transitives.swift"], + deps = [ + "//test/starlark_tests/targets_under_test/ios:swift_common_lib_framework", + "//test/starlark_tests/targets_under_test/ios:swift_shared_lib_framework", + ], + testonly = True, +) + +swift_library( + name = "swift_lib_with_transitives", + module_name = "dynamic_framework_with_resources", + srcs = ["Shared.swift"], + data = [ + "//test/starlark_tests/targets_under_test/ios:swift_common_lib_framework", + "//test/starlark_tests/targets_under_test/ios:swift_shared_lib_framework", + ], + testonly = True, +) + swift_library( name = "swift_framework_lib", srcs = ["//test/testdata/sources:main.swift"], diff --git a/test/starlark_tests/resources/BasicFramework.swift b/test/starlark_tests/resources/BasicFramework.swift new file mode 100644 index 0000000000..d83b7e9029 --- /dev/null +++ b/test/starlark_tests/resources/BasicFramework.swift @@ -0,0 +1,19 @@ +// Copyright 2020 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation +public class BasicFramework { + public init() {} + public func HelloWorld() { print("Hello World from Basic Framework") } +} diff --git a/test/starlark_tests/resources/Common.swift b/test/starlark_tests/resources/Common.swift new file mode 100644 index 0000000000..f7f3edd45a --- /dev/null +++ b/test/starlark_tests/resources/Common.swift @@ -0,0 +1,23 @@ +// Copyright 2020 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation + +func doSomethingCommon() { + print("Doing something common") +} + +public protocol ObjectiveCCommonClass { + func doSomethingShared() +} diff --git a/test/starlark_tests/resources/DirectDependencyTest.swift b/test/starlark_tests/resources/DirectDependencyTest.swift new file mode 100644 index 0000000000..eff25b0e59 --- /dev/null +++ b/test/starlark_tests/resources/DirectDependencyTest.swift @@ -0,0 +1,24 @@ +// Copyright 2020 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation +import BasicFramework +public class DirectDependencyTest { + public init() {} + public func directDependencyTest() { + print("DirectDependencyTest") + let framework = BasicFramework() + framework.HelloWorld() + } +} diff --git a/test/starlark_tests/resources/Shared.swift b/test/starlark_tests/resources/Shared.swift new file mode 100644 index 0000000000..79621fc857 --- /dev/null +++ b/test/starlark_tests/resources/Shared.swift @@ -0,0 +1,35 @@ +// Copyright 2020 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation + +public func dontCallMeShared() { + _ = 0; +} + +public func anotherFunctionShared() { + _ = 0; +} + +public func anticipatedDeadCode() { + _ = 0; +} + +public func doSomethingShared() { + print("Doing something shared") +} + +public protocol ObjectiveCSharedClass { + func doSomethingShared() +} diff --git a/test/starlark_tests/resources/TransitiveDependencyTest.swift b/test/starlark_tests/resources/TransitiveDependencyTest.swift new file mode 100644 index 0000000000..aa98eb03ad --- /dev/null +++ b/test/starlark_tests/resources/TransitiveDependencyTest.swift @@ -0,0 +1,27 @@ +// Copyright 2020 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation +import BasicFramework +import DirectDependencyTest +public class TransitiveDependencyTest { + public init() {} + public func TransitiveDependencyTest() { + print("TransitiveDependencyTest") + let framework = BasicFramework() + framework.HelloWorld() + let framework2 = DirectDependencyTest() + framework2.directDependencyTest() + } +} diff --git a/test/starlark_tests/resources/Transitives.swift b/test/starlark_tests/resources/Transitives.swift new file mode 100644 index 0000000000..ed52f284d4 --- /dev/null +++ b/test/starlark_tests/resources/Transitives.swift @@ -0,0 +1,37 @@ +// Copyright 2020 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation + +public func dontCallMeShared() { + _ = 0; +} + +public func anotherFunctionShared() { + _ = 0; +} + +public func anticipatedDeadCode() { + _ = 0; +} + +public func doSomethingShared() { + print("Doing something shared") +} + +public class Transitives { + public init() {} + public func doSomethingShared() { print("Something shared from transitives") } + public func doSomethingCommon() { print("Something common from transitives") } +} \ No newline at end of file diff --git a/test/starlark_tests/targets_under_test/ios/BUILD b/test/starlark_tests/targets_under_test/ios/BUILD index 28b9f4a596..0ef0763a56 100644 --- a/test/starlark_tests/targets_under_test/ios/BUILD +++ b/test/starlark_tests/targets_under_test/ios/BUILD @@ -5,12 +5,14 @@ load( "ios_application", "ios_extension", "ios_framework", + "ios_dynamic_framework", "ios_imessage_application", "ios_static_framework", "ios_sticker_pack_extension", "ios_ui_test", "ios_unit_test", ) +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") licenses(["notice"]) @@ -1832,3 +1834,269 @@ ios_unit_test( ":test_lib", ], ) + +swift_library( + name = "basic_framework_lib", + module_name = "BasicFramework", + srcs = [ + "//test/starlark_tests/resources:BasicFramework.swift", + ], + visibility = ["//visibility:public"], +) + +ios_dynamic_framework( + name = "basic_framework", + bundle_name = "BasicFramework", + bundle_id = "com.google.example.framework", + families = [ + "iphone", + "ipad", + ], + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "8.0", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_lib", + ], +) + +swift_library( + name = "basic_framework_with_direct_dependency_lib", + module_name = "DirectDependencyTest", + srcs = [ + "//test/starlark_tests/resources:DirectDependencyTest.swift", + ], + visibility = ["//visibility:public"], + deps = [ + ":basic_framework", + ], +) + +ios_dynamic_framework( + name = "basic_framework_with_direct_dependency", + bundle_name = "DirectDependencyTest", + bundle_id = "com.google.example.framework", + families = [ + "iphone", + "ipad", + ], + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "8.0", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_with_direct_dependency_lib", + ], +) + +swift_library( + name = "basic_framework_with_transitive_dependency_lib", + module_name = "TransitiveDependencyTest", + srcs = [ + "//test/starlark_tests/resources:TransitiveDependencyTest.swift", + ], + visibility = ["//visibility:public"], + deps = [ + ":basic_framework", + ":basic_framework_with_direct_dependency", + ], +) + +ios_dynamic_framework( + name = "basic_framework_with_transitive_dependency", + bundle_name = "TransitiveDependencyTest", + bundle_id = "com.google.example.framework", + families = [ + "iphone", + "ipad", + ], + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "8.0", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_with_transitive_dependency_lib", + ], +) + +ios_dynamic_framework( + name = "dynamic_framework_with_resources", + bundle_name = "swift_lib_with_resources", + bundle_id = "com.google.example.framework", + families = [ + "iphone", + "ipad", + ], + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + linkopts = ["-application_extension"], + minimum_os_version = "8.0", + tags = [ + "manual", + "notap", + ], + deps = [ + "//test/starlark_tests/resources:swift_lib_with_resources", + ], +) + +ios_application( + name = "app_with_dynamic_framework_and_resources", + bundle_id = "com.google.example", + families = ["iphone"], + frameworks = [ + ":dynamic_framework_with_resources", + ], + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "11.0", + provisioning_profile = "//test/testdata/provisioning:integration_testing_ios.mobileprovision", + tags = [ + "manual", + "notap", + ], + deps = [ + "//test/starlark_tests/resources:swift_lib_with_resources", + "//test/starlark_tests/resources:objc_main_lib", + ], +) + +ios_dynamic_framework( + name = "swift_common_lib_framework", + bundle_name = "swift_common_lib", + bundle_id = "com.google.example.framework", + families = [ + "iphone", + "ipad", + ], + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "8.0", + tags = [ + "manual", + "notap", + ], + deps = ["//test/starlark_tests/resources:swift_common_lib"] +) + +ios_dynamic_framework( + name = "swift_shared_lib_framework", + bundle_name = "swift_shared_lib", + bundle_id = "com.google.example.framework", + families = [ + "iphone", + "ipad", + ], + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "8.0", + tags = [ + "manual", + "notap", + ], + deps = [ + "//test/starlark_tests/resources:swift_shared_lib", + "//test/starlark_tests/resources:framework_resources_lib", + ] +) + +ios_dynamic_framework( + name = "swift_transitive_lib_framework", + bundle_name = "swift_transitive_lib", + frameworks = [":swift_shared_lib_framework"], + bundle_id = "com.google.example.framework", + families = [ + "iphone", + "ipad", + ], + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "8.0", + tags = [ + "manual", + "notap", + ], + deps = ["//test/starlark_tests/resources:swift_transitive_lib"] +) + +ios_application( + name = "app_with_dynamic_framework_with_dynamic_framework", + bundle_id = "com.google.example", + families = [ + "iphone", + "ipad", + ], + frameworks = [":swift_transitive_lib_framework"], + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "8.0", + tags = [ + "manual", + "notap", + ], + deps = [ + "//test/starlark_tests/resources:ios_non_localized_assets_lib", + "//test/starlark_tests/resources:objc_main_lib", + ], +) + +ios_dynamic_framework( + name = "dynamic_fmwk_with_imported_fmwk", + bundle_id = "com.google.example.framework", + families = [ + "iphone", + "ipad", + ], + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "8.0", + tags = [ + "manual", + "notap", + ], + deps = [ + "//test/starlark_tests/resources:objc_lib_with_resources", + "//test/testdata/frameworks:iOSImportedDynamicFramework", + ], +) + +ios_application( + name = "app_with_inner_and_outer_dynamic_framework", + bundle_id = "com.google.example", + families = ["iphone"], + frameworks = [ + ":dynamic_fmwk_with_imported_fmwk", + ], + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "11.0", + provisioning_profile = "//test/testdata/provisioning:integration_testing_ios.mobileprovision", + tags = [ + "manual", + "notap", + ], + deps = [ + "//test/starlark_tests/resources:objc_main_lib", + ], +) \ No newline at end of file From eea27e5f3ea09224e8d482600aea7f20e4b74920 Mon Sep 17 00:00:00 2001 From: XRV287 Date: Tue, 29 Sep 2020 16:21:16 -0400 Subject: [PATCH 02/26] Fixing lint issues --- .../aspects/swift_dynamic_framework_aspect.bzl | 9 +++++---- apple/internal/partials/swift_dynamic_framework.bzl | 6 +++--- apple/internal/watchos_rules.bzl | 9 +-------- apple/watchos.bzl | 5 +---- test/starlark_tests/ios_dynamic_framework_tests.bzl | 11 +++++++---- test/starlark_tests/resources/BUILD | 1 - 6 files changed, 17 insertions(+), 24 deletions(-) diff --git a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl index 84ee5159ad..f329e4a9e1 100644 --- a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl +++ b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl @@ -91,6 +91,7 @@ def _swift_dynamic_framework_aspect_impl(target, ctx): generated_header = None swiftdocs = {} swiftmodules = {} + modulemap_file = None for dep in swiftdeps: swiftinfo = dep[SwiftInfo] @@ -107,18 +108,18 @@ def _swift_dynamic_framework_aspect_impl(target, ctx): swiftdocs[arch] = swiftinfo.transitive_swiftdocs.to_list().pop() swiftmodules[arch] = swiftinfo.transitive_swiftmodules.to_list().pop() - modulemapFile = ctx.actions.declare_file("{}File.modulemap".format(module_name)) - ctx.actions.write(modulemapFile, _modulemap_contents(module_name)) + modulemap_file = ctx.actions.declare_file("{}File.modulemap".format(module_name)) + ctx.actions.write(modulemap_file, _modulemap_contents(module_name)) # Make sure that all dictionaries contain at least one module before returning the provider. - if all([module_name, generated_header, swiftdocs, swiftmodules, modulemapFile]): + if all([module_name, generated_header, swiftdocs, swiftmodules, modulemap_file]): return [ SwiftDynamicFrameworkInfo( module_name = module_name, generated_header = generated_header, swiftdocs = swiftdocs, swiftmodules = swiftmodules, - modulemap = modulemapFile, + modulemap = modulemap_file, ), ] else: diff --git a/apple/internal/partials/swift_dynamic_framework.bzl b/apple/internal/partials/swift_dynamic_framework.bzl index 1af1e585c7..c8e7915a66 100644 --- a/apple/internal/partials/swift_dynamic_framework.bzl +++ b/apple/internal/partials/swift_dynamic_framework.bzl @@ -60,7 +60,7 @@ frameworks expect a single swift_library dependency with `module_name` set to th generated_header = swift_dynamic_framework_info.generated_header swiftdocs = swift_dynamic_framework_info.swiftdocs swiftmodules = swift_dynamic_framework_info.swiftmodules - modulemapFile = swift_dynamic_framework_info.modulemap + modulemap_file = swift_dynamic_framework_info.modulemap bundle_files = [] modules_parent = paths.join("Modules", "{}.swiftmodule".format(expected_module_name)) @@ -84,9 +84,9 @@ frameworks expect a single swift_library dependency with `module_name` set to th ctx.actions.symlink(target_file = generated_header, output = bundle_header) bundle_files.append((processor.location.bundle, "Headers", depset([bundle_header]))) - if modulemapFile: + if modulemap_file: modulemap = intermediates.file(ctx.actions, ctx.label.name, "module.modulemap") - ctx.actions.symlink(target_file = modulemapFile, output = modulemap) + ctx.actions.symlink(target_file = modulemap_file, output = modulemap) bundle_files.append((processor.location.bundle, "Modules", depset([modulemap]))) providers = [] diff --git a/apple/internal/watchos_rules.bzl b/apple/internal/watchos_rules.bzl index 5db5320a26..17fe23ae04 100644 --- a/apple/internal/watchos_rules.bzl +++ b/apple/internal/watchos_rules.bzl @@ -62,19 +62,12 @@ load( "@build_bazel_rules_apple//apple:providers.bzl", "WatchosApplicationBundleInfo", "WatchosExtensionBundleInfo", -) -load( - "@build_bazel_rules_apple//apple/internal:bundling_support.bzl", - "bundling_support", + "IosFrameworkBundleInfo", ) load( "@build_bazel_rules_apple//apple/internal/aspects:swift_dynamic_framework_aspect.bzl", "SwiftDynamicFrameworkInfo", ) -load( - "@build_bazel_rules_apple//apple:providers.bzl", - "IosFrameworkBundleInfo", -) def _watchos_dynamic_framework_impl(ctx): """Experimental implementation of watchos_dynamic_framework.""" diff --git a/apple/watchos.bzl b/apple/watchos.bzl index d8a18e2904..310453ea18 100644 --- a/apple/watchos.bzl +++ b/apple/watchos.bzl @@ -26,10 +26,6 @@ load( "@build_bazel_rules_apple//apple/internal:binary_support.bzl", "binary_support", ) -load( - "@build_bazel_rules_apple//apple/internal:watchos_rules.bzl", - _watchos_dynamic_framework = "watchos_dynamic_framework", -) load( "@build_bazel_rules_apple//apple/internal:apple_product_type.bzl", "apple_product_type", @@ -41,6 +37,7 @@ load( "@build_bazel_rules_apple//apple/internal:watchos_rules.bzl", _watchos_application = "watchos_application", _watchos_extension = "watchos_extension", + _watchos_dynamic_framework = "watchos_dynamic_framework", ) def watchos_application(name, **kwargs): diff --git a/test/starlark_tests/ios_dynamic_framework_tests.bzl b/test/starlark_tests/ios_dynamic_framework_tests.bzl index 9fa133fd35..974aeeb45e 100644 --- a/test/starlark_tests/ios_dynamic_framework_tests.bzl +++ b/test/starlark_tests/ios_dynamic_framework_tests.bzl @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""ios_framework Starlark tests.""" +"""ios_dynamic_framework Starlark tests.""" load( ":rules/common_verification_tests.bzl", @@ -23,9 +23,12 @@ load( "infoplist_contents_test", ) -def ios_dynamic_framework_test_suite(): - """Test suite for ios_framework.""" - name = "ios_dynamic_framework" +def ios_dynamic_framework_test_suite(name = "ios_dynamic_framework"): + """Test suite for ios_dynamic_framework. + + Args: + name: The name prefix for all the nested tests + """ archive_contents_test( name = "{}_archive_contents_test".format(name), diff --git a/test/starlark_tests/resources/BUILD b/test/starlark_tests/resources/BUILD index 74f9d79f1d..d5b3a2be85 100644 --- a/test/starlark_tests/resources/BUILD +++ b/test/starlark_tests/resources/BUILD @@ -1,4 +1,3 @@ -test/starlark_tests/resources/BUILD load("@rules_cc//cc:defs.bzl", "objc_library") load( "//apple:resources.bzl", From 94cb2296992ff3508198f78f632e9dc939aca4ad Mon Sep 17 00:00:00 2001 From: XRV287 Date: Tue, 29 Sep 2020 16:52:38 -0400 Subject: [PATCH 03/26] Fixing one more linting issues --- apple/watchos.bzl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apple/watchos.bzl b/apple/watchos.bzl index 310453ea18..a6e04ac853 100644 --- a/apple/watchos.bzl +++ b/apple/watchos.bzl @@ -26,10 +26,6 @@ load( "@build_bazel_rules_apple//apple/internal:binary_support.bzl", "binary_support", ) -load( - "@build_bazel_rules_apple//apple/internal:apple_product_type.bzl", - "apple_product_type", -) # Alias the internal rules when we load them. This lets the rules keep their # original name in queries and logs since they collide with the wrapper macros. From 5a0c5a73c0ab2b76edd683109a184566017de3be Mon Sep 17 00:00:00 2001 From: XRV287 Date: Thu, 8 Oct 2020 11:58:33 -0400 Subject: [PATCH 04/26] Made updates to account for rules_swift generating a modulemap file and cleaned up some unneeded code --- .../swift_dynamic_framework_aspect.bzl | 10 ++-- apple/internal/ios_rules.bzl | 52 +++++-------------- .../partials/swift_dynamic_framework.bzl | 16 ------ test/starlark_tests/resources/BUILD | 5 ++ .../targets_under_test/ios/BUILD | 3 ++ 5 files changed, 27 insertions(+), 59 deletions(-) diff --git a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl index f329e4a9e1..d675c2296d 100644 --- a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl +++ b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl @@ -81,7 +81,7 @@ def _swift_dynamic_framework_aspect_impl(target, ctx): """Aspect implementation for Swift dynamic framework support.""" swiftdeps = [x for x in ctx.rule.attr.deps if SwiftInfo in x] - + ccinfos = [x for x in ctx.rule.attr.deps if CcInfo in x] # If there are no Swift dependencies, return nothing. if not swiftdeps: return [] @@ -107,10 +107,14 @@ def _swift_dynamic_framework_aspect_impl(target, ctx): swiftdocs[arch] = swiftinfo.transitive_swiftdocs.to_list().pop() swiftmodules[arch] = swiftinfo.transitive_swiftmodules.to_list().pop() - - modulemap_file = ctx.actions.declare_file("{}File.modulemap".format(module_name)) + modulemap_file = ctx.actions.declare_file("{}_file.modulemap".format(module_name)) ctx.actions.write(modulemap_file, _modulemap_contents(module_name)) + for dep in ccinfos: + headers = dep[CcInfo].compilation_context.headers.to_list() + if headers: + generated_header = headers.pop(0) + # Make sure that all dictionaries contain at least one module before returning the provider. if all([module_name, generated_header, swiftdocs, swiftmodules, modulemap_file]): return [ diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index 828dc1ea58..62694fed71 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -679,57 +679,29 @@ def _ios_dynamic_framework_impl(ctx): processor_result = processor.process(ctx, processor_partials) providers = processor_result.providers - framework_dir = depset() + #=========================================================================================================== + # TODO: Create the objc_provider in a partial, OR just do it here like so (feels hacky) + # In order for swift_dynamic_framework to be used as a dependency of swift_library, + # It needs to pass an objc_provider with a reference to the dynamic_framework_file. + # During the swift_dynamic_framework partial, we don't have access to that file, since it is processed + # in the framework_provider_partial and returned in the AppleDynamicFramework provider + # This feels like the wrong place to do this logic, but it's the only place we had access to all the data + #=========================================================================================================== framework_files = depset() - desired_path = "" for provider in providers: if type(provider) == "AppleDynamicFramework": - framework_dir = provider.framework_dirs framework_files = provider.framework_files - full_path = framework_dir.to_list()[0] - path_parts = full_path.split("/") - for part in path_parts: - if part != path_parts[len(path_parts)-1]: - desired_path = desired_path + part + "/" - else: - desired_path = desired_path[0:len(desired_path)-1] - desired_framework_dir = depset([desired_path]) - #=========================================================================================================== - # TODO: Create the complete CcInfo in a partial, OR just do it here like so (feels hacky) - # As of right now we have a parital CcInfo being created in the dynamic_framework_partial - # But we need the framework_dir from the AppleDynamicFramework returned by the framework_provider_partial - # To be included so the transitive dependencies will work properly - # This feels like the wrong place to do this logic, but it's the only place we had access to all the data - #=========================================================================================================== - - # Make the ObjC provider objc_provider_fields = {} objc_provider_fields["dynamic_framework_file"] = framework_files objc_provider = apple_common.new_objc_provider(**objc_provider_fields) - # Add everything but CcInfo provider so we can make a new one - new_providers = [] - for provider in providers: - if type(provider) != "CcInfo": - new_providers.append(provider) - else: - cc_info = CcInfo( - compilation_context = cc_common.create_compilation_context( - headers = provider.compilation_context.headers, - framework_includes = desired_framework_dir, - ), - ) - new_providers.append(cc_info) - - new_providers.append(objc_provider) - - providers = [ + providers.append(objc_provider) + + return [ DefaultInfo(files = processor_result.output_files), IosFrameworkBundleInfo(), - ] + new_providers - - return providers + ] + providers def _ios_static_framework_impl(ctx): """Experimental implementation of ios_static_framework.""" diff --git a/apple/internal/partials/swift_dynamic_framework.bzl b/apple/internal/partials/swift_dynamic_framework.bzl index c8e7915a66..c58fc254d1 100644 --- a/apple/internal/partials/swift_dynamic_framework.bzl +++ b/apple/internal/partials/swift_dynamic_framework.bzl @@ -89,24 +89,8 @@ frameworks expect a single swift_library dependency with `module_name` set to th ctx.actions.symlink(target_file = modulemap_file, output = modulemap) bundle_files.append((processor.location.bundle, "Modules", depset([modulemap]))) - providers = [] - all_files = [] - for bundle, path, files in bundle_files: - all_files += files.to_list() - - header_imports = _get_header_imports(all_files) - - cc_info_provider = CcInfo( - compilation_context = cc_common.create_compilation_context( - headers = depset(header_imports), - ), - ) - - providers.append(cc_info_provider) - return struct( bundle_files = bundle_files, - providers = providers ) def swift_dynamic_framework_partial(swift_dynamic_framework_info): diff --git a/test/starlark_tests/resources/BUILD b/test/starlark_tests/resources/BUILD index d5b3a2be85..7164983e8c 100644 --- a/test/starlark_tests/resources/BUILD +++ b/test/starlark_tests/resources/BUILD @@ -80,6 +80,7 @@ swift_library( ":structured_resources", ], testonly = True, + features = ["swift.no_generated_module_map"], ) swift_library( @@ -87,6 +88,7 @@ swift_library( module_name = "swift_common_lib", srcs = ["Common.swift"], testonly = True, + features = ["swift.no_generated_module_map"], ) swift_library( @@ -97,6 +99,7 @@ swift_library( "//test/starlark_tests/targets_under_test/ios:swift_common_lib_framework", ], testonly = True, + features = ["swift.no_generated_module_map"], ) swift_library( @@ -108,6 +111,7 @@ swift_library( "//test/starlark_tests/targets_under_test/ios:swift_shared_lib_framework", ], testonly = True, + features = ["swift.no_generated_module_map"], ) swift_library( @@ -119,6 +123,7 @@ swift_library( "//test/starlark_tests/targets_under_test/ios:swift_shared_lib_framework", ], testonly = True, + features = ["swift.no_generated_module_map"], ) swift_library( diff --git a/test/starlark_tests/targets_under_test/ios/BUILD b/test/starlark_tests/targets_under_test/ios/BUILD index 0ef0763a56..361c793371 100644 --- a/test/starlark_tests/targets_under_test/ios/BUILD +++ b/test/starlark_tests/targets_under_test/ios/BUILD @@ -1842,6 +1842,7 @@ swift_library( "//test/starlark_tests/resources:BasicFramework.swift", ], visibility = ["//visibility:public"], + features = ["swift.no_generated_module_map"], ) ios_dynamic_framework( @@ -1875,6 +1876,7 @@ swift_library( deps = [ ":basic_framework", ], + features = ["swift.no_generated_module_map"], ) ios_dynamic_framework( @@ -1909,6 +1911,7 @@ swift_library( ":basic_framework", ":basic_framework_with_direct_dependency", ], + features = ["swift.no_generated_module_map"], ) ios_dynamic_framework( From 19a0280d9ec4eb827d1ebd7e91e1ab0acfb5e741 Mon Sep 17 00:00:00 2001 From: XRV287 Date: Fri, 9 Oct 2020 14:16:23 -0400 Subject: [PATCH 05/26] Adding manual tags to swift_library and ios_dynamic_framework calls used for testing --- test/starlark_tests/resources/BUILD | 15 +++++++++++++++ test/starlark_tests/targets_under_test/ios/BUILD | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/test/starlark_tests/resources/BUILD b/test/starlark_tests/resources/BUILD index 7164983e8c..3c4a0374c9 100644 --- a/test/starlark_tests/resources/BUILD +++ b/test/starlark_tests/resources/BUILD @@ -81,6 +81,9 @@ swift_library( ], testonly = True, features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], ) swift_library( @@ -89,6 +92,9 @@ swift_library( srcs = ["Common.swift"], testonly = True, features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], ) swift_library( @@ -100,6 +106,9 @@ swift_library( ], testonly = True, features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], ) swift_library( @@ -112,6 +121,9 @@ swift_library( ], testonly = True, features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], ) swift_library( @@ -124,6 +136,9 @@ swift_library( ], testonly = True, features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], ) swift_library( diff --git a/test/starlark_tests/targets_under_test/ios/BUILD b/test/starlark_tests/targets_under_test/ios/BUILD index 361c793371..6a19b53674 100644 --- a/test/starlark_tests/targets_under_test/ios/BUILD +++ b/test/starlark_tests/targets_under_test/ios/BUILD @@ -1843,6 +1843,9 @@ swift_library( ], visibility = ["//visibility:public"], features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], ) ios_dynamic_framework( @@ -1877,6 +1880,9 @@ swift_library( ":basic_framework", ], features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], ) ios_dynamic_framework( @@ -1912,6 +1918,9 @@ swift_library( ":basic_framework_with_direct_dependency", ], features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], ) ios_dynamic_framework( From 3b6028cb957a5e0d192b55e245635e94a94d8ea9 Mon Sep 17 00:00:00 2001 From: XRV287 Date: Tue, 10 Nov 2020 15:22:30 -0500 Subject: [PATCH 06/26] Added watchos tests, tvos tests and supports, and macos tests and support --- .../swift_dynamic_framework_aspect.bzl | 3 + apple/internal/macos_rules.bzl | 157 ++++++++++++++ apple/internal/rule_support.bzl | 16 ++ apple/internal/tvos_rules.bzl | 176 ++++++++++++++- apple/internal/watchos_rules.bzl | 201 ++++++++++++------ apple/macos.bzl | 30 +++ apple/tvos.bzl | 30 +++ apple/watchos.bzl | 22 +- test/starlark_tests/BUILD | 9 + .../ios_dynamic_framework_tests.bzl | 1 - .../macos_dynamic_framework_tests.bzl | 111 ++++++++++ test/starlark_tests/resources/BUILD | 6 +- .../resources/Info-watchos.plist | 16 ++ test/starlark_tests/resources/main.swift | 19 ++ .../targets_under_test/ios/BUILD | 7 +- .../targets_under_test/macos/BUILD | 101 +++++++++ .../targets_under_test/tvos/BUILD | 100 +++++++++ .../targets_under_test/watchos/BUILD | 103 +++++++++ .../tvos_dynamic_framework_tests.bzl | 113 ++++++++++ .../watchos_dynamic_framework_tests.bzl | 88 ++++++++ 20 files changed, 1222 insertions(+), 87 deletions(-) create mode 100644 test/starlark_tests/macos_dynamic_framework_tests.bzl create mode 100644 test/starlark_tests/resources/Info-watchos.plist create mode 100644 test/starlark_tests/resources/main.swift create mode 100644 test/starlark_tests/tvos_dynamic_framework_tests.bzl create mode 100644 test/starlark_tests/watchos_dynamic_framework_tests.bzl diff --git a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl index 2089d26f78..07620337b6 100644 --- a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl +++ b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl @@ -79,6 +79,9 @@ framework module {module_name} {{ def _swift_dynamic_framework_aspect_impl(target, ctx): """Aspect implementation for Swift dynamic framework support.""" + if not hasattr(ctx.rule.attr, "deps"): + return [] + swiftdeps = [x for x in ctx.rule.attr.deps if SwiftInfo in x] ccinfos = [x for x in ctx.rule.attr.deps if CcInfo in x] # If there are no Swift dependencies, return nothing. diff --git a/apple/internal/macos_rules.bzl b/apple/internal/macos_rules.bzl index 050b220b13..47e944b26e 100644 --- a/apple/internal/macos_rules.bzl +++ b/apple/internal/macos_rules.bzl @@ -14,6 +14,10 @@ """Implementation of macOS rules.""" +load( + "@build_bazel_rules_apple//apple/internal/aspects:swift_dynamic_framework_aspect.bzl", + "SwiftDynamicFrameworkInfo", +) load( "@build_bazel_rules_apple//apple/internal:apple_product_type.bzl", "apple_product_type", @@ -1282,6 +1286,152 @@ def _macos_dylib_impl(ctx): link_result.binary_provider, ] + processor_result.providers +def _macos_dynamic_framework_impl(ctx): + """Experimental implementation of macos_framework.""" + depsList = [deps for deps in ctx.attr.deps] + binary_target = depsList.pop() + link_result = linking_support.register_linking_action(ctx) + binary_artifact = link_result.binary_provider.binary + debug_outputs_provider = link_result.debug_outputs_provider + + actions = ctx.actions + bin_root_path = ctx.bin_dir.path + bundle_id = ctx.attr.bundle_id + bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) + executable_name = bundling_support.executable_name(ctx) + entitlements = entitlements_support.entitlements( + entitlements_attr = getattr(ctx.attr, "entitlements", None), + entitlements_file = getattr(ctx.file, "entitlements", None), + ) + features = features_support.compute_enabled_features( + requested_features = ctx.features, + unsupported_features = ctx.disabled_features, + ) + label = ctx.label + platform_prerequisites = platform_support.platform_prerequisites_from_rule_ctx(ctx) + predeclared_outputs = ctx.outputs + rule_descriptor = rule_support.rule_descriptor(ctx) + rule_executables = ctx.executable + + signed_frameworks = [] + if getattr(ctx.file, "provisioning_profile", None): + signed_frameworks = [ + bundle_name + rule_descriptor.bundle_extension, + ] + + archive = outputs.archive( + actions = actions, + bundle_extension = bundle_extension, + bundle_name = bundle_name, + platform_prerequisites = platform_prerequisites, + predeclared_outputs = predeclared_outputs, + ) + + processor_partials = [ + partials.apple_bundle_info_partial( + actions = actions, + bundle_extension = bundle_extension, + bundle_id = bundle_id, + bundle_name = bundle_name, + executable_name = executable_name, + entitlements = entitlements, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + predeclared_outputs = predeclared_outputs, + product_type = rule_descriptor.product_type, + ), + partials.binary_partial( + actions = actions, + binary_artifact = binary_artifact, + executable_name = executable_name, + label_name = label.name, + ), + partials.clang_rt_dylibs_partial( + actions = actions, + binary_artifact = binary_artifact, + clangrttool = ctx.executable._clangrttool, + features = features, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + ), + partials.debug_symbols_partial( + actions = actions, + bin_root_path = bin_root_path, + bundle_extension = bundle_extension, + bundle_name = bundle_name, + debug_outputs_provider = debug_outputs_provider, + dsym_info_plist_template = ctx.file._dsym_info_plist_template, + executable_name = executable_name, + platform_prerequisites = platform_prerequisites, + rule_label = label, + ), + partials.embedded_bundles_partial( + frameworks = [archive], + platform_prerequisites = platform_prerequisites, + signed_frameworks = depset(signed_frameworks), + ), + partials.framework_provider_partial( + actions = actions, + bin_root_path = bin_root_path, + binary_provider = link_result.binary_provider, + bundle_name = bundle_name, + rule_label = label, + ), + partials.resources_partial( + actions = actions, + bundle_extension = bundle_extension, + bundle_id = bundle_id, + bundle_name = bundle_name, + environment_plist = ctx.file._environment_plist, + executable_name = executable_name, + launch_storyboard = None, + platform_prerequisites = platform_prerequisites, + plist_attrs = ["infoplists"], + rule_attrs = ctx.attr, + rule_descriptor = rule_descriptor, + rule_executables = rule_executables, + rule_label = label, + top_level_attrs = ["resources"], + version_keys_required = False, + ), + partials.swift_dylibs_partial( + actions = actions, + binary_artifact = binary_artifact, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + swift_stdlib_tool = ctx.executable._swift_stdlib_tool, + ), + partials.swift_dynamic_framework_partial( + swift_dynamic_framework_info = binary_target[SwiftDynamicFrameworkInfo], + ), + ] + + processor_result = processor.process( + ctx = ctx, + actions = actions, + bundle_extension = bundle_extension, + bundle_name = bundle_name, + entitlements = entitlements, + executable_name = executable_name, + partials = processor_partials, + platform_prerequisites = platform_prerequisites, + predeclared_outputs = predeclared_outputs, + provisioning_profile = getattr(ctx.file, "provisioning_profile", None), + rule_descriptor = rule_descriptor, + rule_executables = rule_executables, + rule_label = label, + ) + + return [ + DefaultInfo(files = processor_result.output_files), + OutputGroupInfo( + **outputs.merge_output_groups( + link_result.output_groups, + processor_result.output_groups, + ) + ), + ] + processor_result.providers + macos_application = rule_factory.create_apple_bundling_rule( implementation = _macos_application_impl, platform_type = "macos", @@ -1296,6 +1446,13 @@ macos_bundle = rule_factory.create_apple_bundling_rule( doc = "Builds and bundles a macOS Loadable Bundle.", ) +macos_dynamic_framework = rule_factory.create_apple_bundling_rule( + implementation = _macos_dynamic_framework_impl, + platform_type = "macos", + product_type = apple_product_type.framework, + doc = "Builds and bundles a macos dynamic framework.", +) + macos_extension = rule_factory.create_apple_bundling_rule( implementation = _macos_extension_impl, platform_type = "macos", diff --git a/apple/internal/rule_support.bzl b/apple/internal/rule_support.bzl index ebdc543690..7b0eea109e 100644 --- a/apple/internal/rule_support.bzl +++ b/apple/internal/rule_support.bzl @@ -467,6 +467,22 @@ _RULE_TYPE_DESCRIPTORS = { "@executable_path/../../../../Frameworks", ], ), + # macos_framework + apple_product_type.framework: _describe_rule_type( + allowed_device_families = ["mac"], + bundle_extension = ".framework", + bundle_package_type = bundle_package_type.framework, + binary_type = "dylib", + codesigning_exceptions = _CODESIGNING_EXCEPTIONS.sign_with_provisioning_profile, + deps_cfg = apple_common.multi_arch_split, + product_type = apple_product_type.framework, + rpaths = [ + # Framework binaries live in + # Application.app/Frameworks/Framework.framework/Framework + # Frameworks are packaged in Application.app/Frameworks + "@executable_path/Frameworks", + ], + ), # macos_quick_look_plugin apple_product_type.quicklook_plugin: _describe_rule_type( allowed_device_families = ["mac"], diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index 8e579e28f9..c63d731ee1 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -14,6 +14,10 @@ """Implementation of tvOS rules.""" +load( + "@build_bazel_rules_apple//apple/internal/aspects:swift_dynamic_framework_aspect.bzl", + "SwiftDynamicFrameworkInfo", +) load( "@build_bazel_rules_apple//apple/internal:apple_product_type.bzl", "apple_product_type", @@ -279,6 +283,171 @@ def _tvos_application_impl(ctx): link_result.binary_provider, ] + processor_result.providers +def _tvos_dynamic_framework_impl(ctx): + """Experimental implementation of tvos_framework.""" + depsList = [deps for deps in ctx.attr.deps] + binary_target = depsList.pop() + link_result = linking_support.register_linking_action(ctx) + binary_artifact = link_result.binary_provider.binary + debug_outputs_provider = link_result.debug_outputs_provider + + actions = ctx.actions + bin_root_path = ctx.bin_dir.path + bundle_id = ctx.attr.bundle_id + bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) + executable_name = bundling_support.executable_name(ctx) + entitlements = entitlements_support.entitlements( + entitlements_attr = getattr(ctx.attr, "entitlements", None), + entitlements_file = getattr(ctx.file, "entitlements", None), + ) + features = features_support.compute_enabled_features( + requested_features = ctx.features, + unsupported_features = ctx.disabled_features, + ) + label = ctx.label + platform_prerequisites = platform_support.platform_prerequisites_from_rule_ctx(ctx) + predeclared_outputs = ctx.outputs + rule_descriptor = rule_support.rule_descriptor(ctx) + rule_executables = ctx.executable + + signed_frameworks = [] + if getattr(ctx.file, "provisioning_profile", None): + signed_frameworks = [ + bundle_name + rule_descriptor.bundle_extension, + ] + + archive = outputs.archive( + actions = actions, + bundle_extension = bundle_extension, + bundle_name = bundle_name, + platform_prerequisites = platform_prerequisites, + predeclared_outputs = predeclared_outputs, + ) + + processor_partials = [ + partials.apple_bundle_info_partial( + actions = actions, + bundle_extension = bundle_extension, + bundle_id = bundle_id, + bundle_name = bundle_name, + executable_name = executable_name, + entitlements = entitlements, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + predeclared_outputs = predeclared_outputs, + product_type = rule_descriptor.product_type, + ), + partials.binary_partial( + actions = actions, + binary_artifact = binary_artifact, + executable_name = executable_name, + label_name = label.name, + ), + partials.bitcode_symbols_partial( + actions = actions, + binary_artifact = binary_artifact, + debug_outputs_provider = debug_outputs_provider, + dependency_targets = ctx.attr.frameworks, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + ), + partials.clang_rt_dylibs_partial( + actions = actions, + binary_artifact = binary_artifact, + clangrttool = ctx.executable._clangrttool, + features = features, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + ), + partials.debug_symbols_partial( + actions = actions, + bin_root_path = bin_root_path, + bundle_extension = bundle_extension, + bundle_name = bundle_name, + debug_dependencies = ctx.attr.frameworks, + debug_outputs_provider = debug_outputs_provider, + dsym_info_plist_template = ctx.file._dsym_info_plist_template, + executable_name = executable_name, + platform_prerequisites = platform_prerequisites, + rule_label = label, + ), + partials.embedded_bundles_partial( + frameworks = [archive], + embeddable_targets = ctx.attr.frameworks, + platform_prerequisites = platform_prerequisites, + signed_frameworks = depset(signed_frameworks), + ), + partials.extension_safe_validation_partial( + is_extension_safe = ctx.attr.extension_safe, + rule_label = label, + targets_to_validate = ctx.attr.frameworks, + ), + partials.framework_headers_partial(hdrs = ctx.files.hdrs), + partials.framework_provider_partial( + actions = actions, + bin_root_path = bin_root_path, + binary_provider = link_result.binary_provider, + bundle_name = bundle_name, + rule_label = label, + ), + partials.resources_partial( + actions = actions, + bundle_extension = bundle_extension, + bundle_id = bundle_id, + bundle_name = bundle_name, + environment_plist = ctx.file._environment_plist, + executable_name = executable_name, + launch_storyboard = None, + platform_prerequisites = platform_prerequisites, + plist_attrs = ["infoplists"], + rule_attrs = ctx.attr, + rule_descriptor = rule_descriptor, + rule_executables = rule_executables, + rule_label = label, + targets_to_avoid = ctx.attr.frameworks, + top_level_attrs = ["resources"], + version_keys_required = False, + ), + partials.swift_dylibs_partial( + actions = actions, + binary_artifact = binary_artifact, + dependency_targets = ctx.attr.frameworks, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + swift_stdlib_tool = ctx.executable._swift_stdlib_tool, + ), + partials.swift_dynamic_framework_partial( + swift_dynamic_framework_info = binary_target[SwiftDynamicFrameworkInfo], + ), + ] + + processor_result = processor.process( + ctx = ctx, + actions = actions, + bundle_extension = bundle_extension, + bundle_name = bundle_name, + entitlements = entitlements, + executable_name = executable_name, + partials = processor_partials, + platform_prerequisites = platform_prerequisites, + predeclared_outputs = predeclared_outputs, + provisioning_profile = getattr(ctx.file, "provisioning_profile", None), + rule_descriptor = rule_descriptor, + rule_executables = rule_executables, + rule_label = label, + ) + + return [ + DefaultInfo(files = processor_result.output_files), + OutputGroupInfo( + **outputs.merge_output_groups( + link_result.output_groups, + processor_result.output_groups, + ) + ), + TvosFrameworkBundleInfo(), + ] + processor_result.providers + def _tvos_framework_impl(ctx): """Experimental implementation of tvos_framework.""" link_result = linking_support.register_linking_action(ctx) @@ -712,7 +881,12 @@ tvos_application = rule_factory.create_apple_bundling_rule( product_type = apple_product_type.application, doc = "Builds and bundles a tvOS Application.", ) - +tvos_dynamic_framework = rule_factory.create_apple_bundling_rule( + implementation = _tvos_dynamic_framework_impl, + platform_type = "tvos", + product_type = apple_product_type.framework, + doc = "Builds and bundles a tvOS dynamic framework.", +) tvos_extension = rule_factory.create_apple_bundling_rule( implementation = _tvos_extension_impl, platform_type = "tvos", diff --git a/apple/internal/watchos_rules.bzl b/apple/internal/watchos_rules.bzl index cd37997e9c..9d82583fab 100644 --- a/apple/internal/watchos_rules.bzl +++ b/apple/internal/watchos_rules.bzl @@ -79,109 +79,180 @@ load( def _watchos_dynamic_framework_impl(ctx): """Experimental implementation of watchos_dynamic_framework.""" - platform_prerequisites = platform_support.platform_prerequisites_from_rule_ctx(ctx) + depsList = [deps for deps in ctx.attr.deps] + binary_target = depsList.pop() + extra_linkopts = [] + if ctx.attr.extension_safe: + extra_linkopts.append("-fapplication-extension") - binary_target = ctx.attr.deps[0] - binary_artifact = binary_target[apple_common.AppleDylibBinary].binary + link_result = linking_support.register_linking_action( + ctx, + extra_linkopts = extra_linkopts, + ) + binary_artifact = link_result.binary_provider.binary + debug_outputs_provider = link_result.debug_outputs_provider + actions = ctx.actions + bin_root_path = ctx.bin_dir.path bundle_id = ctx.attr.bundle_id + bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) + executable_name = bundling_support.executable_name(ctx) + entitlements = entitlements_support.entitlements( + entitlements_attr = getattr(ctx.attr, "entitlements", None), + entitlements_file = getattr(ctx.file, "entitlements", None), + ) + features = features_support.compute_enabled_features( + requested_features = ctx.features, + unsupported_features = ctx.disabled_features, + ) + label = ctx.label + platform_prerequisites = platform_support.platform_prerequisites_from_rule_ctx(ctx) + predeclared_outputs = ctx.outputs + rule_descriptor = rule_support.rule_descriptor(ctx) + rule_executables = ctx.executable signed_frameworks = [] if getattr(ctx.file, "provisioning_profile", None): - rule_descriptor = rule_support.rule_descriptor(ctx) signed_frameworks = [ - bundling_support.bundle_name(ctx) + rule_descriptor.bundle_extension, + bundle_name + rule_descriptor.bundle_extension, ] - - dynamic_framework_partial = partials.swift_dynamic_framework_partial( - swift_dynamic_framework_info = binary_target[SwiftDynamicFrameworkInfo], - ) + + archive_for_embedding = outputs.archive_for_embedding( + actions = actions, + bundle_name = bundle_name, + bundle_extension = bundle_extension, + executable_name = executable_name, + label_name = label.name, + rule_descriptor = rule_descriptor, + platform_prerequisites = platform_prerequisites, + predeclared_outputs = predeclared_outputs, + ) + processor_partials = [ - partials.apple_bundle_info_partial(bundle_id = bundle_id), - partials.binary_partial(binary_artifact = binary_artifact), + partials.apple_bundle_info_partial( + actions = actions, + bundle_extension = bundle_extension, + bundle_id = bundle_id, + bundle_name = bundle_name, + executable_name = executable_name, + entitlements = entitlements, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + predeclared_outputs = predeclared_outputs, + product_type = rule_descriptor.product_type, + ), + partials.binary_partial( + actions = actions, + binary_artifact = binary_artifact, + executable_name = executable_name, + label_name = label.name, + ), partials.bitcode_symbols_partial( - actions = ctx.actions, + actions = actions, binary_artifact = binary_artifact, - debug_outputs_provider = binary_target[apple_common.AppleDebugOutputs], - label_name = ctx.label.name, - platform_prerequisites = platform_prerequisites, + debug_outputs_provider = debug_outputs_provider, dependency_targets = ctx.attr.frameworks, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + ), + partials.clang_rt_dylibs_partial( + actions = actions, + binary_artifact = binary_artifact, + clangrttool = ctx.executable._clangrttool, + features = features, + label_name = label.name, + platform_prerequisites = platform_prerequisites, ), - # TODO: Check if clang_rt dylibs are needed in Frameworks, or if - # the can be skipped. - partials.clang_rt_dylibs_partial(binary_artifact = binary_artifact), partials.debug_symbols_partial( + actions = actions, + bin_root_path = bin_root_path, + bundle_extension = bundle_extension, + bundle_name = bundle_name, debug_dependencies = ctx.attr.frameworks, - debug_outputs_provider = binary_target[apple_common.AppleDebugOutputs], + debug_outputs_provider = debug_outputs_provider, + dsym_info_plist_template = ctx.file._dsym_info_plist_template, + executable_name = executable_name, + platform_prerequisites = platform_prerequisites, + rule_label = label, ), partials.embedded_bundles_partial( - frameworks = [outputs.archive(ctx)], + frameworks = [archive_for_embedding], embeddable_targets = ctx.attr.frameworks, + platform_prerequisites = platform_prerequisites, signed_frameworks = depset(signed_frameworks), ), - partials.extension_safe_validation_partial(is_extension_safe = ctx.attr.extension_safe), + partials.extension_safe_validation_partial( + is_extension_safe = ctx.attr.extension_safe, + rule_label = label, + targets_to_validate = ctx.attr.frameworks, + ), + partials.framework_headers_partial(hdrs = ctx.files.hdrs), partials.framework_provider_partial( - binary_provider = binary_target[apple_common.AppleDylibBinary], + actions = actions, + bin_root_path = bin_root_path, + binary_provider = link_result.binary_provider, + bundle_name = bundle_name, + rule_label = label, ), partials.resources_partial( + actions = actions, + bundle_extension = bundle_extension, bundle_id = bundle_id, + bundle_name = bundle_name, + environment_plist = ctx.file._environment_plist, + executable_name = executable_name, + launch_storyboard = None, + platform_prerequisites = platform_prerequisites, plist_attrs = ["infoplists"], + rule_attrs = ctx.attr, + rule_descriptor = rule_descriptor, + rule_executables = rule_executables, + rule_label = label, targets_to_avoid = ctx.attr.frameworks, - version_keys_required = False, top_level_attrs = ["resources"], + version_keys_required = False, ), partials.swift_dylibs_partial( + actions = actions, binary_artifact = binary_artifact, dependency_targets = ctx.attr.frameworks, + label_name = label.name, + platform_prerequisites = platform_prerequisites, + swift_stdlib_tool = ctx.executable._swift_stdlib_tool, + ), + partials.swift_dynamic_framework_partial( + swift_dynamic_framework_info = binary_target[SwiftDynamicFrameworkInfo], ), - dynamic_framework_partial, ] - processor_result = processor.process(ctx, processor_partials) - providers = processor_result.providers - - framework_dir = depset() - framework_files = depset() - for provider in providers: - if type(provider) == "AppleDynamicFramework": - framework_dir = provider.framework_dirs - framework_files = provider.framework_files - - #=========================================================================================================== - # TODO: Create the complete CcInfo in a partial, OR just do it here like so (feels hacky) - # As of right now we have a parital CcInfo being created in the dynamic_framework_partial - # But we need the framework_dir from the AppleDynamicFramework returned by the framework_provider_partial - # To be included so the transitive dependencies will work properly - # This feels like the wrong place to do this logic, but it's the only place we had access to all the data - #=========================================================================================================== - - # Make the ObjC provider - objc_provider_fields = {} - objc_provider_fields["dynamic_framework_file"] = framework_files - objc_provider = apple_common.new_objc_provider(**objc_provider_fields) - - # Add everything but CcInfo provider so we can make a new one - new_providers = [] - for provider in providers: - if type(provider) != "CcInfo": - new_providers.append(provider) - else: - cc_info = CcInfo( - compilation_context = cc_common.create_compilation_context( - headers = provider.compilation_context.headers, - framework_includes = framework_dir, - ), - ) - new_providers.append(cc_info) + processor_result = processor.process( + ctx = ctx, + actions = actions, + bundle_extension = bundle_extension, + bundle_name = bundle_name, + entitlements = entitlements, + executable_name = executable_name, + partials = processor_partials, + platform_prerequisites = platform_prerequisites, + predeclared_outputs = predeclared_outputs, + provisioning_profile = getattr(ctx.file, "provisioning_profile", None), + rule_descriptor = rule_descriptor, + rule_executables = rule_executables, + rule_label = label, + ) - new_providers.append(objc_provider) + providers = processor_result.providers - providers = [ + return [ DefaultInfo(files = processor_result.output_files), IosFrameworkBundleInfo(), - ] + new_providers - - return providers + OutputGroupInfo( + **outputs.merge_output_groups( + link_result.output_groups, + processor_result.output_groups, + ) + ), + ] + providers def _watchos_application_impl(ctx): """Implementation of watchos_application.""" diff --git a/apple/macos.bzl b/apple/macos.bzl index 2f2fd547cc..7e20f80856 100644 --- a/apple/macos.bzl +++ b/apple/macos.bzl @@ -48,6 +48,7 @@ load( _macos_bundle = "macos_bundle", _macos_command_line_application = "macos_command_line_application", _macos_dylib = "macos_dylib", + _macos_dynamic_framework = "macos_dynamic_framework", _macos_extension = "macos_extension", _macos_kernel_extension = "macos_kernel_extension", _macos_quick_look_plugin = "macos_quick_look_plugin", @@ -284,6 +285,35 @@ def macos_dylib(name, **kwargs): **dylib_args ) +def macos_dynamic_framework(name, **kwargs): + # buildifier: disable=function-docstring-args + """Builds and bundles an iOS dynamic framework.""" + binary_args = dict(kwargs) + # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking + # API does not accept extra linkopts and link inputs. With those, it will be possible to merge + # these workarounds into the rule implementations. + linkopts = binary_args.pop("linkopts", []) + bundle_name = binary_args.get("bundle_name", name) + linkopts += ["-install_name", "@rpath/%s.framework/%s" % (bundle_name, bundle_name)] + binary_args["linkopts"] = linkopts + bundling_args = binary_support.add_entitlements_and_swift_linkopts( + name, + include_entitlements = False, + platform_type = str(apple_common.platform_type.macos), + product_type = apple_product_type.framework, + exported_symbols_lists = binary_args.pop("exported_symbols_lists", None), + **binary_args + ) + + # Remove any kwargs that shouldn't be passed to the underlying rule. + bundling_args.pop("entitlements", None) + + _macos_dynamic_framework( + name = name, + extension_safe = kwargs.get("extension_safe"), + **bundling_args + ) + def macos_extension(name, **kwargs): # buildifier: disable=function-docstring-args """Packages a macOS Extension Bundle.""" diff --git a/apple/tvos.bzl b/apple/tvos.bzl index ca21ac200c..0c0fb18b7f 100644 --- a/apple/tvos.bzl +++ b/apple/tvos.bzl @@ -40,6 +40,7 @@ load( load( "@build_bazel_rules_apple//apple/internal:tvos_rules.bzl", _tvos_application = "tvos_application", + _tvos_dynamic_framework = "tvos_dynamic_framework", _tvos_extension = "tvos_extension", _tvos_framework = "tvos_framework", _tvos_static_framework = "tvos_static_framework", @@ -157,6 +158,35 @@ def tvos_ui_test(name, **kwargs): **kwargs ) +def tvos_dynamic_framework(name, **kwargs): + # buildifier: disable=function-docstring-args + """Builds and bundles an iOS dynamic framework.""" + binary_args = dict(kwargs) + # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking + # API does not accept extra linkopts and link inputs. With those, it will be possible to merge + # these workarounds into the rule implementations. + linkopts = binary_args.pop("linkopts", []) + bundle_name = binary_args.get("bundle_name", name) + linkopts += ["-install_name", "@rpath/%s.framework/%s" % (bundle_name, bundle_name)] + binary_args["linkopts"] = linkopts + bundling_args = binary_support.add_entitlements_and_swift_linkopts( + name, + include_entitlements = False, + platform_type = str(apple_common.platform_type.watchos), + product_type = apple_product_type.framework, + exported_symbols_lists = binary_args.pop("exported_symbols_lists", None), + **binary_args + ) + + # Remove any kwargs that shouldn't be passed to the underlying rule. + bundling_args.pop("entitlements", None) + + _tvos_dynamic_framework( + name = name, + extension_safe = kwargs.get("extension_safe"), + **bundling_args + ) + tvos_build_test = apple_build_test_rule( doc = """\ Test rule to check that the given library targets (Swift, Objective-C, C++) diff --git a/apple/watchos.bzl b/apple/watchos.bzl index 4476ccb78b..c072f0292f 100644 --- a/apple/watchos.bzl +++ b/apple/watchos.bzl @@ -68,23 +68,19 @@ def watchos_extension(name, **kwargs): def watchos_dynamic_framework(name, **kwargs): # buildifier: disable=function-docstring-args - """Builds and bundles a watchOS dynamic framework.""" - linkopts = kwargs.get("linkopts", []) - - # Can't read this from the descriptor, since it requires the bundle name as argument. Once this - # is migrated to be a rule, we can move this to the rule implementation. - bundle_name = kwargs.get("bundle_name", name) - linkopts += [ - "-install_name", - "@rpath/%s.framework/%s" % (bundle_name, bundle_name), - ] + """Builds and bundles and watchOS dynamic framework.""" + binary_args = dict(kwargs) + # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking + # API does not accept extra linkopts and link inputs. With those, it will be possible to merge + # these workarounds into the rule implementations. + linkopts = binary_args.pop("linkopts", []) + bundle_name = binary_args.get("bundle_name", name) + linkopts += ["-install_name", "@rpath/%s.framework/%s" % (bundle_name, bundle_name)] binary_args["linkopts"] = linkopts - - # Link the executable from any library deps and sources provided. bundling_args = binary_support.add_entitlements_and_swift_linkopts( name, include_entitlements = False, - platform_type = str(apple_common.platform_type.ios), + platform_type = str(apple_common.platform_type.watchos), product_type = apple_product_type.framework, exported_symbols_lists = binary_args.pop("exported_symbols_lists", None), **binary_args diff --git a/test/starlark_tests/BUILD b/test/starlark_tests/BUILD index 391da44cc5..1254cdc6c0 100644 --- a/test/starlark_tests/BUILD +++ b/test/starlark_tests/BUILD @@ -16,6 +16,7 @@ load(":macos_application_tests.bzl", "macos_application_test_suite") load(":macos_bundle_tests.bzl", "macos_bundle_test_suite") load(":macos_command_line_application_tests.bzl", "macos_command_line_application_test_suite") load(":macos_dylib_tests.bzl", "macos_dylib_test_suite") +load(":macos_dynamic_framework_tests.bzl", "macos_dynamic_framework_test_suite") load(":macos_extension_tests.bzl", "macos_extension_test_suite") load(":macos_kernel_extension_tests.bzl", "macos_kernel_extension_test_suite") load(":macos_quick_look_plugin_tests.bzl", "macos_quick_look_plugin_test_suite") @@ -23,6 +24,7 @@ load(":macos_ui_test_tests.bzl", "macos_ui_test_test_suite") load(":macos_unit_test_tests.bzl", "macos_unit_test_test_suite") load(":tvos_application_swift_tests.bzl", "tvos_application_swift_test_suite") load(":tvos_application_tests.bzl", "tvos_application_test_suite") +load(":tvos_dynamic_framework_tests.bzl", "tvos_dynamic_framework_test_suite") load(":tvos_extension_tests.bzl", "tvos_extension_test_suite") load(":tvos_framework_tests.bzl", "tvos_framework_test_suite") load(":tvos_static_framework_tests.bzl", "tvos_static_framework_test_suite") @@ -30,6 +32,7 @@ load(":tvos_ui_test_tests.bzl", "tvos_ui_test_test_suite") load(":tvos_unit_test_tests.bzl", "tvos_unit_test_test_suite") load(":watchos_application_swift_tests.bzl", "watchos_application_swift_test_suite") load(":watchos_application_tests.bzl", "watchos_application_test_suite") +load(":watchos_dynamic_framework_tests.bzl", "watchos_dynamic_framework_test_suite") load(":watchos_extension_tests.bzl", "watchos_extension_test_suite") licenses(["notice"]) @@ -68,6 +71,8 @@ macos_command_line_application_test_suite() macos_dylib_test_suite() +macos_dynamic_framework_test_suite() + macos_extension_test_suite() macos_kernel_extension_test_suite() @@ -84,6 +89,8 @@ tvos_application_test_suite() tvos_extension_test_suite() +tvos_dynamic_framework_test_suite() + tvos_framework_test_suite() tvos_static_framework_test_suite() @@ -96,6 +103,8 @@ watchos_application_swift_test_suite() watchos_application_test_suite() +watchos_dynamic_framework_test_suite() + watchos_extension_test_suite() test_suite( diff --git a/test/starlark_tests/ios_dynamic_framework_tests.bzl b/test/starlark_tests/ios_dynamic_framework_tests.bzl index 974aeeb45e..2a4d3aa331 100644 --- a/test/starlark_tests/ios_dynamic_framework_tests.bzl +++ b/test/starlark_tests/ios_dynamic_framework_tests.bzl @@ -138,7 +138,6 @@ def ios_dynamic_framework_test_suite(name = "ios_dynamic_framework"): contains = [ "$BUNDLE_ROOT/Frameworks/swift_transitive_lib.framework/swift_transitive_lib", "$BUNDLE_ROOT/Frameworks/swift_transitive_lib.framework/Info.plist", - "$BUNDLE_ROOT/Frameworks/swift_shared_lib.framework/nonlocalized.plist", "$BUNDLE_ROOT/Frameworks/swift_shared_lib.framework/swift_shared_lib", "$BUNDLE_ROOT/Frameworks/swift_shared_lib.framework/Info.plist", ], diff --git a/test/starlark_tests/macos_dynamic_framework_tests.bzl b/test/starlark_tests/macos_dynamic_framework_tests.bzl new file mode 100644 index 0000000000..37e79c933b --- /dev/null +++ b/test/starlark_tests/macos_dynamic_framework_tests.bzl @@ -0,0 +1,111 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""macos_dynamic_framework Starlark tests.""" + +load( + ":rules/common_verification_tests.bzl", + "archive_contents_test", +) +load( + ":rules/infoplist_contents_test.bzl", + "infoplist_contents_test", +) + +def macos_dynamic_framework_test_suite(name = "macos_dynamic_framework"): + """Test suite for macos_dynamic_framework. + + Args: + name: The name prefix for all the nested tests + """ + + archive_contents_test( + name = "{}_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/macos:basic_framework", + binary_test_file = "$BUNDLE_ROOT/BasicFramework", + binary_test_architecture = "x86_64", + macho_load_commands_contain = ["name @rpath/BasicFramework.framework/BasicFramework (offset 24)"], + contains = [ + "$BUNDLE_ROOT/BasicFramework", + "$BUNDLE_ROOT/Headers/BasicFramework.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/BasicFramework.swiftmodule/x86_64.swiftdoc", + "$BUNDLE_ROOT/Modules/BasicFramework.swiftmodule/x86_64.swiftmodule" + ], + tags = [name], + ) + + infoplist_contents_test( + name = "{}_plist_test".format(name), + target_under_test = "//test/starlark_tests/targets_under_test/macos:basic_framework", + expected_values = { + "BuildMachineOSBuild": "*", + "CFBundleExecutable": "BasicFramework", + "CFBundleIdentifier": "com.google.example.framework", + "CFBundleName": "BasicFramework", + "CFBundleSupportedPlatforms:0": "MacOSX*", + "DTCompiler": "com.apple.compilers.llvm.clang.1_0", + "DTPlatformBuild": "*", + "DTPlatformName": "macosx*", + "DTPlatformVersion": "*", + "DTSDKBuild": "*", + "DTSDKName": "macosx*", + "DTXcode": "*", + "DTXcodeBuild": "*", + }, + tags = [name], + ) + + archive_contents_test( + name = "{}_direct_dependency_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/macos:basic_framework_with_direct_dependency", + binary_test_file = "$BUNDLE_ROOT/DirectDependencyTest", + binary_test_architecture = "x86_64", + macho_load_commands_contain = ["name @rpath/DirectDependencyTest.framework/DirectDependencyTest (offset 24)"], + contains = [ + "$BUNDLE_ROOT/DirectDependencyTest", + "$BUNDLE_ROOT/Headers/DirectDependencyTest.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/DirectDependencyTest.swiftmodule/x86_64.swiftdoc", + "$BUNDLE_ROOT/Modules/DirectDependencyTest.swiftmodule/x86_64.swiftmodule" + ], + tags = [name], + ) + + archive_contents_test( + name = "{}_transitive_dependency_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/macos:basic_framework_with_transitive_dependency", + binary_test_file = "$BUNDLE_ROOT/TransitiveDependencyTest", + binary_test_architecture = "x86_64", + macho_load_commands_contain = ["name @rpath/TransitiveDependencyTest.framework/TransitiveDependencyTest (offset 24)"], + contains = [ + "$BUNDLE_ROOT/TransitiveDependencyTest", + "$BUNDLE_ROOT/Headers/TransitiveDependencyTest.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/TransitiveDependencyTest.swiftmodule/x86_64.swiftdoc", + "$BUNDLE_ROOT/Modules/TransitiveDependencyTest.swiftmodule/x86_64.swiftmodule" + ], + tags = [name], + ) + + native.test_suite( + name = name, + tags = [name], + ) \ No newline at end of file diff --git a/test/starlark_tests/resources/BUILD b/test/starlark_tests/resources/BUILD index 71a3cdfb46..57969495ce 100644 --- a/test/starlark_tests/resources/BUILD +++ b/test/starlark_tests/resources/BUILD @@ -102,7 +102,7 @@ swift_library( module_name = "swift_shared_lib", srcs = ["Shared.swift"], deps = [ - "//test/starlark_tests/targets_under_test/ios:swift_common_lib_framework", + "//test/starlark_tests/resources:swift_common_lib", ], testonly = True, features = ["swift.no_generated_module_map"], @@ -116,8 +116,8 @@ swift_library( module_name = "swift_transitive_lib", srcs = ["Transitives.swift"], deps = [ - "//test/starlark_tests/targets_under_test/ios:swift_common_lib_framework", - "//test/starlark_tests/targets_under_test/ios:swift_shared_lib_framework", + "//test/starlark_tests/resources:swift_common_lib", + "//test/starlark_tests/resources:swift_shared_lib", ], testonly = True, features = ["swift.no_generated_module_map"], diff --git a/test/starlark_tests/resources/Info-watchos.plist b/test/starlark_tests/resources/Info-watchos.plist new file mode 100644 index 0000000000..6b0c9c34ec --- /dev/null +++ b/test/starlark_tests/resources/Info-watchos.plist @@ -0,0 +1,16 @@ + + + + + CFBundleName + $(PRODUCT_NAME) + CFBundleVersion + 1.0 + CFBundleShortVersionString + 1.0 + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundlePackageType + WatchOS + + diff --git a/test/starlark_tests/resources/main.swift b/test/starlark_tests/resources/main.swift new file mode 100644 index 0000000000..6d09021215 --- /dev/null +++ b/test/starlark_tests/resources/main.swift @@ -0,0 +1,19 @@ +// Copyright 2020 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation +public class main { + public init() {} + public func main() { print("Hello from main") } +} diff --git a/test/starlark_tests/targets_under_test/ios/BUILD b/test/starlark_tests/targets_under_test/ios/BUILD index 2fd947411a..be35b469a4 100644 --- a/test/starlark_tests/targets_under_test/ios/BUILD +++ b/test/starlark_tests/targets_under_test/ios/BUILD @@ -1941,7 +1941,7 @@ swift_library( ], visibility = ["//visibility:public"], deps = [ - ":basic_framework", + ":basic_framework_lib", ], features = ["swift.no_generated_module_map"], tags = [ @@ -1978,8 +1978,8 @@ swift_library( ], visibility = ["//visibility:public"], deps = [ - ":basic_framework", - ":basic_framework_with_direct_dependency", + ":basic_framework_lib", + ":basic_framework_with_direct_dependency_lib", ], features = ["swift.no_generated_module_map"], tags = [ @@ -2089,7 +2089,6 @@ ios_dynamic_framework( ], deps = [ "//test/starlark_tests/resources:swift_shared_lib", - "//test/starlark_tests/resources:framework_resources_lib", ] ) diff --git a/test/starlark_tests/targets_under_test/macos/BUILD b/test/starlark_tests/targets_under_test/macos/BUILD index 58cbaf516d..8169ed890e 100644 --- a/test/starlark_tests/targets_under_test/macos/BUILD +++ b/test/starlark_tests/targets_under_test/macos/BUILD @@ -5,6 +5,7 @@ load( "macos_bundle", "macos_command_line_application", "macos_dylib", + "macos_dynamic_framework", "macos_extension", "macos_kernel_extension", "macos_quick_look_plugin", @@ -19,6 +20,7 @@ load( "//test/testdata/frameworks:generate_framework.bzl", "generate_import_framework", ) +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") licenses(["notice"]) @@ -646,3 +648,102 @@ macos_unit_test( "//test/starlark_tests/resources:objc_test_lib", ], ) + +# --------------------------------------------------------------------------------------- + +swift_library( + name = "basic_framework_lib", + module_name = "BasicFramework", + srcs = [ + "//test/starlark_tests/resources:BasicFramework.swift", + ], + visibility = ["//visibility:public"], + features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], +) + +macos_dynamic_framework( + name = "basic_framework", + bundle_name = "BasicFramework", + bundle_id = "com.google.example.framework", + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "10.10", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_lib", + ], +) + +swift_library( + name = "basic_framework_with_direct_dependency_lib", + module_name = "DirectDependencyTest", + srcs = [ + "//test/starlark_tests/resources:DirectDependencyTest.swift", + ], + visibility = ["//visibility:public"], + deps = [ + ":basic_framework_lib", + ], + features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], +) + +macos_dynamic_framework( + name = "basic_framework_with_direct_dependency", + bundle_name = "DirectDependencyTest", + bundle_id = "com.google.example.framework", + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "10.10", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_with_direct_dependency_lib", + ], +) + +swift_library( + name = "basic_framework_with_transitive_dependency_lib", + module_name = "TransitiveDependencyTest", + srcs = [ + "//test/starlark_tests/resources:TransitiveDependencyTest.swift", + ], + visibility = ["//visibility:public"], + deps = [ + ":basic_framework_lib", + ":basic_framework_with_direct_dependency_lib", + ], + features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], +) + +macos_dynamic_framework( + name = "basic_framework_with_transitive_dependency", + bundle_name = "TransitiveDependencyTest", + bundle_id = "com.google.example.framework", + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "10.10", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_with_transitive_dependency_lib", + ], +) \ No newline at end of file diff --git a/test/starlark_tests/targets_under_test/tvos/BUILD b/test/starlark_tests/targets_under_test/tvos/BUILD index 20b9b8fcfc..9094b55075 100644 --- a/test/starlark_tests/targets_under_test/tvos/BUILD +++ b/test/starlark_tests/targets_under_test/tvos/BUILD @@ -2,6 +2,7 @@ load("@rules_cc//cc:defs.bzl", "objc_library") load( "//apple:tvos.bzl", "tvos_application", + "tvos_dynamic_framework", "tvos_extension", "tvos_framework", "tvos_static_framework", @@ -452,3 +453,102 @@ objc_library( srcs = ["@bazel_tools//tools/objc:dummy.c"], deps = [":swift_lib"], ) + +# --------------------------------------------------------------------------------------- + +swift_library( + name = "basic_framework_lib", + module_name = "BasicFramework", + srcs = [ + "//test/starlark_tests/resources:BasicFramework.swift", + ], + visibility = ["//visibility:public"], + features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], +) + +tvos_dynamic_framework( + name = "basic_framework", + bundle_name = "BasicFramework", + bundle_id = "com.google.example.framework", + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "14.0", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_lib", + ], +) + +swift_library( + name = "basic_framework_with_direct_dependency_lib", + module_name = "DirectDependencyTest", + srcs = [ + "//test/starlark_tests/resources:DirectDependencyTest.swift", + ], + visibility = ["//visibility:public"], + deps = [ + ":basic_framework_lib", + ], + features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], +) + +tvos_dynamic_framework( + name = "basic_framework_with_direct_dependency", + bundle_name = "DirectDependencyTest", + bundle_id = "com.google.example.framework", + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "14.0", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_with_direct_dependency_lib", + ], +) + +swift_library( + name = "basic_framework_with_transitive_dependency_lib", + module_name = "TransitiveDependencyTest", + srcs = [ + "//test/starlark_tests/resources:TransitiveDependencyTest.swift", + ], + visibility = ["//visibility:public"], + deps = [ + ":basic_framework_lib", + ":basic_framework_with_direct_dependency_lib", + ], + features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], +) + +tvos_dynamic_framework( + name = "basic_framework_with_transitive_dependency", + bundle_name = "TransitiveDependencyTest", + bundle_id = "com.google.example.framework", + infoplists = [ + "//test/starlark_tests/resources:Info.plist", + ], + minimum_os_version = "14.0", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_with_transitive_dependency_lib", + ], +) \ No newline at end of file diff --git a/test/starlark_tests/targets_under_test/watchos/BUILD b/test/starlark_tests/targets_under_test/watchos/BUILD index 46af7a2eab..56055679db 100644 --- a/test/starlark_tests/targets_under_test/watchos/BUILD +++ b/test/starlark_tests/targets_under_test/watchos/BUILD @@ -6,6 +6,7 @@ load( load( "//apple:watchos.bzl", "watchos_application", + "watchos_dynamic_framework", "watchos_extension", ) load( @@ -350,3 +351,105 @@ swift_library( name = "swift_lib", srcs = ["//test/testdata/sources:main.swift"], ) + +# --------------------------------------------------------------------------------------- + +swift_library( + name = "basic_framework_lib", + module_name = "BasicFramework", + srcs = [ + "//test/starlark_tests/resources:BasicFramework.swift", + "//test/starlark_tests/resources:main.swift", + ], + visibility = ["//visibility:public"], + features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], +) + +watchos_dynamic_framework( + name = "basic_framework", + bundle_name = "BasicFramework", + bundle_id = "com.google.example.framework", + infoplists = [ + "//test/starlark_tests/resources:Info-watchos.plist", + ], + minimum_os_version = "6.0", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_lib", + ], +) + +swift_library( + name = "basic_framework_with_direct_dependency_lib", + module_name = "DirectDependencyTest", + srcs = [ + "//test/starlark_tests/resources:DirectDependencyTest.swift", + # "//test/starlark_tests/resources:main.swift", + ], + visibility = ["//visibility:public"], + deps = [ + ":basic_framework_lib", + ], + features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], +) + +watchos_dynamic_framework( + name = "basic_framework_with_direct_dependency", + bundle_name = "DirectDependencyTest", + bundle_id = "com.google.example.framework", + infoplists = [ + "//test/starlark_tests/resources:Info-watchos.plist", + ], + minimum_os_version = "6.0", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_with_direct_dependency_lib", + ], +) + +swift_library( + name = "basic_framework_with_transitive_dependency_lib", + module_name = "TransitiveDependencyTest", + srcs = [ + "//test/starlark_tests/resources:TransitiveDependencyTest.swift", + # "//test/starlark_tests/resources:main.swift", + ], + visibility = ["//visibility:public"], + deps = [ + ":basic_framework_lib", + ":basic_framework_with_direct_dependency_lib", + ], + features = ["swift.no_generated_module_map"], + tags = [ + "manual", + ], +) + +watchos_dynamic_framework( + name = "basic_framework_with_transitive_dependency", + bundle_name = "TransitiveDependencyTest", + bundle_id = "com.google.example.framework", + infoplists = [ + "//test/starlark_tests/resources:Info-watchos.plist", + ], + minimum_os_version = "6.0", + tags = [ + "manual", + "notap", + ], + deps = [ + ":basic_framework_with_transitive_dependency_lib", + ], +) \ No newline at end of file diff --git a/test/starlark_tests/tvos_dynamic_framework_tests.bzl b/test/starlark_tests/tvos_dynamic_framework_tests.bzl new file mode 100644 index 0000000000..499321c280 --- /dev/null +++ b/test/starlark_tests/tvos_dynamic_framework_tests.bzl @@ -0,0 +1,113 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""tvos_dynamic_framework Starlark tests.""" + +load( + ":rules/common_verification_tests.bzl", + "archive_contents_test", +) +load( + ":rules/infoplist_contents_test.bzl", + "infoplist_contents_test", +) + +def tvos_dynamic_framework_test_suite(name = "tvos_dynamic_framework"): + """Test suite for tvos_dynamic_framework. + + Args: + name: The name prefix for all the nested tests + """ + + archive_contents_test( + name = "{}_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/tvos:basic_framework", + binary_test_file = "$BUNDLE_ROOT/BasicFramework", + binary_test_architecture = "x86_64", + macho_load_commands_contain = ["name @rpath/BasicFramework.framework/BasicFramework (offset 24)"], + contains = [ + "$BUNDLE_ROOT/BasicFramework", + "$BUNDLE_ROOT/Headers/BasicFramework.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/BasicFramework.swiftmodule/x86_64.swiftdoc", + "$BUNDLE_ROOT/Modules/BasicFramework.swiftmodule/x86_64.swiftmodule" + ], + tags = [name], + ) + + infoplist_contents_test( + name = "{}_plist_test".format(name), + target_under_test = "//test/starlark_tests/targets_under_test/tvos:basic_framework", + expected_values = { + "BuildMachineOSBuild": "*", + "CFBundleExecutable": "BasicFramework", + "CFBundleIdentifier": "com.google.example.framework", + "CFBundleName": "BasicFramework", + "CFBundleSupportedPlatforms:0": "AppleTV*", + "DTCompiler": "com.apple.compilers.llvm.clang.1_0", + "DTPlatformBuild": "*", + "DTPlatformName": "appletvs*", + "DTPlatformVersion": "*", + "DTSDKBuild": "*", + "DTSDKName": "appletv*", + "DTXcode": "*", + "DTXcodeBuild": "*", + "MinimumOSVersion": "14.0", + "UIDeviceFamily:0": "3", + }, + tags = [name], + ) + + archive_contents_test( + name = "{}_direct_dependency_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/tvos:basic_framework_with_direct_dependency", + binary_test_file = "$BUNDLE_ROOT/DirectDependencyTest", + binary_test_architecture = "x86_64", + macho_load_commands_contain = ["name @rpath/DirectDependencyTest.framework/DirectDependencyTest (offset 24)"], + contains = [ + "$BUNDLE_ROOT/DirectDependencyTest", + "$BUNDLE_ROOT/Headers/DirectDependencyTest.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/DirectDependencyTest.swiftmodule/x86_64.swiftdoc", + "$BUNDLE_ROOT/Modules/DirectDependencyTest.swiftmodule/x86_64.swiftmodule" + ], + tags = [name], + ) + + archive_contents_test( + name = "{}_transitive_dependency_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/tvos:basic_framework_with_transitive_dependency", + binary_test_file = "$BUNDLE_ROOT/TransitiveDependencyTest", + binary_test_architecture = "x86_64", + macho_load_commands_contain = ["name @rpath/TransitiveDependencyTest.framework/TransitiveDependencyTest (offset 24)"], + contains = [ + "$BUNDLE_ROOT/TransitiveDependencyTest", + "$BUNDLE_ROOT/Headers/TransitiveDependencyTest.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/TransitiveDependencyTest.swiftmodule/x86_64.swiftdoc", + "$BUNDLE_ROOT/Modules/TransitiveDependencyTest.swiftmodule/x86_64.swiftmodule" + ], + tags = [name], + ) + + native.test_suite( + name = name, + tags = [name], + ) \ No newline at end of file diff --git a/test/starlark_tests/watchos_dynamic_framework_tests.bzl b/test/starlark_tests/watchos_dynamic_framework_tests.bzl new file mode 100644 index 0000000000..e3197b96a2 --- /dev/null +++ b/test/starlark_tests/watchos_dynamic_framework_tests.bzl @@ -0,0 +1,88 @@ +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""watchos_dynamic_framework Starlark tests.""" + +load( + ":rules/common_verification_tests.bzl", + "archive_contents_test", +) +load( + ":rules/infoplist_contents_test.bzl", + "infoplist_contents_test", +) + +def watchos_dynamic_framework_test_suite(name = "watchos_dynamic_framework"): + """Test suite for watchos_dynamic_framework. + + Args: + name: The name prefix for all the nested tests + """ + + archive_contents_test( + name = "{}_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/watchos:basic_framework", + binary_test_file = "$BUNDLE_ROOT/BasicFramework", + binary_test_architecture = "i386", + contains = [ + "$BUNDLE_ROOT/BasicFramework", + "$BUNDLE_ROOT/Headers/BasicFramework.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/BasicFramework.swiftmodule/i386.swiftdoc", + "$BUNDLE_ROOT/Modules/BasicFramework.swiftmodule/i386.swiftmodule" + ], + tags = [name], + ) + + archive_contents_test( + name = "{}_direct_dependency_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/watchos:basic_framework_with_direct_dependency", + binary_test_file = "$BUNDLE_ROOT/DirectDependencyTest", + binary_test_architecture = "i386", + contains = [ + "$BUNDLE_ROOT/DirectDependencyTest", + "$BUNDLE_ROOT/Headers/DirectDependencyTest.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/DirectDependencyTest.swiftmodule/i386.swiftdoc", + "$BUNDLE_ROOT/Modules/DirectDependencyTest.swiftmodule/i386.swiftmodule" + ], + tags = [name], + ) + + + archive_contents_test( + name = "{}_transitive_dependency_archive_contents_test".format(name), + build_type = "simulator", + target_under_test = "//test/starlark_tests/targets_under_test/watchos:basic_framework_with_transitive_dependency", + binary_test_file = "$BUNDLE_ROOT/TransitiveDependencyTest", + binary_test_architecture = "i386", + contains = [ + "$BUNDLE_ROOT/TransitiveDependencyTest", + "$BUNDLE_ROOT/Headers/TransitiveDependencyTest.h", + "$BUNDLE_ROOT/Info.plist", + "$BUNDLE_ROOT/Modules/module.modulemap", + "$BUNDLE_ROOT/Modules/TransitiveDependencyTest.swiftmodule/i386.swiftdoc", + "$BUNDLE_ROOT/Modules/TransitiveDependencyTest.swiftmodule/i386.swiftmodule" + ], + tags = [name], + ) + + native.test_suite( + name = name, + tags = [name], + ) \ No newline at end of file From 58409a3378b3d8e9ec7226902be21e4ba47ec17b Mon Sep 17 00:00:00 2001 From: XRV287 Date: Tue, 10 Nov 2020 16:20:06 -0500 Subject: [PATCH 07/26] Fixing Buildifier issues --- apple/internal/ios_rules.bzl | 4 ++-- apple/internal/macos_rules.bzl | 4 ++-- apple/internal/tvos_rules.bzl | 4 ++-- apple/internal/watchos_rules.bzl | 4 ++-- .../watchos_dynamic_framework_tests.bzl | 23 +++++++++++++++++++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index 1ec86f96d7..97628ac737 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -904,8 +904,8 @@ def _ios_extension_impl(ctx): def _ios_dynamic_framework_impl(ctx): """Experimental implementation of ios_dynamic_framework.""" - depsList = [deps for deps in ctx.attr.deps] - binary_target = depsList.pop() + deps_list = [deps for deps in ctx.attr.deps] + binary_target = deps_list.pop() extra_linkopts = [] if ctx.attr.extension_safe: extra_linkopts.append("-fapplication-extension") diff --git a/apple/internal/macos_rules.bzl b/apple/internal/macos_rules.bzl index 47e944b26e..048e78254c 100644 --- a/apple/internal/macos_rules.bzl +++ b/apple/internal/macos_rules.bzl @@ -1288,8 +1288,8 @@ def _macos_dylib_impl(ctx): def _macos_dynamic_framework_impl(ctx): """Experimental implementation of macos_framework.""" - depsList = [deps for deps in ctx.attr.deps] - binary_target = depsList.pop() + deps_list = [deps for deps in ctx.attr.deps] + binary_target = deps_list.pop() link_result = linking_support.register_linking_action(ctx) binary_artifact = link_result.binary_provider.binary debug_outputs_provider = link_result.debug_outputs_provider diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index c63d731ee1..4ca21a8b2a 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -285,8 +285,8 @@ def _tvos_application_impl(ctx): def _tvos_dynamic_framework_impl(ctx): """Experimental implementation of tvos_framework.""" - depsList = [deps for deps in ctx.attr.deps] - binary_target = depsList.pop() + deps_list = [deps for deps in ctx.attr.deps] + binary_target = deps_list.pop() link_result = linking_support.register_linking_action(ctx) binary_artifact = link_result.binary_provider.binary debug_outputs_provider = link_result.debug_outputs_provider diff --git a/apple/internal/watchos_rules.bzl b/apple/internal/watchos_rules.bzl index 9d82583fab..0a8dd62403 100644 --- a/apple/internal/watchos_rules.bzl +++ b/apple/internal/watchos_rules.bzl @@ -79,8 +79,8 @@ load( def _watchos_dynamic_framework_impl(ctx): """Experimental implementation of watchos_dynamic_framework.""" - depsList = [deps for deps in ctx.attr.deps] - binary_target = depsList.pop() + deps_list = [deps for deps in ctx.attr.deps] + binary_target = deps_list.pop() extra_linkopts = [] if ctx.attr.extension_safe: extra_linkopts.append("-fapplication-extension") diff --git a/test/starlark_tests/watchos_dynamic_framework_tests.bzl b/test/starlark_tests/watchos_dynamic_framework_tests.bzl index e3197b96a2..1ecb445caa 100644 --- a/test/starlark_tests/watchos_dynamic_framework_tests.bzl +++ b/test/starlark_tests/watchos_dynamic_framework_tests.bzl @@ -47,6 +47,29 @@ def watchos_dynamic_framework_test_suite(name = "watchos_dynamic_framework"): tags = [name], ) + infoplist_contents_test( + name = "{}_plist_test".format(name), + target_under_test = "//test/starlark_tests/targets_under_test/watchos:basic_framework", + expected_values = { + "BuildMachineOSBuild": "*", + "CFBundleExecutable": "BasicFramework", + "CFBundleIdentifier": "com.google.example.framework", + "CFBundleName": "BasicFramework", + "CFBundleSupportedPlatforms:0": "WatchSimulator*", + "DTCompiler": "com.apple.compilers.llvm.clang.1_0", + "DTPlatformBuild": "*", + "DTPlatformName": "watchsimulator*", + "DTPlatformVersion": "*", + "DTSDKBuild": "*", + "DTSDKName": "watchsimulator*", + "DTXcode": "*", + "DTXcodeBuild": "*", + "MinimumOSVersion": "6.0", + "UIDeviceFamily:0": "4", + }, + tags = [name], + ) + archive_contents_test( name = "{}_direct_dependency_archive_contents_test".format(name), build_type = "simulator", From 9be486baaaad36d3a6975103f486ae9d0de2a996 Mon Sep 17 00:00:00 2001 From: Brentley Jones Date: Fri, 13 Nov 2020 10:24:05 -0600 Subject: [PATCH 08/26] PR updates --- apple/internal/ios_rules.bzl | 2 +- apple/internal/macos_rules.bzl | 4 ++-- apple/internal/rule_support.bzl | 5 ++--- apple/internal/tvos_rules.bzl | 2 +- apple/ios.bzl | 1 + apple/macos.bzl | 1 + apple/watchos.bzl | 1 + 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index 041ee342a0..2bf0ed7139 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -1646,7 +1646,7 @@ ios_dynamic_framework = rule_factory.create_apple_bundling_rule( implementation = _ios_dynamic_framework_impl, platform_type = "ios", product_type = apple_product_type.framework, - doc = "Builds and bundles an iOS Dynamic Framework consumable in Xcode.", + doc = "Builds and bundles an iOS dynamic framework that is consumable by Xcode.", ) ios_static_framework = rule_factory.create_apple_bundling_rule( diff --git a/apple/internal/macos_rules.bzl b/apple/internal/macos_rules.bzl index 048e78254c..428e62c7c8 100644 --- a/apple/internal/macos_rules.bzl +++ b/apple/internal/macos_rules.bzl @@ -1287,7 +1287,7 @@ def _macos_dylib_impl(ctx): ] + processor_result.providers def _macos_dynamic_framework_impl(ctx): - """Experimental implementation of macos_framework.""" + """Experimental implementation of macos_dynamic_framework.""" deps_list = [deps for deps in ctx.attr.deps] binary_target = deps_list.pop() link_result = linking_support.register_linking_action(ctx) @@ -1450,7 +1450,7 @@ macos_dynamic_framework = rule_factory.create_apple_bundling_rule( implementation = _macos_dynamic_framework_impl, platform_type = "macos", product_type = apple_product_type.framework, - doc = "Builds and bundles a macos dynamic framework.", + doc = "Builds and bundles a macOS Dynamic Framework that is consumable by Xcode.", ) macos_extension = rule_factory.create_apple_bundling_rule( diff --git a/apple/internal/rule_support.bzl b/apple/internal/rule_support.bzl index 9f5a1e82e4..f2b6aff3a9 100644 --- a/apple/internal/rule_support.bzl +++ b/apple/internal/rule_support.bzl @@ -478,8 +478,8 @@ _RULE_TYPE_DESCRIPTORS = { product_type = apple_product_type.framework, rpaths = [ # Framework binaries live in - # Application.app/Frameworks/Framework.framework/Framework - # Frameworks are packaged in Application.app/Frameworks + # Application.app/Contents/Frameworks/Framework.framework/Framework + # Frameworks are packaged in Application.app/Contents/Frameworks "@executable_path/Frameworks", ], ), @@ -774,7 +774,6 @@ _RULE_TYPE_DESCRIPTORS = { allowed_device_families = ["watch"], bundle_extension = ".framework", codesigning_exceptions = _CODESIGNING_EXCEPTIONS.sign_with_provisioning_profile, - mandatory_families = True, product_type = apple_product_type.framework, rpaths = [ # Framework binaries live in diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index 4ca21a8b2a..470305f7ad 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -284,7 +284,7 @@ def _tvos_application_impl(ctx): ] + processor_result.providers def _tvos_dynamic_framework_impl(ctx): - """Experimental implementation of tvos_framework.""" + """Experimental implementation of tvos_dynamic_framework.""" deps_list = [deps for deps in ctx.attr.deps] binary_target = deps_list.pop() link_result = linking_support.register_linking_action(ctx) diff --git a/apple/ios.bzl b/apple/ios.bzl index bc307381f8..a540f474e0 100644 --- a/apple/ios.bzl +++ b/apple/ios.bzl @@ -129,6 +129,7 @@ def ios_framework(name, **kwargs): def ios_dynamic_framework(name, **kwargs): # buildifier: disable=function-docstring-args """Builds and bundles an iOS dynamic framework.""" + binary_args = dict(kwargs) # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking # API does not accept extra linkopts and link inputs. With those, it will be possible to merge diff --git a/apple/macos.bzl b/apple/macos.bzl index 7e20f80856..3cd3a95571 100644 --- a/apple/macos.bzl +++ b/apple/macos.bzl @@ -288,6 +288,7 @@ def macos_dylib(name, **kwargs): def macos_dynamic_framework(name, **kwargs): # buildifier: disable=function-docstring-args """Builds and bundles an iOS dynamic framework.""" + binary_args = dict(kwargs) # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking # API does not accept extra linkopts and link inputs. With those, it will be possible to merge diff --git a/apple/watchos.bzl b/apple/watchos.bzl index c072f0292f..9ad0f7df5f 100644 --- a/apple/watchos.bzl +++ b/apple/watchos.bzl @@ -69,6 +69,7 @@ def watchos_extension(name, **kwargs): def watchos_dynamic_framework(name, **kwargs): # buildifier: disable=function-docstring-args """Builds and bundles and watchOS dynamic framework.""" + binary_args = dict(kwargs) # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking # API does not accept extra linkopts and link inputs. With those, it will be possible to merge From bce39c0a28f8823d9c711bbfa85819c1dbf0e4ab Mon Sep 17 00:00:00 2001 From: XRV287 Date: Tue, 17 Nov 2020 11:07:43 -0500 Subject: [PATCH 09/26] Enforcing that there can only be one swift_library dependency and addressing PR feedback --- .../aspects/swift_dynamic_framework_aspect.bzl | 17 ++++++++++++----- apple/internal/ios_rules.bzl | 2 +- apple/internal/macos_rules.bzl | 2 +- .../partials/swift_dynamic_framework.bzl | 10 ++-------- apple/internal/rule_factory.bzl | 3 --- apple/internal/rule_support.bzl | 7 +++++-- apple/internal/tvos_rules.bzl | 3 ++- apple/internal/watchos_rules.bzl | 2 +- 8 files changed, 24 insertions(+), 22 deletions(-) diff --git a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl index 07620337b6..0fbb2b269a 100644 --- a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl +++ b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl @@ -79,6 +79,7 @@ framework module {module_name} {{ def _swift_dynamic_framework_aspect_impl(target, ctx): """Aspect implementation for Swift dynamic framework support.""" + if not hasattr(ctx.rule.attr, "deps"): return [] @@ -88,6 +89,14 @@ def _swift_dynamic_framework_aspect_impl(target, ctx): if not swiftdeps: return [] + if len(swiftdeps) != len(ctx.rule.attr.deps): + fail( + """\ +error: Found a mix of swift_library and other rule dependencies. Swift dynamic frameworks expect a \ +single swift_library dependency.\ +""", + ) + # Collect all relevant artifacts for Swift dynamic framework generation. module_name = None generated_header = None @@ -97,21 +106,19 @@ def _swift_dynamic_framework_aspect_impl(target, ctx): for dep in swiftdeps: swiftinfo = dep[SwiftInfo] + # Use the module_name for the first swiftdep + # If there are transitive dependencies, more than one swiftdep will be returned if not module_name: module_name = swiftinfo.module_name arch = _swift_arch_for_dep(dep) - # Collect the interface artifacts. - if swiftinfo.transitive_generated_headers: - if not generated_header: - generated_header = swiftinfo.transitive_generated_headers.to_list().pop() - swiftdocs[arch] = swiftinfo.transitive_swiftdocs.to_list().pop() swiftmodules[arch] = swiftinfo.transitive_swiftmodules.to_list().pop() modulemap_file = ctx.actions.declare_file("{}_file.modulemap".format(module_name)) ctx.actions.write(modulemap_file, _modulemap_contents(module_name)) + # Get the generated_header using the CcInfo provider for dep in ccinfos: headers = dep[CcInfo].compilation_context.headers.to_list() if headers: diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index 2bf0ed7139..168929235c 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -922,11 +922,11 @@ def _ios_dynamic_framework_impl(ctx): bin_root_path = ctx.bin_dir.path bundle_id = ctx.attr.bundle_id bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) - executable_name = bundling_support.executable_name(ctx) entitlements = entitlements_support.entitlements( entitlements_attr = getattr(ctx.attr, "entitlements", None), entitlements_file = getattr(ctx.file, "entitlements", None), ) + executable_name = bundling_support.executable_name(ctx) features = features_support.compute_enabled_features( requested_features = ctx.features, unsupported_features = ctx.disabled_features, diff --git a/apple/internal/macos_rules.bzl b/apple/internal/macos_rules.bzl index 428e62c7c8..ef9f291a27 100644 --- a/apple/internal/macos_rules.bzl +++ b/apple/internal/macos_rules.bzl @@ -1298,11 +1298,11 @@ def _macos_dynamic_framework_impl(ctx): bin_root_path = ctx.bin_dir.path bundle_id = ctx.attr.bundle_id bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) - executable_name = bundling_support.executable_name(ctx) entitlements = entitlements_support.entitlements( entitlements_attr = getattr(ctx.attr, "entitlements", None), entitlements_file = getattr(ctx.file, "entitlements", None), ) + executable_name = bundling_support.executable_name(ctx) features = features_support.compute_enabled_features( requested_features = ctx.features, unsupported_features = ctx.disabled_features, diff --git a/apple/internal/partials/swift_dynamic_framework.bzl b/apple/internal/partials/swift_dynamic_framework.bzl index 39601d3b6b..b35667620c 100644 --- a/apple/internal/partials/swift_dynamic_framework.bzl +++ b/apple/internal/partials/swift_dynamic_framework.bzl @@ -38,16 +38,10 @@ load( def _get_header_imports(framework_imports): """Get the header files from the list of framework imports""" - header_imports = [] - for file in framework_imports: - file_short_path = file.short_path - if file_short_path.endswith(".h"): - header_imports.append(file) - - return header_imports + return [file for file in framework_imports if file.short_path.endswith(".h")] def _swift_dynamic_framework_partial_impl(ctx, swift_dynamic_framework_info): - """Implementation for the Swift static framework processing partial.""" + """Implementation for the Swift dynamic framework processing partial.""" expected_module_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) diff --git a/apple/internal/rule_factory.bzl b/apple/internal/rule_factory.bzl index 9d6ca8bd4b..39964a4e42 100644 --- a/apple/internal/rule_factory.bzl +++ b/apple/internal/rule_factory.bzl @@ -945,9 +945,6 @@ ignored. if rule_descriptor.requires_deps: extra_args = {} - if rule_descriptor.product_type == apple_product_type.application: - extra_args["aspects"] = [framework_import_aspect] - attrs.append({ "frameworks": attr.label_list( providers = [[AppleBundleInfo, IosFrameworkBundleInfo]], diff --git a/apple/internal/rule_support.bzl b/apple/internal/rule_support.bzl index f2b6aff3a9..4e53d530f5 100644 --- a/apple/internal/rule_support.bzl +++ b/apple/internal/rule_support.bzl @@ -470,9 +470,9 @@ _RULE_TYPE_DESCRIPTORS = { # macos_framework apple_product_type.framework: _describe_rule_type( allowed_device_families = ["mac"], + binary_type = "dylib", bundle_extension = ".framework", bundle_package_type = bundle_package_type.framework, - binary_type = "dylib", codesigning_exceptions = _CODESIGNING_EXCEPTIONS.sign_with_provisioning_profile, deps_cfg = apple_common.multi_arch_split, product_type = apple_product_type.framework, @@ -665,9 +665,9 @@ _RULE_TYPE_DESCRIPTORS = { # tvos_framework apple_product_type.framework: _describe_rule_type( allowed_device_families = ["tv"], + binary_type = "dylib", bundle_extension = ".framework", bundle_package_type = bundle_package_type.framework, - binary_type = "dylib", codesigning_exceptions = _CODESIGNING_EXCEPTIONS.sign_with_provisioning_profile, deps_cfg = apple_common.multi_arch_split, product_type = apple_product_type.framework, @@ -772,8 +772,11 @@ _RULE_TYPE_DESCRIPTORS = { # watchos_framework apple_product_type.framework: _describe_rule_type( allowed_device_families = ["watch"], + binary_type = "dylib", bundle_extension = ".framework", + bundle_package_type = bundle_package_type.framework, codesigning_exceptions = _CODESIGNING_EXCEPTIONS.sign_with_provisioning_profile, + deps_cfg = apple_common.multi_arch_split, product_type = apple_product_type.framework, rpaths = [ # Framework binaries live in diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index 470305f7ad..2b58c09d29 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -285,6 +285,7 @@ def _tvos_application_impl(ctx): def _tvos_dynamic_framework_impl(ctx): """Experimental implementation of tvos_dynamic_framework.""" + deps_list = [deps for deps in ctx.attr.deps] binary_target = deps_list.pop() link_result = linking_support.register_linking_action(ctx) @@ -295,11 +296,11 @@ def _tvos_dynamic_framework_impl(ctx): bin_root_path = ctx.bin_dir.path bundle_id = ctx.attr.bundle_id bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) - executable_name = bundling_support.executable_name(ctx) entitlements = entitlements_support.entitlements( entitlements_attr = getattr(ctx.attr, "entitlements", None), entitlements_file = getattr(ctx.file, "entitlements", None), ) + executable_name = bundling_support.executable_name(ctx) 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 0a8dd62403..e8514d91ca 100644 --- a/apple/internal/watchos_rules.bzl +++ b/apple/internal/watchos_rules.bzl @@ -96,11 +96,11 @@ def _watchos_dynamic_framework_impl(ctx): bin_root_path = ctx.bin_dir.path bundle_id = ctx.attr.bundle_id bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) - executable_name = bundling_support.executable_name(ctx) entitlements = entitlements_support.entitlements( entitlements_attr = getattr(ctx.attr, "entitlements", None), entitlements_file = getattr(ctx.file, "entitlements", None), ) + executable_name = bundling_support.executable_name(ctx) features = features_support.compute_enabled_features( requested_features = ctx.features, unsupported_features = ctx.disabled_features, From 87711eeeb79b2d114b23a4feb0b8a5df6272433d Mon Sep 17 00:00:00 2001 From: XRV287 Date: Wed, 18 Nov 2020 17:08:07 -0500 Subject: [PATCH 10/26] Simplified module_name logic and fixed newline issues --- apple/internal/aspects/swift_dynamic_framework_aspect.bzl | 7 +------ apple/internal/ios_rules.bzl | 1 + apple/internal/macos_rules.bzl | 1 + apple/internal/watchos_rules.bzl | 1 + test/starlark_tests/ios_dynamic_framework_tests.bzl | 2 +- test/starlark_tests/macos_dynamic_framework_tests.bzl | 2 +- test/starlark_tests/resources/BasicFramework.swift | 1 + test/starlark_tests/resources/DirectDependencyTest.swift | 1 + test/starlark_tests/targets_under_test/ios/BUILD | 2 +- test/starlark_tests/targets_under_test/macos/BUILD | 2 +- test/starlark_tests/targets_under_test/tvos/BUILD | 2 +- test/starlark_tests/targets_under_test/watchos/BUILD | 2 +- test/starlark_tests/tvos_dynamic_framework_tests.bzl | 2 +- test/starlark_tests/watchos_dynamic_framework_tests.bzl | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl index 0fbb2b269a..c9cee2b8b3 100644 --- a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl +++ b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl @@ -105,12 +105,7 @@ single swift_library dependency.\ modulemap_file = None for dep in swiftdeps: swiftinfo = dep[SwiftInfo] - - # Use the module_name for the first swiftdep - # If there are transitive dependencies, more than one swiftdep will be returned - if not module_name: - module_name = swiftinfo.module_name - + module_name = swiftinfo.module_name arch = _swift_arch_for_dep(dep) swiftdocs[arch] = swiftinfo.transitive_swiftdocs.to_list().pop() diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index 168929235c..2b17c05208 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -905,6 +905,7 @@ def _ios_extension_impl(ctx): def _ios_dynamic_framework_impl(ctx): """Experimental implementation of ios_dynamic_framework.""" + deps_list = [deps for deps in ctx.attr.deps] binary_target = deps_list.pop() extra_linkopts = [] diff --git a/apple/internal/macos_rules.bzl b/apple/internal/macos_rules.bzl index ef9f291a27..214eba95c4 100644 --- a/apple/internal/macos_rules.bzl +++ b/apple/internal/macos_rules.bzl @@ -1288,6 +1288,7 @@ def _macos_dylib_impl(ctx): def _macos_dynamic_framework_impl(ctx): """Experimental implementation of macos_dynamic_framework.""" + deps_list = [deps for deps in ctx.attr.deps] binary_target = deps_list.pop() link_result = linking_support.register_linking_action(ctx) diff --git a/apple/internal/watchos_rules.bzl b/apple/internal/watchos_rules.bzl index e8514d91ca..1d87be8818 100644 --- a/apple/internal/watchos_rules.bzl +++ b/apple/internal/watchos_rules.bzl @@ -79,6 +79,7 @@ load( def _watchos_dynamic_framework_impl(ctx): """Experimental implementation of watchos_dynamic_framework.""" + deps_list = [deps for deps in ctx.attr.deps] binary_target = deps_list.pop() extra_linkopts = [] diff --git a/test/starlark_tests/ios_dynamic_framework_tests.bzl b/test/starlark_tests/ios_dynamic_framework_tests.bzl index 2a4d3aa331..d61e88576f 100644 --- a/test/starlark_tests/ios_dynamic_framework_tests.bzl +++ b/test/starlark_tests/ios_dynamic_framework_tests.bzl @@ -163,4 +163,4 @@ def ios_dynamic_framework_test_suite(name = "ios_dynamic_framework"): native.test_suite( name = name, tags = [name], - ) \ No newline at end of file + ) diff --git a/test/starlark_tests/macos_dynamic_framework_tests.bzl b/test/starlark_tests/macos_dynamic_framework_tests.bzl index 37e79c933b..8bcde88535 100644 --- a/test/starlark_tests/macos_dynamic_framework_tests.bzl +++ b/test/starlark_tests/macos_dynamic_framework_tests.bzl @@ -108,4 +108,4 @@ def macos_dynamic_framework_test_suite(name = "macos_dynamic_framework"): native.test_suite( name = name, tags = [name], - ) \ No newline at end of file + ) diff --git a/test/starlark_tests/resources/BasicFramework.swift b/test/starlark_tests/resources/BasicFramework.swift index d83b7e9029..9e8e35a5c9 100644 --- a/test/starlark_tests/resources/BasicFramework.swift +++ b/test/starlark_tests/resources/BasicFramework.swift @@ -13,6 +13,7 @@ // limitations under the License. import Foundation + public class BasicFramework { public init() {} public func HelloWorld() { print("Hello World from Basic Framework") } diff --git a/test/starlark_tests/resources/DirectDependencyTest.swift b/test/starlark_tests/resources/DirectDependencyTest.swift index eff25b0e59..585b2cb92d 100644 --- a/test/starlark_tests/resources/DirectDependencyTest.swift +++ b/test/starlark_tests/resources/DirectDependencyTest.swift @@ -14,6 +14,7 @@ import Foundation import BasicFramework + public class DirectDependencyTest { public init() {} public func directDependencyTest() { diff --git a/test/starlark_tests/targets_under_test/ios/BUILD b/test/starlark_tests/targets_under_test/ios/BUILD index c777b5ff70..37242aa022 100644 --- a/test/starlark_tests/targets_under_test/ios/BUILD +++ b/test/starlark_tests/targets_under_test/ios/BUILD @@ -2197,4 +2197,4 @@ ios_application( deps = [ "//test/starlark_tests/resources:objc_main_lib", ], -) \ No newline at end of file +) diff --git a/test/starlark_tests/targets_under_test/macos/BUILD b/test/starlark_tests/targets_under_test/macos/BUILD index 8169ed890e..6d247a5cfe 100644 --- a/test/starlark_tests/targets_under_test/macos/BUILD +++ b/test/starlark_tests/targets_under_test/macos/BUILD @@ -746,4 +746,4 @@ macos_dynamic_framework( deps = [ ":basic_framework_with_transitive_dependency_lib", ], -) \ No newline at end of file +) diff --git a/test/starlark_tests/targets_under_test/tvos/BUILD b/test/starlark_tests/targets_under_test/tvos/BUILD index 9094b55075..69366b98af 100644 --- a/test/starlark_tests/targets_under_test/tvos/BUILD +++ b/test/starlark_tests/targets_under_test/tvos/BUILD @@ -551,4 +551,4 @@ tvos_dynamic_framework( deps = [ ":basic_framework_with_transitive_dependency_lib", ], -) \ No newline at end of file +) diff --git a/test/starlark_tests/targets_under_test/watchos/BUILD b/test/starlark_tests/targets_under_test/watchos/BUILD index 56055679db..9b129798a9 100644 --- a/test/starlark_tests/targets_under_test/watchos/BUILD +++ b/test/starlark_tests/targets_under_test/watchos/BUILD @@ -452,4 +452,4 @@ watchos_dynamic_framework( deps = [ ":basic_framework_with_transitive_dependency_lib", ], -) \ No newline at end of file +) diff --git a/test/starlark_tests/tvos_dynamic_framework_tests.bzl b/test/starlark_tests/tvos_dynamic_framework_tests.bzl index 499321c280..6bcac23cfa 100644 --- a/test/starlark_tests/tvos_dynamic_framework_tests.bzl +++ b/test/starlark_tests/tvos_dynamic_framework_tests.bzl @@ -110,4 +110,4 @@ def tvos_dynamic_framework_test_suite(name = "tvos_dynamic_framework"): native.test_suite( name = name, tags = [name], - ) \ No newline at end of file + ) diff --git a/test/starlark_tests/watchos_dynamic_framework_tests.bzl b/test/starlark_tests/watchos_dynamic_framework_tests.bzl index 1ecb445caa..a9e7981edb 100644 --- a/test/starlark_tests/watchos_dynamic_framework_tests.bzl +++ b/test/starlark_tests/watchos_dynamic_framework_tests.bzl @@ -108,4 +108,4 @@ def watchos_dynamic_framework_test_suite(name = "watchos_dynamic_framework"): native.test_suite( name = name, tags = [name], - ) \ No newline at end of file + ) From 9c18251279b381dbf3744763124ff17697d34d8e Mon Sep 17 00:00:00 2001 From: mccorkill1 <69316216+mccorkill1@users.noreply.github.com> Date: Thu, 19 Nov 2020 16:42:25 -0500 Subject: [PATCH 11/26] Update apple/internal/tvos_rules.bzl Co-authored-by: Brentley Jones --- apple/internal/tvos_rules.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index 2b58c09d29..8ba87f59db 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -886,7 +886,7 @@ tvos_dynamic_framework = rule_factory.create_apple_bundling_rule( implementation = _tvos_dynamic_framework_impl, platform_type = "tvos", product_type = apple_product_type.framework, - doc = "Builds and bundles a tvOS dynamic framework.", + doc = "Builds and bundles a tvOS dynamic framework that is consumable by Xcode.", ) tvos_extension = rule_factory.create_apple_bundling_rule( implementation = _tvos_extension_impl, From 9962f78bc75708848b69184fddb4bb1f53a1da5b Mon Sep 17 00:00:00 2001 From: mccorkill1 <69316216+mccorkill1@users.noreply.github.com> Date: Thu, 19 Nov 2020 16:45:21 -0500 Subject: [PATCH 12/26] Update apple/internal/watchos_rules.bzl Co-authored-by: Brentley Jones --- apple/internal/watchos_rules.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/internal/watchos_rules.bzl b/apple/internal/watchos_rules.bzl index 1d87be8818..306bd21703 100644 --- a/apple/internal/watchos_rules.bzl +++ b/apple/internal/watchos_rules.bzl @@ -631,5 +631,5 @@ watchos_dynamic_framework = rule_factory.create_apple_bundling_rule( implementation = _watchos_dynamic_framework_impl, platform_type = "watchos", product_type = apple_product_type.framework, - doc = "Builds and bundles an iOS Dynamic Framework consumable in Xcode.", + doc = "Builds and bundles a watchOS dynamic framework that is consumable by Xcode.", ) From 4cba74545f1257184386b56532421f6cd2f853b4 Mon Sep 17 00:00:00 2001 From: mccorkill1 <69316216+mccorkill1@users.noreply.github.com> Date: Thu, 19 Nov 2020 16:45:59 -0500 Subject: [PATCH 13/26] Update apple/ios.bzl Co-authored-by: Brentley Jones --- apple/ios.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/ios.bzl b/apple/ios.bzl index a540f474e0..ae31763b5d 100644 --- a/apple/ios.bzl +++ b/apple/ios.bzl @@ -128,7 +128,7 @@ def ios_framework(name, **kwargs): def ios_dynamic_framework(name, **kwargs): # buildifier: disable=function-docstring-args - """Builds and bundles an iOS dynamic framework.""" + """Builds and bundles an iOS dynamic framework that is consumable by Xcode.""" binary_args = dict(kwargs) # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking From 928becdeb082bde693ef7c3985d8ae4ac4c807ad Mon Sep 17 00:00:00 2001 From: mccorkill1 <69316216+mccorkill1@users.noreply.github.com> Date: Thu, 19 Nov 2020 16:48:33 -0500 Subject: [PATCH 14/26] Update apple/macos.bzl Co-authored-by: Brentley Jones --- apple/macos.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/macos.bzl b/apple/macos.bzl index 3cd3a95571..330b985b5a 100644 --- a/apple/macos.bzl +++ b/apple/macos.bzl @@ -287,7 +287,7 @@ def macos_dylib(name, **kwargs): def macos_dynamic_framework(name, **kwargs): # buildifier: disable=function-docstring-args - """Builds and bundles an iOS dynamic framework.""" + """Builds and bundles a macOS dynamic framework that is consumable by Xcode.""" binary_args = dict(kwargs) # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking From b4d2e7cbe69f809eef39ab9ed53cc1a9e5202c39 Mon Sep 17 00:00:00 2001 From: mccorkill1 <69316216+mccorkill1@users.noreply.github.com> Date: Thu, 19 Nov 2020 16:49:12 -0500 Subject: [PATCH 15/26] Update apple/tvos.bzl Co-authored-by: Brentley Jones --- apple/tvos.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/tvos.bzl b/apple/tvos.bzl index dae8c9466c..891d239853 100644 --- a/apple/tvos.bzl +++ b/apple/tvos.bzl @@ -160,7 +160,7 @@ def tvos_ui_test(name, **kwargs): def tvos_dynamic_framework(name, **kwargs): # buildifier: disable=function-docstring-args - """Builds and bundles an iOS dynamic framework.""" + """Builds and bundles a tvOS dynamic framework that is consumable by Xcode.""" binary_args = dict(kwargs) # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking # API does not accept extra linkopts and link inputs. With those, it will be possible to merge From 611e242fd25e70d0b39692c60a4fbf50ce125302 Mon Sep 17 00:00:00 2001 From: mccorkill1 <69316216+mccorkill1@users.noreply.github.com> Date: Thu, 19 Nov 2020 16:50:19 -0500 Subject: [PATCH 16/26] Update apple/tvos.bzl Co-authored-by: Brentley Jones --- apple/tvos.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/apple/tvos.bzl b/apple/tvos.bzl index 891d239853..7bcce4cf7f 100644 --- a/apple/tvos.bzl +++ b/apple/tvos.bzl @@ -161,6 +161,7 @@ def tvos_ui_test(name, **kwargs): def tvos_dynamic_framework(name, **kwargs): # buildifier: disable=function-docstring-args """Builds and bundles a tvOS dynamic framework that is consumable by Xcode.""" + binary_args = dict(kwargs) # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking # API does not accept extra linkopts and link inputs. With those, it will be possible to merge From ed4615d13adaede812a24ea1743452f732a1c399 Mon Sep 17 00:00:00 2001 From: mccorkill1 <69316216+mccorkill1@users.noreply.github.com> Date: Thu, 19 Nov 2020 16:59:02 -0500 Subject: [PATCH 17/26] Apply suggestions from code review Co-authored-by: Brentley Jones --- apple/watchos.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/watchos.bzl b/apple/watchos.bzl index 9ad0f7df5f..29825e4d02 100644 --- a/apple/watchos.bzl +++ b/apple/watchos.bzl @@ -68,7 +68,7 @@ def watchos_extension(name, **kwargs): def watchos_dynamic_framework(name, **kwargs): # buildifier: disable=function-docstring-args - """Builds and bundles and watchOS dynamic framework.""" + """Builds and bundles a watchOS dynamic framework that is consumable by Xcode.""" binary_args = dict(kwargs) # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking From 383da658ab9c0544153498d31c8647af486705b8 Mon Sep 17 00:00:00 2001 From: XRV287 Date: Thu, 19 Nov 2020 17:26:07 -0500 Subject: [PATCH 18/26] Removing hdrs parameter support from the dynamic framework rules since they only support a single swift_library dependency right now. Also and addressing styling issues --- apple/internal/ios_rules.bzl | 1 - apple/internal/rule_factory.bzl | 30 ------------------- apple/internal/tvos_rules.bzl | 1 - apple/internal/watchos_rules.bzl | 1 - .../resources/TransitiveDependencyTest.swift | 1 + .../resources/Transitives.swift | 2 +- test/starlark_tests/resources/main.swift | 1 + 7 files changed, 3 insertions(+), 34 deletions(-) diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index 2b17c05208..b4a4d624c6 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -1013,7 +1013,6 @@ def _ios_dynamic_framework_impl(ctx): rule_label = label, targets_to_validate = ctx.attr.frameworks, ), - partials.framework_headers_partial(hdrs = ctx.files.hdrs), partials.framework_provider_partial( actions = actions, bin_root_path = bin_root_path, diff --git a/apple/internal/rule_factory.bzl b/apple/internal/rule_factory.bzl index c46fb32f43..849e6e082c 100644 --- a/apple/internal/rule_factory.bzl +++ b/apple/internal/rule_factory.bzl @@ -928,36 +928,6 @@ ignored. """, ), }) - elif rule_descriptor.product_type == apple_product_type.framework: - attrs.append({ - # TODO: This attribute is not publicly documented, but it is tested in - # http://github.com/bazelbuild/rules_apple/test/ios_framework_test.sh?l=79. Figure out - # what to do with this. - "hdrs": attr.label_list( - allow_files = [".h"], - ), - "extension_safe": attr.bool( - default = False, - doc = """ - If true, compiles and links this framework with `-application-extension`, restricting the binary to - use only extension-safe APIs. - """, - ), - }) - - if rule_descriptor.requires_deps: - extra_args = {} - attrs.append({ - "frameworks": attr.label_list( - providers = [[AppleBundleInfo, IosFrameworkBundleInfo]], - doc = """ - A list of framework targets (see - [`ios_framework`](https://github.com/bazelbuild/rules_apple/blob/master/doc/rules-ios.md#ios_framework)) - that this target depends on. - """, - **extra_args - ), - }) return attrs diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index 2b58c09d29..9f7502730a 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -383,7 +383,6 @@ def _tvos_dynamic_framework_impl(ctx): rule_label = label, targets_to_validate = ctx.attr.frameworks, ), - partials.framework_headers_partial(hdrs = ctx.files.hdrs), partials.framework_provider_partial( actions = actions, bin_root_path = bin_root_path, diff --git a/apple/internal/watchos_rules.bzl b/apple/internal/watchos_rules.bzl index 1d87be8818..217142a22f 100644 --- a/apple/internal/watchos_rules.bzl +++ b/apple/internal/watchos_rules.bzl @@ -187,7 +187,6 @@ def _watchos_dynamic_framework_impl(ctx): rule_label = label, targets_to_validate = ctx.attr.frameworks, ), - partials.framework_headers_partial(hdrs = ctx.files.hdrs), partials.framework_provider_partial( actions = actions, bin_root_path = bin_root_path, diff --git a/test/starlark_tests/resources/TransitiveDependencyTest.swift b/test/starlark_tests/resources/TransitiveDependencyTest.swift index aa98eb03ad..63d72e9121 100644 --- a/test/starlark_tests/resources/TransitiveDependencyTest.swift +++ b/test/starlark_tests/resources/TransitiveDependencyTest.swift @@ -15,6 +15,7 @@ import Foundation import BasicFramework import DirectDependencyTest + public class TransitiveDependencyTest { public init() {} public func TransitiveDependencyTest() { diff --git a/test/starlark_tests/resources/Transitives.swift b/test/starlark_tests/resources/Transitives.swift index ed52f284d4..e74705a8b5 100644 --- a/test/starlark_tests/resources/Transitives.swift +++ b/test/starlark_tests/resources/Transitives.swift @@ -34,4 +34,4 @@ public class Transitives { public init() {} public func doSomethingShared() { print("Something shared from transitives") } public func doSomethingCommon() { print("Something common from transitives") } -} \ No newline at end of file +} diff --git a/test/starlark_tests/resources/main.swift b/test/starlark_tests/resources/main.swift index 6d09021215..c4f2b3c446 100644 --- a/test/starlark_tests/resources/main.swift +++ b/test/starlark_tests/resources/main.swift @@ -13,6 +13,7 @@ // limitations under the License. import Foundation + public class main { public init() {} public func main() { print("Hello from main") } From bc8c1ada8ad64f677bf244706454f5f54399789e Mon Sep 17 00:00:00 2001 From: XRV287 Date: Thu, 19 Nov 2020 22:22:29 -0500 Subject: [PATCH 19/26] Adding back in framework support to fix CI --- apple/internal/rule_factory.bzl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/apple/internal/rule_factory.bzl b/apple/internal/rule_factory.bzl index 849e6e082c..c46fb32f43 100644 --- a/apple/internal/rule_factory.bzl +++ b/apple/internal/rule_factory.bzl @@ -928,6 +928,36 @@ ignored. """, ), }) + elif rule_descriptor.product_type == apple_product_type.framework: + attrs.append({ + # TODO: This attribute is not publicly documented, but it is tested in + # http://github.com/bazelbuild/rules_apple/test/ios_framework_test.sh?l=79. Figure out + # what to do with this. + "hdrs": attr.label_list( + allow_files = [".h"], + ), + "extension_safe": attr.bool( + default = False, + doc = """ + If true, compiles and links this framework with `-application-extension`, restricting the binary to + use only extension-safe APIs. + """, + ), + }) + + if rule_descriptor.requires_deps: + extra_args = {} + attrs.append({ + "frameworks": attr.label_list( + providers = [[AppleBundleInfo, IosFrameworkBundleInfo]], + doc = """ + A list of framework targets (see + [`ios_framework`](https://github.com/bazelbuild/rules_apple/blob/master/doc/rules-ios.md#ios_framework)) + that this target depends on. + """, + **extra_args + ), + }) return attrs From fc2760507e6a747c5f9a130f74ba1b185231301c Mon Sep 17 00:00:00 2001 From: XRV287 Date: Mon, 23 Nov 2020 17:57:07 -0500 Subject: [PATCH 20/26] Removed hdrs support from watchos since it isn't needed for the watchos_dynamic_framework rule at this time --- apple/internal/rule_factory.bzl | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apple/internal/rule_factory.bzl b/apple/internal/rule_factory.bzl index c46fb32f43..303f75ed70 100644 --- a/apple/internal/rule_factory.bzl +++ b/apple/internal/rule_factory.bzl @@ -930,12 +930,6 @@ ignored. }) elif rule_descriptor.product_type == apple_product_type.framework: attrs.append({ - # TODO: This attribute is not publicly documented, but it is tested in - # http://github.com/bazelbuild/rules_apple/test/ios_framework_test.sh?l=79. Figure out - # what to do with this. - "hdrs": attr.label_list( - allow_files = [".h"], - ), "extension_safe": attr.bool( default = False, doc = """ From d933cb9cfb412d2cdbe37a3948b055cc3c9d397c Mon Sep 17 00:00:00 2001 From: XRV287 Date: Thu, 3 Dec 2020 15:44:09 -0500 Subject: [PATCH 21/26] Removed macos_dynamic_framework support to go in a separate PR. Also moved off SwiftInfo.transitive_swift* in the swift_dynamic_framework_aspect --- .../swift_dynamic_framework_aspect.bzl | 12 +- apple/internal/macos_rules.bzl | 158 ------------------ apple/internal/rule_support.bzl | 16 -- apple/macos.bzl | 31 ---- test/starlark_tests/BUILD | 3 - .../macos_dynamic_framework_tests.bzl | 111 ------------ .../targets_under_test/macos/BUILD | 101 ----------- .../targets_under_test/watchos/BUILD | 2 - 8 files changed, 10 insertions(+), 424 deletions(-) delete mode 100644 test/starlark_tests/macos_dynamic_framework_tests.bzl diff --git a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl index c9cee2b8b3..1e5bd7758e 100644 --- a/apple/internal/aspects/swift_dynamic_framework_aspect.bzl +++ b/apple/internal/aspects/swift_dynamic_framework_aspect.bzl @@ -108,8 +108,16 @@ single swift_library dependency.\ module_name = swiftinfo.module_name arch = _swift_arch_for_dep(dep) - swiftdocs[arch] = swiftinfo.transitive_swiftdocs.to_list().pop() - swiftmodules[arch] = swiftinfo.transitive_swiftmodules.to_list().pop() + swiftmodule = None + swiftdoc = None + for module in swiftinfo.transitive_modules.to_list(): + if not module.swift: + continue + swiftmodule = module.swift.swiftmodule + swiftdoc = module.swift.swiftdoc + + swiftdocs[arch] = swiftdoc + swiftmodules[arch] = swiftmodule modulemap_file = ctx.actions.declare_file("{}_file.modulemap".format(module_name)) ctx.actions.write(modulemap_file, _modulemap_contents(module_name)) diff --git a/apple/internal/macos_rules.bzl b/apple/internal/macos_rules.bzl index 7b0986a040..ad23755fe6 100644 --- a/apple/internal/macos_rules.bzl +++ b/apple/internal/macos_rules.bzl @@ -14,10 +14,6 @@ """Implementation of macOS rules.""" -load( - "@build_bazel_rules_apple//apple/internal/aspects:swift_dynamic_framework_aspect.bzl", - "SwiftDynamicFrameworkInfo", -) load( "@build_bazel_rules_apple//apple/internal:apple_product_type.bzl", "apple_product_type", @@ -1287,153 +1283,6 @@ def _macos_dylib_impl(ctx): link_result.binary_provider, ] + processor_result.providers -def _macos_dynamic_framework_impl(ctx): - """Experimental implementation of macos_dynamic_framework.""" - - deps_list = [deps for deps in ctx.attr.deps] - binary_target = deps_list.pop() - link_result = linking_support.register_linking_action(ctx) - binary_artifact = link_result.binary_provider.binary - debug_outputs_provider = link_result.debug_outputs_provider - - actions = ctx.actions - bin_root_path = ctx.bin_dir.path - bundle_id = ctx.attr.bundle_id - bundle_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) - entitlements = entitlements_support.entitlements( - entitlements_attr = getattr(ctx.attr, "entitlements", None), - entitlements_file = getattr(ctx.file, "entitlements", None), - ) - executable_name = bundling_support.executable_name(ctx) - features = features_support.compute_enabled_features( - requested_features = ctx.features, - unsupported_features = ctx.disabled_features, - ) - label = ctx.label - platform_prerequisites = platform_support.platform_prerequisites_from_rule_ctx(ctx) - predeclared_outputs = ctx.outputs - rule_descriptor = rule_support.rule_descriptor(ctx) - rule_executables = ctx.executable - - signed_frameworks = [] - if getattr(ctx.file, "provisioning_profile", None): - signed_frameworks = [ - bundle_name + rule_descriptor.bundle_extension, - ] - - archive = outputs.archive( - actions = actions, - bundle_extension = bundle_extension, - bundle_name = bundle_name, - platform_prerequisites = platform_prerequisites, - predeclared_outputs = predeclared_outputs, - ) - - processor_partials = [ - partials.apple_bundle_info_partial( - actions = actions, - bundle_extension = bundle_extension, - bundle_id = bundle_id, - bundle_name = bundle_name, - executable_name = executable_name, - entitlements = entitlements, - label_name = label.name, - platform_prerequisites = platform_prerequisites, - predeclared_outputs = predeclared_outputs, - product_type = rule_descriptor.product_type, - ), - partials.binary_partial( - actions = actions, - binary_artifact = binary_artifact, - executable_name = executable_name, - label_name = label.name, - ), - partials.clang_rt_dylibs_partial( - actions = actions, - binary_artifact = binary_artifact, - clangrttool = ctx.executable._clangrttool, - features = features, - label_name = label.name, - platform_prerequisites = platform_prerequisites, - ), - partials.debug_symbols_partial( - actions = actions, - bin_root_path = bin_root_path, - bundle_extension = bundle_extension, - bundle_name = bundle_name, - debug_outputs_provider = debug_outputs_provider, - dsym_info_plist_template = ctx.file._dsym_info_plist_template, - executable_name = executable_name, - platform_prerequisites = platform_prerequisites, - rule_label = label, - ), - partials.embedded_bundles_partial( - frameworks = [archive], - platform_prerequisites = platform_prerequisites, - signed_frameworks = depset(signed_frameworks), - ), - partials.framework_provider_partial( - actions = actions, - bin_root_path = bin_root_path, - binary_provider = link_result.binary_provider, - bundle_name = bundle_name, - rule_label = label, - ), - partials.resources_partial( - actions = actions, - bundle_extension = bundle_extension, - bundle_id = bundle_id, - bundle_name = bundle_name, - environment_plist = ctx.file._environment_plist, - executable_name = executable_name, - launch_storyboard = None, - platform_prerequisites = platform_prerequisites, - plist_attrs = ["infoplists"], - rule_attrs = ctx.attr, - rule_descriptor = rule_descriptor, - rule_executables = rule_executables, - rule_label = label, - top_level_attrs = ["resources"], - version_keys_required = False, - ), - partials.swift_dylibs_partial( - actions = actions, - binary_artifact = binary_artifact, - label_name = label.name, - platform_prerequisites = platform_prerequisites, - swift_stdlib_tool = ctx.executable._swift_stdlib_tool, - ), - partials.swift_dynamic_framework_partial( - swift_dynamic_framework_info = binary_target[SwiftDynamicFrameworkInfo], - ), - ] - - processor_result = processor.process( - ctx = ctx, - actions = actions, - bundle_extension = bundle_extension, - bundle_name = bundle_name, - entitlements = entitlements, - executable_name = executable_name, - partials = processor_partials, - platform_prerequisites = platform_prerequisites, - predeclared_outputs = predeclared_outputs, - provisioning_profile = getattr(ctx.file, "provisioning_profile", None), - rule_descriptor = rule_descriptor, - rule_executables = rule_executables, - rule_label = label, - ) - - return [ - DefaultInfo(files = processor_result.output_files), - OutputGroupInfo( - **outputs.merge_output_groups( - link_result.output_groups, - processor_result.output_groups, - ) - ), - ] + processor_result.providers - macos_application = rule_factory.create_apple_bundling_rule( implementation = _macos_application_impl, platform_type = "macos", @@ -1448,13 +1297,6 @@ macos_bundle = rule_factory.create_apple_bundling_rule( doc = "Builds and bundles a macOS Loadable Bundle.", ) -macos_dynamic_framework = rule_factory.create_apple_bundling_rule( - implementation = _macos_dynamic_framework_impl, - platform_type = "macos", - product_type = apple_product_type.framework, - doc = "Builds and bundles a macOS Dynamic Framework that is consumable by Xcode.", -) - macos_extension = rule_factory.create_apple_bundling_rule( implementation = _macos_extension_impl, platform_type = "macos", diff --git a/apple/internal/rule_support.bzl b/apple/internal/rule_support.bzl index 4e53d530f5..8411f2ba3e 100644 --- a/apple/internal/rule_support.bzl +++ b/apple/internal/rule_support.bzl @@ -467,22 +467,6 @@ _RULE_TYPE_DESCRIPTORS = { "@executable_path/../../../../Frameworks", ], ), - # macos_framework - apple_product_type.framework: _describe_rule_type( - allowed_device_families = ["mac"], - binary_type = "dylib", - bundle_extension = ".framework", - bundle_package_type = bundle_package_type.framework, - codesigning_exceptions = _CODESIGNING_EXCEPTIONS.sign_with_provisioning_profile, - deps_cfg = apple_common.multi_arch_split, - product_type = apple_product_type.framework, - rpaths = [ - # Framework binaries live in - # Application.app/Contents/Frameworks/Framework.framework/Framework - # Frameworks are packaged in Application.app/Contents/Frameworks - "@executable_path/Frameworks", - ], - ), # macos_quick_look_plugin apple_product_type.quicklook_plugin: _describe_rule_type( allowed_device_families = ["mac"], diff --git a/apple/macos.bzl b/apple/macos.bzl index 330b985b5a..2f2fd547cc 100644 --- a/apple/macos.bzl +++ b/apple/macos.bzl @@ -48,7 +48,6 @@ load( _macos_bundle = "macos_bundle", _macos_command_line_application = "macos_command_line_application", _macos_dylib = "macos_dylib", - _macos_dynamic_framework = "macos_dynamic_framework", _macos_extension = "macos_extension", _macos_kernel_extension = "macos_kernel_extension", _macos_quick_look_plugin = "macos_quick_look_plugin", @@ -285,36 +284,6 @@ def macos_dylib(name, **kwargs): **dylib_args ) -def macos_dynamic_framework(name, **kwargs): - # buildifier: disable=function-docstring-args - """Builds and bundles a macOS dynamic framework that is consumable by Xcode.""" - - binary_args = dict(kwargs) - # TODO(b/120861201): The linkopts macro additions here only exist because the Starlark linking - # API does not accept extra linkopts and link inputs. With those, it will be possible to merge - # these workarounds into the rule implementations. - linkopts = binary_args.pop("linkopts", []) - bundle_name = binary_args.get("bundle_name", name) - linkopts += ["-install_name", "@rpath/%s.framework/%s" % (bundle_name, bundle_name)] - binary_args["linkopts"] = linkopts - bundling_args = binary_support.add_entitlements_and_swift_linkopts( - name, - include_entitlements = False, - platform_type = str(apple_common.platform_type.macos), - product_type = apple_product_type.framework, - exported_symbols_lists = binary_args.pop("exported_symbols_lists", None), - **binary_args - ) - - # Remove any kwargs that shouldn't be passed to the underlying rule. - bundling_args.pop("entitlements", None) - - _macos_dynamic_framework( - name = name, - extension_safe = kwargs.get("extension_safe"), - **bundling_args - ) - def macos_extension(name, **kwargs): # buildifier: disable=function-docstring-args """Packages a macOS Extension Bundle.""" diff --git a/test/starlark_tests/BUILD b/test/starlark_tests/BUILD index 1254cdc6c0..b11c82d8a6 100644 --- a/test/starlark_tests/BUILD +++ b/test/starlark_tests/BUILD @@ -16,7 +16,6 @@ load(":macos_application_tests.bzl", "macos_application_test_suite") load(":macos_bundle_tests.bzl", "macos_bundle_test_suite") load(":macos_command_line_application_tests.bzl", "macos_command_line_application_test_suite") load(":macos_dylib_tests.bzl", "macos_dylib_test_suite") -load(":macos_dynamic_framework_tests.bzl", "macos_dynamic_framework_test_suite") load(":macos_extension_tests.bzl", "macos_extension_test_suite") load(":macos_kernel_extension_tests.bzl", "macos_kernel_extension_test_suite") load(":macos_quick_look_plugin_tests.bzl", "macos_quick_look_plugin_test_suite") @@ -71,8 +70,6 @@ macos_command_line_application_test_suite() macos_dylib_test_suite() -macos_dynamic_framework_test_suite() - macos_extension_test_suite() macos_kernel_extension_test_suite() diff --git a/test/starlark_tests/macos_dynamic_framework_tests.bzl b/test/starlark_tests/macos_dynamic_framework_tests.bzl deleted file mode 100644 index 8bcde88535..0000000000 --- a/test/starlark_tests/macos_dynamic_framework_tests.bzl +++ /dev/null @@ -1,111 +0,0 @@ -# Copyright 2019 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""macos_dynamic_framework Starlark tests.""" - -load( - ":rules/common_verification_tests.bzl", - "archive_contents_test", -) -load( - ":rules/infoplist_contents_test.bzl", - "infoplist_contents_test", -) - -def macos_dynamic_framework_test_suite(name = "macos_dynamic_framework"): - """Test suite for macos_dynamic_framework. - - Args: - name: The name prefix for all the nested tests - """ - - archive_contents_test( - name = "{}_archive_contents_test".format(name), - build_type = "simulator", - target_under_test = "//test/starlark_tests/targets_under_test/macos:basic_framework", - binary_test_file = "$BUNDLE_ROOT/BasicFramework", - binary_test_architecture = "x86_64", - macho_load_commands_contain = ["name @rpath/BasicFramework.framework/BasicFramework (offset 24)"], - contains = [ - "$BUNDLE_ROOT/BasicFramework", - "$BUNDLE_ROOT/Headers/BasicFramework.h", - "$BUNDLE_ROOT/Info.plist", - "$BUNDLE_ROOT/Modules/module.modulemap", - "$BUNDLE_ROOT/Modules/BasicFramework.swiftmodule/x86_64.swiftdoc", - "$BUNDLE_ROOT/Modules/BasicFramework.swiftmodule/x86_64.swiftmodule" - ], - tags = [name], - ) - - infoplist_contents_test( - name = "{}_plist_test".format(name), - target_under_test = "//test/starlark_tests/targets_under_test/macos:basic_framework", - expected_values = { - "BuildMachineOSBuild": "*", - "CFBundleExecutable": "BasicFramework", - "CFBundleIdentifier": "com.google.example.framework", - "CFBundleName": "BasicFramework", - "CFBundleSupportedPlatforms:0": "MacOSX*", - "DTCompiler": "com.apple.compilers.llvm.clang.1_0", - "DTPlatformBuild": "*", - "DTPlatformName": "macosx*", - "DTPlatformVersion": "*", - "DTSDKBuild": "*", - "DTSDKName": "macosx*", - "DTXcode": "*", - "DTXcodeBuild": "*", - }, - tags = [name], - ) - - archive_contents_test( - name = "{}_direct_dependency_archive_contents_test".format(name), - build_type = "simulator", - target_under_test = "//test/starlark_tests/targets_under_test/macos:basic_framework_with_direct_dependency", - binary_test_file = "$BUNDLE_ROOT/DirectDependencyTest", - binary_test_architecture = "x86_64", - macho_load_commands_contain = ["name @rpath/DirectDependencyTest.framework/DirectDependencyTest (offset 24)"], - contains = [ - "$BUNDLE_ROOT/DirectDependencyTest", - "$BUNDLE_ROOT/Headers/DirectDependencyTest.h", - "$BUNDLE_ROOT/Info.plist", - "$BUNDLE_ROOT/Modules/module.modulemap", - "$BUNDLE_ROOT/Modules/DirectDependencyTest.swiftmodule/x86_64.swiftdoc", - "$BUNDLE_ROOT/Modules/DirectDependencyTest.swiftmodule/x86_64.swiftmodule" - ], - tags = [name], - ) - - archive_contents_test( - name = "{}_transitive_dependency_archive_contents_test".format(name), - build_type = "simulator", - target_under_test = "//test/starlark_tests/targets_under_test/macos:basic_framework_with_transitive_dependency", - binary_test_file = "$BUNDLE_ROOT/TransitiveDependencyTest", - binary_test_architecture = "x86_64", - macho_load_commands_contain = ["name @rpath/TransitiveDependencyTest.framework/TransitiveDependencyTest (offset 24)"], - contains = [ - "$BUNDLE_ROOT/TransitiveDependencyTest", - "$BUNDLE_ROOT/Headers/TransitiveDependencyTest.h", - "$BUNDLE_ROOT/Info.plist", - "$BUNDLE_ROOT/Modules/module.modulemap", - "$BUNDLE_ROOT/Modules/TransitiveDependencyTest.swiftmodule/x86_64.swiftdoc", - "$BUNDLE_ROOT/Modules/TransitiveDependencyTest.swiftmodule/x86_64.swiftmodule" - ], - tags = [name], - ) - - native.test_suite( - name = name, - tags = [name], - ) diff --git a/test/starlark_tests/targets_under_test/macos/BUILD b/test/starlark_tests/targets_under_test/macos/BUILD index 0245d8cb7c..01275237b0 100644 --- a/test/starlark_tests/targets_under_test/macos/BUILD +++ b/test/starlark_tests/targets_under_test/macos/BUILD @@ -5,7 +5,6 @@ load( "macos_bundle", "macos_command_line_application", "macos_dylib", - "macos_dynamic_framework", "macos_extension", "macos_kernel_extension", "macos_quick_look_plugin", @@ -21,7 +20,6 @@ load( "//test/testdata/frameworks:generate_framework.bzl", "generate_import_framework", ) -load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") licenses(["notice"]) @@ -563,102 +561,3 @@ macos_unit_test( "//test/starlark_tests/resources:objc_test_lib", ], ) - -# --------------------------------------------------------------------------------------- - -swift_library( - name = "basic_framework_lib", - module_name = "BasicFramework", - srcs = [ - "//test/starlark_tests/resources:BasicFramework.swift", - ], - visibility = ["//visibility:public"], - features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], -) - -macos_dynamic_framework( - name = "basic_framework", - bundle_name = "BasicFramework", - bundle_id = "com.google.example.framework", - infoplists = [ - "//test/starlark_tests/resources:Info.plist", - ], - minimum_os_version = "10.10", - tags = [ - "manual", - "notap", - ], - deps = [ - ":basic_framework_lib", - ], -) - -swift_library( - name = "basic_framework_with_direct_dependency_lib", - module_name = "DirectDependencyTest", - srcs = [ - "//test/starlark_tests/resources:DirectDependencyTest.swift", - ], - visibility = ["//visibility:public"], - deps = [ - ":basic_framework_lib", - ], - features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], -) - -macos_dynamic_framework( - name = "basic_framework_with_direct_dependency", - bundle_name = "DirectDependencyTest", - bundle_id = "com.google.example.framework", - infoplists = [ - "//test/starlark_tests/resources:Info.plist", - ], - minimum_os_version = "10.10", - tags = [ - "manual", - "notap", - ], - deps = [ - ":basic_framework_with_direct_dependency_lib", - ], -) - -swift_library( - name = "basic_framework_with_transitive_dependency_lib", - module_name = "TransitiveDependencyTest", - srcs = [ - "//test/starlark_tests/resources:TransitiveDependencyTest.swift", - ], - visibility = ["//visibility:public"], - deps = [ - ":basic_framework_lib", - ":basic_framework_with_direct_dependency_lib", - ], - features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], -) - -macos_dynamic_framework( - name = "basic_framework_with_transitive_dependency", - bundle_name = "TransitiveDependencyTest", - bundle_id = "com.google.example.framework", - infoplists = [ - "//test/starlark_tests/resources:Info.plist", - ], - minimum_os_version = "10.10", - tags = [ - "manual", - "notap", - ], - deps = [ - ":basic_framework_with_transitive_dependency_lib", - ], -) diff --git a/test/starlark_tests/targets_under_test/watchos/BUILD b/test/starlark_tests/targets_under_test/watchos/BUILD index 042cc46082..9bf5d9b69e 100644 --- a/test/starlark_tests/targets_under_test/watchos/BUILD +++ b/test/starlark_tests/targets_under_test/watchos/BUILD @@ -347,7 +347,6 @@ swift_library( module_name = "DirectDependencyTest", srcs = [ "//test/starlark_tests/resources:DirectDependencyTest.swift", - # "//test/starlark_tests/resources:main.swift", ], visibility = ["//visibility:public"], deps = [ @@ -381,7 +380,6 @@ swift_library( module_name = "TransitiveDependencyTest", srcs = [ "//test/starlark_tests/resources:TransitiveDependencyTest.swift", - # "//test/starlark_tests/resources:main.swift", ], visibility = ["//visibility:public"], deps = [ From 436776253483ee498630eec254c62a18925f32a1 Mon Sep 17 00:00:00 2001 From: XRV287 Date: Thu, 3 Dec 2020 16:11:02 -0500 Subject: [PATCH 22/26] fixed tags --- test/starlark_tests/resources/BUILD | 20 +++++-------------- .../targets_under_test/ios/BUILD | 12 +++-------- .../targets_under_test/tvos/BUILD | 12 +++-------- .../targets_under_test/watchos/BUILD | 12 +++-------- 4 files changed, 14 insertions(+), 42 deletions(-) diff --git a/test/starlark_tests/resources/BUILD b/test/starlark_tests/resources/BUILD index 13b7fb4bce..65c3e6b9e8 100644 --- a/test/starlark_tests/resources/BUILD +++ b/test/starlark_tests/resources/BUILD @@ -84,9 +84,7 @@ swift_library( ], testonly = True, features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) swift_library( @@ -95,9 +93,7 @@ swift_library( srcs = ["Common.swift"], testonly = True, features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) swift_library( @@ -109,9 +105,7 @@ swift_library( ], testonly = True, features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) swift_library( @@ -124,9 +118,7 @@ swift_library( ], testonly = True, features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) swift_library( @@ -139,9 +131,7 @@ swift_library( ], testonly = True, features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) swift_library( diff --git a/test/starlark_tests/targets_under_test/ios/BUILD b/test/starlark_tests/targets_under_test/ios/BUILD index 0b31ab4f0a..24fc783c46 100644 --- a/test/starlark_tests/targets_under_test/ios/BUILD +++ b/test/starlark_tests/targets_under_test/ios/BUILD @@ -1688,9 +1688,7 @@ swift_library( ], visibility = ["//visibility:public"], features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) ios_dynamic_framework( @@ -1725,9 +1723,7 @@ swift_library( ":basic_framework_lib", ], features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) ios_dynamic_framework( @@ -1763,9 +1759,7 @@ swift_library( ":basic_framework_with_direct_dependency_lib", ], features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) ios_dynamic_framework( diff --git a/test/starlark_tests/targets_under_test/tvos/BUILD b/test/starlark_tests/targets_under_test/tvos/BUILD index 78b428b27c..8a8624b6e0 100644 --- a/test/starlark_tests/targets_under_test/tvos/BUILD +++ b/test/starlark_tests/targets_under_test/tvos/BUILD @@ -404,9 +404,7 @@ swift_library( ], visibility = ["//visibility:public"], features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) tvos_dynamic_framework( @@ -437,9 +435,7 @@ swift_library( ":basic_framework_lib", ], features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) tvos_dynamic_framework( @@ -471,9 +467,7 @@ swift_library( ":basic_framework_with_direct_dependency_lib", ], features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) tvos_dynamic_framework( diff --git a/test/starlark_tests/targets_under_test/watchos/BUILD b/test/starlark_tests/targets_under_test/watchos/BUILD index 9bf5d9b69e..6fa841098d 100644 --- a/test/starlark_tests/targets_under_test/watchos/BUILD +++ b/test/starlark_tests/targets_under_test/watchos/BUILD @@ -320,9 +320,7 @@ swift_library( ], visibility = ["//visibility:public"], features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) watchos_dynamic_framework( @@ -353,9 +351,7 @@ swift_library( ":basic_framework_lib", ], features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) watchos_dynamic_framework( @@ -387,9 +383,7 @@ swift_library( ":basic_framework_with_direct_dependency_lib", ], features = ["swift.no_generated_module_map"], - tags = [ - "manual", - ], + tags = FIXTURE_TAGS, ) watchos_dynamic_framework( From 1a5a7f47528e21e63594043a3e1ccfad65b9a7fa Mon Sep 17 00:00:00 2001 From: XRV287 Date: Mon, 7 Dec 2020 10:20:34 -0500 Subject: [PATCH 23/26] Fix more tags --- .../targets_under_test/ios/BUILD | 55 ++++--------------- .../targets_under_test/tvos/BUILD | 15 +---- .../targets_under_test/watchos/BUILD | 15 +---- 3 files changed, 17 insertions(+), 68 deletions(-) diff --git a/test/starlark_tests/targets_under_test/ios/BUILD b/test/starlark_tests/targets_under_test/ios/BUILD index 24fc783c46..19c5b6df08 100644 --- a/test/starlark_tests/targets_under_test/ios/BUILD +++ b/test/starlark_tests/targets_under_test/ios/BUILD @@ -1703,10 +1703,7 @@ ios_dynamic_framework( "//test/starlark_tests/resources:Info.plist", ], minimum_os_version = "8.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ ":basic_framework_lib", ], @@ -1738,10 +1735,7 @@ ios_dynamic_framework( "//test/starlark_tests/resources:Info.plist", ], minimum_os_version = "8.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ ":basic_framework_with_direct_dependency_lib", ], @@ -1774,10 +1768,7 @@ ios_dynamic_framework( "//test/starlark_tests/resources:Info.plist", ], minimum_os_version = "8.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ ":basic_framework_with_transitive_dependency_lib", ], @@ -1796,10 +1787,7 @@ ios_dynamic_framework( ], linkopts = ["-application_extension"], minimum_os_version = "8.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ "//test/starlark_tests/resources:swift_lib_with_resources", ], @@ -1817,10 +1805,7 @@ ios_application( ], minimum_os_version = "11.0", provisioning_profile = "//test/testdata/provisioning:integration_testing_ios.mobileprovision", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ "//test/starlark_tests/resources:swift_lib_with_resources", "//test/starlark_tests/resources:objc_main_lib", @@ -1839,10 +1824,7 @@ ios_dynamic_framework( "//test/starlark_tests/resources:Info.plist", ], minimum_os_version = "8.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = ["//test/starlark_tests/resources:swift_common_lib"] ) @@ -1858,10 +1840,7 @@ ios_dynamic_framework( "//test/starlark_tests/resources:Info.plist", ], minimum_os_version = "8.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ "//test/starlark_tests/resources:swift_shared_lib", ] @@ -1880,10 +1859,7 @@ ios_dynamic_framework( "//test/starlark_tests/resources:Info.plist", ], minimum_os_version = "8.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = ["//test/starlark_tests/resources:swift_transitive_lib"] ) @@ -1899,10 +1875,7 @@ ios_application( "//test/starlark_tests/resources:Info.plist", ], minimum_os_version = "8.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ "//test/starlark_tests/resources:ios_non_localized_assets_lib", "//test/starlark_tests/resources:objc_main_lib", @@ -1920,10 +1893,7 @@ ios_dynamic_framework( "//test/starlark_tests/resources:Info.plist", ], minimum_os_version = "8.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ "//test/starlark_tests/resources:objc_lib_with_resources", "//test/testdata/frameworks:iOSImportedDynamicFramework", @@ -1942,10 +1912,7 @@ ios_application( ], minimum_os_version = "11.0", provisioning_profile = "//test/testdata/provisioning:integration_testing_ios.mobileprovision", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ "//test/starlark_tests/resources:objc_main_lib", ], diff --git a/test/starlark_tests/targets_under_test/tvos/BUILD b/test/starlark_tests/targets_under_test/tvos/BUILD index 8a8624b6e0..059a3cde96 100644 --- a/test/starlark_tests/targets_under_test/tvos/BUILD +++ b/test/starlark_tests/targets_under_test/tvos/BUILD @@ -415,10 +415,7 @@ tvos_dynamic_framework( "//test/starlark_tests/resources:Info.plist", ], minimum_os_version = "14.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ ":basic_framework_lib", ], @@ -446,10 +443,7 @@ tvos_dynamic_framework( "//test/starlark_tests/resources:Info.plist", ], minimum_os_version = "14.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ ":basic_framework_with_direct_dependency_lib", ], @@ -478,10 +472,7 @@ tvos_dynamic_framework( "//test/starlark_tests/resources:Info.plist", ], minimum_os_version = "14.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ ":basic_framework_with_transitive_dependency_lib", ], diff --git a/test/starlark_tests/targets_under_test/watchos/BUILD b/test/starlark_tests/targets_under_test/watchos/BUILD index 6fa841098d..d05b848425 100644 --- a/test/starlark_tests/targets_under_test/watchos/BUILD +++ b/test/starlark_tests/targets_under_test/watchos/BUILD @@ -331,10 +331,7 @@ watchos_dynamic_framework( "//test/starlark_tests/resources:Info-watchos.plist", ], minimum_os_version = "6.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ ":basic_framework_lib", ], @@ -362,10 +359,7 @@ watchos_dynamic_framework( "//test/starlark_tests/resources:Info-watchos.plist", ], minimum_os_version = "6.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ ":basic_framework_with_direct_dependency_lib", ], @@ -394,10 +388,7 @@ watchos_dynamic_framework( "//test/starlark_tests/resources:Info-watchos.plist", ], minimum_os_version = "6.0", - tags = [ - "manual", - "notap", - ], + tags = FIXTURE_TAGS, deps = [ ":basic_framework_with_transitive_dependency_lib", ], From 8f8eeb97510684db752167bead1ce3cfe48386ff Mon Sep 17 00:00:00 2001 From: XRV287 Date: Mon, 7 Dec 2020 15:39:45 -0500 Subject: [PATCH 24/26] Removed the need for ctx to be passed into the swift_dynamic_framework partial and updated how the binary_target is selected so it not dependent on the order of the deps_list --- apple/internal/ios_rules.bzl | 6 ++- .../partials/swift_dynamic_framework.bzl | 49 ++++++++++++------- apple/internal/tvos_rules.bzl | 6 ++- apple/internal/watchos_rules.bzl | 6 ++- 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/apple/internal/ios_rules.bzl b/apple/internal/ios_rules.bzl index b4a4d624c6..f5fd6a7ae7 100644 --- a/apple/internal/ios_rules.bzl +++ b/apple/internal/ios_rules.bzl @@ -906,8 +906,7 @@ def _ios_extension_impl(ctx): def _ios_dynamic_framework_impl(ctx): """Experimental implementation of ios_dynamic_framework.""" - deps_list = [deps for deps in ctx.attr.deps] - binary_target = deps_list.pop() + binary_target = [deps for deps in ctx.attr.deps if deps.label.name.endswith("swift_runtime_linkopts")][0] extra_linkopts = [] if ctx.attr.extension_safe: extra_linkopts.append("-fapplication-extension") @@ -1047,6 +1046,9 @@ def _ios_dynamic_framework_impl(ctx): swift_stdlib_tool = ctx.executable._swift_stdlib_tool, ), partials.swift_dynamic_framework_partial( + actions = actions, + bundle_name = bundle_name, + label_name = label.name, swift_dynamic_framework_info = binary_target[SwiftDynamicFrameworkInfo], ), ] diff --git a/apple/internal/partials/swift_dynamic_framework.bzl b/apple/internal/partials/swift_dynamic_framework.bzl index b35667620c..16d579491f 100644 --- a/apple/internal/partials/swift_dynamic_framework.bzl +++ b/apple/internal/partials/swift_dynamic_framework.bzl @@ -40,17 +40,21 @@ def _get_header_imports(framework_imports): return [file for file in framework_imports if file.short_path.endswith(".h")] -def _swift_dynamic_framework_partial_impl(ctx, swift_dynamic_framework_info): +def _swift_dynamic_framework_partial_impl( + *, + ctx, + actions, + bundle_name, + label_name, + swift_dynamic_framework_info): """Implementation for the Swift dynamic framework processing partial.""" - expected_module_name, bundle_extension = bundling_support.bundle_full_name_from_rule_ctx(ctx) - - if expected_module_name != swift_dynamic_framework_info.module_name: + if bundle_name != swift_dynamic_framework_info.module_name: fail(""" error: Found swift_library with module name {} but expected {}. Swift dynamic \ frameworks expect a single swift_library dependency with `module_name` set to the same \ `bundle_name` as the dynamic framework target.\ -""".format(swift_dynamic_framework_info.module_name, expected_module_name)) +""".format(swift_dynamic_framework_info.module_name, bundle_name)) generated_header = swift_dynamic_framework_info.generated_header swiftdocs = swift_dynamic_framework_info.swiftdocs @@ -58,43 +62,51 @@ frameworks expect a single swift_library dependency with `module_name` set to th modulemap_file = swift_dynamic_framework_info.modulemap bundle_files = [] - modules_parent = paths.join("Modules", "{}.swiftmodule".format(expected_module_name)) + modules_parent = paths.join("Modules", "{}.swiftmodule".format(bundle_name)) for arch, swiftdoc in swiftdocs.items(): - bundle_doc = intermediates.file(ctx.actions, ctx.label.name, "{}.swiftdoc".format(arch)) - ctx.actions.symlink(target_file = swiftdoc, output = bundle_doc) + bundle_doc = intermediates.file(actions, label_name, "{}.swiftdoc".format(arch)) + actions.symlink(target_file = swiftdoc, output = bundle_doc) bundle_files.append((processor.location.bundle, modules_parent, depset([bundle_doc]))) for arch, swiftmodule in swiftmodules.items(): - bundle_doc = intermediates.file(ctx.actions, ctx.label.name, "{}.swiftmodule".format(arch)) - ctx.actions.symlink(target_file = swiftmodule, output = bundle_doc) + bundle_doc = intermediates.file(actions, label_name, "{}.swiftmodule".format(arch)) + actions.symlink(target_file = swiftmodule, output = bundle_doc) bundle_files.append((processor.location.bundle, modules_parent, depset([bundle_doc]))) if generated_header: bundle_header = intermediates.file( - ctx.actions, - ctx.label.name, - "{}.h".format(expected_module_name), + actions, + label_name, + "{}.h".format(bundle_name), ) - ctx.actions.symlink(target_file = generated_header, output = bundle_header) + actions.symlink(target_file = generated_header, output = bundle_header) bundle_files.append((processor.location.bundle, "Headers", depset([bundle_header]))) if modulemap_file: - modulemap = intermediates.file(ctx.actions, ctx.label.name, "module.modulemap") - ctx.actions.symlink(target_file = modulemap_file, output = modulemap) + modulemap = intermediates.file(actions, label_name, "module.modulemap") + actions.symlink(target_file = modulemap_file, output = modulemap) bundle_files.append((processor.location.bundle, "Modules", depset([modulemap]))) return struct( bundle_files = bundle_files, ) -def swift_dynamic_framework_partial(swift_dynamic_framework_info): +def swift_dynamic_framework_partial( + *, + actions, + bundle_name, + label_name, + swift_dynamic_framework_info): """Constructor for the Swift dynamic framework processing partial. This partial collects and bundles the necessary files to construct a Swift based dynamic framework. Args: + actions: The actions provider from `ctx.actions`. + bundle_name: The name of the output bundle. + label_name: Name of the target being built. swift_dynamic_framework_info: The SwiftDynamicFrameworkInfo provider containing the required artifacts. @@ -104,5 +116,8 @@ def swift_dynamic_framework_partial(swift_dynamic_framework_info): """ return partial.make( _swift_dynamic_framework_partial_impl, + actions = actions, + bundle_name = bundle_name, + label_name = label_name, swift_dynamic_framework_info = swift_dynamic_framework_info, ) diff --git a/apple/internal/tvos_rules.bzl b/apple/internal/tvos_rules.bzl index ab08911abc..118fc9b312 100644 --- a/apple/internal/tvos_rules.bzl +++ b/apple/internal/tvos_rules.bzl @@ -286,8 +286,7 @@ def _tvos_application_impl(ctx): def _tvos_dynamic_framework_impl(ctx): """Experimental implementation of tvos_dynamic_framework.""" - deps_list = [deps for deps in ctx.attr.deps] - binary_target = deps_list.pop() + binary_target = [deps for deps in ctx.attr.deps if deps.label.name.endswith("swift_runtime_linkopts")][0] link_result = linking_support.register_linking_action(ctx) binary_artifact = link_result.binary_provider.binary debug_outputs_provider = link_result.debug_outputs_provider @@ -417,6 +416,9 @@ def _tvos_dynamic_framework_impl(ctx): swift_stdlib_tool = ctx.executable._swift_stdlib_tool, ), partials.swift_dynamic_framework_partial( + actions = actions, + bundle_name = bundle_name, + label_name = label.name, swift_dynamic_framework_info = binary_target[SwiftDynamicFrameworkInfo], ), ] diff --git a/apple/internal/watchos_rules.bzl b/apple/internal/watchos_rules.bzl index 2a2bbf6ed1..c3f616311d 100644 --- a/apple/internal/watchos_rules.bzl +++ b/apple/internal/watchos_rules.bzl @@ -80,8 +80,7 @@ load( def _watchos_dynamic_framework_impl(ctx): """Experimental implementation of watchos_dynamic_framework.""" - deps_list = [deps for deps in ctx.attr.deps] - binary_target = deps_list.pop() + binary_target = [deps for deps in ctx.attr.deps if deps.label.name.endswith("swift_runtime_linkopts")][0] extra_linkopts = [] if ctx.attr.extension_safe: extra_linkopts.append("-fapplication-extension") @@ -221,6 +220,9 @@ def _watchos_dynamic_framework_impl(ctx): swift_stdlib_tool = ctx.executable._swift_stdlib_tool, ), partials.swift_dynamic_framework_partial( + actions = actions, + bundle_name = bundle_name, + label_name = label.name, swift_dynamic_framework_info = binary_target[SwiftDynamicFrameworkInfo], ), ] From 999cdb401821bc53a231124bcb6092f48197f0af Mon Sep 17 00:00:00 2001 From: XRV287 Date: Mon, 7 Dec 2020 15:49:27 -0500 Subject: [PATCH 25/26] Fixing buildifier issue --- apple/internal/partials/swift_dynamic_framework.bzl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apple/internal/partials/swift_dynamic_framework.bzl b/apple/internal/partials/swift_dynamic_framework.bzl index 16d579491f..cb2e718627 100644 --- a/apple/internal/partials/swift_dynamic_framework.bzl +++ b/apple/internal/partials/swift_dynamic_framework.bzl @@ -14,10 +14,6 @@ """Partial implementation for Swift dynamic frameworks.""" -load( - "@build_bazel_rules_apple//apple/internal:bundling_support.bzl", - "bundling_support", -) load( "@build_bazel_rules_apple//apple/internal:intermediates.bzl", "intermediates", From a2c676a2bc12ba7f8ef729a79ad357f38373f989 Mon Sep 17 00:00:00 2001 From: XRV287 Date: Tue, 8 Dec 2020 11:33:11 -0500 Subject: [PATCH 26/26] Added TODO to remove context from the swift_dynamic_framework_partial when it is removed from all partials and fixed a comment --- apple/internal/partials/swift_dynamic_framework.bzl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apple/internal/partials/swift_dynamic_framework.bzl b/apple/internal/partials/swift_dynamic_framework.bzl index cb2e718627..b5a880ced6 100644 --- a/apple/internal/partials/swift_dynamic_framework.bzl +++ b/apple/internal/partials/swift_dynamic_framework.bzl @@ -36,6 +36,7 @@ def _get_header_imports(framework_imports): return [file for file in framework_imports if file.short_path.endswith(".h")] +# TODO(b/161370390): Remove ctx from the args when ctx is removed from all partials. def _swift_dynamic_framework_partial_impl( *, ctx, @@ -108,7 +109,7 @@ def swift_dynamic_framework_partial( Returns: A partial that returns the bundle location of the supporting Swift artifacts needed in a - Swift based static framework. + Swift based dynamic framework. """ return partial.make( _swift_dynamic_framework_partial_impl,