@@ -1333,39 +1333,8 @@ ClangImporter::create(ASTContext &ctx,
1333
1333
// Avoid creating indirect file system when using include tree.
1334
1334
if (!ctx.ClangImporterOpts .HasClangIncludeTreeRoot ) {
1335
1335
// Wrap Swift's FS to allow Clang to override the working directory
1336
- VFS = llvm::vfs::RedirectingFileSystem::create (
1337
- fileMapping.redirectedFiles , true , *ctx.SourceMgr .getFileSystem ());
1338
- if (importerOpts.DumpClangDiagnostics ) {
1339
- llvm::errs () << " clang importer redirected file mappings:\n " ;
1340
- for (const auto &mapping : fileMapping.redirectedFiles ) {
1341
- llvm::errs () << " mapping real file '" << mapping.second
1342
- << " ' to virtual file '" << mapping.first << " '\n " ;
1343
- }
1344
- llvm::errs () << " \n " ;
1345
- }
1346
-
1347
- if (!fileMapping.overridenFiles .empty ()) {
1348
- llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> overridenVFS =
1349
- new llvm::vfs::InMemoryFileSystem ();
1350
- for (const auto &file : fileMapping.overridenFiles ) {
1351
- if (importerOpts.DumpClangDiagnostics ) {
1352
- llvm::errs () << " clang importer overriding file '" << file.first
1353
- << " ' with the following contents:\n " ;
1354
- llvm::errs () << file.second << " \n " ;
1355
- }
1356
- auto contents = ctx.Allocate <char >(file.second .size () + 1 );
1357
- std::copy (file.second .begin (), file.second .end (), contents.begin ());
1358
- // null terminate the buffer.
1359
- contents[contents.size () - 1 ] = ' \0 ' ;
1360
- overridenVFS->addFile (file.first , 0 ,
1361
- llvm::MemoryBuffer::getMemBuffer (StringRef (
1362
- contents.begin (), contents.size () - 1 )));
1363
- }
1364
- llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> overlayVFS =
1365
- new llvm::vfs::OverlayFileSystem (VFS);
1366
- VFS = overlayVFS;
1367
- overlayVFS->pushOverlay (overridenVFS);
1368
- }
1336
+ VFS = createClangInvocationFileMappingVFS (fileMapping, ctx,
1337
+ ctx.SourceMgr .getFileSystem ());
1369
1338
}
1370
1339
1371
1340
// Create a new Clang compiler invocation.
0 commit comments