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 anupdatedapproachthatworks inside Xcode. (Same as my last article, I’m still using git, the tag.sh script, and Apple Generic Versioning (agv).)
- In your Xcode project, create a Shell Script target called GenGitVersion.
- Insert the following script in GenGitVersion’s Run Script phase, replacing the path to your git executable if need be:
1 2 3 4
git=/usr/local/git/bin/git version=`$git describe` echo "#define GIT_VERSION $version" > InfoPlist.h touch Info.plist
- Make GenGitVersion a dependency of your main target.
- Add “InfoPlist.h” to your .gitignore file.
- In your main target’s build settings:
- Turn on Preprocess Info.plist File
- Set Info.plist Preprocessor Prefix File to InfoPlist.h
Now each time you build the main target, the version will be populated in the build’s Info.plist.
- If you tag a commit, the version returned by
git describeis the tag name.
- You can optionally add
git describeand the version will have
-dirtyappended if there are uncommitted changes to your working tree.
git describewill fail if there are no tags in the current working tree.
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.