@@ -74,54 +74,58 @@ _SANITIZER_FEATURE_FLAG_MAP = {
7474}
7575
7676def _create_swift_info (
77- additional_inputs = [],
7877 defines = [],
79- libraries = [],
80- linkopts = [],
8178 module_name = None ,
8279 swiftdocs = [],
8380 swiftmodules = [],
81+ swift_infos = [],
8482 swift_version = None ):
8583 """Creates a new `SwiftInfo` provider with the given values.
8684
8785 This function is recommended instead of directly creating a `SwiftInfo` provider because it
8886 encodes reasonable defaults for fields that some rules may not be interested in and ensures
8987 that the direct and transitive fields are set consistently.
9088
89+ This function can also be used to do a simple merge of `SwiftInfo` providers, by leaving all
90+ of the arguments except for `swift_infos` as their empty defaults. In that case, the returned
91+ provider will not represent a true Swift module; it is merely a "collector" for other
92+ dependencies.
93+
9194 Args:
92- additional_inputs: A list of additional input files passed into a library or binary target
93- via the `swiftc_inputs` attribute.
9495 defines: A list of defines that will be provided as `copts` of the target being built.
95- libraries: A list of `.a` files that are the direct outputs of the target being built.
96- linkopts: A list of linker flags that will be passed to the linker when the target being
97- built is linked into a binary.
98- module_name: A string containing the name of the Swift module, or `None` if the provider
99- does not represent a compiled module (this happens, for example, with `proto_library`
100- targets that act as "collectors" of other modules but have no sources of their own).
96+ module_name: A string containing the name of the Swift module. If this is `None`, the
97+ provider does not represent a compiled module but rather a collection of modules (this
98+ happens, for example, with `proto_library` targets that have no sources of their own
99+ but depend on others that do).
101100 swiftdocs: A list of `.swiftdoc` files that are the direct outputs of the target being
102- built.
101+ built. If omitted, an empty list is used.
103102 swiftmodules: A list of `.swiftmodule` files that are the direct outputs of the target
104- being built.
103+ being built. If omitted, an empty list is used.
104+ swift_infos: A list of `SwiftInfo` providers from dependencies, whose transitive fields
105+ should be merged into the new one. If omitted, no transitive data is collected.
105106 swift_version: A string containing the value of the `-swift-version` flag used when
106- compiling this target, or `None` if it was not set or is not relevant.
107+ compiling this target, or `None` (the default) if it was not set or is not relevant.
107108
108109 Returns:
109110 A new `SwiftInfo` provider with the given values.
110111 """
112+ transitive_defines = []
113+ transitive_swiftdocs = []
114+ transitive_swiftmodules = []
115+ for swift_info in swift_infos :
116+ transitive_defines .append (swift_info .transitive_defines )
117+ transitive_swiftdocs .append (swift_info .transitive_swiftdocs )
118+ transitive_swiftmodules .append (swift_info .transitive_swiftmodules )
119+
111120 return SwiftInfo (
112121 direct_defines = defines ,
113- direct_libraries = libraries ,
114- direct_linkopts = linkopts ,
115122 direct_swiftdocs = swiftdocs ,
116123 direct_swiftmodules = swiftmodules ,
117124 module_name = module_name ,
118125 swift_version = swift_version ,
119- transitive_additional_inputs = depset (direct = additional_inputs ),
120- transitive_defines = depset (direct = defines ),
121- transitive_libraries = depset (direct = libraries , order = "topological" ),
122- transitive_linkopts = depset (direct = linkopts ),
123- transitive_swiftdocs = depset (direct = swiftdocs ),
124- transitive_swiftmodules = depset (direct = swiftmodules ),
126+ transitive_defines = depset (defines , transitive = transitive_defines ),
127+ transitive_swiftdocs = depset (swiftdocs , transitive = transitive_swiftdocs ),
128+ transitive_swiftmodules = depset (swiftmodules , transitive = transitive_swiftmodules ),
125129 )
126130
127131def _compilation_attrs (additional_deps_aspects = []):
@@ -831,46 +835,6 @@ conformance.
831835 },
832836 )
833837
834- def _merge_swift_infos (swift_infos ):
835- """Merges a list of `SwiftInfo` providers into one.
836-
837- Args:
838- swift_infos: A sequence of `SwiftInfo`providers to merge.
839-
840- Returns:
841- A new `SwiftInfo` provider.
842- """
843- transitive_additional_inputs = []
844- transitive_defines = []
845- transitive_libraries = []
846- transitive_linkopts = []
847- transitive_swiftdocs = []
848- transitive_swiftmodules = []
849-
850- for swift_info in swift_infos :
851- transitive_additional_inputs .append (swift_info .transitive_additional_inputs )
852- transitive_defines .append (swift_info .transitive_defines )
853- transitive_libraries .append (swift_info .transitive_libraries )
854- transitive_linkopts .append (swift_info .transitive_linkopts )
855- transitive_swiftdocs .append (swift_info .transitive_swiftdocs )
856- transitive_swiftmodules .append (swift_info .transitive_swiftmodules )
857-
858- return SwiftInfo (
859- direct_defines = [],
860- direct_libraries = [],
861- direct_linkopts = [],
862- direct_swiftdocs = [],
863- direct_swiftmodules = [],
864- module_name = None ,
865- swift_version = None ,
866- transitive_additional_inputs = depset (transitive = transitive_additional_inputs ),
867- transitive_defines = depset (transitive = transitive_defines ),
868- transitive_libraries = depset (transitive = transitive_libraries ),
869- transitive_linkopts = depset (transitive = transitive_linkopts ),
870- transitive_swiftdocs = depset (transitive = transitive_swiftdocs ),
871- transitive_swiftmodules = depset (transitive = transitive_swiftmodules ),
872- )
873-
874838def _swift_runtime_linkopts (is_static , toolchain , is_test = False ):
875839 """Returns the flags that should be passed to `clang` when linking a binary.
876840
@@ -1064,7 +1028,6 @@ swift_common = struct(
10641028 derive_module_name = _derive_module_name ,
10651029 is_enabled = _is_enabled ,
10661030 library_rule_attrs = _library_rule_attrs ,
1067- merge_swift_infos = _merge_swift_infos ,
10681031 run_toolchain_action = run_toolchain_action ,
10691032 run_toolchain_shell_action = run_toolchain_shell_action ,
10701033 run_toolchain_swift_action = run_toolchain_swift_action ,
0 commit comments