Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[NEW] Use `xcode-select` to dynamically discover our way to `momc`. (…

…Josh Abernathy)
  • Loading branch information...
commit 93b4c6bfcde93701875174040e76ed192643bc87 1 parent ffffc65
Jonathan 'Wolf' Rentzsch authored
Showing with 36 additions and 4 deletions.
  1. +36 −4 mogenerator.m
40 mogenerator.m
View
@@ -362,7 +362,34 @@ - (void) printUsage;
"Inspired by eogenerator.\n");
}
-- (void) setModel: (NSString *) path;
+- (NSString*)currentXcodePath {
+ NSMutableString *result = @"";
+
+ @try {
+ NSTask *task = [[[NSTask alloc] init] autorelease];
+ [task setLaunchPath:@"/usr/bin/xcode-select"];
+
+ [task setArguments:[NSArray arrayWithObject:@"-print-path"]];
+
+ NSPipe *pipe = [NSPipe pipe];
+ [task setStandardOutput:pipe];
+
+ NSFileHandle *file = [pipe fileHandleForReading];
+
+ [task launch];
+
+ NSData *data = [file readDataToEndOfFile];
+
+ NSMutableString *result = [[[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
Nikita Zhuk Collaborator
nzhuk added a note

This is a bug. 'result' variable shadows the one declared at line 366, so the end result is that this method always returns an empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ [result deleteCharactersInRange:NSMakeRange([result length]-1, 1)]; // trim newline
+ } @catch(NSException *ex) {
+ ddprintf(@"WARNING couldn't launch /usr/bin/xcode-select\n");
+ }
+
+ return result;
+}
+
+- (void)setModel:(NSString*)path;
{
assert(!model); // Currently we only can load one model.
@@ -377,12 +404,17 @@ - (void) setModel: (NSString *) path;
// We've been handed a .xcdatamodel data model, transparently compile it into a .mom managed object model.
// Find where Xcode installed momc this week.
+ NSFileManager *fm = [NSFileManager defaultManager];
NSString *momc = nil;
- if ([[NSFileManager defaultManager] fileExistsAtPath:@"/Developer/usr/bin/momc"]) { // Xcode 3.1 installs it here.
+ NSString *defaultLocation = [NSString stringWithFormat:@"%@/usr/bin/momc", [self currentXcodePath]];
+
+ if([fm fileExistsAtPath:defaultLocation]) {
+ momc = defaultLocation;
+ } else if ([fm fileExistsAtPath:@"/Developer/usr/bin/momc"]) { // Xcode 3.1 installs it here.
momc = @"/Developer/usr/bin/momc";
- } else if ([[NSFileManager defaultManager] fileExistsAtPath:@"/Library/Application Support/Apple/Developer Tools/Plug-ins/XDCoreDataModel.xdplugin/Contents/Resources/momc"]) { // Xcode 3.0.
+ } else if ([fm fileExistsAtPath:@"/Library/Application Support/Apple/Developer Tools/Plug-ins/XDCoreDataModel.xdplugin/Contents/Resources/momc"]) { // Xcode 3.0.
momc = @"/Library/Application Support/Apple/Developer Tools/Plug-ins/XDCoreDataModel.xdplugin/Contents/Resources/momc";
- } else if ([[NSFileManager defaultManager] fileExistsAtPath:@"/Developer/Library/Xcode/Plug-ins/XDCoreDataModel.xdplugin/Contents/Resources/momc"]) { // Xcode 2.4.
+ } else if ([fm fileExistsAtPath:@"/Developer/Library/Xcode/Plug-ins/XDCoreDataModel.xdplugin/Contents/Resources/momc"]) { // Xcode 2.4.
momc = @"/Developer/Library/Xcode/Plug-ins/XDCoreDataModel.xdplugin/Contents/Resources/momc";
}
assert(momc && "momc not found");
Nikita Zhuk
Collaborator

This is a bug. 'result' variable shadows the one declared at line 366, so the end result is that this method always returns an empty string.

Please sign in to comment.
Something went wrong with that request. Please try again.