Build Numbers in Xcode (Revisited)

So after the suggestions given in the comments section the build script I’m using now uses PlistBuddy (which I wanted to use before but didn’t know the correct path), and increments only if we’re building the release build. (It was an interesting exercise to see my project’s build number go up into the thousands–but a build number that looks like a zip code isn’t really useful.)

Here is the current script which I’m using.

# Auto increment version number from build common file

use strict;

die "$0: Must be run from Xcode" unless $ENV{"BUILT_PRODUCTS_DIR"};

# Get the current revision number and use it to set the CFBundleVersion value
open FH, "build.count" or die;
my $version = join("",);
close(FH);

if ($ENV{CONFIGURATION} eq "Release") {
	++$version;

	open FH, ">build.count" or die;
	print FH $version;
	close(FH);
}

$version = "1.1 ($version)";
print "Build $versionn"; 

# Update info.plist in build product. Use defaults command
	
my $INFO = "$ENV{BUILT_PRODUCTS_DIR}/$ENV{WRAPPER_NAME}/Info.plist";
my @cmd = ( '/usr/libexec/PlistBuddy', '-c', "Set :CFBundleVersion $version", $INFO );
exec @cmd;

Note that this is Perl, which means you need to set the Shell to “/usr/bin/perl -w” when you set this as the run script phase.

This works on my iPhone software. For Macintosh builds you need to change the third-to-last line to:

my $INFO = "$ENV{BUILT_PRODUCTS_DIR}/$ENV{WRAPPER_NAME}/Contents/Info.plist";

And don’t forget to create a build.count file in the same directory as your project file and set the text file to the starting build count.

4 thoughts on “Build Numbers in Xcode (Revisited)

  1. ^^ err… I see how this could happened. !@#$!@#$ WordPress – either do HTML or not?! anyway the FH needs to be surrounded by “less than” and “greater than” symbols.

    Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s