[llvm] r249762 - [dsymutil] Try to find lipo first besides dsymutil before looking up the PATH.

Frederic Riss via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 8 15:35:53 PDT 2015


Author: friss
Date: Thu Oct  8 17:35:53 2015
New Revision: 249762

URL: http://llvm.org/viewvc/llvm-project?rev=249762&view=rev
Log:
[dsymutil] Try to find lipo first besides dsymutil before looking up the PATH.

Even if we don't have it in PATH, lipo should usually exist in the same directory
as dsymutil. Keep the fallback looking up the PATH, it's very useful when
testing a non-installed executable.

Modified:
    llvm/trunk/tools/dsymutil/MachOUtils.cpp
    llvm/trunk/tools/dsymutil/MachOUtils.h
    llvm/trunk/tools/dsymutil/dsymutil.cpp

Modified: llvm/trunk/tools/dsymutil/MachOUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/MachOUtils.cpp?rev=249762&r1=249761&r2=249762&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/MachOUtils.cpp (original)
+++ llvm/trunk/tools/dsymutil/MachOUtils.cpp Thu Oct  8 17:35:53 2015
@@ -32,8 +32,10 @@ std::string getArchName(StringRef Arch)
   return Arch;
 }
 
-static bool runLipo(SmallVectorImpl<const char *> &Args) {
-  auto Path = sys::findProgramByName("lipo");
+static bool runLipo(StringRef SDKPath, SmallVectorImpl<const char *> &Args) {
+  auto Path = sys::findProgramByName("lipo", makeArrayRef(SDKPath));
+  if (!Path)
+    Path = sys::findProgramByName("lipo");
 
   if (!Path) {
     errs() << "error: lipo: " << Path.getError().message() << "\n";
@@ -53,7 +55,7 @@ static bool runLipo(SmallVectorImpl<cons
 
 bool generateUniversalBinary(SmallVectorImpl<ArchAndFilename> &ArchFiles,
                              StringRef OutputFileName,
-                             const LinkOptions &Options) {
+                             const LinkOptions &Options, StringRef SDKPath) {
   // No need to merge one file into a universal fat binary. First, try
   // to move it (rename) to the final location. If that fails because
   // of cross-device link issues then copy and delete.
@@ -95,7 +97,7 @@ bool generateUniversalBinary(SmallVector
       outs() << ' ' << ((Arg == nullptr) ? "\n" : Arg);
   }
 
-  return Options.NoOutput ? true : runLipo(Args);
+  return Options.NoOutput ? true : runLipo(SDKPath, Args);
 }
 
 // Return a MachO::segment_command_64 that holds the same values as

Modified: llvm/trunk/tools/dsymutil/MachOUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/MachOUtils.h?rev=249762&r1=249761&r2=249762&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/MachOUtils.h (original)
+++ llvm/trunk/tools/dsymutil/MachOUtils.h Thu Oct  8 17:35:53 2015
@@ -26,7 +26,8 @@ struct ArchAndFilename {
 };
 
 bool generateUniversalBinary(SmallVectorImpl<ArchAndFilename> &ArchFiles,
-                             StringRef OutputFileName, const LinkOptions &);
+                             StringRef OutputFileName, const LinkOptions &,
+                             StringRef SDKPath);
 
 bool generateDsymCompanion(const DebugMap &DM, MCStreamer &MS,
                            raw_fd_ostream &OutFile);

Modified: llvm/trunk/tools/dsymutil/dsymutil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.cpp?rev=249762&r1=249761&r2=249762&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.cpp (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.cpp Thu Oct  8 17:35:53 2015
@@ -237,6 +237,9 @@ int main(int argc, char **argv) {
   llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
   llvm::llvm_shutdown_obj Shutdown;
   LinkOptions Options;
+  void *MainAddr = reinterpret_cast<void *>(&exitDsymutil);
+  std::string SDKPath = llvm::sys::fs::getMainExecutable(argv[0], MainAddr);
+  SDKPath = llvm::sys::path::parent_path(SDKPath);
 
   HideUnrelatedOptions(DsymCategory);
   llvm::cl::ParseCommandLineOptions(
@@ -330,7 +333,7 @@ int main(int argc, char **argv) {
 
     if (NeedsTempFiles &&
         !MachOUtils::generateUniversalBinary(
-            TempFiles, getOutputFileName(InputFile), Options))
+            TempFiles, getOutputFileName(InputFile), Options, SDKPath))
       exitDsymutil(1);
   }
 




More information about the llvm-commits mailing list