Mac v2 signing - Bug 1064910 - Update Webapp Runtime to work with the new v2 bundle structure of Firefox on OSX. r=myk
authorStephen Pohl <spohl.mozilla.bugs@gmail.com>
Mon, 29 Sep 2014 11:51:43 -0700
changeset 207878 09e4c6245f6d7a3070da126086df01486661919e
parent 207877 5af85a6db219c32ff98b4178d1c9235d2fe9e151
child 207879 47c2f60b1174d44e948e341628274908b2ef21db
push idunknown
push userunknown
push dateunknown
reviewersmyk
bugs1064910
milestone35.0a1
Mac v2 signing - Bug 1064910 - Update Webapp Runtime to work with the new v2 bundle structure of Firefox on OSX. r=myk
toolkit/webapps/tests/Makefile.in
webapprt/mac/webapprt.mm
--- a/toolkit/webapps/tests/Makefile.in
+++ b/toolkit/webapps/tests/Makefile.in
@@ -1,7 +1,12 @@
 # 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/.
 
 PROGRAMS_DEST = $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
 
 include $(topsrcdir)/config/rules.mk
+
+# Don't create a dependency on mozglue, which is impossible (difficult?)
+# to dynamically link into our executable, as we copy it to arbitrary locations.
+MOZ_GLUE_LDFLAGS =
+MOZ_GLUE_PROGRAM_LDFLAGS =
--- a/webapprt/mac/webapprt.mm
+++ b/webapprt/mac/webapprt.mm
@@ -33,17 +33,18 @@
 using namespace mozilla;
 
 const char WEBAPPRT_EXECUTABLE[] = "webapprt-stub";
 const char FXAPPINI_NAME[] = "application.ini";
 const char WEBAPPINI_NAME[] = "webapp.ini";
 const char WEBRTINI_NAME[] = "webapprt.ini";
 
 //need the correct relative path here
-const char APP_CONTENTS_PATH[] = "/Contents/MacOS/";
+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);
 
 NSString *PathToWebRT(NSString* alternateBinaryID);
 
@@ -114,23 +115,31 @@ main(int argc, char **argv)
     NSLog(@"USING FIREFOX : %@", firefoxPath);
 
     NSString *myWebRTPath = [myBundle pathForAuxiliaryExecutable: @"webapprt"];
     if (!myWebRTPath) {
       @throw MakeException(@"Missing Web Runtime Files", @"Cannot locate binary for this App");
     }
 
     //GET FIREFOX BUILD ID
-    NSString *firefoxINIFilePath = [NSString stringWithFormat:@"%@%s%s", firefoxPath, APP_CONTENTS_PATH, FXAPPINI_NAME];
+    NSString *firefoxINIFilePath =
+      [NSString stringWithFormat:@"%@%s%s", firefoxPath, APP_RESOURCES_PATH,
+                                            FXAPPINI_NAME];
     nsINIParser ffparser;
     NSLog(@"Looking for firefox ini file here: %@", firefoxINIFilePath);
-
     if (NS_FAILED(ffparser.Init([firefoxINIFilePath UTF8String]))) {
-      NSLog(@"Unable to locate Firefox application.ini");
-      @throw MakeException(@"Error", @"Unable to parse environment files for application startup");
+      firefoxINIFilePath = [NSString stringWithFormat:@"%@%s%s", firefoxPath,
+                                                                 APP_MACOS_PATH,
+                                                                 FXAPPINI_NAME];
+      NSLog(@"Looking for firefox ini file here: %@", firefoxINIFilePath);
+      if (NS_FAILED(ffparser.Init([firefoxINIFilePath UTF8String]))) {
+        NSLog(@"Unable to locate Firefox application.ini");
+        @throw MakeException(@"Error",
+          @"Unable to parse environment files for application startup");
+      }
     }
 
     char ffVersChars[MAXPATHLEN];
     if (NS_FAILED(ffparser.GetString("App", "BuildID", ffVersChars, MAXPATHLEN))) {
       NSLog(@"Unable to retrieve Firefox BuildID");
       @throw MakeException(@"Error", @"Unable to determine Firefox version.");
     }
     NSString* firefoxVersion = [NSString stringWithFormat:@"%s", ffVersChars];
@@ -144,17 +153,19 @@ main(int argc, char **argv)
       // it is newer or older.  If we don't find a webapprt, then the current Firefox must not be new enough to run webapps.
       NSLog(@"### This Application has an old webrt. Updating it.");
       NSLog(@"### My webapprt path: %@", myWebRTPath);
 
       NSFileManager* fileClerk = [[NSFileManager alloc] init];
       NSError *errorDesc = nil;
 
       //we know the firefox path, so copy the new webapprt here
