Skip to content

Commit

Permalink
Merge pull request #17 from stevenlei/feat/check-xcode
Browse files Browse the repository at this point in the history
Improve Xcode and Command Line Tools Detection
  • Loading branch information
mxcl authored Dec 16, 2024
2 parents 2280ca3 + 6e81817 commit a358e53
Showing 1 changed file with 49 additions and 9 deletions.
58 changes: 49 additions & 9 deletions Sources/teaBASE.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,55 @@ - (BOOL)checkForSSHPassphraseICloudKeychainIntegration {
}

- (BOOL)xcodeCLTInstalled {
if ([NSFileManager.defaultManager isExecutableFileAtPath:@"/Library/Developer/CommandLineTools/usr/bin/git"]) {
return YES;
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/xcode-select"];
[task setArguments:@[@"-p"]];

NSPipe *nullPipe = [NSPipe pipe];
[task setStandardOutput:nullPipe];
[task setStandardError:nullPipe];

NSError *error = nil;
[task launchAndReturnError:&error];

if (error) {
NSLog(@"teaBASE: xcodeCLTInstalled [error]: %@", error);
return NO;
}
//TODO Xcode can be installed anywhere, instead check for the bundle ID with spotlight API or mdfind
if ([NSFileManager.defaultManager isExecutableFileAtPath:@"/Applications/Xcode.app"]) {
return YES;

[task waitUntilExit];

NSLog(@"teaBASE: xcodeCLTInstalled [output]: %d", task.terminationStatus);

return task.terminationStatus == 0;
}

- (BOOL)xcodeInstalled {
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/mdfind"];
[task setArguments:@[@"kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"]];

NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput:pipe];
[task setStandardError:pipe];

NSError *error = nil;
[task launchAndReturnError:&error];

if (error) {
NSLog(@"teaBASE: xcodeInstalled [error]: %@", error);
return NO;
}
return NO;

NSFileHandle *fileHandle = [pipe fileHandleForReading];
NSData *data = [fileHandle readDataToEndOfFile];
NSString *output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

[task waitUntilExit];

NSLog(@"teaBASE: xcodeInstalled [output]: %@", output);

return output.length > 0;
}

- (void)updateVersions {
Expand All @@ -192,9 +233,8 @@ - (void)updateVersions {

NSString *docker_version = output(path, @[]);

BOOL has_clt = [NSFileManager.defaultManager isExecutableFileAtPath:@"/Library/Developer/CommandLineTools/usr/bin/git"];
//TODO Xcode can be installed anywhere, instead check for the bundle ID with spotlight API or mdfind
BOOL has_xcode = [NSFileManager.defaultManager isExecutableFileAtPath:@"/Applications/Xcode.app"];
BOOL has_clt = [self xcodeCLTInstalled];
BOOL has_xcode = [self xcodeInstalled];
// emulate login shell to ensure PATH contains everything the user has configured
// ∵ GUI apps do not have full user PATH set otherwise
NSString *git_out = nil;
Expand Down

0 comments on commit a358e53

Please sign in to comment.