Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XcodeCapp : Add build project options #2025

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tools/XcodeCapp/XcodeCapp/AppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
- (IBAction)loadProject:(id)aSender;
- (IBAction)openHelp:(id)aSender;
- (IBAction)openAbout:(id)aSender;

- (IBAction)buildProject:(id)sender;
@end

29 changes: 29 additions & 0 deletions Tools/XcodeCapp/XcodeCapp/AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@

AppController *SharedAppControllerInstance = nil;

static const NSInteger kBuildProjectDebugTag = 1;
static const NSInteger kBuildProjectReleaseTag = 2;
static const NSInteger kBuildProjectRunDebugTag = 3;
static const NSInteger kBuildProjectRunReleaseTag = 4;
static const NSInteger kBuildProjectDeployTag = 5;
static const NSInteger kBuildProjectCleanTag = 6;

@interface AppController ()

Expand Down Expand Up @@ -421,6 +427,29 @@ - (IBAction)createProject:(id)sender
[self loadProjectAtPath:projectPath reopening:YES];
}

- (IBAction)buildProject:(id)sender
{
NSInteger tag = [sender tag];
if(tag == kBuildProjectDebugTag) {
[self.xcc buildProject:@"debug"];
}
else if (tag == kBuildProjectReleaseTag) {
[self.xcc buildProject:@"release"];
}
else if (tag == kBuildProjectRunDebugTag) {
[self.xcc buildProject:@"run"];
}
else if (tag == kBuildProjectRunReleaseTag) {
[self.xcc buildProject:@"run-release"];
}
else if (tag == kBuildProjectDeployTag) {
[self.xcc buildProject:@"deploy"];
}
else if (tag == kBuildProjectCleanTag) {
[self.xcc buildProject:@"clean"];
}
}

#pragma mark - Delegates

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app
Expand Down
2 changes: 1 addition & 1 deletion Tools/XcodeCapp/XcodeCapp/ProcessSourceOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ - (void)postErrorNotificationForPath:(NSString *)path line:(int)line message:(NS
nil];

info[@"projectId"] = self.projectId;
info[@"message"] = [NSString stringWithFormat:@"%@, line %d\n%@", [self.sourcePath lastPathComponent], 0, message];
info[@"message"] = [NSString stringWithFormat:@"%@, line %d\n%@", [self.sourcePath lastPathComponent], line, message];

if (self.isCancelled)
return;
Expand Down
8 changes: 8 additions & 0 deletions Tools/XcodeCapp/XcodeCapp/XcodeCapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,15 @@ extern NSString * const XCCProjectDidFinishLoadingNotification;
@property (unsafe_unretained) IBOutlet NSTableView *errorTable;
@property (strong) IBOutlet NSArrayController *errorListController;

// Panel, textView and progress indicator used to display build progress
@property (strong) IBOutlet NSPanel *consolePanel;
@property (strong) IBOutlet NSTextView* consoleTextView;
@property (strong) IBOutlet NSProgressIndicator* consoleProgressIndicator;

- (IBAction)openErrorsPanel:(id)sender;
- (IBAction)openConsolePanel:(id)sender;
- (IBAction)clearErrors:(id)sender;
- (IBAction)clearBuildConsole:(id)sender;
- (IBAction)openErrorInEditor:(id)sender;
- (IBAction)openXcodeProject:(id)aSender;
- (IBAction)synchronizeProject:(id)aSender;
Expand All @@ -142,6 +149,7 @@ extern NSString * const XCCProjectDidFinishLoadingNotification;

- (NSDictionary*)createProject:(NSString*)aPath;

- (void)buildProject:(NSString*)config;
@end

@interface XcodeCapp (SnowLeopard)
Expand Down
121 changes: 120 additions & 1 deletion Tools/XcodeCapp/XcodeCapp/XcodeCapp.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ @interface XcodeCapp ()
// A queue for threaded operations to perform
@property NSOperationQueue *operationQueue;

// Standard output used during build project process
@property (strong) NSTask *task;
@property (strong) NSPipe *stdOut;
@property (strong) NSPipe *stdErr;

// We have to declare this because it is referenced by the fsevents_callback function
- (void)handleFSEventsWithPaths:(NSArray *)paths flags:(const FSEventStreamEventFlags[])eventFlags ids:(const FSEventStreamEventId[])eventIds;

Expand Down Expand Up @@ -241,7 +246,7 @@ - (void)initTaskEnvironment
// Make sure we are using jsc as the narwhal engine!
self.environment[@"NARWHAL_ENGINE"] = @"jsc";

self.executables = @[@"python", @"narwhal-jsc", @"objj", @"nib2cib", @"capp"];
self.executables = @[@"python", @"narwhal-jsc", @"objj", @"nib2cib", @"capp", @"jake"];

// This is used to get the env var of $CAPP_BUILD
NSDictionary *processEnvironment = [[NSProcessInfo processInfo] environment];
Expand Down Expand Up @@ -508,6 +513,47 @@ - (void)stop
[[NSUserDefaults standardUserDefaults] synchronize];
}

