groups

Link to this snippet:


Download to Code Collector

language: Ruby
licence: BSD

Build number script (Xcode phase)

options: send to code collectorview all jfro's snippets
#!/usr/bin/env ruby

begin
require 'rubygems'
rescue LoadError
	error_string = "\n\nYou must install rubygems in order to use this script"
	raise error_string
end

begin
require 'osx/plist'
rescue LoadError
	error_string = "\n\nYou must install the plist ruby gem in order to use this script. \n gem sources -a http://gems.github.com \n sudo gem install kballard-osx-plist\n"
	raise error_string
end

PLIST_FILE = File.join(ENV['BUILT_PRODUCTS_DIR'], ENV['INFOPLIST_PATH'])
PROJECT_DIR = ENV['PROJECT_DIR']
RELEASE_DIR = File.join(PROJECT_DIR, 'Releases')
BUILD_NUMBER_FILE = File.join(PROJECT_DIR, 'build.num')
BUILD_STYLE = ENV['BUILD_STYLE']
# styles that get counted for build number and zipping
RELEASE_STYLES = ['Release', 'Beta']

def updateBuildNumber
	buildNumber = 0
    begin
		File.open(BUILD_NUMBER_FILE, 'r') do |file|
			buildNumber = file.read().to_i
    	end
    rescue
    end

    File.open(BUILD_NUMBER_FILE, 'w') do |file|
	    buildNumber += 1
	    file.write(buildNumber.to_s)
	end
    return buildNumber
end

def updatePlistVersion(buildNumber)
    plist = OSX::PropertyList.load(File.open(PLIST_FILE))
	oldVersion = plist['CFBundleVersion']
	plist['CFBundleVersion'] = buildNumber.to_s # has to be string, standard about box will crash if it's NSNumber
	
	File.open(PLIST_FILE, "w+") do |plistFile|
		OSX::PropertyList.dump(plistFile, plist, :xml1)
	end
end

# check for plist file
if not File.exists? PLIST_FILE
    puts "** No plist file found: #{PLIST_FILE} "
    exit(1)
end

# check valid build style
if BUILD_STYLE != 'Release' and BUILD_STYLE != 'Beta'
    exit(0)
end

# do it up

require 'rubygems'
require 'osx/plist'

# productName = ENV['PRODUCT_NAME']
# productFilename = ENV['FULL_PRODUCT_NAME']

updatePlistVersion(updateBuildNumber())