英文:
Is it possible to run an Xcode Build Phase Script when running xcodebuild from the command line?
问题
我有一个在我的Xcode项目中的构建阶段运行脚本,用于确保模块捆绑包是最新的。当通过Xcode GUI执行操作时,脚本会运行,而Swift Package能够成功构建和运行测试。但是,当我尝试在CI/CD的命令行中运行xcodebuild test
时,测试会失败,因为在构建过程中未执行运行脚本。
有没有办法告诉xcodebuild
使用我Xcode项目中的运行脚本?或者是否有一个标志可以用来指定要运行的脚本?
英文:
I have a build phase Run Script in my Xcode project that is required for ensuring the module bundle is up to date. The script runs when actions are executed through the Xcode GUI, and the Swift Package is able to build and run tests successfully. But when I try to run xcodebuild test
from the command line for CI/CD, the tests fail because the Run Script did not get executed during the build process.
Is there a way to tell xcodebuild
to use the Run Scripts from my Xcode project? Or is there a flag I can use to specify a script for it to run?
答案1
得分: 0
根据无线电静默,我猜想使用xcodebuild
标志或更改任何Xcode设置都不可能实现这一点。
作为解决方法,我最终采取的措施是分割构建和测试命令,然后在两者之间运行我的脚本。
# 之所以使用build-for-test是因为普通构建不会构建测试包,这在我的用例中很重要
xcodebuild build-for-test ...
bash path/to/run-script.sh
xcodebuild test ...
xcodebuild test
命令将使用先前构建命令编译的文件,因此它不会清除运行脚本对Xcode构建目录所做的任何更改(这就是我所做的事情)。
英文:
Judging by the radio silence, I'm guessing this isn't possible using an xcodebuild
flag or changing any Xcode settings.
What I ended up doing as a workaround was splitting build and test commands and then running my script in between.
# build-for-test is used bcus normal build wont build the test bundle, which was important in my use case
xcodebuild build-for-test ...
bash path/to/run-script.sh
xcodebuild test ...
The xcodebuild test
command will use the files compiled by the earlier build command, so it won't clean any changes made to the xcode build dir by the run script (which is what I was doing).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论