Bug 1168737 - specify runtime with command-line arg on Mac for tests; r=jmaher,marco
☠☠ backed out by ed1115ca4083 ☠ ☠
authorMyk Melez <myk@mozilla.org>
Fri, 19 Jun 2015 09:41:54 -0700
changeset 249850 cd741d3ae78a7ef127b6baf7c4efc0fff0472267
parent 249849 6b847a10bbb1996436d05cd8b64fb64775a37fe7
child 249851 3f025568ad349d7b4a4da45feef6812c4e4d4101
push id61365
push usermyk@mozilla.com
push dateSat, 20 Jun 2015 18:15:12 +0000
treeherdermozilla-inbound@cd741d3ae78a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher, marco
bugs1168737
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1168737 - specify runtime with command-line arg on Mac for tests; r=jmaher,marco
testing/mochitest/mach_commands.py
webapprt/mac/webapprt.mm
--- a/testing/mochitest/mach_commands.py
+++ b/testing/mochitest/mach_commands.py
@@ -328,16 +328,20 @@ class MochitestRunner(MozbuildObject):
             if not options.app or options.app == self.get_binary_path():
                 options.app = self.get_webapp_runtime_path()
             options.xrePath = self.get_webapp_runtime_xre_path()
         elif suite == 'webapprt-chrome':
             options.browserArgs.append("-test-mode")
             if not options.app or options.app == self.get_binary_path():
                 options.app = self.get_webapp_runtime_path()
             options.xrePath = self.get_webapp_runtime_xre_path()
+            # On Mac, pass the path to the runtime, to ensure the test app
+            # uses that specific runtime instead of another one on the system.
+            if sys.platform.startswith('darwin'):
+                options.browserArgs.extend(('-runtime', os.path.join(self.distdir, self.substs['MOZ_MACBUNDLE_NAME'])))
 
         from manifestparser import TestManifest
         manifest = TestManifest()
         manifest.tests.extend(tests)
         options.manifestFile = manifest
 
         # XXX why is this such a special case?
         if len(tests) == 1 and options.closeWhenDone and suite == 'plain':
--- a/webapprt/mac/webapprt.mm
+++ b/webapprt/mac/webapprt.mm
@@ -39,17 +39,17 @@ const char WEBRTINI_NAME[] = "webapprt.i
 
 //need the correct relative path here
 const char APP_MACOS_PATH[]     = "/Contents/MacOS/";
 const char APP_RESOURCES_PATH[] = "/Contents/Resources/";
 
 //the path to the WebappRT subdir within the Firefox app contents dir
 const char WEBAPPRT_PATH[] = "webapprt/";
 
-void ExecNewBinary(NSString* launchPath);
+void ExecNewBinary(NSString* launchPath, NSDictionary* args);
 
 NSString *PathToWebRT(NSString* alternateBinaryID);
 
 NSException* MakeException(NSString* name, NSString* message);
 
 void DisplayErrorAlert(NSString* title, NSString* message);
 
 XRE_GetFileFromPathType XRE_GetFileFromPath;
