Xcodebuild'ing一个工作区,并设置一个自定义的构建路径。

时间:2023-01-24 13:46:42

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.

我正在尝试使用xcodebuild在工作区中构建一个多项目项目。当XCode构建一个工作空间时,它会自动地将所有的构建工件放到一个通用的目录中,这样每个项目都可以访问它的依赖项。

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

Eveything工作,但是工件被放置在通常的派生数据目录中。然后我想要出现在一个特定的目录中,我可以从CI构建中访问它。所以我试着这

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

However xcodebuild fails with this saying

但是xcodebuild并没有这样说。

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.

问题似乎是xcodebuild不再为工作区中的所有项目使用*目录,而是将工件存储在每个项目中。因此,它无法定位正在编译的代码和在其他项目中生成的工件之间的依赖关系。

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.

Xcode的构建设置引用已经两年没有更新了,所以我不知道是否有新的构建设置可以应用。

4 个解决方案

#1


33  

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.

我不确定这是不是一个新选项,但是xcodebuild的5.0版本有一个选项-derivedDataPath,它允许您指定您希望所有构建产品的目录。

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.

例如,通过-derivedDataPath构建创建一个相对于您运行xcodebuild的文件夹,并且您可以在诸如构建/构建/产品/发布-iphoneos这样的子文件夹中找到您的应用程序。

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

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

#2


18  

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:

到目前为止,我发现的最好的解决方案是使用一个绝对路径的CONFIGURATION_BUILD_DIR参数(例如/tmp/$PROJECT/build)。是这样的:

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.

我使用Jenkins,这里有一个名为$WORKSPACE的变量。使用$WORKSPACE/构建作为我的CONFIGURATION_BUILD_DIR,我有一个满意的解决方案。

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

相对路径似乎不像预期的那样工作。我们应该提交错误报告。

#3


5  

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:

当我从Jenkins CI工具构建我的项目时,我也遇到了这个问题。我的主要项目是一个子项目。我尝试过这样的方法:

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

它们都出现了错误,无法在/用户/mobileserver/jenkins_home/jobs/ travelguide-buid /workspace/build中找到iphoneos。

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.

这就是:用绝对路径来设置SYMROOT。

#4


-1  

I had a similar problem, and it worked locally but not on the build machine. Turned out I forgot to init the git submodule on the build machine. Hope this helps someone.

我有一个类似的问题,它在本地工作,而不是在构建机器上。结果,我忘记了在构建机器上初始化git子模块。希望这可以帮助别人。

#1


33  

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.

我不确定这是不是一个新选项,但是xcodebuild的5.0版本有一个选项-derivedDataPath,它允许您指定您希望所有构建产品的目录。

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.

例如,通过-derivedDataPath构建创建一个相对于您运行xcodebuild的文件夹,并且您可以在诸如构建/构建/产品/发布-iphoneos这样的子文件夹中找到您的应用程序。

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

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

#2


18  

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:

到目前为止,我发现的最好的解决方案是使用一个绝对路径的CONFIGURATION_BUILD_DIR参数(例如/tmp/$PROJECT/build)。是这样的:

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.

我使用Jenkins,这里有一个名为$WORKSPACE的变量。使用$WORKSPACE/构建作为我的CONFIGURATION_BUILD_DIR,我有一个满意的解决方案。

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

相对路径似乎不像预期的那样工作。我们应该提交错误报告。

#3


5  

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:

当我从Jenkins CI工具构建我的项目时,我也遇到了这个问题。我的主要项目是一个子项目。我尝试过这样的方法:

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

它们都出现了错误,无法在/用户/mobileserver/jenkins_home/jobs/ travelguide-buid /workspace/build中找到iphoneos。

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.

这就是:用绝对路径来设置SYMROOT。

#4


-1  

I had a similar problem, and it worked locally but not on the build machine. Turned out I forgot to init the git submodule on the build machine. Hope this helps someone.

我有一个类似的问题,它在本地工作,而不是在构建机器上。结果,我忘记了在构建机器上初始化git子模块。希望这可以帮助别人。