将Xcode捆绑版本设置为git哈希 [英] Set Xcode bundle version to git hash
问题描述
在Xcode中,我想将项目捆绑版本设置为git哈希,以在修订和构建之间创建一个独特的链接。
(我见过有几篇关于这个帖子的文章增加了每个版本的内部版本号,但对我来说这似乎过分了,我希望有一个内部版本号,测试人员可以在发送者反馈时参考它。)
我在构建阶段添加了以下内容作为运行脚本:
/ usr / libexec / PlistBuddy -cSet :CFBundleVersion`git rev-parse --short HEAD`* .plist
然后我读出包含以下代码的包版本:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@CFBundleVersion];
然而,新的修订版号并未出现在代码中,直到 next 建立。我认为这是因为当我的脚本运行时,编译器文件已被编译器读取。
另外,由于plist在修改字符串 提交给git,这会在项目中造成一个令人讨厌的差异,所以也许我并不聪明。
另一种方法是编写修订版数字转换为git忽略的文本文件(build.txt)。但我仍然希望项目内部版本号也遵循git。
任何人都知道这样做的好方法吗?
https://gist.github.com/966838是一个简短的bash脚本,它符合Apple的要求 CFBundleVersion应该是一个单调增加的字符串。
In Xcode, I want to set the project bundle version to the git hash, to create a unique link between a revision and a build.
(I have seen several postings about this that increase the build number for each build, but to me this seems excessive, and I would like to have a build number that testers can refer to when sender feedback).
I added the following as a Run Script in Build Phases:
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion `git rev-parse --short HEAD`" *.plist
And then I read out the bundle version in the code with:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
However, then the new revision number does not appear in the code until the next build. I assume this is because the plist file is already read by the compiler when my script is run.
Also, since the plist is changed with the revision string after committing to git, this causes an annoying diff in the project, so maybe I am not so smart after all.
An alternative would be to write the revision number to a text file (build.txt) which is ignored by git. But I would still like the project build number to follow git as well.
Anyone know a brilliant way to do this?
https://gist.github.com/966838 is a short bash script that meets Apple's requirement that CFBundleVersion should be a monotonically increased string.
这篇关于将Xcode捆绑版本设置为git哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!