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: mkbuild.zip
The basic idea is that you create a build-config.sh file with some instructions on how to build your particular project, place it into a checked-out working copy of your project, and run mkbuild.sh from within the same directory. When you ask it to create a new build (mkbuild.sh new), it will:
- Tag your repository with a build number (e.g., build-0023).
- Export that tag to a RAM disk.
- Compile and package your app as instructed by the configuration file.
- 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 mkbuild.sh script will talk to either Subversion or git, depending on how you configure it.
Here is a summary of the operations it supports:
- mkbuild.sh new creates a new build
- mkbuild.sh rebuild n recreates build n, in case you deleted it
- mkbuild.sh log n prints changes between build n and build n – 1
- mkbuild.sh log n m prints changes between build n and build m
- mkbuild.sh list lists all builds in the repository
- mkbuild.sh archive n creates a zip file of the source of build n
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.