r250164 - [Driver] Use the parent_path of the clang executable as the default InstalledDir
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 13 08:19:32 PDT 2015
Author: d0k
Date: Tue Oct 13 10:19:32 2015
New Revision: 250164
URL: http://llvm.org/viewvc/llvm-project?rev=250164&view=rev
Log:
[Driver] Use the parent_path of the clang executable as the default InstalledDir
This is what most people want anyways. Clang -cc1's main() will override
this but for other tools this is the most sensible default and avoids
some work.
Modified:
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/unittests/Driver/ToolChainTest.cpp
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=250164&r1=250163&r2=250164&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Oct 13 10:19:32 2015
@@ -65,6 +65,7 @@ Driver::Driver(StringRef ClangExecutable
Name = llvm::sys::path::filename(ClangExecutable);
Dir = llvm::sys::path::parent_path(ClangExecutable);
+ InstalledDir = Dir; // Provide a sensible default installed dir.
// Compute the path to the resource directory.
StringRef ClangResourceDir(CLANG_RESOURCE_DIR);
Modified: cfe/trunk/unittests/Driver/ToolChainTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Driver/ToolChainTest.cpp?rev=250164&r1=250163&r2=250164&view=diff
==============================================================================
--- cfe/trunk/unittests/Driver/ToolChainTest.cpp (original)
+++ cfe/trunk/unittests/Driver/ToolChainTest.cpp Tue Oct 13 10:19:32 2015
@@ -33,12 +33,12 @@ TEST(ToolChainTest, VFSGCCInstallation)
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
new vfs::InMemoryFileSystem);
- Driver TheDriver("/usr/bin/clang", "arm-linux-gnueabihf", Diags,
+ Driver TheDriver("/bin/clang", "arm-linux-gnueabihf", Diags,
InMemoryFileSystem);
const char *EmptyFiles[] = {
"foo.cpp",
- "/usr/bin/clang",
+ "/bin/clang",
"/usr/lib/gcc/arm-linux-gnueabi/4.6.1/crtbegin.o",
"/usr/lib/gcc/arm-linux-gnueabi/4.6.1/crtend.o",
"/usr/lib/gcc/arm-linux-gnueabihf/4.6.3/crtbegin.o",
@@ -78,4 +78,43 @@ TEST(ToolChainTest, VFSGCCInstallation)
S);
}
+TEST(ToolChainTest, VFSGCCInstallationRelativeDir) {
+ IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
+
+ IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
+ struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+ DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+ IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
+ new vfs::InMemoryFileSystem);
+ Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
+ InMemoryFileSystem);
+
+ const char *EmptyFiles[] = {
+ "foo.cpp", "/home/test/lib/gcc/arm-linux-gnueabi/4.6.1/crtbegin.o",
+ "/home/test/include/arm-linux-gnueabi/.keep"};
+
+ for (const char *Path : EmptyFiles)
+ InMemoryFileSystem->addFile(Path, 0,
+ llvm::MemoryBuffer::getMemBuffer("\n"));
+
+ std::unique_ptr<Compilation> C(
+ TheDriver.BuildCompilation({"-fsyntax-only", "foo.cpp"}));
+
+ std::string S;
+ {
+ llvm::raw_string_ostream OS(S);
+ C->getDefaultToolChain().printVerboseInfo(OS);
+ }
+#if LLVM_ON_WIN32
+ std::replace(S.begin(), S.end(), '\\', '/');
+#endif
+ EXPECT_EQ("Found candidate GCC installation: "
+ "/home/test/lib/gcc/arm-linux-gnueabi/4.6.1\n"
+ "Selected GCC installation: "
+ "/home/test/bin/../lib/gcc/arm-linux-gnueabi/4.6.1\n"
+ "Candidate multilib: .;@m32\n"
+ "Selected multilib: .;@m32\n",
+ S);
+}
+
} // end anonymous namespace
More information about the cfe-commits
mailing list