aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Driver/ToolChainTest.cpp
diff options
context:
space:
mode:
authorSerge Pavlov <sepavloff@gmail.com>2022-08-29 12:50:36 +0700
committerSerge Pavlov <sepavloff@gmail.com>2022-09-09 16:28:51 +0700
commit9424497e43aff088e014d65fd952ec557e28e6cf (patch)
tree9ad728dfd34df836e6678050656acc5e3441bc47 /clang/unittests/Driver/ToolChainTest.cpp
parent1f639d1bd2f202f9bdf7c5023c93b4e3c8563413 (diff)
downloadllvm-9424497e43aff088e014d65fd952ec557e28e6cf.zip
llvm-9424497e43aff088e014d65fd952ec557e28e6cf.tar.gz
llvm-9424497e43aff088e014d65fd952ec557e28e6cf.tar.bz2
[Clang] Use virtual FS in processing config files
Clang has support of virtual file system for the purpose of testing, but treatment of config files did not use it. This change enables VFS in it as well. Differential Revision: https://reviews.llvm.org/D132867
Diffstat (limited to 'clang/unittests/Driver/ToolChainTest.cpp')
-rw-r--r--clang/unittests/Driver/ToolChainTest.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp
index 3faa285..a9ac309 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -484,4 +484,61 @@ TEST(ToolChainTest, Toolsets) {
}
}
+TEST(ToolChainTest, ConfigFileSearch) {
+ IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
+ IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
+ struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+ DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+ IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FS(
+ new llvm::vfs::InMemoryFileSystem);
+
+#ifdef _WIN32
+ const char *TestRoot = "C:\\";
+#else
+ const char *TestRoot = "/";
+#endif
+ FS->setCurrentWorkingDirectory(TestRoot);
+
+ FS->addFile(
+ "/opt/sdk/root.cfg", 0,
+ llvm::MemoryBuffer::getMemBuffer("--sysroot=/opt/sdk/platform0\n"));
+ FS->addFile(
+ "/home/test/sdk/root.cfg", 0,
+ llvm::MemoryBuffer::getMemBuffer("--sysroot=/opt/sdk/platform1\n"));
+ FS->addFile(
+ "/home/test/bin/root.cfg", 0,
+ llvm::MemoryBuffer::getMemBuffer("--sysroot=/opt/sdk/platform2\n"));
+
+ {
+ Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
+ "clang LLVM compiler", FS);
+ std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
+ {"/home/test/bin/clang", "--config", "root.cfg",
+ "--config-system-dir=/opt/sdk", "--config-user-dir=/home/test/sdk"}));
+ ASSERT_TRUE(C);
+ ASSERT_FALSE(C->containsError());
+ EXPECT_EQ("/opt/sdk/platform1", TheDriver.SysRoot);
+ }
+ {
+ Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
+ "clang LLVM compiler", FS);
+ std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
+ {"/home/test/bin/clang", "--config", "root.cfg",
+ "--config-system-dir=/opt/sdk", "--config-user-dir="}));
+ ASSERT_TRUE(C);
+ ASSERT_FALSE(C->containsError());
+ EXPECT_EQ("/opt/sdk/platform0", TheDriver.SysRoot);
+ }
+ {
+ Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
+ "clang LLVM compiler", FS);
+ std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(
+ {"/home/test/bin/clang", "--config", "root.cfg",
+ "--config-system-dir=", "--config-user-dir="}));
+ ASSERT_TRUE(C);
+ ASSERT_FALSE(C->containsError());
+ EXPECT_EQ("/opt/sdk/platform2", TheDriver.SysRoot);
+ }
+}
+
} // end anonymous namespace.