From a218312da283131996f0b14dcc5c02e8e674adf8 Mon Sep 17 00:00:00 2001 From: Luis Padron Date: Fri, 21 Jun 2024 13:12:47 -0400 Subject: [PATCH] Make it an error to specify both `swiftinterface` and `swiftmodule` in `swift_import` (#1253) --- doc/rules.md | 4 ++-- swift/swift_import.bzl | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/rules.md b/doc/rules.md index 0fcf4efc2..d4723e989 100644 --- a/doc/rules.md +++ b/doc/rules.md @@ -226,8 +226,8 @@ the `.private.swiftinterface` files are required in order to build any code that | archives | The list of `.a` files provided to Swift targets that depend on this target. | List of labels | optional | `[]` | | module_name | The name of the module represented by this target. | String | required | | | swiftdoc | The `.swiftdoc` file provided to Swift targets that depend on this target. | Label | optional | `None` | -| swiftinterface | The `.swiftinterface` file that defines the module interface for this target. The interface files are ignored if `swiftmodule` is specified. | Label | optional | `None` | -| swiftmodule | The `.swiftmodule` file provided to Swift targets that depend on this target. | Label | optional | `None` | +| swiftinterface | The `.swiftinterface` file that defines the module interface for this target. May not be specified if `swiftmodule` is specified. | Label | optional | `None` | +| swiftmodule | The `.swiftmodule` file provided to Swift targets that depend on this target. May not be specified if `swiftinterface` is specified. | Label | optional | `None` | diff --git a/swift/swift_import.bzl b/swift/swift_import.bzl index 8eb6ab9ec..8d3f9272f 100644 --- a/swift/swift_import.bzl +++ b/swift/swift_import.bzl @@ -46,9 +46,13 @@ def _swift_import_impl(ctx): ) if not (swiftinterface or swiftmodule): - fail("One or both of 'swiftinterface' and 'swiftmodule' must be " + + fail("One of 'swiftinterface' or 'swiftmodule' must be " + "specified.") + if swiftinterface and swiftmodule: + fail("'swiftinterface' may not be specified when " + + "'swiftmodule' is specified.") + swift_toolchain = swift_common.get_toolchain(ctx) feature_configuration = swift_common.configure_features( ctx = ctx, @@ -82,7 +86,7 @@ def _swift_import_impl(ctx): swift_infos = get_providers(deps, SwiftInfo) - if swiftinterface and not swiftmodule: + if swiftinterface: module_context = swift_common.compile_module_interface( actions = ctx.actions, compilation_contexts = get_compilation_contexts(ctx.attr.deps), @@ -97,9 +101,6 @@ def _swift_import_impl(ctx): module_context.swift.swiftmodule, ] + compact([module_context.swift.swiftdoc]) else: - # TODO: make this a failure in version 2.x - if swiftinterface: - print("WARNING: Provided `swiftinterface` attribute will be ignored because `swiftmodule` was provided. This will be an error in a future version of rules_swift.") # buildifier: disable=print module_context = swift_common.create_module( name = ctx.attr.module_name, clang = swift_common.create_clang_module( @@ -174,7 +175,7 @@ The `.swiftdoc` file provided to Swift targets that depend on this target. allow_single_file = ["swiftinterface"], doc = """\ The `.swiftinterface` file that defines the module interface for this target. -The interface files are ignored if `swiftmodule` is specified. +May not be specified if `swiftmodule` is specified. """, mandatory = False, ), @@ -182,6 +183,7 @@ The interface files are ignored if `swiftmodule` is specified. allow_single_file = ["swiftmodule"], doc = """\ The `.swiftmodule` file provided to Swift targets that depend on this target. +May not be specified if `swiftinterface` is specified. """, mandatory = False, ),