libin (owner)

Revisions

gist: 64066 Download_button fork
public
Public Clone URL: git://gist.github.com/64066.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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