Mac v2 signing - Bug 1060562 - Update xpcshell-tests for the new v2 bundle structure on OSX. r=jmaher
authorStephen Pohl <spohl.mozilla.bugs@gmail.com>
Sat, 27 Sep 2014 21:05:06 -0700
changeset 491291 fdb81875e53bcdf80b986ba8f6189562ddaa3637
parent 491290 dbf4069f434a4bdb96a119de9d12ef50703d452a
child 491292 63a6f57407397ab1c3cc68c1801302f04bb0c6f6
push id47343
push userbmo:dothayer@mozilla.com
push dateWed, 01 Mar 2017 22:58:58 +0000
reviewersjmaher
bugs1060562
milestone35.0a1
Mac v2 signing - Bug 1060562 - Update xpcshell-tests for the new v2 bundle structure on OSX. r=jmaher
browser/app/macbuild/Contents/MacOS-files.in
js/xpconnect/src/XPCShellImpl.cpp
netwerk/test/unit/test_socks.js
python/mozbuild/mozbuild/base.py
security/manager/ssl/tests/unit/head_psm.js
testing/xpcshell/runxpcshelltests.py
testing/xpcshell/selftest.py
toolkit/crashreporter/test/unit/head_crashreporter.js
xpcom/tests/unit/head_xpcom.js
--- a/browser/app/macbuild/Contents/MacOS-files.in
+++ b/browser/app/macbuild/Contents/MacOS-files.in
@@ -1,8 +1,9 @@
 /*.app/***
 /*.dylib
 /certutil
 /firefox-bin
 /pk12util
 /ssltunnel
 /webapprt-stub
+/xpcshell
 /XUL
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -1346,26 +1346,44 @@ XRE_XPCShellMain(int argc, char **argv, 
             return 1;
         }
 
         dirprovider.SetGREDir(greDir);
 
         argc -= 2;
         argv += 2;
     } else {
+#ifdef XP_MACOSX
+        // On OSX, the GreD needs to point to Contents/Resources in the .app
+        // bundle. Libraries will be loaded at a relative path to GreD, i.e.
+        // ../MacOS.
+        XRE_GetFileFromPath(argv[0], getter_AddRefs(greDir));
+        nsCOMPtr<nsIFile> parentDir;
+        greDir->GetParent(getter_AddRefs(parentDir));
+        parentDir->GetParent(getter_AddRefs(greDir));
+        greDir->AppendNative(NS_LITERAL_CSTRING("Resources"));
+        bool dirExists = false;
+        greDir->Exists(&dirExists);
+        if (!dirExists) {
+            printf("Setting GreD failed.\n");
+            return 1;
+        }
+        dirprovider.SetGREDir(greDir);
+#else
         nsAutoString workingDir;
         if (!GetCurrentWorkingDirectory(workingDir)) {
             printf("GetCurrentWorkingDirectory failed.\n");
             return 1;
         }
         rv = NS_NewLocalFile(workingDir, true, getter_AddRefs(greDir));
         if (NS_FAILED(rv)) {
             printf("NS_NewLocalFile failed.\n");
             return 1;
         }
+#endif
     }
 
     if (argc > 1 && !strcmp(argv[1], "-a")) {
         if (argc < 3)
             return usage();
 
         nsCOMPtr<nsIFile> dir;
         rv = XRE_GetFileFromPath(argv[2], getter_AddRefs(dir));
--- a/netwerk/test/unit/test_socks.js
+++ b/netwerk/test/unit/test_socks.js
@@ -25,26 +25,20 @@ function getAvailableBytes(input)
   } catch (e) {
   }
   
   return len;
 }
 
 function runScriptSubprocess(script, args)
 {
-  // logic copied from ted's crashreporter unit test
   var ds = new DirectoryService();
-  var bin = ds.get("CurProcD", Ci.nsILocalFile);
-
-  bin.append("xpcshell");
+  var bin = ds.get("XREExeF", Ci.nsILocalFile);
   if (!bin.exists()) {
-    bin.leafName = "xpcshell.exe";
-    do_check_true(bin.exists());
-    if (!bin.exists())
-      do_throw("Can't find xpcshell binary");
+    do_throw("Can't find xpcshell binary");
   }
 
   var script = do_get_file(script);
   var proc = new Process(bin);
   var args = [script.path].concat(args);
 
   proc.run(false, args, args.length);
 
--- a/python/mozbuild/mozbuild/base.py
+++ b/python/mozbuild/mozbuild/base.py
@@ -269,16 +269,19 @@ class MozbuildObject(ProcessExecutionMix
         return self.config_environment.substs
 
     @property
     def distdir(self):
         return os.path.join(self.topobjdir, 'dist')
 
     @property
     def bindir(self):
+        import mozinfo
+        if mozinfo.os == "mac":
+            return os.path.join(self.topobjdir, 'dist', self.substs['MOZ_MACBUNDLE_NAME'], 'Contents', 'Resources')
         return os.path.join(self.topobjdir, 'dist', 'bin')
 
     @property
     def includedir(self):
         return os.path.join(self.topobjdir, 'dist', 'include')
 
     @property
     def statedir(self):
--- a/security/manager/ssl/tests/unit/head_psm.js
+++ b/security/manager/ssl/tests/unit/head_psm.js
@@ -356,17 +356,19 @@ function _setupTLSServerTest(serverBinNa
 
   const CALLBACK_PORT = 8444;
 
   let directoryService = Cc["@mozilla.org/file/directory_service;1"]
                            .getService(Ci.nsIProperties);
   let envSvc = Cc["@mozilla.org/process/environment;1"]
                  .getService(Ci.nsIEnvironment);
   let greDir = directoryService.get("GreD", Ci.nsIFile);
-  envSvc.set("DYLD_LIBRARY_PATH", greDir.path);
+  let macOSDir = greDir.parent;
+  macOSDir.append("MacOS");
+  envSvc.set("DYLD_LIBRARY_PATH", macOSDir.path);
   envSvc.set("LD_LIBRARY_PATH", greDir.path);
   envSvc.set("MOZ_TLS_SERVER_DEBUG_LEVEL", "3");
   envSvc.set("MOZ_TLS_SERVER_CALLBACK_PORT", CALLBACK_PORT);
 
   let httpServer = new HttpServer();
   httpServer.registerPathHandler("/",
       function handleServerCallback(aRequest, aResponse) {
         aResponse.setStatusLine(aRequest.httpVersion, 200, "OK");
--- a/testing/xpcshell/runxpcshelltests.py
+++ b/testing/xpcshell/runxpcshelltests.py
@@ -3,16 +3,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import copy
 import json
 import math
 import mozdebug
+import mozinfo
 import os
 import os.path
 import random
 import re
 import shutil
 import signal
 import socket
 import sys
@@ -836,16 +837,22 @@ class XPCShellTests(object):
         self.httpdJSPath = os.path.join(os.path.dirname(self.xpcshell), 'components', 'httpd.js')
         self.httpdJSPath = replaceBackSlashes(self.httpdJSPath)
 
         self.httpdManifest = os.path.join(os.path.dirname(self.xpcshell), 'components', 'httpd.manifest')
         self.httpdManifest = replaceBackSlashes(self.httpdManifest)
 
         if self.xrePath is None:
             self.xrePath = os.path.dirname(self.xpcshell)
+            if mozinfo.isMac:
+                # Check if we're run from an OSX app bundle and override
+                # self.xrePath if we are.
+                appBundlePath = os.path.join(os.path.dirname(os.path.dirname(self.xpcshell)), 'Resources')
+                if os.path.exists(os.path.join(appBundlePath, 'application.ini')):
+                    self.xrePath = appBundlePath
         else:
             self.xrePath = os.path.abspath(self.xrePath)
 
         if self.mozInfo is None:
             self.mozInfo = os.path.join(self.testharnessdir, "mozinfo.json")
 
     def buildCoreEnvironment(self):
         """
@@ -875,17 +882,17 @@ class XPCShellTests(object):
         self.env = dict(os.environ)
         self.buildCoreEnvironment()
         if sys.platform == 'win32':
             self.env["PATH"] = self.env["PATH"] + ";" + self.xrePath
         elif sys.platform in ('os2emx', 'os2knix'):
             os.environ["BEGINLIBPATH"] = self.xrePath + ";" + self.env["BEGINLIBPATH"]
             os.environ["LIBPATHSTRICT"] = "T"
         elif sys.platform == 'osx' or sys.platform == "darwin":
-            self.env["DYLD_LIBRARY_PATH"] = self.xrePath
+            self.env["DYLD_LIBRARY_PATH"] = os.path.join(os.path.dirname(self.xrePath), 'MacOS')
         else: # unix or linux?
             if not "LD_LIBRARY_PATH" in self.env or self.env["LD_LIBRARY_PATH"] is None:
                 self.env["LD_LIBRARY_PATH"] = self.xrePath
             else:
                 self.env["LD_LIBRARY_PATH"] = ":".join([self.xrePath, self.env["LD_LIBRARY_PATH"]])
 
         if "asan" in self.mozInfo and self.mozInfo["asan"]:
             # ASan symbolizer support
--- a/testing/xpcshell/selftest.py
+++ b/testing/xpcshell/selftest.py
@@ -15,18 +15,23 @@ from mozbuild.base import MozbuildObject
 os.environ.pop('MOZ_OBJDIR', None)
 build_obj = MozbuildObject.from_environment()
 
 from runxpcshelltests import XPCShellTests
 
 mozinfo.find_and_update_from_json()
 
 objdir = build_obj.topobjdir.encode("utf-8")
-xpcshellBin = os.path.join(objdir, "dist", "bin", "xpcshell")
-if sys.platform == "win32":
+
+if mozinfo.isMac:
+  from buildconfig import substs
+  xpcshellBin = os.path.join(objdir, "dist", substs['MOZ_MACBUNDLE_NAME'], "Contents", "MacOS", "xpcshell")
+else:
+  xpcshellBin = os.path.join(objdir, "dist", "bin", "xpcshell")
+  if sys.platform == "win32":
     xpcshellBin += ".exe"
 
 SIMPLE_PASSING_TEST = "function run_test() { do_check_true(true); }"
 SIMPLE_FAILING_TEST = "function run_test() { do_check_true(false); }"
 
 ADD_TEST_SIMPLE = '''
 function run_test() { run_next_test(); }
 
--- a/toolkit/crashreporter/test/unit/head_crashreporter.js
+++ b/toolkit/crashreporter/test/unit/head_crashreporter.js
@@ -30,24 +30,20 @@ function getEventDir() {
  *       Certain types of crashes may not cause the process to
  *       exit with an error.
  */
 function do_crash(setup, callback, canReturnZero)
 {
   // get current process filename (xpcshell)
   let ds = Components.classes["@mozilla.org/file/directory_service;1"]
     .getService(Components.interfaces.nsIProperties);
-  let bin = ds.get("CurProcD", Components.interfaces.nsILocalFile);
-  bin.append("xpcshell");
+  let bin = ds.get("XREExeF", Components.interfaces.nsILocalFile);
   if (!bin.exists()) {
-    bin.leafName = "xpcshell.exe";
-    do_check_true(bin.exists());
-    if (!bin.exists())
-      // weird, can't find xpcshell binary?
-      do_throw("Can't find xpcshell binary!");
+    // weird, can't find xpcshell binary?
+    do_throw("Can't find xpcshell binary!");
   }
   // get Gre dir (GreD)
   let greD = ds.get("GreD", Components.interfaces.nsILocalFile);
   let headfile = do_get_file("crasher_subprocess_head.js");
   let tailfile = do_get_file("crasher_subprocess_tail.js");
   // run xpcshell -g GreD -f head -e "some setup code" -f tail
   let process = Components.classes["@mozilla.org/process/util;1"]
                   .createInstance(Components.interfaces.nsIProcess);
--- a/xpcom/tests/unit/head_xpcom.js
+++ b/xpcom/tests/unit/head_xpcom.js
@@ -11,15 +11,16 @@ function get_test_program(prog)
 
 function set_process_running_environment()
 {
   var envSvc = Components.classes["@mozilla.org/process/environment;1"].
     getService(Components.interfaces.nsIEnvironment);
   var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"].
     getService(Components.interfaces.nsIProperties);
   var greDir = dirSvc.get("GreD", Components.interfaces.nsIFile);
-
-  envSvc.set("DYLD_LIBRARY_PATH", greDir.path);
+  var macOSDir = greDir.parent;
+  macOSDir.append("MacOS");
+  envSvc.set("DYLD_LIBRARY_PATH", macOSDir.path);
   // For Linux
   envSvc.set("LD_LIBRARY_PATH", greDir.path);
   //XXX: handle windows
 }