]> granicus.if.org Git - clang/commitdiff
Driver: When re'execing clang, use path to the main executable instead of
authorDaniel Dunbar <daniel@zuster.org>
Wed, 14 Jul 2010 18:46:27 +0000 (18:46 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 14 Jul 2010 18:46:27 +0000 (18:46 +0000)
looking up Clang in the normal search paths (which may end up finding the wrong
clang).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108346 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Driver.h
lib/Driver/Driver.cpp
lib/Driver/Tools.cpp

index 153981f842d3ba7ded4f4d227634985c1f8164bc..bb578b516ce33c0a77bb95e3c2af54dfd482cb7e 100644 (file)
@@ -62,6 +62,9 @@ public:
   /// command line.
   std::string Dir;
 
+  /// The original path to the clang executable.
+  std::string ClangExecutable;
+
   /// The path to the compiler resource directory.
   std::string ResourceDir;
 
@@ -163,6 +166,11 @@ public:
   const std::string &getTitle() { return DriverTitle; }
   void setTitle(std::string Value) { DriverTitle = Value; }
 
+  /// \brief Get the path to the main clang executable.
+  std::string getClangProgramPath() const {
+    return ClangExecutable;
+  }
+
   /// @}
   /// @name Primary Functionality
   /// @{
index 5da7908434d353cd9b80011e63485d6bde791733..2fc0a5354d80ef0f7a65be605bf10947634a52ad 100644 (file)
@@ -75,6 +75,11 @@ Driver::Driver(llvm::StringRef _Name, llvm::StringRef _Dir,
   P.appendComponent("clang");
   P.appendComponent(CLANG_VERSION_STRING);
   ResourceDir = P.str();
+
+  // Save the original clang executable path.
+  P = Dir;
+  P.appendComponent(Name);
+  ClangExecutable = P.str();
 }
 
 Driver::~Driver() {
index 14744998f161a762ab0f87571fb36721b8b81819..f423d4e3b918699e85890f9f9957faa02596e763 100644 (file)
@@ -1489,8 +1489,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
 
   Args.AddAllArgs(CmdArgs, options::OPT_undef);
 
-  const char *Exec =
-    Args.MakeArgString(getToolChain().GetProgramPath("clang"));
+  std::string Exec = getToolChain().getDriver().getClangProgramPath();
 
   // Optionally embed the -cc1 level arguments into the debug info, for build
   // analysis.
@@ -1510,7 +1509,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back(Args.MakeArgString(Flags.str()));
   }
 
-  Dest.addCommand(new Command(JA, *this, Exec, CmdArgs));
+  Dest.addCommand(new Command(JA, *this, Exec.c_str(), CmdArgs));
 
   // Explicitly warn that these options are unsupported, even though
   // we are allowing compilation to continue.
@@ -1589,9 +1588,8 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back(Input.getFilename());
   }
 
-  const char *Exec =
-    Args.MakeArgString(getToolChain().GetProgramPath("clang"));
-  Dest.addCommand(new Command(JA, *this, Exec, CmdArgs));
+  std::string Exec = getToolChain().getDriver().getClangProgramPath();
+  Dest.addCommand(new Command(JA, *this, Exec.c_str(), CmdArgs));
 }
 
 void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA,