summaryrefslogtreecommitdiff
path: root/unittests/Tooling
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-10-24 07:51:24 +0000
committerManuel Klimek <klimek@google.com>2013-10-24 07:51:24 +0000
commitee0cd37fe4a9f4e2ee73ae34cf93c410cb299a82 (patch)
tree08076a3c090eed496bb77ac84b198887fe94ea2c /unittests/Tooling
parent1bf080e8f1283aa3c85418a3da3a49457896f0cc (diff)
downloadclang-ee0cd37fe4a9f4e2ee73ae34cf93c410cb299a82.tar.gz
clang-ee0cd37fe4a9f4e2ee73ae34cf93c410cb299a82.tar.bz2
clang-ee0cd37fe4a9f4e2ee73ae34cf93c410cb299a82.tar.xz
Use the same SourceManager for ModuleMaps and compilations.
This allows using virtual file mappings on the original SourceManager to map in virtual module.map files. Without this patch, the ModuleMap search will find a module.map file (as the FileEntry exists in the FileManager), but will be unable to get the content from the SourceManager (as ModuleMap previously created its own SourceManager). Two problems needed to be fixed which this patch exposed: 1. Storing the inferred module map When writing out a module, the ASTWriter stores the names of the files in the main source manager; when loading the AST again, the ASTReader errs out if such a file is found missing, unless it is overridden. Previously CompilerInstance's compileModule method would store the inferred module map to a temporary file; the problem with this approach is that now that the module map is handled by the main source manager, the ASTWriter stores the name of the temporary module map as source to the compilation; later, when the module is loaded, the temporary file has already been deleted, which leads to a compilation error. This patch changes the inferred module map to instead inject a virtual file into the source manager. This both saves some disk IO, and works with how the ASTWriter/ASTReader handle overridden source files. 2. Changing test input in test/Modules/Inputs/* Now that the module map file is handled by the main source manager, the VerifyDiagnosticConsumer will not ignore diagnostics created while parsing the module map file. The module test test/Modules/renamed.m uses -I test/Modules/Inputs and triggers recursive loading of all module maps in test/Modules/Inputs, some of which had conflicting names, thus leading errors while parsing the module maps. Those diagnostics already occur on trunk, but before this patch they would not break the test, as they were ignored by the VerifyDiagnosticConsumer. This patch thus changes the module maps that have been recently introduced which broke the invariant of compatible modules maps in test/Modules/Inputs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193314 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Tooling')
-rw-r--r--unittests/Tooling/ToolingTest.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/unittests/Tooling/ToolingTest.cpp b/unittests/Tooling/ToolingTest.cpp
index e435ea92e2..412af7adda 100644
--- a/unittests/Tooling/ToolingTest.cpp
+++ b/unittests/Tooling/ToolingTest.cpp
@@ -131,6 +131,26 @@ TEST(ToolInvocation, TestMapVirtualFile) {
EXPECT_TRUE(Invocation.run());
}
+TEST(ToolInvocation, TestVirtualModulesCompilation) {
+ // FIXME: Currently, this only tests that we don't exit with an error if a
+ // mapped module.map is found on the include path. In the future, expand this
+ // test to run a full modules enabled compilation, so we make sure we can
+ // rerun modules compilations with a virtual file system.
+ clang::FileManager Files((clang::FileSystemOptions()));
+ std::vector<std::string> Args;
+ Args.push_back("tool-executable");
+ Args.push_back("-Idef");
+ Args.push_back("-fsyntax-only");
+ Args.push_back("test.cpp");
+ clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction, &Files);
+ Invocation.mapVirtualFile("test.cpp", "#include <abc>\n");
+ Invocation.mapVirtualFile("def/abc", "\n");
+ // Add a module.map file in the include directory of our header, so we trigger
+ // the module.map header search logic.
+ Invocation.mapVirtualFile("def/module.map", "\n");
+ EXPECT_TRUE(Invocation.run());
+}
+
struct VerifyEndCallback : public SourceFileCallbacks {
VerifyEndCallback() : BeginCalled(0), EndCalled(0), Matched(false) {}
virtual bool handleBeginSource(CompilerInstance &CI,