All articles, tagged with “sync

Sync Svn version and CFBundleVersion in Xcode


For end users every application has a version number. But for us developer, every application has also a build number too, that is used by the system (e.g. Launch Services) and is needed to track down the source code powering the application.

When creating a Cocoa application you can set these numbers by filling CFBundleShortVersionString and CFBundleVersion keys within info.plist. How to choose the right numbers? Some info on the web:

We use Subversion to handle our source code, so we agreed it would be cool having the Svn version number synced to the CFBundleVersion. We’ve created a Python script that effortlessly does the job syncing the two numbers:

#!/usr/bin/python

from AppKit import NSMutableDictionary
import os

def increaseVersion():
    # reading svn version
    version = os.popen('svnversion -n').read()

    version = version.split(':')[-1]

    if not version[-1].isdigit():
        version = version[:-1]

    # reading info.plist file
    projectPlist = NSMutableDictionary.dictionaryWithContentsOfFile_('Info.plist')

    # setting the svn version for CFBundleVersion key
    projectPlist['CFBundleVersion'] = version
    projectPlist.writeToFile_atomically_('Info.plist', True)

if __name__ == '__main__':
    increaseVersion()

How to use the script in Xcode:

  1. Add a new build phase at the end of your target’s build phases: right click on your Target , Add -> New build Phase -> New Run Script Build Phase.
  2. Double click on the new “Run Script” item and copy/paste the script in the Script field.
  3. Make sure that the Shell field is set to: /usr/bin/python.

When you build your application, the Svn version number will be applied for the CFBundleVersion key.

This script is designed to run on Mac OS X 10.5; can run also on 10.4 provided you install PyObjC.

blog powered by byteflow


  • OLDER POSTS
  • TOP
  • NEWER POSTS