Xcode 4:使用Git repo commit版本更新每个版本上的CFBundleVersion [英] Xcode 4: Update CFBundleVersion on each build using Git repo commit version

查看:100
本文介绍了Xcode 4:使用Git repo commit版本更新每个版本上的CFBundleVersion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Xcode 4与Git结合使用,并希望在每个版本的Info.plist中增加CFBundleVersion。键值CFBundleVersion应该更新为最后一次提交给Git仓库的提交数量。

I'm using Xcode 4 in combination with Git and would like to increment the CFBundleVersion in Info.plist on each build. The value for the key CFBundleVersion should be updated to the number of the last commit I made to the Git repository.

我发现 ,它可以很好地工作,但不幸的是它不会更新我的Xcode项目中的Info.plist - 它只是更新了BUILT_PRODUCTS_DIR中的Info.plist。

I found that python script which works well, but unfortunately doesn't update the Info.plist in my Xcode project - it just updates the Info.plist in the "BUILT_PRODUCTS_DIR".

有谁知道如何让Xcode 4获取最新提交的版本并将这些信息放入该项目的Info.plist?

Does anyone has an idea how to get Xcode 4 to fetch the version of the latest commit and put that information into the project's Info.plist?

感谢!

推荐答案

字符串需要格式为[xx]。[yy]。[zz]其中x,y,z是数字。

The version string needs to be of the format [xx].[yy].[zz] where x, y, z are numbers.

我使用 git tag 给出特定的提交x和y的有意义标记号(例如0.4),然后通过脚本构建阶段,z获取自最后一个标记以来提交的次数,返回由 git describe

I deal with this by using git tag to give specific commits meaningful tag numbers for x and y (eg 0.4), and then via a script build phase, z gets the number of commits since the last tag, as returned by git describe.

H ere的脚本,我从这一个<一>。它可以作为构建阶段直接添加到目标中( shell / usr / bin / env ruby​​ ):

Here's the script, which I adapted from this one. It can be added straight to the target as a build phase (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}'"

这篇关于Xcode 4:使用Git repo commit版本更新每个版本上的CFBundleVersion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