[PATCH] D50160: [c-index-test] Use correct executable path to discover resource directory.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 1 14:45:14 PDT 2018


vsapsai created this revision.
vsapsai added reviewers: nathawes, akyrtzi, bob.wilson.
Herald added a subscriber: dexonsmith.

Driver builds resource directory path based on provided executable path.
Instead of string "clang" use actual executable path.

rdar://problem/42699514


https://reviews.llvm.org/D50160

Files:
  clang/tools/c-index-test/core_main.cpp


Index: clang/tools/c-index-test/core_main.cpp
===================================================================
--- clang/tools/c-index-test/core_main.cpp
+++ clang/tools/c-index-test/core_main.cpp
@@ -20,6 +20,7 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Serialization/ASTReader.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/PrettyStackTrace.h"
@@ -202,11 +203,13 @@
   });
 }
 
-static bool printSourceSymbols(ArrayRef<const char *> Args,
-                               bool dumpModuleImports,
-                               bool indexLocals) {
+static bool printSourceSymbols(const char *ProgName,
+                               ArrayRef<const char *> Args,
+                               bool dumpModuleImports, bool indexLocals) {
+  void *P = (void*) (intptr_t) indextest_core_main;
+  std::string Executable = llvm::sys::fs::getMainExecutable(ProgName, P);
   SmallVector<const char *, 4> ArgsWithProgName;
-  ArgsWithProgName.push_back("clang");
+  ArgsWithProgName.push_back(Executable.c_str());
   ArgsWithProgName.append(Args.begin(), Args.end());
   IntrusiveRefCntPtr<DiagnosticsEngine>
     Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions));
@@ -314,6 +317,7 @@
 int indextest_core_main(int argc, const char **argv) {
   sys::PrintStackTraceOnErrorSignal(argv[0]);
   PrettyStackTraceProgram X(argc, argv);
+  const char *ProgName = argv[0];
 
   assert(argv[1] == StringRef("core"));
   ++argv;
@@ -343,7 +347,8 @@
       errs() << "error: missing compiler args; pass '-- <compiler arguments>'\n";
       return 1;
     }
-    return printSourceSymbols(CompArgs, options::DumpModuleImports, options::IncludeLocals);
+    return printSourceSymbols(ProgName, CompArgs, options::DumpModuleImports,
+                              options::IncludeLocals);
   }
 
   return 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50160.158643.patch
Type: text/x-patch
Size: 1954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180801/1fdd0bc7/attachment.bin>


More information about the cfe-commits mailing list