Posted on February 27, 2009 at 9:39pm EST. More.

mkbuild, an iPhone project build script

Note: The information in this post is over three years old, and has been obsoleted by Xcode 4’s Archive feature.

When I wrote “Good Practices: iPhone Development”, I promised to share the script I wrote to create numbered builds of iPhone applications. I am certain that I am not the only programmer who feels uncomfortable sharing source code until it is ready (i.e., Perfect), but we must not forget that Real Artists Ship. This is a long winded way of saying that I finally cleaned up my build script and made it available for download.

The impatient can get it here:

The basic idea is that you create a file with some instructions on how to build your particular project, place it into a checked-out working copy of your project, and run from within the same directory. When you ask it to create a new build ( new), it will:

  1. Tag your repository with a build number (e.g., build-0023).
  2. Export that tag to a RAM disk.
  3. Compile and package your app as instructed by the configuration file.
  4. Destroy the RAM disk.
I like using RAM disks for this sort of thing, since there is no doubt the build is clean.

The build number is always a four digit, monotonically increasing integer. When you make a new build, the script scans your existing tags and automatically determines the next available build number. I briefly experimented with using the repository revision number, but decided it would be better to decouple the build numbering from the revision control system used.

That turned out to be a good move, because although I developed the script to work against a Subversion repository, I made a git version for a different project I worked on. I have since merged the two, so the script will talk to either Subversion or git, depending on how you configure it.

Here is a summary of the operations it supports:

Everywhere it asks for a build number, you can specify 3 and it will automatically interpret that as 0003.

Although I wrote the script to simplify iPhone project builds, it could be easily adapted to handle any Xcode project.

Please try it out and let me know what you think. This link will always redirect you to the latest version and I’ll make previous versions available here. Since the script will tag your repository, be responsible and make a backup before you start experimenting. The zip file contains a sample configuration file and there is documentation is in the script source itself.