Skip to content

Commit

Permalink
Write entries for clang modules in explicit swift module map.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 542275780
  • Loading branch information
Googler authored and swiple-rules-gardener committed Jun 21, 2023
1 parent 1a44999 commit 2167072
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions swift/internal/explicit_module_map_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,37 @@ def write_explicit_swift_module_map_file(
module_descriptions = []

for module_context in module_contexts:
if not module_context.swift:
continue

swift_context = module_context.swift
# Set attributes that are applicable to a swift module entry or a
# clang module entry
module_description = {"moduleName": module_context.name}
if swift_context.swiftmodule:
module_description["modulePath"] = swift_context.swiftmodule.path
if module_context.is_system:
module_description["isSystem"] = module_context.is_system
if module_context.is_framework:
module_description["isFramework"] = module_context.is_framework
module_descriptions.append(module_description)

# Append a swift moule entry if available
if module_context.swift:
swift_context = module_context.swift
swift_description = dict(module_description)
if swift_context.swiftmodule:
swift_description["modulePath"] = swift_context.swiftmodule.path
module_descriptions.append(swift_description)

# Append a clang module entry if available
if module_context.clang:
clang_context = module_context.clang
if not clang_context.module_map and not clang_context.precompiled_module:
# One of these must be set for our explicit clang module entry
# to be valid
continue
clang_description = dict(module_description)
if clang_context.module_map:
# If path is not an attribute of `module_map`, then `module_map` is a string and we use it as our path.
clang_description["clangModuleMapPath"] = getattr(clang_context.module_map, "path", clang_context.module_map)
if clang_context.precompiled_module:
clang_description["clangModulePath"] = clang_context.precompiled_module.path

module_descriptions.append(clang_description)

actions.write(
content = json.encode(module_descriptions),
Expand Down

1 comment on commit 2167072

@brentleyjones
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.