Monthly Archives: February 2011

 
20
Feb
2011
 

Revisiting git tags and building

by Fraser Hess

A couple of years ago I posted my scripts for tagging and building. The build script doesn’t work so well for the App Stores and the Build and Archive-based submission process, so here’s an updated approach that works inside Xcode. (Same as my last article, I’m still using git, the tag.sh script, and Apple Generic Versioning (agv).)

  1. In your Xcode project, create a Shell Script target called GenGitVersion.
  2. Insert the following script in GenGitVersion’s Run Script phase, replacing the path to your git executable if need be:
    git=/usr/local/git/bin/git
    version=`$git describe`
    echo "#define GIT_VERSION $version" > InfoPlist.h
    touch Info.plist
  3. Make GenGitVersion a dependency of your main target.
  4. Add “InfoPlist.h” to your .gitignore file.
  5. In your main target’s build settings:
    1. Turn on Preprocess Info.plist File
    2. Set Info.plist Preprocessor Prefix File to InfoPlist.h
  6. In your app’s Info.plist set the Bundle versions string, short to GIT_VERSION

Now each time you build the main target, the version will be populated in the build’s Info.plist.

Examples

  • If you tag a commit, the version returned by git describe is the tag name.
  • If the current commit isn’t tagged, you’ll get the most recent tag plus the number of additional commits and an abbreviated commit name. Here’s a 1.0b1 tag with 2 additional commits: 1.0b1-2-g3925f3b. This can be a good way to identify a private developer build.
  • You can optionally add --dirty to git describe and the version will have -dirty appended if there are uncommitted changes to your working tree.
  • git describe will fail if there are no tags in the current working tree.