@@ -105,19 +105,25 @@ main(int argc, char **argv)
 
   //I need to look in our bundle first, before deciding what firefox binary to use
   NSBundle* myBundle = [NSBundle mainBundle];
   NSString* myBundlePath = [myBundle bundlePath];
   alternateBinaryID = [myBundle objectForInfoDictionaryKey:@"FirefoxBinary"];
   NSLog(@"found override firefox binary: %@", alternateBinaryID);
 
   @try {
-    //find a webapprt binary to launch with.  throws an exception with error dialog if none found.
-    firefoxPath = PathToWebRT(alternateBinaryID);
-    NSLog(@"USING FIREFOX : %@", firefoxPath);
+    // Determine the runtime with which to run the application.
+    // Throws an exception with an error dialog if it can't find one.
+    firefoxPath = [args objectForKey:@"runtime"];
+    if (firefoxPath) {
+      NSLog(@"Runtime specified with -runtime flag: %@", firefoxPath);
+    } else {
+      firefoxPath = PathToWebRT(alternateBinaryID);
+      NSLog(@"Found runtime: %@", firefoxPath);
+    }
 
     NSString* myWebRTPath = [myBundle pathForResource:@"webapprt"
                                                ofType:nil];
     if (!myWebRTPath) {
       myWebRTPath = [myBundlePath stringByAppendingPathComponent:@"Contents"];
       myWebRTPath = [myWebRTPath stringByAppendingPathComponent:@"MacOS"];
       myWebRTPath = [myWebRTPath stringByAppendingPathComponent:@"webapprt"];
       if ([[NSFileManager defaultManager] fileExistsAtPath:myWebRTPath] == NO) {
@@ -193,17 +199,17 @@ main(int argc, char **argv)
       if (errorDesc != nil) {
         NSLog(@"failed to copy new webrt file: %@", errorDesc);
         @throw MakeException(@"Unable To Update Web Runtime", @"Failed to update Web Runtime");
       } else {
         NSLog(@"### Successfully updated webapprt, relaunching");
       }
 
       //execv the new binary, and ride off into the sunset
-      ExecNewBinary(myWebRTPath);
+      ExecNewBinary(myWebRTPath, args);
 
     } else {
       //we are ready to load XUL and such, and go go go
 
       NSLog(@"This Application has the newest webrt.  Launching!");
 
       int result = 0;
       char rtINIPath[MAXPATHLEN];
@@ -262,17 +268,17 @@ main(int argc, char **argv)
         nsXREAppData *webShellAppData;
         if (NS_FAILED(XRE_CreateAppData(rtINI, &webShellAppData))) {
           NSLog(@"Couldn't read WebappRT application.ini: %s", rtINIPath);
           @throw MakeException(@"Error", @"Unable to parse base INI file.");
         }
 
         NSString *profile = [args objectForKey:@"profile"];
         if (profile) {
-          NSLog(@"Profile specified with --profile: %@", profile);
+          NSLog(@"Profile specified with -profile flag: %@", profile);
         }
         else {
           nsINIParser parser;
           if (NS_FAILED(parser.Init(appEnv))) {
             NSLog(@"%s was not found\n", appEnv);
             @throw MakeException(@"Error", @"Unable to parse environment files for application startup");
           }
           char profile[MAXPATHLEN];
@@ -346,25 +352,16 @@ DisplayErrorAlert(NSString* title, NSStr
 /* Find the currently installed Firefox, if any, and return
  * an absolute path to it. may return nil */
 NSString
 *PathToWebRT(NSString* alternateBinaryID)
 {
   //default is firefox
   NSString *binaryPath = nil;
 
-  // We're run from the Firefox bundle during WebappRT chrome and content tests.
-  NSString *myBundlePath = [[NSBundle mainBundle] bundlePath];
-  NSString *fxPath =
-    [NSString stringWithFormat:@"%@%sfirefox-bin", myBundlePath,
-                                                   APP_MACOS_PATH];
-  if ([[NSFileManager defaultManager] fileExistsAtPath:fxPath]) {
-    return myBundlePath;
-  }
-
   //we look for these flavors of Firefox, in this order
   NSArray* launchBinarySearchList = [NSArray arrayWithObjects: @"org.mozilla.nightly",
                                                                 @"org.mozilla.firefoxdeveloperedition",
                                                                 @"org.mozilla.firefox", nil];
 
   // If they provided a binary ID, use that.
   if (alternateBinaryID != nil && ([alternateBinaryID length] > 0)) {
     binaryPath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:alternateBinaryID];
@@ -384,17 +381,31 @@ NSString
 
   NSLog(@"unable to find a valid webrt path");
   @throw MakeException(@"This App requires that Firefox version 16 or above is installed.", @"Firefox 16+ has not been detected.");
 
   return nil;
 }
 
 void
-ExecNewBinary(NSString* launchPath)
+ExecNewBinary(NSString* launchPath, NSDictionary* args)
 {
   NSLog(@" launching webrt at path: %@\n", launchPath);
 
-  const char *const newargv[] = {[launchPath UTF8String], NULL};
+  NSUInteger numArgs = [args count];
+  const char *newargv[numArgs + 2];
+  NSMutableString *commandLine = [NSMutableString string];
+  newargv[0] = [launchPath UTF8String];
+  [commandLine appendString:launchPath];
 
-  NSLog(@"COMMAND LINE: '%@ %s'", launchPath, newargv[0]);
+  NSUInteger i = 1;
+  for (id key in args) {
+    NSString *name = [@"-" stringByAppendingString:key];
+    NSString *value = [args objectForKey:key];
+    newargv[i++] = [name UTF8String];
+    newargv[i++] = [value UTF8String];
+    [commandLine appendFormat:@" %@ %@", name, value];
+  }
+  newargv[i] = NULL;
+
+  NSLog(@"Command line: '%@'", commandLine);
   execv([launchPath UTF8String], (char **)newargv);
 }