仅为 Xcode 4 中的“存档”构建运行脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5471396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:41:18  来源:igfitidea点击:

Running script only for an 'Archive' build in Xcode 4

iphonexcodexcode4

提问by Wex

I have a script that I run using osascript from a Run Script Build Phase in Xcode 4. This script does some checks to try and catch any human-error in plists and suchlike.

我有一个脚本,我在 Xcode 4 的运行脚本构建阶段使用 osascript 运行该脚本。该脚本执行一些检查以尝试捕获 plist 等中的任何人为错误。

However, I only really want to run this script when a developer chooses 'Archive' as opposed to running it every time they build.

但是,我真的只想在开发人员选择“存档”时运行此脚本,而不是每次构建时都运行它。

Is there any way of testing for this situation? Either in Shell Script or Apple Script?

有没有办法测试这种情况?使用 Shell Script 还是 Apple Script?

回答by BJ Homer

In Xcode 4+, you could run this script as a pre- or post-action script on the "Archive" action. However, pre- and post-action scripts are not considered part of the build itself; their output is not part of the build log, and a failing script will not cause the build to fail.

在 Xcode 4+ 中,您可以将此脚本作为“存档”操作上的操作前或操作后脚本运行。但是,操作前和操作后脚本不被视为构建本身的一部分;它们的输出不是构建日志的一部分,失败的脚本不会导致构建失败。

If you want to include this script as a first-class part of the build, such that its failure will cause the build to fail, then you'll want to do something else. Make a new "External Build System" target, and configure it to run your script. The path to your script can be a relative path, relative to the project root.

如果您想将此脚本作为构建的首要部分包含在内,这样它的失败将导致构建失败,那么您需要做一些其他事情。创建一个新的“外部构建系统”目标,并将其配置为运行您的脚本。脚本的路径可以是相对于项目根目录的相对路径。

Finally, open your main project scheme, and in the "Build" tag add the new checker target, and set it to only be included in the "Archive" action. This should cause your checker script to be run as part of the build only when "Archive" is selected, and if the script returns a non-zero value the build will fail.

最后,打开您的主项目方案,并在“Build”标签中添加新的检查器目标,并将其设置为仅包含在“Archive”操作中。这应该会导致您的检查器脚本仅在选择“存档”时作为构建的一部分运行,并且如果脚本返回非零值,构建将失败。

A screenshot showing how to configure the scheme

显示如何配置方案的屏幕截图

回答by Mike

  1. Add a "New Run Script Phase" to your project's "Build Phases"
  2. Move (drag&drop) your script in the right position
  3. Check the "Run script only when installing"
  1. 将“新运行脚本阶段”添加到项目的“构建阶段”
  2. 将您的脚本移动(拖放)到正确的位置
  3. 勾选“仅在安装时运行脚本”

If you don't do 3.the script will run all the time, but if you check that box, it will only run when archiving.

如果你不做3.脚本会一直运行,但如果你选中那个框,它只会在归档时运行。

回答by Philippe

A quick test on my own system shows no difference in the detailed script output between straight "Build" and "Build and Archive".

在我自己的系统上进行的快速测试显示,直接“构建”和“构建和存档”之间的详细脚本输出没有区别。

Also, you can't test for the presence (or absence) of the archive, since it only gets created at the very end of the process, when all scripts have been run.

此外,您无法测试存档是否存在(或不存在),因为它只会在进程的最后创建,即所有脚本都已运行时。

As far as I can see, there is no current option within Xcode 3 to do this. Maybe file an enhancement request with Apple?

据我所知,Xcode 3 中没有当前选项可以执行此操作。也许向 Apple 提出增强请求?

While you wait on Apple, the only solution I can offer is to use xcodebuild and xcrun as part of a command-line shell script, where you would knowif you are archiving or not. This is not a stay-in-Xcode solution, but it does have a lot of flexibility.

当您等待 Apple 时,我可以提供的唯一解决方案是使用 xcodebuild 和 xcrun 作为命令行 shell 脚本的一部分,您将知道是否正在存档。这不是留在 Xcode 中的解决方案,但它确实具有很大的灵活性。

Xcode "Build and Archive" from command line

命令行中的Xcode“构建和存档”