Skip to content

Commit

Permalink
Support Xcode betas with xcode-locator
Browse files Browse the repository at this point in the history
Previously if you had 2 builds of the same version of Xcode, for example
10.2.0 beta 1 and 10.2.0 beta 2, there was no way to disambiguate them.
This change appends the `ProductBuildVersion` of each Xcode version to
allow you to specify that if desired.

Closes #7371.

PiperOrigin-RevId: 234858854
  • Loading branch information
keith authored and copybara-github committed Feb 20, 2019
1 parent 8a7cbe8 commit ab72246
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* {@code 5.0.1beta2}. Components must start with a non-negative integer and at least one component
* must be present.
*
* <p>Specifically, the format of a component is {@code \d+([a-z]+\d*)?}.
* <p>Specifically, the format of a component is {@code \d+([a-z0-9]*?)?(\d+)?}.
*
* <p>Dotted versions are ordered using natural integer sorting on components in order from first to
* last where any missing element is considered to have the value 0 if they don't contain any
Expand Down Expand Up @@ -122,9 +122,10 @@ public static Option option(DottedVersion version) {
return version == null ? null : new Option(version);
}
private static final Splitter DOT_SPLITTER = Splitter.on('.');
private static final Pattern COMPONENT_PATTERN = Pattern.compile("(\\d+)(?:([a-z]+)(\\d*))?");
private static final Pattern COMPONENT_PATTERN =
Pattern.compile("(\\d+)([a-z0-9]*?)?(\\d+)?", Pattern.CASE_INSENSITIVE);
private static final String ILLEGAL_VERSION =
"Dotted version components must all be of the form \\d+([a-z]+\\d*)? but got %s";
"Dotted version components must all be of the form \\d+([a-z0-9]*?)?(\\d+)? but got %s";
private static final String NO_ALPHA_SEQUENCE = null;
private static final Component ZERO_COMPONENT = new Component(0, NO_ALPHA_SEQUENCE, 0, "0");

Expand Down Expand Up @@ -165,7 +166,7 @@ private static Component toComponent(String component, String version) {
int secondNumber = 0;
firstNumber = parseNumber(parsedComponent, 1, version);

if (parsedComponent.group(2) != null) {
if (!Strings.isNullOrEmpty(parsedComponent.group(2))) {
alphaSequence = parsedComponent.group(2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void testCompareTo() throws Exception {
.addEqualityGroup(DottedVersion.fromString("1.2beta12.1"))
.addEqualityGroup(DottedVersion.fromString("1.2.0"), DottedVersion.fromString("1.2"))
.addEqualityGroup(DottedVersion.fromString("1.20"))
.addEqualityGroup(DottedVersion.fromString("10.2.0.10P99q"))
.testCompare();
}

Expand All @@ -52,6 +53,8 @@ public void testEquals() throws Exception {
.addEqualityGroup(DottedVersion.fromString("0.1"), DottedVersion.fromString("0.01"))
.addEqualityGroup(DottedVersion.fromString("0.2"), DottedVersion.fromString("0.2.0"))
.addEqualityGroup(DottedVersion.fromString("1.2xy2"), DottedVersion.fromString("1.2xy2"))
.addEqualityGroup(
DottedVersion.fromString("10.2.0.10P99q"), DottedVersion.fromString("10.2.0.10P99q0"))
.addEqualityGroup(
DottedVersion.fromString("1.2x"),
DottedVersion.fromString("1.2x0"),
Expand Down
14 changes: 8 additions & 6 deletions tools/osx/xcode_locator.m
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ static void AddEntryToDictionary(
NSLog(@"Version strings for %@: short=%@, expanded=%@",
url, version, expandedVersion);

NSURL *versionPlistUrl = [url URLByAppendingPathComponent:@"Contents/version.plist"];
NSDictionary *versionPlistContents = [[NSDictionary alloc] initWithContentsOfURL:versionPlistUrl
error:nil];
NSString *productVersion = [versionPlistContents objectForKey:@"ProductBuildVersion"];
if (productVersion) {
expandedVersion = [expandedVersion stringByAppendingFormat:@".%@", productVersion];
}

NSURL *developerDir =
[url URLByAppendingPathComponent:@"Contents/Developer"];
XcodeVersionEntry *entry =
Expand Down Expand Up @@ -259,12 +267,6 @@ int main(int argc, const char * argv[]) {
versionArg = @"";
} else {
versionArg = firstArg;
NSCharacterSet *versSet =
[NSCharacterSet characterSetWithCharactersInString:@"0123456789."];
if ([versionArg rangeOfCharacterFromSet:versSet.invertedSet].length
!= 0) {
versionArg = nil;
}
}
}
if (versionArg == nil) {
Expand Down

0 comments on commit ab72246

Please sign in to comment.