Sunday, 7 December 2008

Updating Leopard's Pre-Installed Subversion

Here's the how to update Leopard's pre-installed copy of subversion.

Download and install the latest universal binary from CollabNet:
http://www.collab.net/downloads/community/includes/communitydownloads-getit-mac.html

The installer puts everything into /opt/subversion and creates symbolic links in /usr/local/bin but this doesn't disable the pre-installed copy in /usr/bin.

You need to get adventurous:
  1. Create symbolic links in /usr/bin/ and /usr/lib/ to the new subversion files in /opt/subversion/bin/ and /op/subversion/lib/
  2. Update your apache subversion configuration to use the new /opt/subversion/lib/svn-apache/mod_dav_svn.so
Note: do not update libapr to 1.0.2.12 as it will cause a problem with Apache.

Step by step using Terminal:

  1. Commit all your files and close all subversion clients eg Xcode
  2. If not logged in as an admin account switch user to an admin account:
    su admin
  3. Create links to the new subversion files:
    sudo ln -sf /opt/subversion/bin/svn* /usr/bin/
    sudo ln -sf /opt/subversion/lib/libsvn* /usr/lib/
  4. Edit your apache2 subversion configuration file: (your location may be different)
    sudo pico /etc/apache2/other/svn.conf
  5. Update LoadModule to:
    LoadModule dav_svn_module /opt/subversion/lib/svn-apache/mod_dav_svn.so

Saturday, 6 December 2008

Incrementing Your Build Number in Xcode

Here's a little shell script to increment a build number automatically with each build.

It assumes the following about your versions in info.plist:
  • Your product version is CFBundleShortVersionString in info.plist
    eg 1.0.0
  • Your build number is appended to your product version in CFBundleVersion
    eg 1.0.0.133
Step by step:

  1. Enter some default values in info.plist
    Bundle versions string, short: 0.1.0 (CFBundleShortVersionString)
    Bundle version: 0.1.0.1 (CFBundleVersion)
  2. Select your Target in Xcode
  3. Add a new run script build phase:
    Project -> New Build Phase -> New Run Script Build Phase
  4. Paste the script below into the script box
  5. Build your project
version=$(sed -n '
/^[[:blank:]]*CFBundleShortVersionString<\/key>$/ {
N
s/^[[:blank:]]*CFBundleShortVersionString<\/key>\n[[:blank:]]*\(.*\)<\/string>/\1/
p
}' info.plist)

build=$(sed -n '

/^[[:blank:]]*CFBundleVersion<\/key>$/ {
N
s/^[[:blank:]]*CFBundleVersion<\/key>\n[[:blank:]]*.*\.\(.*\)<\/string>/\1/
p
}' info.plist)

build=$(($build +1))


cp Info.plist 'Backup of Info.plist'


sed '

/^[[:blank:]]*CFBundleVersion<\/key>$/ {

N
s/\(\).*\(<\/string>\)/\1'"$version\.$build"'\2/
P
D
}' 'Backup of info.plist' > Info.plist

Each time you build using that target the build number will be incremented. A backup of your info.plist is made (just in case).

You could easily extend this script to commit files to your subversion repository.

The script uses multi-line sed and I'm no sed magician. If you're looking for a sed tutorial try here.