@@ -176,24 +176,49 @@ class ExplicitSwiftModuleLoader: public SerializedModuleLoaderBase {
176
176
~ExplicitSwiftModuleLoader ();
177
177
};
178
178
179
- // / Information about explicitly specified Swift and Clang module files.
180
- struct ExplicitModuleInfo {
181
- // Path of the .swiftmodule file. Empty for pure Clang modules.
179
+
180
+ // Explicitly-specified Swift module inputs
181
+ struct ExplicitSwiftModuleInputInfo {
182
+ ExplicitSwiftModuleInputInfo (std::string modulePath,
183
+ llvm::Optional<std::string> moduleDocPath,
184
+ llvm::Optional<std::string> moduleSourceInfoPath,
185
+ bool isFramework = false ,
186
+ bool isSystem = false )
187
+ : modulePath(modulePath),
188
+ moduleDocPath (moduleDocPath),
189
+ moduleSourceInfoPath(moduleSourceInfoPath),
190
+ isFramework(isFramework),
191
+ isSystem(isSystem) {}
192
+ // Path of the .swiftmodule file.
193
+ std::string modulePath;
194
+ // Path of the .swiftmoduledoc file.
195
+ llvm::Optional<std::string> moduleDocPath;
196
+ // Path of the .swiftsourceinfo file.
197
+ llvm::Optional<std::string> moduleSourceInfoPath;
198
+ // A flag that indicates whether this module is a framework
199
+ bool isFramework = false ;
200
+ // A flag that indicates whether this module is a system module
201
+ bool isSystem = false ;
202
+ };
203
+
204
+ // Explicitly-specified Clang module inputs
205
+ struct ExplicitClangModuleInputInfo {
206
+ ExplicitClangModuleInputInfo (std::string moduleMapPath,
207
+ std::string modulePath,
208
+ bool isFramework = false ,
209
+ bool isSystem = false )
210
+ : moduleMapPath(moduleMapPath),
211
+ modulePath (modulePath),
212
+ isFramework(isFramework),
213
+ isSystem(isSystem) {}
214
+ // Path of the Clang module map file.
215
+ std::string moduleMapPath;
216
+ // Path of a compiled Clang explicit module file (pcm).
182
217
std::string modulePath;
183
- // Path of the .swiftmoduledoc file. Empty for pure Clang modules.
184
- std::string moduleDocPath;
185
- // Path of the .swiftsourceinfo file. Empty for pure Clang modules.
186
- std::string moduleSourceInfoPath;
187
218
// A flag that indicates whether this module is a framework
188
219
bool isFramework = false ;
189
220
// A flag that indicates whether this module is a system module
190
- // Set the default to be false.
191
221
bool isSystem = false ;
192
- // Path of the Clang module map file. Empty for pure Swift modules.
193
- std::string clangModuleMapPath;
194
- // Path of a compiled Clang explicit module file. Empty for pure Swift
195
- // modules.
196
- std::string clangModulePath;
197
222
};
198
223
199
224
// / Parser of explicit module maps passed into the compiler.
@@ -223,7 +248,8 @@ class ExplicitModuleMapParser {
223
248
224
249
std::error_code
225
250
parseSwiftExplicitModuleMap (llvm::StringRef fileName,
226
- llvm::StringMap<ExplicitModuleInfo> &moduleMap) {
251
+ llvm::StringMap<ExplicitSwiftModuleInputInfo> &swiftModuleMap,
252
+ llvm::StringMap<ExplicitClangModuleInputInfo> &clangModuleMap) {
227
253
using namespace llvm ::yaml;
228
254
// Load the input file.
229
255
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileBufOrErr =
@@ -240,7 +266,7 @@ class ExplicitModuleMapParser {
240
266
assert (DI != Stream.end () && " Failed to read a document" );
241
267
if (auto *MN = dyn_cast_or_null<SequenceNode>(DI->getRoot ())) {
242
268
for (auto &entry : *MN) {
243
- if (parseSingleModuleEntry (entry, moduleMap )) {
269
+ if (parseSingleModuleEntry (entry, swiftModuleMap, clangModuleMap )) {
244
270
return std::make_error_code (std::errc::invalid_argument);
245
271
}
246
272
}
@@ -269,40 +295,65 @@ class ExplicitModuleMapParser {
269
295
}
270
296
271
297
bool parseSingleModuleEntry (llvm::yaml::Node &node,
272
- llvm::StringMap<ExplicitModuleInfo> &moduleMap) {
298
+ llvm::StringMap<ExplicitSwiftModuleInputInfo> &swiftModuleMap,
299
+ llvm::StringMap<ExplicitClangModuleInputInfo> &clangModuleMap) {
273
300
using namespace llvm ::yaml;
274
301
auto *mapNode = dyn_cast<MappingNode>(&node);
275
302
if (!mapNode)
276
303
return true ;
277
304
StringRef moduleName;
278
- ExplicitModuleInfo result;
305
+ llvm::Optional<std::string> swiftModulePath, swiftModuleDocPath,
306
+ swiftModuleSourceInfoPath;
307
+ std::string clangModuleMapPath = " " , clangModulePath = " " ;
308
+ bool isFramework = false , isSystem = false ;
279
309
for (auto &entry : *mapNode) {
280
310
auto key = getScalaNodeText (entry.getKey ());
281
311
auto val = getScalaNodeText (entry.getValue ());
282
312
if (key == " moduleName" ) {
283
313
moduleName = val;
284
314
} else if (key == " modulePath" ) {
285
- result. modulePath = val.str ();
315
+ swiftModulePath = val.str ();
286
316
} else if (key == " docPath" ) {
287
- result. moduleDocPath = val.str ();
317
+ swiftModuleDocPath = val.str ();
288
318
} else if (key == " sourceInfoPath" ) {
289
- result. moduleSourceInfoPath = val.str ();
319
+ swiftModuleSourceInfoPath = val.str ();
290
320
} else if (key == " isFramework" ) {
291
- result. isFramework = parseBoolValue (val);
321
+ isFramework = parseBoolValue (val);
292
322
} else if (key == " isSystem" ) {
293
- result. isSystem = parseBoolValue (val);
323
+ isSystem = parseBoolValue (val);
294
324
} else if (key == " clangModuleMapPath" ) {
295
- result. clangModuleMapPath = val.str ();
325
+ clangModuleMapPath = val.str ();
296
326
} else if (key == " clangModulePath" ) {
297
- result. clangModulePath = val.str ();
327
+ clangModulePath = val.str ();
298
328
} else {
299
329
// Being forgiving for future fields.
300
330
continue ;
301
331
}
302
332
}
303
333
if (moduleName.empty ())
304
334
return true ;
305
- moduleMap[moduleName] = std::move (result);
335
+
336
+ if (swiftModulePath.has_value ()) {
337
+ assert ((clangModuleMapPath.empty () &&
338
+ clangModulePath.empty ()) &&
339
+ " Unexpected Clang dependency details for Swift module" );
340
+ ExplicitSwiftModuleInputInfo entry (swiftModulePath.value (),
341
+ swiftModuleDocPath,
342
+ swiftModuleSourceInfoPath,
343
+ isFramework,
344
+ isSystem);
345
+ swiftModuleMap.try_emplace (moduleName, std::move (entry));
346
+ } else {
347
+ assert ((!clangModuleMapPath.empty () ||
348
+ !clangModulePath.empty ()) &&
349
+ " Expected Clang dependency module" );
350
+ ExplicitClangModuleInputInfo entry (clangModuleMapPath,
351
+ clangModulePath,
352
+ isFramework,
353
+ isSystem);
354
+ clangModuleMap.try_emplace (moduleName, std::move (entry));
355
+ }
356
+
306
357
return false ;
307
358
}
308
359
0 commit comments