@@ -425,9 +425,17 @@ class ModuleInterfaceLoaderImpl {
425
425
}
426
426
427
427
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) {
428
436
if (backupInterfaceDir.empty ())
429
437
return std::string ();
430
- auto &fs = *ctx. SourceMgr .getFileSystem ();
438
+ auto &fs = *SM .getFileSystem ();
431
439
auto fileName = llvm::sys::path::filename (interfacePath);
432
440
{
433
441
llvm::SmallString<256 > path (backupInterfaceDir);
@@ -1145,21 +1153,6 @@ ModuleInterfaceCheckerImpl::getCompiledModuleCandidatesForInterface(
1145
1153
return results;
1146
1154
}
1147
1155
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
-
1163
1156
bool ModuleInterfaceCheckerImpl::tryEmitForwardingModule (
1164
1157
StringRef moduleName, StringRef interfacePath,
1165
1158
ArrayRef<std::string> candidates, StringRef outputPath) {
@@ -1212,9 +1205,29 @@ bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface(
1212
1205
LoaderOpts.disableInterfaceLock );
1213
1206
// FIXME: We really only want to serialize 'important' dependencies here, if
1214
1207
// 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 );
1218
1231
}
1219
1232
1220
1233
void ModuleInterfaceLoader::collectVisibleTopLevelModuleNames (
0 commit comments