@@ -44,24 +44,38 @@ def check_output(cmd, verbose=False):
44
44
45
45
46
46
def get_sdk_path (platform ):
47
+ if platform .startswith ('iosmac' ):
48
+ platform = 'macosx'
47
49
return check_output (['xcrun' , '-sdk' , platform , '-show-sdk-path' ])
48
50
49
51
52
+ def write_fixed_module (file , platform , infix , verbose ):
53
+ common_modules_path = os .path .join (INFER_IMPORT_DIR , 'fixed-' + infix +
54
+ '-modules-common.txt' )
55
+ platform_modules_path = os .path .join (INFER_IMPORT_DIR , 'fixed-' + infix +
56
+ '-modules-' + platform + '.txt' )
57
+ with open (common_modules_path , 'r' ) as extra :
58
+ if verbose :
59
+ print ('Including modules in: ' + common_modules_path )
60
+ file .write (extra .read ())
61
+ with open (platform_modules_path , 'r' ) as extra :
62
+ if verbose :
63
+ print ('Including modules in: ' + platform_modules_path )
64
+ file .write (extra .read ())
65
+
66
+
50
67
def prepare_module_list (platform , file , verbose , module_filter_flags ,
51
- include_fixed_modules ):
68
+ include_fixed_clang_modules ):
52
69
cmd = [INFER_IMPORT_PATH , '-s' , get_sdk_path (platform )]
53
70
cmd .extend (module_filter_flags )
54
71
if verbose :
55
72
cmd .extend (['--v' ])
56
73
check_call (cmd , output = file )
57
- # The fixed modules are all objc frameworks.
58
- if not include_fixed_modules :
59
- return
60
- with open (INFER_IMPORT_DIR + '/fixed-modules-common.txt' , 'r' ) as extra :
61
- file .write (extra .read ())
62
- with open (INFER_IMPORT_DIR + '/fixed-modules-' + platform + '.txt' ,
63
- 'r' ) as extra :
64
- file .write (extra .read ())
74
+ # Always include fixed swift modules
75
+ write_fixed_module (file , platform , 'swift' , verbose )
76
+ # Check if we need fixed clang modules
77
+ if include_fixed_clang_modules :
78
+ write_fixed_module (file , platform , 'clang' , verbose )
65
79
66
80
67
81
def get_api_digester_path (tool_path ):
@@ -82,50 +96,69 @@ def __init__(self, tool_path, platform):
82
96
'macosx' : 'x86_64-apple-macosx10.15' ,
83
97
'appletvos' : 'arm64-apple-tvos13.0' ,
84
98
'watchos' : 'armv7k-apple-watchos6.0' ,
99
+ 'iosmac' : 'x86_64-apple-ios13.0-macabi' ,
85
100
}
86
101
self .tool_path = get_api_digester_path (tool_path )
87
102
self .platform = platform
88
103
self .target = target_map [platform ]
89
104
self .sdk = get_sdk_path (platform )
105
+ self .inputs = []
106
+ if self .platform == 'macosx' :
107
+ # We need this input search path for CreateML
108
+ self .inputs .extend ([self .sdk + '/usr/lib/swift/' ])
90
109
self .frameworks = [
91
110
self .sdk + '/System/Library/Frameworks/' ,
92
111
os .path .realpath (self .sdk + '/../../Library/Frameworks/' )]
112
+ if self .platform .startswith ('iosmac' ):
113
+ # Catalyst modules need this extra framework dir
114
+ iOSSupport = self .sdk + \
115
+ '/System/iOSSupport/System/Library/Frameworks'
116
+ self .frameworks .extend ([iOSSupport ])
93
117
94
118
def run (self , output , module , swift_ver , opts , verbose ,
95
- module_filter_flags , include_fixed_modules , separate_by_module ):
119
+ module_filter_flags , include_fixed_clang_modules ,
120
+ separate_by_module ):
96
121
cmd = [self .tool_path , '-sdk' , self .sdk , '-target' ,
97
122
self .target , '-dump-sdk' , '-module-cache-path' ,
98
123
'/tmp/ModuleCache' , '-swift-version' ,
99
124
swift_ver , '-abort-on-module-fail' ]
125
+ _environ = dict (os .environ )
126
+ _environ ['SWIFT_FORCE_MODULE_LOADING' ] = 'prefer-interface'
100
127
for path in self .frameworks :
101
128
cmd .extend (['-iframework' , path ])
129
+ for path in self .inputs :
130
+ cmd .extend (['-I' , path ])
102
131
cmd .extend (['-' + o for o in opts ])
103
132
if verbose :
104
133
cmd .extend (['-v' ])
105
134
if module :
106
135
cmd .extend (['-module' , module ])
107
136
cmd .extend (['-o' , output ])
108
- check_call (cmd , verbose = verbose )
137
+ check_call (cmd , env = _environ , verbose = verbose )
109
138
else :
110
139
with tempfile .NamedTemporaryFile () as tmp :
111
140
prepare_module_list (self .platform , tmp , verbose ,
112
- module_filter_flags , include_fixed_modules )
141
+ module_filter_flags ,
142
+ include_fixed_clang_modules )
113
143
if separate_by_module :
114
144
tmp .seek (0 )
115
145
create_directory (output )
116
146
for module in [name .strip () for name in tmp .readlines ()]:
147
+ # Skip comments
148
+ if module .startswith ('//' ):
149
+ continue
117
150
dir_path = os .path .realpath (output + '/' + module )
118
151
file_path = os .path .realpath (dir_path + '/' +
119
152
self .platform + '.json' )
120
153
create_directory (dir_path )
121
154
current_cmd = list (cmd )
122
155
current_cmd .extend (['-module' , module ])
123
156
current_cmd .extend (['-o' , file_path ])
124
- check_call (current_cmd , verbose = verbose )
157
+ check_call (current_cmd , env = _environ , verbose = verbose )
125
158
else :
126
159
cmd .extend (['-o' , output ])
127
160
cmd .extend (['-module-list-file' , tmp .name ])
128
- check_call (cmd , verbose = verbose )
161
+ check_call (cmd , env = _environ , verbose = verbose )
129
162
130
163
131
164
class DiagnoseConfig :
@@ -214,21 +247,21 @@ def main():
214
247
fatal_error ("Need to specify --output" )
215
248
if args .module_filter == '' :
216
249
module_filter_flags = []
217
- include_fixed_modules = True
250
+ include_fixed_clang_modules = True
218
251
elif args .module_filter == 'swift-frameworks-only' :
219
252
module_filter_flags = ['--swift-frameworks-only' ]
220
- include_fixed_modules = False
253
+ include_fixed_clang_modules = False
221
254
elif args .module_filter == 'swift-overlay-only' :
222
255
module_filter_flags = ['--swift-overlay-only' ]
223
- include_fixed_modules = False
256
+ include_fixed_clang_modules = False
224
257
else :
225
258
fatal_error ("cannot recognize --module-filter" )
226
259
runner = DumpConfig (tool_path = args .tool_path , platform = args .target )
227
260
runner .run (output = args .output , module = args .module ,
228
261
swift_ver = args .swift_version , opts = args .opts ,
229
262
verbose = args .v ,
230
263
module_filter_flags = module_filter_flags ,
231
- include_fixed_modules = include_fixed_modules ,
264
+ include_fixed_clang_modules = include_fixed_clang_modules ,
232
265
separate_by_module = args .separate_by_module )
233
266
elif args .action == 'diagnose' :
234
267
if not args .dump_before :
0 commit comments