Skip to content

Instantly share code, notes, and snippets.

@libin
Created February 13, 2009 19:51
Show Gist options
  • Save libin/64066 to your computer and use it in GitHub Desktop.
Save libin/64066 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# iPhone Application Post Build Script
# 1. 在XCode左边栏选中相应的Target
# 2. 在菜单中选择Project -> New Build Phase -> New Run Script Build Phase .
# 3. 弹出的对话框中,Shell里填写/usr/bin/ruby, Script中填写上面的脚本代码.
# http://www.robinlu.com/blog/archives/371
if ENV["BUILD_STYLE"] == "Distribution" && ENV["ARCHS"] == 'armv6'
common_git_paths = %w[/usr/local/bin/git /usr/local/git/bin/git /opt/local/bin/git]
git_path = ""
common_git_paths.each do |p|
if File.exist?(p)
git_path = p
break
end
end
if git_path == ""
puts "Path to git not found"
exit
end
command_line = git_path + " rev-parse --short HEAD"
sha = `#{command_line}`.chomp
info_file = ENV['INFOPLIST_FILE']
f = File.open(info_file, "r").read
re = /([\t ]+<key>CFBundleVersion< \/key>\n[\t ]+<string>)(.*?)(< \/string>)/
f =~ re
# Get the version info from the source Info.plist file
# If the script has already been run we need to remove the git sha
# from the bundle’s Info.plist.
version = $2.sub(/ \([\w]+\)/, "")
cmdline = "cd #{ENV['BUILT_PRODUCTS_DIR']};zip -r #{ENV['CONTENTS_FOLDER_PATH']}.#{version}.zip #{ENV['CONTENTS_FOLDER_PATH']};zip -r #{ENV['CONTENTS_FOLDER_PATH']}.dSYM.#{version}.#{sha}.zip #{ENV['CONTENTS_FOLDER_PATH']}.dSYM"
`#{cmdline}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment