From eca50db5a95a50b2be8367d644aebf4d1d880c52 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Wed, 2 Dec 2020 08:26:26 -0800 Subject: [PATCH] Migration off SwiftInfo.module_name. - Make module alias use the direct modules instead with legacy fall back for the existing support. - Validate during creation of SwiftInfo that any provided module_name matches the first module (if any modules are provided). RELNOTES: None PiperOrigin-RevId: 345237478 (cherry picked from commit 46613b2f6056cfd9b0c491f72f1faa57c938e3db) --- swift/internal/providers.bzl | 2 ++ swift/internal/swift_module_alias.bzl | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/swift/internal/providers.bzl b/swift/internal/providers.bzl index e85dc13ad..d0fb34a08 100644 --- a/swift/internal/providers.bzl +++ b/swift/internal/providers.bzl @@ -350,6 +350,8 @@ def create_swift_info( # was one, and if the legacy `module_name` parameter wasn't already # given. module_name = modules[0].name + elif module_name and modules and module_name != modules[0].name: + fail("Explicit module name should be the first provided module.") transitive_defines = [] transitive_modules = [] diff --git a/swift/internal/swift_module_alias.bzl b/swift/internal/swift_module_alias.bzl index cff5a9abd..927daab86 100644 --- a/swift/internal/swift_module_alias.bzl +++ b/swift/internal/swift_module_alias.bzl @@ -29,11 +29,18 @@ load(":utils.bzl", "compact", "create_cc_info", "get_providers") def _swift_module_alias_impl(ctx): deps = ctx.attr.deps module_mapping = { - dep[SwiftInfo].module_name: dep.label + module.name: dep.label for dep in deps - if dep[SwiftInfo].module_name + for module in dep[SwiftInfo].direct_modules } + # TODO(b/149999519): remove the support for SwiftInfo.module_name that + # didn't have any direct_modules. + for dep in deps: + swift_info = dep[SwiftInfo] + if not swift_info.direct_modules and swift_info.module_name: + module_mapping[swift_info.module_name] = dep.label + module_name = ctx.attr.module_name if not module_name: module_name = swift_common.derive_module_name(ctx.label)