aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar jmmv <jmmv@google.com>2018-08-01 08:36:18 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-08-01 08:37:39 -0700
commit7372c04d40d7ab45fa2649c8be002ee6909668d1 (patch)
tree2482507f0a4a145e614f962084ba351d953a403d /tools
parent81a2dddbcfd4a9c7ea9c664195f2f44ae8abeb55 (diff)
Add extra logging to xcode-locator when scanning Xcode bundles.
RELNOTES: None. PiperOrigin-RevId: 206933729
Diffstat (limited to 'tools')
-rw-r--r--tools/osx/xcode_locator.m53
1 files changed, 38 insertions, 15 deletions
diff --git a/tools/osx/xcode_locator.m b/tools/osx/xcode_locator.m
index dc967693c3..1565f6f7f8 100644
--- a/tools/osx/xcode_locator.m
+++ b/tools/osx/xcode_locator.m
@@ -111,39 +111,62 @@ static NSString *ExpandVersion(NSString *version) {
// maps version identifiers of any form (X, X.Y, and X.Y.Z) to the directory
// where the Xcode bundle lives.
//
-// If there is a problem locating the Xcodes, prints an error message and
-// returns nil.
+// If there is a problem locating the Xcodes, prints one or more error messages
+// and returns nil.
static NSMutableDictionary *FindXcodes() __attribute((ns_returns_retained)) {
+ CFStringRef bundleID = CFSTR("com.apple.dt.Xcode");
+
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
CFErrorRef cfError;
NSArray *array = CFBridgingRelease(LSCopyApplicationURLsForBundleIdentifier(
- CFSTR("com.apple.dt.Xcode"), &cfError));
+ bundleID, &cfError));
if (array == nil) {
NSError *nsError = (__bridge NSError *)cfError;
fprintf(stderr, "error: %s\n", nsError.description.UTF8String);
return nil;
}
+
+ // Scan all bundles but delay returning in case of errors until we are
+ // done. This is to let us log details about all the bundles that were
+ // processed so that a faulty bundle doesn't hide useful information about
+ // other bundles that were found.
+ BOOL errors = NO;
for (NSURL *url in array) {
+ NSArray *contents = [
+ [NSFileManager defaultManager] contentsOfDirectoryAtURL:url
+ includingPropertiesForKeys:nil
+ options:0
+ error:nil];
+ NSLog(@"Found bundle %@ in %@; contents on disk: %@",
+ bundleID, url, contents);
+
NSBundle *bundle = [NSBundle bundleWithURL:url];
- if (!bundle) {
- fprintf(stderr, "error: Unable to open bundle at URL: %s\n",
- url.description.UTF8String);
- return nil;
+ if (bundle == nil) {
+ NSLog(@"ERROR: Unable to open bundle at URL: %@\n", url);
+ errors = YES;
+ continue;
}
- NSString *version = bundle.infoDictionary[@"CFBundleShortVersionString"];
- if (!version) {
- fprintf(stderr, "error: Unable to extract CFBundleShortVersionString "
- "from URL: %s\n", url.description.UTF8String);
- return nil;
+
+ NSString *versionKey = @"CFBundleShortVersionString";
+ NSString *version = [bundle.infoDictionary objectForKey:versionKey];
+ if (version == nil) {
+ NSLog(@"ERROR: Cannot find %@ in info for bundle %@; info: %@\n",
+ versionKey, url, bundle.infoDictionary);
+ errors = YES;
+ continue;
}
- version = ExpandVersion(version);
+ NSString *expandedVersion = ExpandVersion(version);
+ NSLog(@"Version strings for %@: short=%@, expanded=%@",
+ url, version, expandedVersion);
+
NSURL *developerDir =
[url URLByAppendingPathComponent:@"Contents/Developer"];
XcodeVersionEntry *entry =
- [[XcodeVersionEntry alloc] initWithVersion:version url:developerDir];
+ [[XcodeVersionEntry alloc] initWithVersion:expandedVersion
+ url:developerDir];
AddEntryToDictionary(entry, dict);
}
- return dict;
+ return errors ? nil : dict;
}
// Prints out the located Xcodes as a set of lines where each line contains the