Xcodebuild'ing a workspace and setting a custo

2019-02-04 01:18发布

问题:

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.

回答1:

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



回答2:

The best solution i have found so far is to use the CONFIGURATION_BUILD_DIR parameter with an ABSOLUTE path (e.g. /tmp/$PROJECT/build). Like this:

xcodebuild -scheme "scheme" -configuration Debug -sdk iphoneos clean build CONFIGURATION_BUILD_DIR=$ABSOLUTE_BUILD_PATH

I use Jenkins and there I have an variable named $WORKSPACE. With $WORKSPACE/build as my CONFIGURATION_BUILD_DIR I have a solution I'm happy with.

The relative paths don't seem to work as expected. We should file a bug report.



回答3:

I also met this problem when I build my project from Jenkins CI tool. My main project depends a sub-project. I have tried building follow @Chilloutman's solution like this:

xcodebuild -target TravelGuideMdd -sdk iphoneos -configuration DailyBuild clean build CONFIGURATION_BUILD_DIR=/Users/mobileserver/jenkins_home/jobs/TravelGuide-Buid-For-Me/workspace/build BUILD_DIR =/Users/mobileserver/jenkins_home/jobs/TravelGuide-Buid-For-Me/workspace/build

or

xcodebuild -target TravelGuideMdd -sdk iphoneos -configuration DailyBuild clean build CONFIGURATION_BUILD_DIR=/Users/mobileserver/jenkins_home/jobs/TravelGuide-Buid-For-Me/workspace/build 

Both of them occur errors Could not find iphoneos in /Users/mobileserver/jenkins_home/jobs/TravelGuide-Buid-For-Me/workspace/build

But I get success finally using this:

xcodebuild -target TravelGuideMdd -sdk iphoneos6.1 -configuration DailyBuild clean build SYMROOT=/Users/mobileserver/jenkins_home/jobs/TravelGuide-Buid-For-Me/workspace/build 

That is: Setting the SYMROOT with a absolute paths.