[dsymutil] Try to find lipo first besides dsymutil before looking up the PATH.
authorFrederic Riss <friss@apple.com>
Thu, 8 Oct 2015 22:35:53 +0000 (22:35 +0000)
committerFrederic Riss <friss@apple.com>
Thu, 8 Oct 2015 22:35:53 +0000 (22:35 +0000)
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.

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

tools/dsymutil/MachOUtils.cpp
tools/dsymutil/MachOUtils.h
tools/dsymutil/dsymutil.cpp

index b643878946574c1c19444fbbd640410bce7d4809..44cc528ed8f2b2cc4becf40ec9c4d6b81030b856 100644 (file)
@@ -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<const char *> &Args) {
 
 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(SmallVectorImpl<ArchAndFilename> &ArchFiles,
       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
index 9a63645ab4ae0653d06bc4955d069c2cdc8e899d..61dfadc702702670450f923e9e3bec80476fdba8 100644 (file)
@@ -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);
index fef4cbd8e5279c346992ab0cf539725a2d4c6b14..419d220aa4bd0fd449284e868643a9d87729cf56 100644 (file)
@@ -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);
   }