-      NSString *newWebRTPath = [NSString stringWithFormat: @"%@%s%s", firefoxPath, APP_CONTENTS_PATH, WEBAPPRT_EXECUTABLE];
+      NSString *newWebRTPath =
+        [NSString stringWithFormat: @"%@%s%s", firefoxPath, APP_MACOS_PATH,
+                                               WEBAPPRT_EXECUTABLE];
       NSLog(@"### Firefox webapprt path: %@", newWebRTPath);
       if (![fileClerk fileExistsAtPath:newWebRTPath]) {
         NSString* msg = [NSString stringWithFormat: @"This version of Firefox (%@) cannot run web applications, because it is not recent enough or damaged", firefoxVersion];
         @throw MakeException(@"Missing Web Runtime Files", msg);
       }
 
       [fileClerk removeItemAtPath: myWebRTPath error: &errorDesc];
       if (errorDesc != nil) {
@@ -179,42 +190,49 @@ main(int argc, char **argv)
 
       NSLog(@"This Application has the newest webrt.  Launching!");
 
       int result = 0;
       char rtINIPath[MAXPATHLEN];
 
       // Set up our environment to know where webapp.ini was loaded from.
       char appEnv[MAXPATHLEN];
-      snprintf(appEnv, MAXPATHLEN, "%s%s%s", [myBundlePath UTF8String], APP_CONTENTS_PATH, WEBAPPINI_NAME);
+      snprintf(appEnv, MAXPATHLEN, "%s%s%s", [myBundlePath UTF8String],
+                                             APP_MACOS_PATH, WEBAPPINI_NAME);
       if (setenv("XUL_APP_FILE", appEnv, 1)) {
         NSLog(@"Couldn't set XUL_APP_FILE to: %s", appEnv);
         @throw MakeException(@"Error", @"Unable to set Web Runtime INI file.");
       }
       NSLog(@"Set XUL_APP_FILE to: %s", appEnv);
 
       //CONSTRUCT GREDIR AND CALL XPCOMGLUE WITH IT
       char greDir[MAXPATHLEN];
-      snprintf(greDir, MAXPATHLEN, "%s%s", [firefoxPath UTF8String], APP_CONTENTS_PATH);
+      snprintf(greDir, MAXPATHLEN, "%s%s", [firefoxPath UTF8String],
+                                           APP_RESOURCES_PATH);
       if (!NS_SUCCEEDED(AttemptGRELoad(greDir))) {
           @throw MakeException(@"Error", @"Unable to load XUL files for application startup");
       }
 
       // NOTE: The GRE has successfully loaded, so we can use XPCOM now
 
       NS_LogInit();
       { // Scope for any XPCOM stuff we create
 
         // Get the path to the runtime directory.
         char rtDir[MAXPATHLEN];
-        snprintf(rtDir, MAXPATHLEN, "%s%s%s", [firefoxPath UTF8String], APP_CONTENTS_PATH, WEBAPPRT_PATH);
+        snprintf(rtDir, MAXPATHLEN, "%s%s%s", [firefoxPath UTF8String],
+                                              APP_RESOURCES_PATH,
+                                              WEBAPPRT_PATH);
 
         // Get the path to the runtime's INI file.  This is in the runtime
         // directory.
-        snprintf(rtINIPath, MAXPATHLEN, "%s%s%s%s", [firefoxPath UTF8String], APP_CONTENTS_PATH, WEBAPPRT_PATH, WEBRTINI_NAME);
+        snprintf(rtINIPath, MAXPATHLEN, "%s%s%s%s", [firefoxPath UTF8String],
+                                                    APP_RESOURCES_PATH,
+                                                    WEBAPPRT_PATH,
+                                                    WEBRTINI_NAME);
         NSLog(@"WebappRT application.ini path: %s", rtINIPath);
 
         // Load the runtime's INI from its path.
         nsCOMPtr<nsIFile> rtINI;
         if (NS_FAILED(XRE_GetFileFromPath(rtINIPath, getter_AddRefs(rtINI)))) {
           NSLog(@"Runtime INI path not recognized: '%s'\n", rtINIPath);
           @throw MakeException(@"Error", @"Incorrect path to base INI file.");
         }
@@ -315,18 +333,19 @@ DisplayErrorAlert(NSString* title, NSStr
 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_CONTENTS_PATH];
+  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.aurora",
                                                                 @"org.mozilla.firefox", nil];