[llvm] r244270 - [dsymutil] Implement dSYM bundle creation

Frederic Riss via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 14:05:06 PDT 2015


Author: friss
Date: Thu Aug  6 16:05:06 2015
New Revision: 244270

URL: http://llvm.org/viewvc/llvm-project?rev=244270&view=rev
Log:
[dsymutil] Implement dSYM bundle creation

A dSYM bundle is a file hierarchy that looks slike this:
 <bundle name>.dSYM/
     Contents/
        Info.plist
        Resources/
           DWARF/
              <DWARF file(s)>

This is the default output mode of dsymutil.

Added:
    llvm/trunk/test/tools/dsymutil/X86/basic-linking-bundle.test
Modified:
    llvm/trunk/test/tools/dsymutil/X86/multiple-inputs.test
    llvm/trunk/tools/dsymutil/dsymutil.cpp

Added: llvm/trunk/test/tools/dsymutil/X86/basic-linking-bundle.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/basic-linking-bundle.test?rev=244270&view=auto
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/basic-linking-bundle.test (added)
+++ llvm/trunk/test/tools/dsymutil/X86/basic-linking-bundle.test Thu Aug  6 16:05:06 2015
@@ -0,0 +1,33 @@
+REQUIRES: shell
+RUN: rm -rf %T/basic-linking-bundle
+RUN: mkdir -p %T/basic-linking-bundle/dsymdest
+RUN: cat %p/../Inputs/basic.macho.x86_64 > %T/basic-linking-bundle/basic.macho.x86_64
+
+RUN: llvm-dsymutil -oso-prepend-path=%p/.. %T/basic-linking-bundle/basic.macho.x86_64
+RUN: llvm-dwarfdump %T/basic-linking-bundle/basic.macho.x86_64.dSYM/Contents/Resources/DWARF/basic.macho.x86_64 | FileCheck %S/basic-linking-x86.test
+RUN: FileCheck %s --input-file %T/basic-linking-bundle/basic.macho.x86_64.dSYM/Contents/Info.plist
+
+RUN: llvm-dsymutil -oso-prepend-path=%p/.. %T/basic-linking-bundle/basic.macho.x86_64 -o %T/basic-linking-bundle/dsymdest/basic.macho.x86_64.dSYM
+RUN: llvm-dwarfdump %T/basic-linking-bundle/dsymdest/basic.macho.x86_64.dSYM/Contents/Resources/DWARF/basic.macho.x86_64 | FileCheck %S/basic-linking-x86.test
+RUN: FileCheck %s --input-file %T/basic-linking-bundle/dsymdest/basic.macho.x86_64.dSYM/Contents/Info.plist
+
+CHECK: <?xml version="1.0" encoding="UTF-8"?>
+CHECK-NEXT: <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+CHECK-NEXT: <plist version="1.0">
+CHECK-NEXT:         <dict>
+CHECK-NEXT:                 <key>CFBundleDevelopmentRegion</key>
+CHECK-NEXT:                 <string>English</string>
+CHECK-NEXT:                 <key>CFBundleIdentifier</key>
+CHECK-NEXT:                 <string>com.apple.xcode.dsym.basic.macho.x86_64</string>
+CHECK-NEXT:                 <key>CFBundleInfoDictionaryVersion</key>
+CHECK-NEXT:                 <string>6.0</string>
+CHECK-NEXT:                 <key>CFBundlePackageType</key>
+CHECK-NEXT:                 <string>dSYM</string>
+CHECK-NEXT:                 <key>CFBundleSignature</key>
+CHECK-NEXT:                 <string>????</string>
+CHECK-NEXT:                 <key>CFBundleShortVersionString</key>
+CHECK-NEXT:                 <string>1.0</string>
+CHECK-NEXT:                 <key>CFBundleVersion</key>
+CHECK-NEXT:                 <string>1</string>
+CHECK-NEXT:         </dict>
+CHECK-NEXT: </plist>

Modified: llvm/trunk/test/tools/dsymutil/X86/multiple-inputs.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/multiple-inputs.test?rev=244270&r1=244269&r2=244270&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/multiple-inputs.test (original)
+++ llvm/trunk/test/tools/dsymutil/X86/multiple-inputs.test Thu Aug  6 16:05:06 2015
@@ -1,12 +1,32 @@
 REQUIRES: shell
