Note that there are some explanatory texts on larger screens.

plurals
  1. PORunning xcodebuild twice from a Cocoa app (via NSTask) silently fails
    text
    copied!<p>I have a Cocoa app that does a number of things, but among them, uses '<code>xcodebuild</code>' to clean and re-build a iOS project in XCode. The Cocoa app was developed using XCode 4.1, and runs only on OS X 10.7 (because of the NSTask termination handlers). I hadn't touched it for a few months, and after I had upgraded to XCode 4.2 I found that only the first NSTask that ran xcodebuild actually did anything. Subsequent calls do nothing.</p> <p>Some details:</p> <ul> <li>The iOS project being built sits within the resource bundle of the Cocoa app. So basically, the Cocoa app is a wrapper for an iOS project. Imagine a GUI with a big red button that says: "Build me an iOS app!"</li> <li>This code worked perfectly in XCode 4.1. Task 1 executed, then in the termination handler for task 1, task 2 was called, and ran just fine. The problem is that task 2 no longer runs at all.</li> <li>I have since upgraded to xcode 4.3, which required me to also install the standalone Xcode command line tools. The code still doesn't work properly though.</li> <li>I can run both the '<code>xcodebuild clean</code>' and '<code>xcodebuild</code>' commands in Terminal with no problems.</li> </ul> <p>Below is a (paraphrased) version of the offending code.</p> <pre><code>#import "AppDelegate.h" @implementation AppDelegate @synthesize window = _window; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [self runTaskOne]; } // Clean the iOS Project - (void) runTaskOne { NSTask *task = [[NSTask alloc] init]; [task setCurrentDirectoryPath:@".../myproject/DerivedData/myproject/Build/Products/Debug/myproject.app/Contents/Resources/iOSProjectFolder"]; [task setLaunchPath:@"/usr/bin/xcodebuild"]; [task setArguments:[NSArray arrayWithObjects:@"clean", nil]]; [task setTerminationHandler:^(NSTask *task) { [self runTaskTwo]; }]; [task launch]; } // Build the same iOS project that was just cleaned - (void) runTaskTwo; { NSTask *task = [[NSTask alloc] init]; [task setCurrentDirectoryPath:@".../myproject/DerivedData/myproject/Build/Products/Debug/myproject.app/Contents/Resources/iOSProjectFolder"]; [task setLaunchPath:@"/usr/bin/xcodebuild"]; [task launch]; } @end </code></pre> <p>So just to re-iterate: Task 1 (the clean) works fine. Task 2 (the build) doesn't even seem launch. This behaviour is only observed after upgrading to XCode 4.2. I must be doing something wrong, but what?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload