@@ -425,9 +425,17 @@ class ModuleInterfaceLoaderImpl {
425425 }
426426
427427 std::string getBackupPublicModuleInterfacePath () {
428+ return getBackupPublicModuleInterfacePath (ctx.SourceMgr , backupInterfaceDir,
429+ moduleName, interfacePath);
430+ }
431+
432+ static std::string getBackupPublicModuleInterfacePath (SourceManager &SM,
433+ StringRef backupInterfaceDir,
434+ StringRef moduleName,
435+ StringRef interfacePath) {
428436 if (backupInterfaceDir.empty ())
429437 return std::string ();
430- auto &fs = *ctx. SourceMgr .getFileSystem ();
438+ auto &fs = *SM .getFileSystem ();
431439 auto fileName = llvm::sys::path::filename (interfacePath);
432440 {
433441 llvm::SmallString<256 > path (backupInterfaceDir);
@@ -1145,21 +1153,6 @@ ModuleInterfaceCheckerImpl::getCompiledModuleCandidatesForInterface(
11451153 return results;
11461154}
11471155
1148- std::string
1149- ModuleInterfaceCheckerImpl::getBackupPublicModuleInterfacePath (StringRef moduleName,
1150- StringRef interfacePath) {
1151- // Derive .swiftmodule path from the .swiftinterface path.
1152- auto newExt = file_types::getExtension (file_types::TY_SwiftModuleFile);
1153- llvm::SmallString<32 > modulePath = interfacePath;
1154- llvm::sys::path::replace_extension (modulePath, newExt);
1155- ModuleInterfaceLoaderImpl Impl (Ctx, modulePath, interfacePath, moduleName,
1156- CacheDir, PrebuiltCacheDir, BackupInterfaceDir,
1157- SourceLoc (), Opts,
1158- RequiresOSSAModules, nullptr ,
1159- ModuleLoadingMode::PreferSerialized);
1160- return Impl.getBackupPublicModuleInterfacePath ();
1161- }
1162-
11631156bool ModuleInterfaceCheckerImpl::tryEmitForwardingModule (
11641157 StringRef moduleName, StringRef interfacePath,
11651158 ArrayRef<std::string> candidates, StringRef outputPath) {
@@ -1212,9 +1205,29 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
12121205 LoaderOpts.disableInterfaceLock );
12131206 // FIXME: We really only want to serialize 'important' dependencies here, if
12141207 // we want to ship the built swiftmodules to another machine.
1215- return builder.buildSwiftModule (OutPath, /* shouldSerializeDeps*/ true ,
1216- /* ModuleBuffer*/ nullptr , nullptr ,
1217- SearchPathOpts.CandidateCompiledModules );
1208+ auto failed = builder.buildSwiftModule (OutPath, /* shouldSerializeDeps*/ true ,
1209+ /* ModuleBuffer*/ nullptr , nullptr ,
1210+ SearchPathOpts.CandidateCompiledModules );
1211+ if (!failed)
1212+ return false ;
1213+ auto backInPath =
1214+ ModuleInterfaceLoaderImpl::getBackupPublicModuleInterfacePath (SourceMgr,
1215+ BackupInterfaceDir, ModuleName, InPath);
1216+ if (backInPath.empty ())
1217+ return true ;
1218+ assert (failed);
1219+ assert (!backInPath.empty ());
1220+ ModuleInterfaceBuilder backupBuilder (SourceMgr, &Diags, astDelegate, backInPath,
1221+ ModuleName, CacheDir, PrebuiltCacheDir,
1222+ BackupInterfaceDir,
1223+ LoaderOpts.disableInterfaceLock );
1224+ // Ensure we can rebuild module after user changed the original interface file.
1225+ backupBuilder.addExtraDependency (InPath);
1226+ // FIXME: We really only want to serialize 'important' dependencies here, if
1227+ // we want to ship the built swiftmodules to another machine.
1228+ return backupBuilder.buildSwiftModule (OutPath, /* shouldSerializeDeps*/ true ,
1229+ /* ModuleBuffer*/ nullptr , nullptr ,
1230+ SearchPathOpts.CandidateCompiledModules );
12181231}
12191232
12201233void ModuleInterfaceLoader::collectVisibleTopLevelModuleNames (
0 commit comments