我将 Xcode 4 与 Git 结合使用,并希望在每次构建时增加 Info.plist 中的 CFBundleVersion。 CFBundleVersion 键的值应更新为我对 Git 存储库所做的最后一次提交的编号。
I found thatpython 脚本运行良好,但不幸的是,它没有更新我的 Xcode 项目中的 Info.plist - 它只是更新“BUILT_PRODUCTS_DIR”中的 Info.plist。
有谁知道如何让 Xcode 4 获取最新提交的版本并将该信息放入项目的 Info.plist 中?
Thanks!
版本字符串的格式必须为 [xx].[yy].[zz],其中 x、y、z 是数字。
我通过使用来处理这个问题git tag
为 x 和 y 提供有意义的特定提交标记编号(例如 0.4),然后通过脚本构建阶段,z 获取自最后一个标记以来的提交数量,如git describe
.
这是我改编的剧本this one。它可以作为构建阶段直接添加到目标(shell
is /usr/bin/env ruby
):
# add git tag + version number to Info.plist
version = `/usr/bin/env git describe`.chomp
puts "raw version "+version
version_fancy_re = /(\d*\.\d*)-?(\d*)-?/
version =~ version_fancy_re
commit_num = $2
if ( $2.empty? )
commit_num = "0"
end
fancy_version = ""+$1+"."+commit_num
puts "compatible: "+fancy_version
# backup
source_plist_path = File.join(ENV['PROJECT_DIR'], ENV['INFOPLIST_FILE'])
orig_plist = File.open( source_plist_path, "r").read;
File.open( source_plist_path+".bak", "w") { |file| file.write(orig_plist) }
# put in CFBundleVersion key
version_re = /([\t ]+<key>CFBundleVersion<\/key>\n[\t ]+<string>).*?(<\/string>)/
orig_plist =~ version_re
bundle_version_string = $1 + fancy_version + $2
orig_plist.gsub!(version_re, bundle_version_string)
# put in CFBundleShortVersionString key
version_re = /([\t ]+<key>CFBundleShortVersionString<\/key>\n[\t ]+<string>).*?(<\/string>)/
orig_plist =~ version_re
bundle_version_string = $1 + fancy_version + $2
orig_plist.gsub!(version_re, bundle_version_string)
# write
File.open(source_plist_path, "w") { |file| file.write(orig_plist) }
puts "Set version string to '#{fancy_version}'"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)