简体   繁体   English

在 Xcode 项目中构建所有目标(或方案)

[英]Build all targets (or schemes) in Xcode project

I have an Xcode project with many targets.我有一个包含许多目标的 Xcode 项目。 Six of them are aggregates which build final release products (static libraries, frameworks) using Run Scripts under Build Phases.其中六个是使用构建阶段下的运行脚本构建最终发布产品(静态库、框架)的聚合体。 I can build them each individually fine, but I can't find any way to hit "one button" to build them all.我可以单独构建它们,但是我找不到任何方法来点击“一个按钮”来构建它们。

Approach #1方法#1

First I tried using -alltargets from the command line, like so:首先,我尝试从命令行使用 -alltargets,如下所示:

xcodebuild -project MyProject.xcodeproj -alltargets

With that I get errors on my test targets, claiming that they aren't built for testing.因此,我的测试目标出现错误,声称它们不是为测试而构建的。 I don't know what that means because they normally "test" correctly.我不知道这意味着什么,因为他们通常正确地“测试”。 Something is different when attempted this way.以这种方式尝试时会有所不同。 But technically it's including targets I'm not interested in. I wouldn't mind much if it worked.但从技术上讲,它包括我不感兴趣的目标。如果它有效,我不会介意。

Approach #2方法#2

Next I tried making an aggregate which had a run script that individually built each aggregate target, like so:接下来,我尝试制作一个聚合,它有一个单独构建每个聚合目标的运行脚本,如下所示:

xcodebuild -project MyProject.xcodeproj -target FirstAggregateTarget
xcodebuild -project MyProject.xcodeproj -target SecondAggregateTarget
xcodebuild -project MyProject.xcodeproj -target ThirdAggregateTarget
xcodebuild -project MyProject.xcodeproj -target FourthAggregateTarget
xcodebuild -project MyProject.xcodeproj -target FifthAggregateTarget
xcodebuild -project MyProject.xcodeproj -target SixthAggregateTarget

It doesn't get any errors from Xcode's point of view, but several of the aggregates just don't build properly.从 Xcode 的角度来看,它没有出现任何错误,但有几个聚合只是没有正确构建。 Somehow the run scripts in the individual aggregates were influenced by the top-level aggregate, I guess.我猜想,各个聚合中的运行脚本以某种方式受到顶级聚合的影响。

Approach #3方法#3

Next I then tried making a new "RELEASE_PRODUCTS" scheme that in the build section had the six aggregates listed.接下来,我尝试创建一个新的“RELEASE_PRODUCTS”方案,该方案在构建部分列出了六个聚合。 With that I got errors like this:有了这个,我得到了这样的错误:

在此处输入图片说明

There were also other obscure errors about build products not being found where they were expected to be.还有其他一些关于构建产品未在预期位置找到的模糊错误。

Approach #4方法#4

Next I created a script that I run completely outside of Xcode, like so:接下来,我创建了一个完全在 Xcode 之外运行的脚本,如下所示:

#!/bin/bash

# Builds all release products

xcodebuild -project MyProject.xcodeproj -target FirstAggregateTarget

xcodebuild -project MyProject.xcodeproj -target SecondAggregateTarget

xcodebuild -project MyProject.xcodeproj -target ThirdAggregateTarget

xcodebuild -project MyProject.xcodeproj -target FourthAggregateTarget

xcodebuild -project MyProject.xcodeproj -target FifthAggregateTarget

xcodebuild -project MyProject.xcodeproj -target SixthAggregateTarget

That seems to be the only thing that works.这似乎是唯一有效的方法。 But I wish I could get this to work from within Xcode, preferably as something I could hit from the command line if I wanted to, because then I wouldn't have to leave the IDE and it could report to be success or fail.但我希望我可以在 Xcode 中使用它,如果我愿意的话,最好是我可以从命令行点击的东西,因为这样我就不必离开 IDE,它可以报告成功或失败。

You could make a dummy target that depends on the other six.你可以制作一个依赖于其他六个的虚拟目标。 Use Target Dependencies in the Build Phases tab在构建阶段选项卡中使用目标依赖项

Inspired by sansumbrella's answer in another forum .受到sansumbrella 在另一个论坛中的回答的启发。

Create a new target in your project (I chose to use a CLI tool since my project is CLI based).在您的项目中创建一个新目标(我选择使用 CLI 工具,因为我的项目是基于 CLI 的)。

According to sansumbrella , you can create an application and delete it's plist.根据sansumbrella ,您可以创建一个应用程序并删除它的 plist。 My approach does not rely on any special (or non-existent) plists.我的方法不依赖于任何特殊(或不存在)的 plist。

  1. Give your target a name, such as ALL , satisfy the remaining fields, and press "Finish".为您的目标命名,例如ALL ,满足其余字段,然后按“完成”。

  2. Click on the new target's Build Phases link and:单击新目标的Build Phases链接,然后:

    1. Delete the entry in the Compile Sources , which will be main.c if you're doing it how I did.删除Compile Sources 中的条目,如果您按照我的方式进行操作,它将是main.c
    2. Open the Target Dependencies and add all the other targets by clicking the + or dragging targets into this space.打开Target Dependencies并通过单击+或将目标拖到此空间来添加所有其他目标。

You can now build and clean your whole project when you have this target selected as the active schema.当您将此目标选为活动模式时,您现在可以构建清理整个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM