summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-01-23 12:30:02 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-01-23 12:30:02 +0000
commit5da21edb3537af70b8b5a87d1c3bed990742a632 (patch)
treea6ddb76676283eb2ab7214663b9cf3332a5e83c9 /clang
parent78fdc9007d3fe6c58aa182e63386f5c17269188e (diff)
downloadbcm5719-llvm-5da21edb3537af70b8b5a87d1c3bed990742a632.tar.gz
bcm5719-llvm-5da21edb3537af70b8b5a87d1c3bed990742a632.zip
[Tooling] Added a VFS parameter to ClangTool
Summary: The parameter overrides the underlying vfs used by ClangTool for filesystem operations. Patch by Vladimir Plyashkun. Reviewers: alexfh, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D41947 llvm-svn: 323195
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Tooling/Tooling.h6
-rw-r--r--clang/lib/Tooling/Tooling.cpp5
-rw-r--r--clang/unittests/Tooling/ToolingTest.cpp18
3 files changed, 26 insertions, 3 deletions
diff --git a/clang/include/clang/Tooling/Tooling.h b/clang/include/clang/Tooling/Tooling.h
index e64be07d9ab..ea3b0e04214 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -296,10 +296,14 @@ class ClangTool {
/// not found in Compilations, it is skipped.
/// \param PCHContainerOps The PCHContainerOperations for loading and creating
/// clang modules.
+ /// \param BaseFS VFS used for all underlying file accesses when running the
+ /// tool.
ClangTool(const CompilationDatabase &Compilations,
ArrayRef<std::string> SourcePaths,
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
- std::make_shared<PCHContainerOperations>());
+ std::make_shared<PCHContainerOperations>(),
+ IntrusiveRefCntPtr<vfs::FileSystem> BaseFS =
+ vfs::getRealFileSystem());
~ClangTool();
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 4fbfa4f0047..b6185086176 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -328,10 +328,11 @@ bool FrontendActionFactory::runInvocation(
ClangTool::ClangTool(const CompilationDatabase &Compilations,
ArrayRef<std::string> SourcePaths,
- std::shared_ptr<PCHContainerOperations> PCHContainerOps)
+ std::shared_ptr<PCHContainerOperations> PCHContainerOps,
+ IntrusiveRefCntPtr<vfs::FileSystem> BaseFS)
: Compilations(Compilations), SourcePaths(SourcePaths),
PCHContainerOps(std::move(PCHContainerOps)),
- OverlayFileSystem(new vfs::OverlayFileSystem(vfs::getRealFileSystem())),
+ OverlayFileSystem(new vfs::OverlayFileSystem(BaseFS)),
InMemoryFileSystem(new vfs::InMemoryFileSystem),
Files(new FileManager(FileSystemOptions(), OverlayFileSystem)),
DiagConsumer(nullptr) {
diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp
index 891907a4d08..6dd0e53c4dd 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -402,6 +402,24 @@ TEST(ClangToolTest, ArgumentAdjusters) {
EXPECT_FALSE(Found);
}
+TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
+ FixedCompilationDatabase Compilations("/", std::vector<std::string>());
+ llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem(
+ new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
+ llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
+ new vfs::InMemoryFileSystem);
+ OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+
+ InMemoryFileSystem->addFile(
+ "a.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int main() {}"));
+
+ ClangTool Tool(Compilations, std::vector<std::string>(1, "a.cpp"),
+ std::make_shared<PCHContainerOperations>(), OverlayFileSystem);
+ std::unique_ptr<FrontendActionFactory> Action(
+ newFrontendActionFactory<SyntaxOnlyAction>());
+ EXPECT_EQ(0, Tool.run(Action.get()));
+}
+
// Check getClangStripDependencyFileAdjuster doesn't strip args after -MD/-MMD.
TEST(ClangToolTest, StripDependencyFileAdjuster) {
FixedCompilationDatabase Compilations("/", {"-MD", "-c", "-MMD", "-w"});
OpenPOWER on IntegriCloud