Driver: Keep track of a separate "install dir", which is the path where clang
was invoked from (which may not be where the executable itself is).
- This allows having e.g., /Developer/usr/bin/clang be a symlink to some other
location, while still making sure the Driver finds 'as', 'ld', etc. relative
to itself.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109989 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp
index 34d3327..0e99314 100644
--- a/tools/driver/driver.cpp
+++ b/tools/driver/driver.cpp
@@ -31,6 +31,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Host.h"
#include "llvm/System/Path.h"
+#include "llvm/System/Program.h"
#include "llvm/System/Signals.h"
using namespace clang;
using namespace clang::driver;
@@ -304,6 +305,23 @@
"a.out", IsProduction, CXXIsProduction,
Diags);
+ // Attempt to find the original path used to invoke the driver, to determine
+ // the installed path. We do this manually, because we want to support that
+ // path being a symlink.
+ llvm::sys::Path InstalledPath(argv[0]);
+
+ // Do a PATH lookup, if there are no directory components.
+ if (InstalledPath.getLast() == InstalledPath.str()) {
+ llvm::sys::Path Tmp =
+ llvm::sys::Program::FindProgramByName(InstalledPath.getLast());
+ if (!Tmp.empty())
+ InstalledPath = Tmp;
+ }
+ InstalledPath.makeAbsolute();
+ InstalledPath.eraseComponent();
+ if (InstalledPath.exists())
+ TheDriver.setInstalledDir(InstalledPath.str());
+
// Check for ".*++" or ".*++-[^-]*" to determine if we are a C++
// compiler. This matches things like "c++", "clang++", and "clang++-1.1".
//