@@ -22,10 +22,11 @@ load(
22
22
)
23
23
load (":actions.bzl" , "run_toolchain_swift_action" )
24
24
load (":derived_files.bzl" , "derived_files" )
25
- load (":providers.bzl" , "SwiftInfo" )
25
+ load (":providers.bzl" , "SwiftClangModuleInfo" , " SwiftInfo" )
26
26
load (
27
27
":utils.bzl" ,
28
28
"collect_cc_libraries" ,
29
+ "collect_transitive" ,
29
30
"get_providers" ,
30
31
"objc_provider_framework_name" ,
31
32
)
@@ -49,67 +50,58 @@ def collect_transitive_compile_inputs(args, deps, direct_defines = []):
49
50
input_depsets = []
50
51
51
52
# Collect all the search paths, module maps, flags, and so forth from transitive dependencies.
52
- transitive_cc_defines = []
53
- transitive_cc_headers = []
54
- transitive_cc_includes = []
55
- transitive_cc_quote_includes = []
56
- transitive_cc_system_includes = []
57
- transitive_defines = []
58
- transitive_modulemaps = []
59
- transitive_swiftmodules = []
60
- for dep in deps :
61
- if SwiftInfo in dep :
62
- swift_info = dep [SwiftInfo ]
63
- transitive_defines .append (swift_info .transitive_defines )
64
- transitive_modulemaps .append (swift_info .transitive_modulemaps )
65
- transitive_swiftmodules .append (swift_info .transitive_swiftmodules )
66
- if CcInfo in dep :
67
- compilation_context = dep [CcInfo ].compilation_context
68
- transitive_cc_defines .append (compilation_context .defines )
69
- transitive_cc_headers .append (compilation_context .headers )
70
- transitive_cc_includes .append (compilation_context .includes )
71
- transitive_cc_quote_includes .append (compilation_context .quote_includes )
72
- transitive_cc_system_includes .append (compilation_context .system_includes )
73
-
74
- # Add import paths for the directories containing dependencies' swiftmodules.
75
- all_swiftmodules = depset (transitive = transitive_swiftmodules )
76
- args .add_all (all_swiftmodules , format_each = "-I%s" , map_each = _dirname_map_fn )
77
- input_depsets .append (all_swiftmodules )
78
-
79
- # Pass Swift defines propagated by dependencies.
80
- all_defines = depset (direct_defines , transitive = transitive_defines )
81
- args .add_all (all_defines , format_each = "-D%s" )
82
-
83
- # Pass module maps from C/C++ dependencies to ClangImporter.
84
- # TODO(allevato): Will `CcInfo` eventually keep these in its compilation context?
85
- all_modulemaps = depset (transitive = transitive_modulemaps )
86
- input_depsets .append (all_modulemaps )
87
- args .add_all (all_modulemaps , before_each = "-Xcc" , format_each = "-fmodule-map-file=%s" )
88
-
89
- # Add C++ headers from dependencies to the action inputs so the compiler can read them.
90
- input_depsets .append (depset (transitive = transitive_cc_headers ))
91
-
92
- # Pass any C++ defines and include search paths to ClangImporter.
93
- args .add_all (
94
- depset (transitive = transitive_cc_defines ),
95
- before_each = "-Xcc" ,
96
- format_each = "-D%s" ,
53
+ transitive_swiftmodules = collect_transitive (
54
+ deps ,
55
+ SwiftInfo ,
56
+ "transitive_swiftmodules" ,
97
57
)
98
- args .add_all (
99
- depset (transitive = transitive_cc_includes ),
100
- before_each = "-Xcc" ,
101
- format_each = "-I%s" ,
58
+ args .add_all (transitive_swiftmodules , format_each = "-I%s" , map_each = _dirname_map_fn )
59
+ input_depsets .append (transitive_swiftmodules )
60
+
61
+ transitive_defines = collect_transitive (
62
+ deps ,
63
+ SwiftInfo ,
64
+ "transitive_defines" ,
65
+ direct = direct_defines ,
102
66
)
103
- args .add_all (
104
- depset (transitive = transitive_cc_quote_includes ),
105
- before_each = "-Xcc" ,
106
- format_each = "-iquote%s" ,
67
+ args .add_all (transitive_defines , format_each = "-D%s" )
68
+
69
+ transitive_modulemaps = collect_transitive (
70
+ deps ,
71
+ SwiftClangModuleInfo ,
72
+ "transitive_modulemaps" ,
107
73
)
74
+ input_depsets .append (transitive_modulemaps )
108
75
args .add_all (
109
- depset ( transitive = transitive_cc_system_includes ) ,
76
+ transitive_modulemaps ,
110
77
before_each = "-Xcc" ,
111
- format_each = "-isystem%s" ,
78
+ format_each = "-fmodule-map-file=%s" ,
79
+ )
80
+
81
+ transitive_cc_headers = collect_transitive (
82
+ deps ,
83
+ SwiftClangModuleInfo ,
84
+ "transitive_headers" ,
85
+ )
86
+ input_depsets .append (transitive_cc_headers )
87
+
88
+ transitive_cc_compile_flags = collect_transitive (
89
+ deps ,
90
+ SwiftClangModuleInfo ,
91
+ "transitive_compile_flags" ,
92
+ )
93
+
94
+ # Handle possible spaces in these arguments correctly (for example,
95
+ # `-isystem foo`) by prepending `-Xcc` to each one.
96
+ for arg in transitive_cc_compile_flags .to_list ():
97
+ args .add_all (arg .split (" " ), before_each = "-Xcc" )
98
+
99
+ transitive_cc_defines = collect_transitive (
100
+ deps ,
101
+ SwiftClangModuleInfo ,
102
+ "transitive_defines" ,
112
103
)
104
+ args .add_all (transitive_cc_defines , before_each = "-Xcc" , format_each = "-D%s" )
113
105
114
106
return input_depsets
115
107
0 commit comments