<rdar://problem/15487072> Modernize WebKit.app's OS X version checking logic.
authormrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Nov 2013 06:01:19 +0000 (06:01 +0000)
committermrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Nov 2013 06:01:19 +0000 (06:01 +0000)
Gestalt is deprecated on recent OS X versions so we should switch off it.

Reviewed by Sam Weinig.

* WebKitLauncher/main.m:
(currentMacOSXVersion): Retrieve the version string from SystemVersion.plist.
(currentMacOSXMajorVersion): Split the version string at the periods, retrieve the first
two components, then join them back up.
(main): Switch to using currentMacOSXMajorVersion to make it clearer which part of
the version we care about.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@159549 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/WebKitLauncher/main.m

index 3877296..37b2696 100644 (file)
@@ -1,3 +1,18 @@
+2013-11-19  Mark Rowe  <mrowe@apple.com>
+
+        <rdar://problem/15487072> Modernize WebKit.app's OS X version checking logic.
+
+        Gestalt is deprecated on recent OS X versions so we should switch off it.
+
+        Reviewed by Sam Weinig.
+
+        * WebKitLauncher/main.m:
+        (currentMacOSXVersion): Retrieve the version string from SystemVersion.plist.
+        (currentMacOSXMajorVersion): Split the version string at the periods, retrieve the first
+        two components, then join them back up.
+        (main): Switch to using currentMacOSXMajorVersion to make it clearer which part of
+        the version we care about.
+
 2013-11-19  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r159538.
index 45e4a0d..e121da0 100644 (file)
@@ -185,11 +185,18 @@ static NSString *determineExecutablePath(NSBundle *bundle)
 
 static NSString *currentMacOSXVersion()
 {
-    SInt32 version;
-    if (Gestalt(gestaltSystemVersion, &version) != noErr)
-        return @"10.4";
+    // Can't use -[NSProcessInfo operatingSystemVersionString] because it has too much stuff we don't want.
+    NSString *systemLibraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSSystemDomainMask, YES) objectAtIndex:0];
+    NSString *systemVersionPlistPath = [systemLibraryPath stringByAppendingPathComponent:@"CoreServices/SystemVersion.plist"];
+    NSDictionary *systemVersionInfo = [NSDictionary dictionaryWithContentsOfFile:systemVersionPlistPath];
+    return [systemVersionInfo objectForKey:@"ProductVersion"];
+}
 
-    return [NSString stringWithFormat:@"%lx.%lx", (long)(version & 0xFF00) >> 8, (long)(version & 0x00F0) >> 4l];
+static NSString *currentMacOSXMajorVersion()
+{
+    NSArray *allComponents = [currentMacOSXVersion() componentsSeparatedByString:@"."];
+    NSArray *majorAndMinorComponents = [allComponents objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)]];
+    return [majorAndMinorComponents componentsJoinedByString:@"."];
 }
 
 static NSString *fallbackMacOSXVersion(NSString *systemVersion)
@@ -221,7 +228,7 @@ int main(int argc, char *argv[])
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
-    NSString *systemVersion = currentMacOSXVersion();
+    NSString *systemVersion = currentMacOSXMajorVersion();
     NSString *frameworkPath = [[[NSBundle mainBundle] privateFrameworksPath] stringByAppendingPathComponent:systemVersion];
 
     BOOL frameworkPathIsUsable = checkFrameworkPath(frameworkPath);