@@ -176,24 +176,49 @@ class ExplicitSwiftModuleLoader: public SerializedModuleLoaderBase {
176176 ~ExplicitSwiftModuleLoader ();
177177};
178178
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).
182217 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;
187218 // A flag that indicates whether this module is a framework
188219 bool isFramework = false ;
189220 // A flag that indicates whether this module is a system module
190- // Set the default to be false.
191221 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;
197222};
198223
199224// / Parser of explicit module maps passed into the compiler.
@@ -223,7 +248,8 @@ class ExplicitModuleMapParser {
223248
224249 std::error_code
225250 parseSwiftExplicitModuleMap (llvm::StringRef fileName,
226- llvm::StringMap<ExplicitModuleInfo> &moduleMap) {
251+ llvm::StringMap<ExplicitSwiftModuleInputInfo> &swiftModuleMap,
252+ llvm::StringMap<ExplicitClangModuleInputInfo> &clangModuleMap) {
227253 using namespace llvm ::yaml;
228254 // Load the input file.
229255 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileBufOrErr =
@@ -240,7 +266,7 @@ class ExplicitModuleMapParser {
240266 assert (DI != Stream.end () && " Failed to read a document" );
241267 if (auto *MN = dyn_cast_or_null<SequenceNode>(DI->getRoot ())) {
242268 for (auto &entry : *MN) {
243- if (parseSingleModuleEntry (entry, moduleMap )) {
269+ if (parseSingleModuleEntry (entry, swiftModuleMap, clangModuleMap )) {
244270 return std::make_error_code (std::errc::invalid_argument);
245271 }
246272 }
@@ -269,40 +295,65 @@ class ExplicitModuleMapParser {
269295 }
270296
271297 bool parseSingleModuleEntry (llvm::yaml::Node &node,
272- llvm::StringMap<ExplicitModuleInfo> &moduleMap) {
298+ llvm::StringMap<ExplicitSwiftModuleInputInfo> &swiftModuleMap,
299+ llvm::StringMap<ExplicitClangModuleInputInfo> &clangModuleMap) {
273300 using namespace llvm ::yaml;
274301 auto *mapNode = dyn_cast<MappingNode>(&node);
275302 if (!mapNode)
276303 return true ;
277304 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 ;
279309 for (auto &entry : *mapNode) {
280310 auto key = getScalaNodeText (entry.getKey ());
281311 auto val = getScalaNodeText (entry.getValue ());
282312 if (key == " moduleName" ) {
283313 moduleName = val;
284314 } else if (key == " modulePath" ) {
285- result. modulePath = val.str ();
315+ swiftModulePath = val.str ();
286316 } else if (key == " docPath" ) {
287- result. moduleDocPath = val.str ();
317+ swiftModuleDocPath = val.str ();
288318 } else if (key == " sourceInfoPath" ) {
289- result. moduleSourceInfoPath = val.str ();
319+ swiftModuleSourceInfoPath = val.str ();
290320 } else if (key == " isFramework" ) {
291- result. isFramework = parseBoolValue (val);
321+ isFramework = parseBoolValue (val);
292322 } else if (key == " isSystem" ) {
293- result. isSystem = parseBoolValue (val);
323+ isSystem = parseBoolValue (val);
294324 } else if (key == " clangModuleMapPath" ) {
295- result. clangModuleMapPath = val.str ();
325+ clangModuleMapPath = val.str ();
296326 } else if (key == " clangModulePath" ) {
297- result. clangModulePath = val.str ();
327+ clangModulePath = val.str ();
298328 } else {
299329 // Being forgiving for future fields.
300330 continue ;
301331 }
302332 }
303333 if (moduleName.empty ())
304334 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+
306357 return false ;
307358 }
308359
0 commit comments