-RUN: cat %p/../Inputs/basic.macho.x86_64 > %t1
-RUN: cat %p/../Inputs/basic-archive.macho.x86_64 > %t2
-RUN: cat %p/../Inputs/basic-lto.macho.x86_64 > %t3
-RUN: cat %p/../Inputs/basic-lto-dw4.macho.x86_64 > %t4
-RUN: llvm-dsymutil -f -oso-prepend-path=%p/.. %t1 %t2 %t3 %t4
-RUN: llvm-dwarfdump %t1.dwarf \
-RUN:   | FileCheck %S/basic-linking-x86.test --check-prefix=CHECK --check-prefix=BASIC
-RUN: llvm-dwarfdump %t2.dwarf \
-RUN:   | FileCheck %S/basic-linking-x86.test --check-prefix=CHECK --check-prefix=ARCHIVE
-RUN: llvm-dwarfdump %t3.dwarf | FileCheck %S/basic-lto-linking-x86.test
-RUN: llvm-dwarfdump %t4.dwarf | FileCheck %S/basic-lto-dw4-linking-x86.test
+RUN: rm -rf %T/multiple-inputs
+RUN: mkdir -p %T/multiple-inputs
+
+RUN: cat %p/../Inputs/basic.macho.x86_64 > %T/multiple-inputs/basic.macho.x86_64
+RUN: cat %p/../Inputs/basic-archive.macho.x86_64 > %T/multiple-inputs/basic-archive.macho.x86_64
+RUN: cat %p/../Inputs/basic-lto.macho.x86_64 > %T/multiple-inputs/basic-lto.macho.x86_64
+RUN: cat %p/../Inputs/basic-lto-dw4.macho.x86_64 > %T/multiple-inputs/basic-lto-dw4.macho.x86_64
+
+# Multiple inputs in flat mode
+RUN: llvm-dsymutil -f -oso-prepend-path=%p/.. %T/multiple-inputs/basic.macho.x86_64 %T/multiple-inputs/basic-archive.macho.x86_64 %T/multiple-inputs/basic-lto.macho.x86_64 %T/multiple-inputs/basic-lto-dw4.macho.x86_64
+RUN: llvm-dwarfdump %T/multiple-inputs/basic.macho.x86_64.dwarf \
+RUN: | FileCheck %S/basic-linking-x86.test --check-prefix=CHECK --check-prefix=BASIC
+RUN: llvm-dwarfdump %T/multiple-inputs/basic-archive.macho.x86_64.dwarf \
+RUN: | FileCheck %S/basic-linking-x86.test --check-prefix=CHECK --check-prefix=ARCHIVE
+RUN: llvm-dwarfdump %T/multiple-inputs/basic-lto.macho.x86_64.dwarf | FileCheck %S/basic-lto-linking-x86.test
+RUN: llvm-dwarfdump %T/multiple-inputs/basic-lto-dw4.macho.x86_64.dwarf | FileCheck %S/basic-lto-dw4-linking-x86.test
+
+# Multiple inputs that end up in the same named bundle
+RUN: llvm-dsymutil -oso-prepend-path=%p/.. %T/multiple-inputs/basic.macho.x86_64 %T/multiple-inputs/basic-archive.macho.x86_64 %T/multiple-inputs/basic-lto.macho.x86_64 %T/multiple-inputs/basic-lto-dw4.macho.x86_64 -o %t.dSYM
+RUN: llvm-dwarfdump %t.dSYM/Contents/Resources/DWARF/basic.macho.x86_64 \
+RUN: | FileCheck %S/basic-linking-x86.test --check-prefix=CHECK --check-prefix=BASIC
+RUN: llvm-dwarfdump %t.dSYM/Contents/Resources/DWARF/basic-archive.macho.x86_64 \
+RUN: | FileCheck %S/basic-linking-x86.test --check-prefix=CHECK --check-prefix=ARCHIVE
+RUN: llvm-dwarfdump %t.dSYM/Contents/Resources/DWARF/basic-lto.macho.x86_64 | FileCheck %S/basic-lto-linking-x86.test
+RUN: llvm-dwarfdump %t.dSYM/Contents/Resources/DWARF/basic-lto-dw4.macho.x86_64 | FileCheck %S/basic-lto-dw4-linking-x86.test
+
+# Multiple inputs in a named bundle in flat mode... impossible.
+RUN: not llvm-dsymutil -f -oso-prepend-path=%p/.. %T/multiple-inputs/basic.macho.x86_64 %T/multiple-inputs/basic-archive.macho.x86_64 %T/multiple-inputs/basic-lto.macho.x86_64 %T/multiple-inputs/basic-lto-dw4.macho.x86_64 -o %t.dSYM 2>&1 | FileCheck %s
+
+CHECK: error: cannot use -o with multiple inputs in flat mode
+

Modified: llvm/trunk/tools/dsymutil/dsymutil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.cpp?rev=244270&r1=244269&r2=244270&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.cpp (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.cpp Thu Aug  6 16:05:06 2015
@@ -16,6 +16,7 @@
 #include "MachOUtils.h"
 #include "dsymutil.h"
 #include "llvm/Object/MachO.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Options.h"
@@ -84,6 +85,74 @@ static opt<bool> InputIsYAMLDebugMap(
     init(false), cat(DsymCategory));
 }
 
