Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Uniquify -fmodule-map-file= flags passed to swiftc.
Browse files Browse the repository at this point in the history
In some cases (e.g., if a module map defines multiple modules and both or more were present in the dependency graph), the `depset` won't deduplicate the module structures because their values are distinct (they contain different module names). That's the behavior we want, but it also resulted in the `-fmodule-map-file=` for that module map appearing multiple times on the command line.

PiperOrigin-RevId: 348139990
  • Loading branch information
allevato authored and swiple-rules-gardener committed Dec 18, 2020
1 parent 3c85e63 commit df1198b
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -792,50 +792,49 @@ def _collect_clang_module_inputs(
)

def _clang_modulemap_dependency_args(module):
"""Returns `swiftc` arguments for the module map of a Clang module.
"""Returns a `swiftc` argument for the module map of a Clang module.
Args:
module: A struct containing information about the module, as defined by
`swift_common.create_module`.
Returns:
A list of arguments to pass to `swiftc`.
The argument to pass to `swiftc` (without the `-Xcc` prefix).
"""
module_map = module.clang.module_map
if types.is_string(module_map):
module_map_path = module_map
else:
module_map_path = module_map.path

return [
"-Xcc",
"-fmodule-map-file={}".format(module_map_path),
]
return "-fmodule-map-file={}".format(module_map_path)

def _clang_module_dependency_args(module):
"""Returns `swiftc` arguments for a precompiled Clang module, if possible.
If no precompiled module was emitted for this module, then this function
falls back to the textual module map.
If a precompiled module is present for this module, then flags for both it
and the module map are returned (the latter is required in order to map
headers to mdules in some scenarios, since the precompiled modules are
passed by name). If no precompiled module is present for this module, then
this function falls back to the textual module map alone.
Args:
module: A struct containing information about the module, as defined by
`swift_common.create_module`.
Returns:
A list of arguments to pass to `swiftc`.
A list of arguments to pass to `swiftc` (without the `-Xcc` prefix).
"""
args = []
if module.clang.precompiled_module:
args.extend([
"-Xcc",
args.append(
"-fmodule-file={}={}".format(
module.name,
module.clang.precompiled_module.path,
),
])
)
if module.clang.module_map:
args.extend(_clang_modulemap_dependency_args(module))
args.append(_clang_modulemap_dependency_args(module))
return args

def _dependencies_clang_modulemaps_configurator(prerequisites, args):
Expand All @@ -846,7 +845,15 @@ def _dependencies_clang_modulemaps_configurator(prerequisites, args):
if module.clang
]

args.add_all(modules, map_each = _clang_modulemap_dependency_args)
# Uniquify the arguments because different modules might be defined in the
# same module map file, so it only needs to be present once on the command
# line.
args.add_all(
modules,
before_each = "-Xcc",
map_each = _clang_modulemap_dependency_args,
uniquify = True,
)

return _collect_clang_module_inputs(
cc_info = prerequisites.cc_info,
Expand All @@ -864,7 +871,15 @@ def _dependencies_clang_modules_configurator(prerequisites, args):
if module.clang
]

args.add_all(modules, map_each = _clang_module_dependency_args)
# Uniquify the arguments because different modules might be defined in the
# same module map file, so it only needs to be present once on the command
# line.
args.add_all(
modules,
before_each = "-Xcc",
map_each = _clang_module_dependency_args,
uniquify = True,
)

return _collect_clang_module_inputs(
cc_info = prerequisites.cc_info,
Expand Down

0 comments on commit df1198b

Please sign in to comment.