- (void)buildProject:(NSString*)config
{

DDLogVerbose(@"Build project launched with config: %@", config);

[self openConsolePanel:self];
self.task = nil;
self.task = [NSTask new];

//setup system pipes and filehandles to process output data
self.stdOut = [[NSPipe alloc] init];
self.stdErr = [[NSPipe alloc] init];
NSFileHandle* fhOut = [self.stdOut fileHandleForReading];
NSFileHandle* fhErr = [self.stdErr fileHandleForReading];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(buildReceivedData:) name:NSFileHandleReadCompletionNotification object:fhOut];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(buildReceivedError:) name:NSFileHandleReadCompletionNotification object:fhErr];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(buildComplete:) name:NSTaskDidTerminateNotification object:self.task];

//setup the task
self.task.launchPath = self.executablePaths[@"jake"];
self.task.arguments = [NSMutableArray arrayWithObjects:config , nil];
self.task.environment = self.environment;
self.task.standardOutput = self.stdOut;
self.task.standardError = self.stdErr;

if(self.projectPath){
self.task.currentDirectoryPath = self.projectPath;
}

[fhOut readInBackgroundAndNotify];
[fhErr readInBackgroundAndNotify];

// Start building
[self.consoleProgressIndicator startAnimation:nil];
[self.task launch];
[self appendText:[NSString stringWithFormat:@"START building your app to %@\n", config] toTextView:self.consoleTextView withColor:[NSColor blackColor]];

}


#pragma mark - Processing

- (void)waitForOperationQueueToFinishWithSelector:(SEL)selector
Expand Down Expand Up @@ -733,6 +779,55 @@ - (void)sourceConversionDidEnd:(NSNotification *)note
DDLogVerbose(@"%@ %@", NSStringFromSelector(_cmd), path);
}

-(void)buildReceivedData:(NSNotification*)notification

{
if(self.task == nil)
return;

NSData *data = [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem];
NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

if ([string rangeOfString:@"ERROR"].location != NSNotFound) {
[self appendText:string toTextView:self.consoleTextView withColor:[NSColor redColor]];
}
else if ([string rangeOfString:@"WARNING"].location != NSNotFound) {
[self appendText:string toTextView:self.consoleTextView withColor:[NSColor orangeColor]];
}
else {
[self appendText:string toTextView:self.consoleTextView withColor:[NSColor blackColor]];
}
if([notification object] != nil)
[[notification object] readInBackgroundAndNotify];
}

-(void) buildReceivedError:(NSNotification*)notification
{
if (self.task == nil) {
return;
}

NSData *data = [[notification userInfo] objectForKey:NSFileHandleNotificationDataItem];
NSString *string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
DDLogVerbose(@"Build project received error : %@", string);
[self appendText:string toTextView:self.consoleTextView withColor:[NSColor redColor]];

}

-(void)buildComplete:(NSNotification*)notification
{
DDLogVerbose(@"Build project complete");
[self.consoleProgressIndicator stopAnimation:nil];
[self appendText:@"\nBUILD COMPLETE\n" toTextView:self.consoleTextView withColor:[NSColor blueColor]];

[self.task terminate];
self.task = nil;
[[self.stdOut fileHandleForReading] closeFile];
[[self.stdErr fileHandleForReading] closeFile];
self.stdOut = nil;
self.stdErr = nil;
}

#pragma mark - Event Stream

- (void)startEventStream
Expand Down Expand Up @@ -1522,6 +1617,13 @@ - (IBAction)openErrorsPanel:(id)aSender
[self.errorsPanel makeKeyAndOrderFront:nil];
}

- (IBAction)openConsolePanel:(id)sender
{
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
[self.consolePanel makeKeyAndOrderFront:nil];

}

- (IBAction)openErrorInEditor:(id)sender
{
id info = self.errorListController.selection;
Expand Down Expand Up @@ -1664,6 +1766,11 @@ - (IBAction)clearErrors:(id)sender
self.errorListController.content = self.errorList;
}

- (IBAction)clearBuildConsole:(id)sender
{
[self.consoleTextView setString:@""];
}

- (BOOL)hasErrors
{
NSInteger index = [self.errorList indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop)
Expand Down Expand Up @@ -1723,6 +1830,18 @@ - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentN
return YES;
}

#pragma mark - Utils
- (void)appendText:(NSString*)text toTextView:(NSTextView*)textView withColor:(NSColor*)color
{
dispatch_async(dispatch_get_main_queue(), ^{

NSMutableAttributedString* attr = [[NSMutableAttributedString alloc] initWithString:text];
[attr addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, attr.length)];
[[textView textStorage] appendAttributedString:attr];
[textView scrollRangeToVisible:NSMakeRange([[textView string] length], 0)];

});
}
@end


Expand Down
Loading