[cfe-commits] [PATCH] Use executable name from compilation database.

Sean Silva silvas at purdue.edu
Sun Jan 6 17:04:26 PST 2013


silvas added you to the CC list for the revision "Use executable name from compilation database.".

Hi klimek, alexfh,

When creating the Driver for Tooling, initialize the driver with the
same executable name as is present in the compilation database.

If the path in the compilation database is absolute (such as in the
compilation databases created by CMake), this lets the driver
automatically find the resource directory "as usual".

So basically, this makes tools built with libTooling Just Work™.

In the JSON compilation database specification, it may be worthwhile to
require that the executable path is absolute.

http://llvm-reviews.chandlerc.com/D265

Files:
  lib/Tooling/Tooling.cpp

Index: lib/Tooling/Tooling.cpp
===================================================================
--- lib/Tooling/Tooling.cpp
+++ lib/Tooling/Tooling.cpp
@@ -270,17 +270,6 @@
 }
 
 int ClangTool::run(FrontendActionFactory *ActionFactory) {
-  // Exists solely for the purpose of lookup of the resource path.
-  // This just needs to be some symbol in the binary.
-  static int StaticSymbol;
-  // The driver detects the builtin header path based on the path of the
-  // executable.
-  // FIXME: On linux, GetMainExecutable is independent of the value of the
-  // first argument, thus allowing ClangTool and runToolOnCode to just
-  // pass in made-up names here. Make sure this works on other platforms.
-  std::string MainExecutable =
-    llvm::sys::Path::GetMainExecutable("clang_tool", &StaticSymbol).str();
-
   bool ProcessingFailed = false;
   for (unsigned I = 0; I < CompileCommands.size(); ++I) {
     std::string File = CompileCommands[I].first;
@@ -297,7 +286,6 @@
     std::vector<std::string> CommandLine =
       ArgsAdjuster->Adjust(CompileCommands[I].second.CommandLine);
     assert(!CommandLine.empty());
-    CommandLine[0] = MainExecutable;
     llvm::outs() << "Processing: " << File << ".\n";
     ToolInvocation Invocation(CommandLine, ActionFactory->create(), &Files);
     for (int I = 0, E = MappedFileContents.size(); I != E; ++I) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D265.1.patch
Type: text/x-patch
Size: 1364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130106/7de4c993/attachment.bin>


More information about the cfe-commits mailing list