[ClangImporter] Merge Swift & Clang VFS

The clang importer has to deal with two virtual file systems, one coming
from clang, and one coming from swift. Currently, if both are set, we
emit a diagnostic that we'll pick the swift one.

This commit changes that, by merging the two virtual file systems into a
single overlay file system, and using that. To make this possible, we
always initialize the file manager with an overlay file system. In the
clang importer, we then create a new overlay file system, starting with
the one coming from clang, and adding overlays from swift on top.

The motivation for this change is the reproducer infrastructure in LLDB,
which adds a third virtual file system to the mix.
This commit is contained in:
Jonas Devlieghere
2019-07-02 17:04:25 -07:00
parent 6bf46b9350
commit f359cef5d0
10 changed files with 76 additions and 37 deletions

View File

@@ -87,8 +87,10 @@ protected:
SourceManager sourceMgr;
// Create a file system that tracks how many times a file has been opened.
llvm::IntrusiveRefCntPtr<OpenTrackingFileSystem> fs(
new OpenTrackingFileSystem(sourceMgr.getFileSystem()));
llvm::IntrusiveRefCntPtr<OpenTrackingFileSystem> baseFS(
new OpenTrackingFileSystem(sourceMgr.getFileSystem()));
auto fs = llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>(
new llvm::vfs::OverlayFileSystem(baseFS));
sourceMgr.setFileSystem(fs);
PrintingDiagnosticConsumer printingConsumer;
@@ -126,7 +128,7 @@ protected:
ASSERT_TRUE(fs->exists(cachedModulePath));
// Assert that we've only opened this file once, to write it.
ASSERT_EQ((unsigned)1, fs->numberOfOpens(cachedModulePath));
ASSERT_EQ((unsigned)1, baseFS->numberOfOpens(cachedModulePath));
auto bufOrErr = fs->getBufferForFile(cachedModulePath);
ASSERT_TRUE(bufOrErr);