可以在使用命令行运行 xcodebuild 时运行 Xcode 构建阶段脚本吗?

huangapple go评论59阅读模式
英文:

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).

huangapple
  • 本文由 发表于 2023年2月14日 08:59:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75442557.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定