<pre style='margin:0'>
Chris Jones (cjones051073) pushed a commit to branch master
in repository macports-ports.
</pre>
<p><a href="https://github.com/macports/macports-ports/commit/a98adeb53007c54a7812d28428f9ef8ba896604f">https://github.com/macports/macports-ports/commit/a98adeb53007c54a7812d28428f9ef8ba896604f</a></p>
<pre style="white-space: pre; background: #F8F8F8">The following commit(s) were added to refs/heads/master by this push:
<span style='display:block; white-space:pre;color:#404040;'> new a98adeb bazel: update Xcode locate fix
</span>a98adeb is described below
<span style='display:block; white-space:pre;color:#808000;'>commit a98adeb53007c54a7812d28428f9ef8ba896604f
</span>Author: Chris Jones <jonesc@macports.org>
AuthorDate: Sat May 18 22:07:09 2019 +0100
<span style='display:block; white-space:pre;color:#404040;'> bazel: update Xcode locate fix
</span>---
devel/bazel/Portfile | 4 +
.../xcode_locator_fixes/Xcode8-xcode_locator.m | 293 +++++++++++++++++++++
2 files changed, 297 insertions(+)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/devel/bazel/Portfile b/devel/bazel/Portfile
</span><span style='display:block; white-space:pre;color:#808080;'>index 13f371b..c39453a 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/devel/bazel/Portfile
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/devel/bazel/Portfile
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -99,6 +99,10 @@ post-patch {
</span> # Revert xcode-locator to an older version
# https://raw.githubusercontent.com/bazelbuild/bazel/7372c04d40d7ab45fa2649c8be002ee6909668d1/tools/osx/xcode_locator.m
file copy -force ${filespath}/xcode_locator_fixes/Xcode7-xcode_locator.m ${worksrcpath}/tools/osx/xcode_locator.m
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ } elseif {[vercmp ${xcodeversion} 9.0] < 0} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # Revert xcode-locator to an older version
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ # From bazel 0.21.0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ file copy -force ${filespath}/xcode_locator_fixes/Xcode8-xcode_locator.m ${worksrcpath}/tools/osx/xcode_locator.m
</span> }
}
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/devel/bazel/files/xcode_locator_fixes/Xcode8-xcode_locator.m b/devel/bazel/files/xcode_locator_fixes/Xcode8-xcode_locator.m
</span>new file mode 100755
<span style='display:block; white-space:pre;color:#808080;'>index 0000000..6e318d7
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>--- /dev/null
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/devel/bazel/files/xcode_locator_fixes/Xcode8-xcode_locator.m
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -0,0 +1,293 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// Copyright 2015 Google Inc. All rights reserved.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+//
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// Licensed under the Apache License, Version 2.0 (the "License");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// you may not use this file except in compliance with the License.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// You may obtain a copy of the License at
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+//
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// http://www.apache.org/licenses/LICENSE-2.0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+//
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// Unless required by applicable law or agreed to in writing, software
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// distributed under the License is distributed on an "AS IS" BASIS,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// See the License for the specific language governing permissions and
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// limitations under the License.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// Application that finds all Xcodes installed on a given Mac and will return a
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// path for a given version number.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+//
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// If you have 7.0, 6.4.1 and 6.3 installed the inputs will map to:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+//
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// 7,7.0,7.0.0 = 7.0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// 6,6.4,6.4.1 = 6.4.1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// 6.3,6.3.0 = 6.3
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#if !defined(__has_feature) || !__has_feature(objc_arc)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#error "This file requires ARC support."
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#import <CoreServices/CoreServices.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#import <Foundation/Foundation.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// Simple data structure for tracking a version of Xcode (i.e. 6.4) with an URL
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// to the appplication.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@interface XcodeVersionEntry : NSObject
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@property(readonly) NSString *version;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@property(readonly) NSURL *url;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@end
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@implementation XcodeVersionEntry
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- (id)initWithVersion:(NSString *)version url:(NSURL *)url {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if ((self = [super init])) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ _version = version;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ _url = url;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return self;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- (id)description {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return [NSString stringWithFormat:@"<%@ %p>: %@ %@",
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ [self class], self, _version, _url];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@end
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// Given an entry, insert it into a dictionary that is keyed by versions.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+//
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// For an entry that is 6.4.1:/Applications/Xcode.app, add it for 6.4.1 and
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// optionally add it for 6.4 and 6 if it is "better" than any entry that may
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// already be there, where "better" is defined as:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+//
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// 1. Under /Applications/. (This avoids mounted xcode versions taking
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// precedence over installed versions.)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+//
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// 2. Not older (at least as high version number).
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static void AddEntryToDictionary(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ XcodeVersionEntry *entry,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSMutableDictionary<NSString *, XcodeVersionEntry *> *dict) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ BOOL inApplications =
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ [entry.url.path rangeOfString:@"/Applications/"].location != NSNotFound;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSString *entryVersion = entry.version;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSString *subversion = entryVersion;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (dict[entryVersion] && !inApplications) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ dict[entryVersion] = entry;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ while (YES) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSRange range = [subversion rangeOfString:@"." options:NSBackwardsSearch];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (range.length == 0 || range.location == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ subversion = [subversion substringToIndex:range.location];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ XcodeVersionEntry *subversionEntry = dict[subversion];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (subversionEntry) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ BOOL atLeastAsLarge = ([subversionEntry.version compare:entry.version]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ == NSOrderedDescending);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (inApplications && atLeastAsLarge) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ dict[subversion] = entry;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ dict[subversion] = entry;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// Given a "version", expand it to at least 3 components by adding .0 as
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// necessary.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static NSString *ExpandVersion(NSString *version) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSArray *components = [version componentsSeparatedByString:@"."];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSString *appendage = nil;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (components.count == 2) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ appendage = @".0";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (components.count == 1) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ appendage = @".0.0";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (appendage) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ version = [version stringByAppendingString:appendage];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return version;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// Searches for all available Xcodes in the system and returns a dictionary that
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// maps version identifiers of any form (X, X.Y, and X.Y.Z) to the directory
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// where the Xcode bundle lives.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+//
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// If there is a problem locating the Xcodes, prints one or more error messages
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// and returns nil.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static NSMutableDictionary<NSString *, XcodeVersionEntry *> *FindXcodes()
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ __attribute((ns_returns_retained)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ CFStringRef cfBundleID = CFSTR("com.apple.dt.Xcode");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSString *bundleID = (__bridge NSString *)cfBundleID;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSMutableDictionary<NSString *, XcodeVersionEntry *> *dict =
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ [[NSMutableDictionary alloc] init];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ CFErrorRef cfError;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSArray *array = CFBridgingRelease(LSCopyApplicationURLsForBundleIdentifier(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ cfBundleID, &cfError));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (array == nil) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSError *nsError = (__bridge NSError *)cfError;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fprintf(stderr, "error: %s\n", nsError.description.UTF8String);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return nil;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // Scan all bundles but delay returning in case of errors until we are
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // done. This is to let us log details about all the bundles that were
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // processed so that a faulty bundle doesn't hide useful information about
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // other bundles that were found.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ BOOL errors = NO;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for (NSURL *url in array) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSArray *contents = [
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ [NSFileManager defaultManager] contentsOfDirectoryAtURL:url
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ includingPropertiesForKeys:nil
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ options:0
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ error:nil];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSLog(@"Found bundle %@ in %@; contents on disk: %@",
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ bundleID, url, contents);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSBundle *bundle = [NSBundle bundleWithURL:url];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (bundle == nil) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSLog(@"ERROR: Unable to open bundle at URL: %@\n", url);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ errors = YES;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ continue;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // LSCopyApplicationURLsForBundleIdentifier seems to sometimes return
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // invalid bundles (e.g. an arbitrary folder), which we should ignore (but
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // don't treat as an error).
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ //
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // To work around this issue, we double check to make sure the NSBundle's
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // bundleIdentifier is that of Xcode's, as invalid bundles won't match.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (![bundle.bundleIdentifier isEqualToString:bundleID]) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSLog(@"WARNING: Ignoring bundle %@ due to bundleID mismatch "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @"(got \"%@\" but expected \"%@\"); info: %@",
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ url, bundle.bundleIdentifier, bundleID, bundle.infoDictionary);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ continue;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSString *versionKey = @"CFBundleShortVersionString";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSString *version = [bundle.infoDictionary objectForKey:versionKey];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (version == nil) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSLog(@"ERROR: Cannot find %@ in info for bundle %@; info: %@\n",
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ versionKey, url, bundle.infoDictionary);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ errors = YES;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ continue;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSString *expandedVersion = ExpandVersion(version);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSLog(@"Version strings for %@: short=%@, expanded=%@",
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ url, version, expandedVersion);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSURL *developerDir =
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ [url URLByAppendingPathComponent:@"Contents/Developer"];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ XcodeVersionEntry *entry =
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ [[XcodeVersionEntry alloc] initWithVersion:expandedVersion
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ url:developerDir];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ AddEntryToDictionary(entry, dict);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return errors ? nil : dict;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// Prints out the located Xcodes as a set of lines where each line contains the
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// list of versions for a given Xcode and its location on disk.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static void DumpAsVersionsOnly(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ FILE *output,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSMutableDictionary<NSString *, XcodeVersionEntry *> *dict) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSMutableDictionary<NSString *, NSMutableSet <NSString *> *> *aliasDict =
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ [[NSMutableDictionary alloc] init];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ [dict enumerateKeysAndObjectsUsingBlock:^(NSString *aliasVersion,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ XcodeVersionEntry *entry,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ BOOL *stop) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSString *versionString = entry.version;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (aliasDict[versionString] == nil) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ aliasDict[versionString] = [[NSMutableSet alloc] init];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ [aliasDict[versionString] addObject:aliasVersion];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for (NSString *version in aliasDict) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ XcodeVersionEntry *entry = dict[version];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fprintf(output, "%s:%s:%s\n",
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ version.UTF8String,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ [[aliasDict[version] allObjects]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ componentsJoinedByString: @","].UTF8String,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ entry.url.fileSystemRepresentation);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// Prints out the located Xcodes in JSON format.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static void DumpAsJson(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ FILE *output,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSMutableDictionary<NSString *, XcodeVersionEntry *> *dict) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fprintf(output, "{\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for (NSString *version in dict) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ XcodeVersionEntry *entry = dict[version];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fprintf(output, "\t\"%s\": \"%s\",\n",
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ version.UTF8String, entry.url.fileSystemRepresentation);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fprintf(output, "}\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+// Dumps usage information.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static void usage(FILE *output) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fprintf(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ output,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "xcode-locator [-v|<version_number>]"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "\n\n"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "Given a version number or partial version number in x.y.z format, "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "will attempt to return the path to the appropriate developer "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "directory."
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "\n\n"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "Omitting a version number will list all available versions in JSON "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "format, alongside their paths."
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "\n\n"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "Passing -v will list all available fully-specified version numbers "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "along with their possible aliases and their developer directory, "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "each on a new line. For example:"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "\n\n"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "7.3.1:7,7.3,7.3.1:/Applications/Xcode.app/Contents/Developer"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int main(int argc, const char * argv[]) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @autoreleasepool {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSString *versionArg = nil;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ BOOL versionsOnly = NO;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (argc == 1) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ versionArg = @"";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (argc == 2) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSString *firstArg = [NSString stringWithUTF8String:argv[1]];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if ([@"-v" isEqualToString:firstArg]) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ versionsOnly = YES;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ versionArg = @"";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ versionArg = firstArg;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSCharacterSet *versSet =
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if ([versionArg rangeOfCharacterFromSet:versSet.invertedSet].length
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ != 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ versionArg = nil;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (versionArg == nil) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ usage(stderr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ NSMutableDictionary<NSString *, XcodeVersionEntry *> *dict = FindXcodes();
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (dict == nil) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ XcodeVersionEntry *entry = [dict objectForKey:versionArg];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (entry) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("%s\n", entry.url.fileSystemRepresentation);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (versionsOnly) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ DumpAsVersionsOnly(stdout, dict);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ DumpAsJson(stdout, dict);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return ([@"" isEqualToString:versionArg] ? 0 : 1);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span></pre><pre style='margin:0'>
</pre>