Xcodebuild'ing a workspace and setting a custom build path

drekka picture drekka · Aug 15, 2012 · Viewed 34.8k times · Source

I'm trying to use xcodebuild to build a multi-project project in a workspace. When XCode builds a workspace it automatically places all build artifacts in a common directory in DerivedData so that each project can access it dependencies.

If I use this command:

xcodebuild -workspace myWorkspace.xcworkspace -schema builtIt -configuration Release

Eveything works, but the artifacts are placed in usual derived data directory. I want then to appear in a specific directory which I can access from CI builds. So I tried this

xcodebuild -workspace myWorkspace.xcworkspace -schema builtIt -configuration Release SYMROOT=build/products OBJROOT=build/intermediates

However xcodebuild fails with this saying

Details:  Failed to load dependencies output contents from ``/Users/d4rkf1br3/projects/dNodi/build/intermediates/dNodi.build/Debug-iphoneos/dNodi.build/StaticAnalyzer/normal/armv7/DNRootSelector.d''. 
Error: Error Domain=NSCocoaErrorDomain Code=260 "The file “DNRootSelector.d” couldn’t be opened because there is no such file." 
UserInfo=0x4012fea40 {NSFilePath=/Users/d4rkf1br3/projects/dNodi/build/intermediates/dNodi.build/Debug-iphoneos/dNodi.build/StaticAnalyzer/normal/armv7/DNRootSelector.d, NSUnderlyingError=0x4012fc240 "The operation couldn’t be completed. No such file or directory"}. 
User info: {
    NSFilePath = "/Users/d4rkf1br3/projects/dNodi/build/intermediates/dNodi.build/Debug-iphoneos/dNodi.build/StaticAnalyzer/normal/armv7/DNRootSelector.d";
    NSUnderlyingError = "Error Domain=NSPOSIXErrorDomain Code=2 \"The operation couldn\U2019t be completed. No such file or directory\"";
}

The problem appears to be that xcodebuild is no longer using a central directory for all projects in the workspace and is storing the artifacts in each project instead. Hence it cannot locate the dependencies between code being compiled and artifacts produced in other projects.

Does anyone know the correct parameter to set on the command line?

Xcode's Build Setting Reference has not been updated for two years so I don't know if there are new build settings I can apply.

Answer

Nick Farina picture Nick Farina · Apr 29, 2014

I'm not sure if this is a new option but the 5.0 release of xcodebuild has an option -derivedDataPath which allows you to specify the directory you'd like all the build products to sit in.

For instance, passing -derivedDataPath build creates the folder build relative to where you ran xcodebuild from, and you can find your app predictably in a subfolder like build/Build/Products/Release-iphoneos.

Documentation: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html