Skip to content

Commit 884a46e

Browse files
authored
Merge Swift and Clang entries in .swift-explicit-module-map.json (#1545)
In Swift 6.2, entries in `.swift-explicit-module-map.json` must have unique names, so Swift and Clang entries must be merged. swiftlang/swift@8dd9a12
1 parent bffd22a commit 884a46e

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

swift/internal/explicit_module_map_file.bzl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ def write_explicit_swift_module_map_file(
3232
module_contexts: A list of module contexts that provide the Swift
3333
dependencies for the compilation.
3434
"""
35-
module_descriptions = []
35+
module_descriptions = {}
3636

3737
for module_context in module_contexts:
38+
if module_context.name in module_descriptions:
39+
# As of Swift 6.2, only one entry per module is permitted.
40+
continue
41+
3842
# Set attributes that are applicable to a swift module entry or a
3943
# clang module entry
4044
module_description = {
@@ -47,30 +51,31 @@ def write_explicit_swift_module_map_file(
4751
module_description["isFramework"] = module_context.is_framework
4852

4953
# Append a swift moule entry if available
54+
has_swift_description = False
55+
5056
if module_context.swift:
5157
swift_context = module_context.swift
52-
swift_description = dict(module_description)
5358
if swift_context.swiftmodule:
54-
swift_description["modulePath"] = swift_context.swiftmodule.path
55-
module_descriptions.append(swift_description)
59+
has_swift_description = True
60+
module_description["modulePath"] = swift_context.swiftmodule.path
5661

5762
# Append a clang module entry if available
63+
has_clang_description = False
64+
5865
if module_context.clang:
5966
clang_context = module_context.clang
60-
if not clang_context.module_map and not clang_context.precompiled_module:
61-
# One of these must be set for our explicit clang module entry
62-
# to be valid
63-
continue
64-
clang_description = dict(module_description)
6567
if clang_context.module_map:
6668
# If path is not an attribute of `module_map`, then `module_map` is a string and we use it as our path.
67-
clang_description["clangModuleMapPath"] = getattr(clang_context.module_map, "path", clang_context.module_map)
69+
module_description["clangModuleMapPath"] = getattr(clang_context.module_map, "path", clang_context.module_map)
70+
has_clang_description = True
6871
if clang_context.precompiled_module:
69-
clang_description["clangModulePath"] = clang_context.precompiled_module.path
72+
module_description["clangModulePath"] = clang_context.precompiled_module.path
73+
has_clang_description = True
7074

71-
module_descriptions.append(clang_description)
75+
if has_swift_description or has_clang_description:
76+
module_descriptions[module_context.name] = module_description
7277

7378
actions.write(
74-
content = json.encode(module_descriptions),
79+
content = json.encode(module_descriptions.values()),
7580
output = explicit_swift_module_map_file,
7681
)

0 commit comments

Comments
 (0)