Last active
June 15, 2020 04:29
-
-
Save xcodereleases/615b1f51b4faa12feb89ff3a45c721e8 to your computer and use it in GitHub Desktop.
Extract beta information from a local copy of Xcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Cocoa/Cocoa.h> | |
@protocol FilePath <NSObject> | |
+ (instancetype)filePathForPathString:(NSString *)path; | |
@end | |
@protocol NamedVersion <NSObject> | |
- (NSString *)name; | |
@end | |
@protocol ToolsInfo <NSObject> | |
- (instancetype)initWithXcodeFilePath:(id<FilePath>)path error:(NSError **)error; | |
- (BOOL)isAppleInternal; | |
- (BOOL)isBeta; | |
- (NSUInteger)toolsBetaVersion; | |
- (id<NamedVersion>)toolsVersion; | |
- (id<NamedVersion>)toolsBuildVersion; | |
@end | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
NSURL *xcode; | |
if (argc < 2) { | |
// no path passed in | |
xcode = [[NSURL fileURLWithPath:@"/var/db/xcode_select_link"] URLByResolvingSymlinksInPath]; | |
} else { | |
NSURL *currentFolder = [NSURL fileURLWithPath:[[NSFileManager defaultManager] currentDirectoryPath]]; | |
xcode = [NSURL fileURLWithPath:@(argv[1]) relativeToURL:currentFolder]; | |
} | |
while ([[xcode lastPathComponent] hasSuffix:@".app"] == NO) { | |
xcode = [xcode URLByDeletingLastPathComponent]; | |
} | |
NSURL *bundleURL = [NSURL fileURLWithPath:@"./Contents/SharedFrameworks/DVTFoundation.framework" relativeToURL:xcode]; | |
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL]; | |
if (bundle == nil) { return -1; } | |
if ([bundle load] == NO) { return -1; } | |
id<FilePath> path = [NSClassFromString(@"DVTFilePath") filePathForPathString: [xcode absoluteURL].path]; | |
id<ToolsInfo> info = [[NSClassFromString(@"DVTToolsInfo") alloc] initWithXcodeFilePath:path error:nil]; | |
if (info == nil) { return -1; } | |
if (info.toolsVersion.name == nil) { return -1; } | |
if (info.toolsBuildVersion.name == nil) { return -1; } | |
NSString *final = [NSString stringWithFormat:@"{ \"beta\": %lu, \"version\": \"%@\", \"build\": \"%@\" }", | |
(unsigned long)info.toolsBetaVersion, | |
info.toolsVersion.name, | |
info.toolsBuildVersion.name]; | |
printf("%s", final.UTF8String); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Psst…you may want to consider
+[DVTToolsInfo toolsInfo]
.