Bug 1048687: Read dependentlibs.list from Contents/Resources due to the new .app bundle structure. r=bsmedberg
authorStephen Pohl <spohl.mozilla.bugs@gmail.com>
Thu, 18 Sep 2014 16:22:24 -0400
changeset 491234 e305e14d93cf69313b837a81e22fe89ae67dacae
parent 491233 012e80a2ad45e29fa7a6f8d25d73ba4c4575a1b0
child 491235 f4e266d5f8f21824c19e9e5d121f41737b73eefe
push id47343
push userbmo:dothayer@mozilla.com
push dateWed, 01 Mar 2017 22:58:58 +0000
reviewersbsmedberg
bugs1048687
milestone35.0a1
Bug 1048687: Read dependentlibs.list from Contents/Resources due to the new .app bundle structure. r=bsmedberg
xpcom/glue/standalone/nsXPCOMGlue.cpp
--- a/xpcom/glue/standalone/nsXPCOMGlue.cpp
+++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp
@@ -362,48 +362,79 @@ ns_strrpbrk(const char* string, const ch
   return found;
 }
 #endif
 
 static GetFrozenFunctionsFunc
 XPCOMGlueLoad(const char* aXPCOMFile)
 {
   char xpcomDir[MAXPATHLEN];
-#if defined(XP_WIN)
+#ifdef XP_WIN
   const char* lastSlash = ns_strrpbrk(aXPCOMFile, "/\\");
+#elif XP_MACOSX
+  // On OSX, the dependentlibs.list file lives under Contents/Resources.
+  // However, the actual libraries listed in dependentlibs.list live under
+  // Contents/MacOS. We want to read the list from Contents/Resources, then
+  // load the libraries from Contents/MacOS.
+  const char *tempSlash = strrchr(aXPCOMFile, '/');
+  size_t tempLen = size_t(tempSlash - aXPCOMFile);
+  if (tempLen > MAXPATHLEN) {
+    return nullptr;
+  }
+  char tempBuffer[MAXPATHLEN];
+  memcpy(tempBuffer, aXPCOMFile, tempLen);
+  const char *slash = strrchr(tempBuffer, '/');
+  tempLen = size_t(slash - tempBuffer);
+  const char *lastSlash = aXPCOMFile + tempLen;
 #else
   const char* lastSlash = strrchr(aXPCOMFile, '/');
 #endif
   char* cursor;
   if (lastSlash) {
     size_t len = size_t(lastSlash - aXPCOMFile);
 
     if (len > MAXPATHLEN - sizeof(XPCOM_FILE_PATH_SEPARATOR
+#ifdef XP_MACOSX
+                                  "Resources"
+                                  XPCOM_FILE_PATH_SEPARATOR
+#endif
                                   XPCOM_DEPENDENT_LIBS_LIST)) {
       return nullptr;
     }
     memcpy(xpcomDir, aXPCOMFile, len);
     strcpy(xpcomDir + len, XPCOM_FILE_PATH_SEPARATOR
-           XPCOM_DEPENDENT_LIBS_LIST);
+#ifdef XP_MACOSX
+                           "Resources"
+                           XPCOM_FILE_PATH_SEPARATOR
+#endif
+                           XPCOM_DEPENDENT_LIBS_LIST);
     cursor = xpcomDir + len + 1;
   } else {
     strcpy(xpcomDir, XPCOM_DEPENDENT_LIBS_LIST);
     cursor = xpcomDir;
   }
 
   if (getenv("MOZ_RUN_GTEST")) {
     strcat(xpcomDir, ".gtest");
   }
 
   ScopedCloseFile flist;
   flist = TS_tfopen(xpcomDir, READ_TEXTMODE);
   if (!flist) {
     return nullptr;
   }
 
+#ifdef XP_MACOSX
+  tempLen = size_t(cursor - xpcomDir);
+  if (tempLen > MAXPATHLEN - sizeof("MacOS" XPCOM_FILE_PATH_SEPARATOR) - 1) {
+    return nullptr;
+  }
+  strcpy(cursor, "MacOS" XPCOM_FILE_PATH_SEPARATOR);
+  cursor += strlen(cursor);
+#endif
   *cursor = '\0';
 
   char buffer[MAXPATHLEN];
 
   while (fgets(buffer, sizeof(buffer), flist)) {
     int l = strlen(buffer);
 
     // ignore empty lines and comments