drodriguez (owner)

Revisions

  • c94dcb drodriguez Thu Apr 02 02:47:40 -0700 2009
  • c0a37c drodriguez Thu Apr 02 02:47:00 -0700 2009
  • 39f9a0 drodriguez Thu Apr 02 02:23:40 -0700 2009
  • 6cc74f drodriguez Thu Apr 02 02:19:43 -0700 2009
gist: 89109 Download_button fork
public
Public Clone URL: git://gist.github.com/89109.git
README
1
2
3
4
5
6
7
8
9
10
11
12
This script and build target will take the revision number from a Subversion repository (or a Git
repository using git-svn) and substitute the last dotted component of the CFBundleVersion in your
Info.plist file (you can put something like "1.0.0.xx" for your first run).
 
Instructions:
 
- Save update_build_number.rb into ${PROJECT_DIR}/Scripts (or wherever you want, but remember to
  change the paths accordigly in the build phase).
- Add a new target to your project (I named mines as "Update FooBar Build Number"). In new target
  dialog choose from "Other" category "Shell Script Target".
- In the "Run Script" build phase include the contents shown above.
- Make your main target depend on "Update FooBar Build Number".
update_build_number.rb
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'osx/cocoa'
 
class InvalidRepository < Exception; end
 
class GitInfo
  def initialize(path)
    unless File.exist?(File.join(path, '.git'))
      raise InvalidRepository.new(path)
    end
    @path = File.join(path, '.git')
  end
  
  def build_number
    result = `git --git-dir=#{@path} svn info`
    if $?.success?
      result = result.split("\n").inject({}) do |memo, item|
        pair = item.split(':', 2)
        memo[pair.first] = pair.last.strip
        memo
      end
      
      result = result["Revision"]
      return nil if result.nil?
      begin
        Integer(result)
      rescue ArgumentError => e
        result = result[0..-2]
        if result.length > 0
          retry
        else
          nil
        end
      end
    else
      nil
    end
  end
end
 
class SVNInfo
  def initialize(path)
    unless File.exist?(File.join(path, '.svn'))
      raise InvalidRepository.new(path)
    end
    @path = path
  end
  
  def build_number
    result = `svnversion #{@path}`
    if $?.success?
      result = result.split(':').last
      begin
        Integer(result)
      rescue ArgumentError => e
        result = result[0..-2]
        if result.length > 0
          retry
        else
          nil
        end
      end
    else
      nil
    end
  end
end
 
def main
  begin
    info = SVNInfo.new(ARGV[0])
  rescue InvalidRepository => e
    begin
      info = GitInfo.new(ARGV[0])
    rescue InvalidRepository => e
      return
    end
  end
  
  build_number = info.build_number
  
  plist = OSX::NSMutableDictionary.dictionaryWithContentsOfFile_(ARGV[1])
  main_version = plist['CFBundleVersion'].split('.')[0..-2]
  plist['CFBundleVersion'] = (main_version << build_number).join('.')
  plist.writeToFile_atomically_(ARGV[1], true)
end
 
if __FILE__ == $0
  main
end
Bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Script to paste in the Run Script phase
 
update_build_number() {
# This is where my git binaries are
PATH=$PATH:/opt/local/bin
 
/usr/bin/env ruby ${PROJECT_DIR}/Scripts/update_build_number.rb ${PROJECT_DIR} ${PROJECT_DIR}/Path/To/Your/Info.plist
}
 
case "$CONFIGURATION" in
Beta|Distribution)
update_build_number
;;
*)
esac