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

Commit df1198b

Browse files
allevatoswiple-rules-gardener
authored andcommitted
Uniquify -fmodule-map-file= flags passed to swiftc.
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
1 parent 3c85e63 commit df1198b

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

swift/internal/compiling.bzl

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -792,50 +792,49 @@ def _collect_clang_module_inputs(
792792
)
793793

794794
def _clang_modulemap_dependency_args(module):
795-
"""Returns `swiftc` arguments for the module map of a Clang module.
795+
"""Returns a `swiftc` argument for the module map of a Clang module.
796796
797797
Args:
798798
module: A struct containing information about the module, as defined by
799799
`swift_common.create_module`.
800800
801801
Returns:
802-
A list of arguments to pass to `swiftc`.
802+
The argument to pass to `swiftc` (without the `-Xcc` prefix).
803803
"""
804804
module_map = module.clang.module_map
805805
if types.is_string(module_map):
806806
module_map_path = module_map
807807
else:
808808
module_map_path = module_map.path
809809

810-
return [
811-
"-Xcc",
812-
"-fmodule-map-file={}".format(module_map_path),
813-
]
810+
return "-fmodule-map-file={}".format(module_map_path)
814811

815812
def _clang_module_dependency_args(module):
816813
"""Returns `swiftc` arguments for a precompiled Clang module, if possible.
817814
818-
If no precompiled module was emitted for this module, then this function
819-
falls back to the textual module map.
815+
If a precompiled module is present for this module, then flags for both it
816+
and the module map are returned (the latter is required in order to map
817+
headers to mdules in some scenarios, since the precompiled modules are
818+
passed by name). If no precompiled module is present for this module, then
819+
this function falls back to the textual module map alone.
820820
821821
Args:
822822
module: A struct containing information about the module, as defined by
823823
`swift_common.create_module`.
824824
825825
Returns:
826-
A list of arguments to pass to `swiftc`.
826+
A list of arguments to pass to `swiftc` (without the `-Xcc` prefix).
827827
"""
828828
args = []
829829
if module.clang.precompiled_module:
830-
args.extend([
831-
"-Xcc",
830+
args.append(
832831
"-fmodule-file={}={}".format(
833832
module.name,
834833
module.clang.precompiled_module.path,
835834
),
836-
])
835+
)
837836
if module.clang.module_map:
838-
args.extend(_clang_modulemap_dependency_args(module))
837+
args.append(_clang_modulemap_dependency_args(module))
839838
return args
840839

841840
def _dependencies_clang_modulemaps_configurator(prerequisites, args):
@@ -846,7 +845,15 @@ def _dependencies_clang_modulemaps_configurator(prerequisites, args):
846845
if module.clang
847846
]
848847

849-
args.add_all(modules, map_each = _clang_modulemap_dependency_args)
848+
# Uniquify the arguments because different modules might be defined in the
849+
# same module map file, so it only needs to be present once on the command
850+
# line.
851+
args.add_all(
852+
modules,
853+
before_each = "-Xcc",
854+
map_each = _clang_modulemap_dependency_args,
855+
uniquify = True,
856+
)
850857

851858
return _collect_clang_module_inputs(
852859
cc_info = prerequisites.cc_info,
@@ -864,7 +871,15 @@ def _dependencies_clang_modules_configurator(prerequisites, args):
864871
if module.clang
865872
]
866873

867-
args.add_all(modules, map_each = _clang_module_dependency_args)
874+
# Uniquify the arguments because different modules might be defined in the
875+
# same module map file, so it only needs to be present once on the command
876+
# line.
877+
args.add_all(
878+
modules,
879+
before_each = "-Xcc",
880+
map_each = _clang_module_dependency_args,
881+
uniquify = True,
882+
)
868883

869884
return _collect_clang_module_inputs(
870885
cc_info = prerequisites.cc_info,

0 commit comments

Comments
 (0)