From e610f17c27cc092c853db0dfd72c7a748df1e9e7 Mon Sep 17 00:00:00 2001 From: Robert Sayre Date: Fri, 19 Apr 2019 07:49:00 -0700 Subject: [PATCH] Conditionally use deprecated signature for initWithContentsOfURL Homebrew's CI is breaking on 10.12 (Sierra), for Bazel 0.24+ due to the signature used for NSDictionary:initWithContentsOfURL introduced in the fix for #7371. This signature with an error parameter is only available on 10.13+ (High Sierra). Here's Apple's documentation: https://developer.apple.com/documentation/foundation/nsdictionary/1416069-initwithcontentsofurl?language=objc The Homebrew issue: https://github.com/Homebrew/homebrew-core/pull/38651 Closes #8068. PiperOrigin-RevId: 244357959 --- tools/osx/xcode_locator.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/osx/xcode_locator.m b/tools/osx/xcode_locator.m index 71b0b1427bf2be..90c00fafcc5b74 100644 --- a/tools/osx/xcode_locator.m +++ b/tools/osx/xcode_locator.m @@ -177,8 +177,16 @@ static void AddEntryToDictionary( url, version, expandedVersion); NSURL *versionPlistUrl = [url URLByAppendingPathComponent:@"Contents/version.plist"]; - NSDictionary *versionPlistContents = [[NSDictionary alloc] initWithContentsOfURL:versionPlistUrl - error:nil]; + + // macOS 10.13 changed the signature of initWithContentsOfURL, + // and deprecated the old one. + NSDictionary *versionPlistContents; +#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_12 + versionPlistContents = [[NSDictionary alloc] initWithContentsOfURL:versionPlistUrl error:nil]; +#else + versionPlistContents = [[NSDictionary alloc] initWithContentsOfURL:versionPlistUrl]; +#endif + NSString *productVersion = [versionPlistContents objectForKey:@"ProductBuildVersion"]; if (productVersion) { expandedVersion = [expandedVersion stringByAppendingFormat:@".%@", productVersion];