Skip to content

Commit

Permalink
Conditionally use deprecated signature for initWithContentsOfURL
Browse files Browse the repository at this point in the history
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 bazelbuild#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:
Homebrew/homebrew-core#38651

Closes bazelbuild#8068.

PiperOrigin-RevId: 244357959
  • Loading branch information
sayrer authored and copybara-github committed Apr 19, 2019
1 parent 771c641 commit 231270c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tools/osx/xcode_locator.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 231270c

Please sign in to comment.