+static bool createPlistFile(llvm::StringRef BundleRoot) {
+  if (NoOutput)
+    return true;
+
+  // Create plist file to write to.
+  llvm::SmallString<128> InfoPlist(BundleRoot);
+  llvm::sys::path::append(InfoPlist, "Contents/Info.plist");
+  std::error_code EC;
+  llvm::raw_fd_ostream PL(InfoPlist, EC, llvm::sys::fs::F_Text);
+  if (EC) {
+    llvm::errs() << "error: cannot create plist file " << InfoPlist << ": "
+                 << EC.message() << '\n';
+    return false;
+  }
+
+  // FIXME: Use CoreFoundation to get executable bundle info. Use
+  // dummy values for now.
+  std::string bundleVersionStr = "1", bundleShortVersionStr = "1.0",
+              bundleIDStr;
+
+  llvm::StringRef BundleID = *llvm::sys::path::rbegin(BundleRoot);
+  if (llvm::sys::path::extension(BundleRoot) == ".dSYM")
+    bundleIDStr = llvm::sys::path::stem(BundleID);
+  else
+    bundleIDStr = BundleID;
+
+  // Print out information to the plist file.
+  PL << "<?xml version=\"1.0\" encoding=\"UTF-8\"\?>\n"
+     << "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" "
+     << "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
+     << "<plist version=\"1.0\">\n"
+     << "\t<dict>\n"
+     << "\t\t<key>CFBundleDevelopmentRegion</key>\n"
+     << "\t\t<string>English</string>\n"
+     << "\t\t<key>CFBundleIdentifier</key>\n"
+     << "\t\t<string>com.apple.xcode.dsym." << bundleIDStr << "</string>\n"
+     << "\t\t<key>CFBundleInfoDictionaryVersion</key>\n"
+     << "\t\t<string>6.0</string>\n"
+     << "\t\t<key>CFBundlePackageType</key>\n"
+     << "\t\t<string>dSYM</string>\n"
+     << "\t\t<key>CFBundleSignature</key>\n"
+     << "\t\t<string>\?\?\?\?</string>\n"
+     << "\t\t<key>CFBundleShortVersionString</key>\n"
+     << "\t\t<string>" << bundleShortVersionStr << "</string>\n"
+     << "\t\t<key>CFBundleVersion</key>\n"
+     << "\t\t<string>" << bundleVersionStr << "</string>\n"
+     << "\t</dict>\n"
+     << "</plist>\n";
+
+  PL.close();
+  return true;
+}
+
+static bool createBundleDir(llvm::StringRef BundleBase) {
+  if (NoOutput)
+    return true;
+
+  llvm::SmallString<128> Bundle(BundleBase);
+  llvm::sys::path::append(Bundle, "Contents", "Resources", "DWARF");
+  if (std::error_code EC = create_directories(Bundle.str(), true,
+                                              llvm::sys::fs::perms::all_all)) {
+    llvm::errs() << "error: cannot create directory " << Bundle << ": "
+                 << EC.message() << "\n";
+    return false;
+  }
+  return true;
+}
+
 static std::error_code getUniqueFile(const llvm::Twine &Model, int &ResultFD,
                                      llvm::SmallVectorImpl<char> &ResultPath) {
   // If in NoOutput mode, use the createUniqueFile variant that
@@ -99,7 +168,9 @@ static std::error_code getUniqueFile(con
 static std::string getOutputFileName(llvm::StringRef InputFile,
                                      bool TempFile = false) {
   if (TempFile) {
-    llvm::Twine OutputFile = InputFile + ".tmp%%%%%%.dwarf";
+    llvm::StringRef Basename =
+        OutputFileOpt.empty() ? InputFile : llvm::StringRef(OutputFileOpt);
+    llvm::Twine OutputFile = Basename + ".tmp%%%%%%.dwarf";
     int FD;
     llvm::SmallString<128> UniqueFile;
     if (auto EC = getUniqueFile(OutputFile, FD, UniqueFile)) {
@@ -116,12 +187,36 @@ static std::string getOutputFileName(llv
     return UniqueFile.str();
   }
 
-  if (OutputFileOpt.empty()) {
-    if (InputFile == "-")
-      return "a.out.dwarf";
-    return (InputFile + ".dwarf").str();
+  if (FlatOut) {
+    // If a flat dSYM has been requested, things are pretty simple.
+    if (OutputFileOpt.empty()) {
+      if (InputFile == "-")
+        return "a.out.dwarf";
+      return (InputFile + ".dwarf").str();
+    }
+
+    return OutputFileOpt;
   }
-  return OutputFileOpt;
+
+  // We need to create/update a dSYM bundle.
+  // A bundle hierarchy looks like this:
+  //   <bundle name>.dSYM/
+  //       Contents/
+  //          Info.plist
+  //          Resources/
+  //             DWARF/
+  //                <DWARF file(s)>
+  std::string DwarfFile =
+      InputFile == "-" ? llvm::StringRef("a.out") : InputFile;
+  llvm::SmallString<128> BundleDir(OutputFileOpt);
+  if (BundleDir.empty())
+    BundleDir = DwarfFile + ".dSYM";
+  if (!createBundleDir(BundleDir) || !createPlistFile(BundleDir))
+    return "";
+
+  llvm::sys::path::append(BundleDir, "Contents", "Resources", "DWARF",
+                          llvm::sys::path::filename(DwarfFile));
+  return BundleDir.str();
 }
 
 void llvm::dsymutil::exitDsymutil(int ExitStatus) {




More information about the llvm-commits mailing list