From 9e10d3e9c90d0d0962f59a55fdd347ad2c20f8a2 Mon Sep 17 00:00:00 2001 From: jmmv Date: Wed, 1 Aug 2018 10:25:07 -0700 Subject: Use a parameterized dict and simplify an iteration in xcode-locator. This raises the minimum version with which xcode-locator must be built to Xcode 7. Changes suggested by davg@ during the review of another change to the xcode-locator. RELNOTES: None. PiperOrigin-RevId: 206949696 --- tools/osx/xcode_locator.m | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'tools') diff --git a/tools/osx/xcode_locator.m b/tools/osx/xcode_locator.m index 1565f6f7f8..e2473957c3 100644 --- a/tools/osx/xcode_locator.m +++ b/tools/osx/xcode_locator.m @@ -62,8 +62,9 @@ // precedence over installed versions.) // // 2. Not older (at least as high version number). -static void AddEntryToDictionary(XcodeVersionEntry *entry, - NSMutableDictionary *dict) { +static void AddEntryToDictionary( + XcodeVersionEntry *entry, + NSMutableDictionary *dict) { BOOL inApplications = [entry.url.path rangeOfString:@"/Applications/"].location != NSNotFound; NSString *entryVersion = entry.version; @@ -113,10 +114,12 @@ static NSString *ExpandVersion(NSString *version) { // // If there is a problem locating the Xcodes, prints one or more error messages // and returns nil. -static NSMutableDictionary *FindXcodes() __attribute((ns_returns_retained)) { +static NSMutableDictionary *FindXcodes() + __attribute((ns_returns_retained)) { CFStringRef bundleID = CFSTR("com.apple.dt.Xcode"); - NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; + NSMutableDictionary *dict = + [[NSMutableDictionary alloc] init]; CFErrorRef cfError; NSArray *array = CFBridgingRelease(LSCopyApplicationURLsForBundleIdentifier( bundleID, &cfError)); @@ -171,17 +174,22 @@ static NSMutableDictionary *FindXcodes() __attribute((ns_returns_retained)) { // Prints out the located Xcodes as a set of lines where each line contains the // list of versions for a given Xcode and its location on disk. -static void DumpAsVersionsOnly(FILE *output, NSMutableDictionary *dict) { - NSSet *distinctValues = [[NSSet alloc] initWithArray:[dict allValues]]; - NSMutableDictionary *aliasDict = [[NSMutableDictionary alloc] init]; - for (XcodeVersionEntry *value in distinctValues) { - NSString *versionString = value.version; +static void DumpAsVersionsOnly( + FILE *output, + NSMutableDictionary *dict) { + NSSet *distinctValues = + [[NSSet alloc] initWithArray:dict.allValues]; + NSMutableDictionary *> *aliasDict = + [[NSMutableDictionary alloc] init]; + [dict enumerateKeysAndObjectsUsingBlock:^(NSString *aliasVersion, + XcodeVersionEntry *entry, + BOOL *stop) { + NSString *versionString = entry.version; if (aliasDict[versionString] == nil) { aliasDict[versionString] = [[NSMutableSet alloc] init]; } - [aliasDict[versionString] - addObjectsFromArray:[dict allKeysForObject:value]]; - } + [aliasDict[versionString] addObject:aliasVersion]; + }]; for (NSString *version in aliasDict) { XcodeVersionEntry *entry = dict[version]; fprintf(output, "%s:%s:%s\n", @@ -193,7 +201,9 @@ static void DumpAsVersionsOnly(FILE *output, NSMutableDictionary *dict) { } // Prints out the located Xcodes in JSON format. -static void DumpAsJson(FILE *output, NSMutableDictionary *dict) { +static void DumpAsJson( + FILE *output, + NSMutableDictionary *dict) { fprintf(output, "{\n"); for (NSString *version in dict) { XcodeVersionEntry *entry = dict[version]; @@ -250,7 +260,7 @@ int main(int argc, const char * argv[]) { return 1; } - NSMutableDictionary *dict = FindXcodes(); + NSMutableDictionary *dict = FindXcodes(); if (dict == nil) { return 1; } -- cgit v1.2.3