aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Chris Parsons <cparsons@google.com>2016-06-08 18:17:51 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-06-09 08:01:30 +0000
commit8bddd69856530c699cca6770f18ab7d2b87adf17 (patch)
tree04dcc5f7289347adda73cdd9d580cea09f49d7c5 /src
parentfac8383b7ca371e7e604327569aa5b35bb9576f4 (diff)
xcode_locator supports -v mode, which outputs only system-supported xcode versions and their aliases in easily-parsed format
This is convenient as skylark does not have extensive string-parsing (regex) features, and when xcode-locator is invoked from a skylark rule, this format is cleanest and contains only relevant info. -- MOS_MIGRATED_REVID=124372740
Diffstat (limited to 'src')
-rw-r--r--src/tools/xcode/xcodelocator/xcode_locator.m42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/tools/xcode/xcodelocator/xcode_locator.m b/src/tools/xcode/xcodelocator/xcode_locator.m
index 09ebc0002b..49392591e6 100644
--- a/src/tools/xcode/xcodelocator/xcode_locator.m
+++ b/src/tools/xcode/xcodelocator/xcode_locator.m
@@ -92,20 +92,30 @@ static NSString *ExpandVersion(NSString *version) {
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *versionArg = nil;
+ BOOL versionsOnly = NO;
if (argc == 1) {
versionArg = @"";
} else if (argc == 2) {
- versionArg = [NSString stringWithUTF8String:argv[1]];
- NSCharacterSet *versSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
- if ([versionArg rangeOfCharacterFromSet:versSet.invertedSet].length != 0) {
- versionArg = nil;
+ NSString *firstArg = [NSString stringWithUTF8String:argv[1]];
+ if ([@"-v" isEqualToString:firstArg]) {
+ versionsOnly = YES;
+ versionArg = @"";
+ } else {
+ versionArg = firstArg;
+ NSCharacterSet *versSet =
+ [NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
+ if ([versionArg rangeOfCharacterFromSet:versSet.invertedSet].length != 0) {
+ versionArg = nil;
+ }
}
}
if (versionArg == nil) {
- printf("xcode_locator <version_number>\n"
+ printf("xcode_locator [-v|<version_number>]\n"
"Given a version number, or partial version number in x.y.z format, will attempt "
"to return the path to the appropriate developer directory.\nOmitting a version "
- "number will list all available versions in JSON format.\n");
+ "number will list all available versions in JSON format, alongside their paths.\n"
+ "Passing -v will list all available fully-specified version numbers along with "
+ "their possible aliases, each on a new line. For example: '7.3.1:7,7.3,7.3.1'.\n");
return 1;
}
@@ -143,13 +153,21 @@ int main(int argc, const char * argv[]) {
return 0;
}
- // Print out list in json format.
- printf("{\n");
- for (NSString *version in dict) {
- XcodeVersionEntry *entry = dict[version];
- printf("\t\"%s\": \"%s\",\n", version.UTF8String, entry.url.fileSystemRepresentation);
+ if (versionsOnly) {
+ NSSet *distinctValues = [[NSSet alloc] initWithArray:[dict allValues]];
+ for (XcodeVersionEntry *value in distinctValues) {
+ printf("%s:", value.version.UTF8String);
+ printf("%s\n", [[dict allKeysForObject:value] componentsJoinedByString: @","].UTF8String);
+ }
+ } else {
+ // Print out list in json format.
+ printf("{\n");
+ for (NSString *version in dict) {
+ XcodeVersionEntry *entry = dict[version];
+ printf("\t\"%s\": \"%s\",\n", version.UTF8String, entry.url.fileSystemRepresentation);
+ }
+ printf("}\n");
}
- printf("}\n");
return ([@"" isEqualToString:versionArg] ? 0 : 1);
}
}