Thursday, July 12, 2012

Automatically add Git hash to Info.plist in Xcode

Here is a script to add a git hash to your app Info.plist when building. The script can also add the git status (clean or not). It does not require preprocessing of the Info.plist, extra targets, or temporary files that must be ignored by git. The script works by modifying the Info.plist in the finished build, so it does not disturb the project working directory and your clean git state.

Open up the Info.plist file and add two properties with keys GitShaHash, and GitState. These values will be overwritten during the build process. I have seen similar scripts that work by storing the hash in CFBundleVersion instead. However, OS X uses CFBundleVersion to compare versions of the same app, and the Mac App Store also requires updates to have a sequential CFBundleVersion. Since the git hash is not sequential, it's better to just leave CFBundleVersion alone and relegate it to an under the hood value.

Select the project target, and add a run script build phase:

Copy and paste the script in. This is a perl scrip so the shell must be set to /usr/bin/perl . Note that the line “my $INFO …” is set for Mac app bundles, you can switch the commented lines around for iOS apps.

use strict;
use warnings;

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

my $FH;
my $output;

# SHA hash :

open $FH, "xcrun git rev-parse HEAD|" or die;
$output = <$FH>;

chomp( $output );
my $gitShaHash = $output;

# clean state :

$output = `xcrun git status`;

my $gitState;
if ( index( $output, "nothing to commit (working directory clean)" ) != -1 ) {
    $gitState = "clean";
} else {
    $gitState = "dirty";

print "gitShaHash : $gitShaHash\n";
print "gitState : $gitState";

# Update Info.plist in build product. Use defaults command


my @defaults = ( 'defaults', 'write', $INFO, 'GitShaHash', "$gitShaHash" );
system( @defaults );

@defaults = ( 'defaults', 'write', $INFO, 'GitState', "$gitState" );
system( @defaults );

All done, now the values will be generated every time you build and the values can be accessed easily from the Info.plist using code:

NSURL *url = [[[NSBundle mainBundle] bundleURL] URLByAppendingPathComponent:@"Contents/Info.plist"];
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfURL:url];

NSString *hash = [dictionary objectForKey:@"GitShaHash"];
NSString *state = [dictionary objectForKey:@"GitState"];

It’s a good idea to place the values within the about panel or a similar location. The hash can make it easier to track issues with beta testers. And the git state makes it easier to prevent dirty builds from being distributed.

Monday, February 20, 2012

10.6 back for Minesweeper

The last update for Minesweeper 2.7 required OS X 10.7 because the Lion technology Auto layout was included as an experiment. It was working fine before and should not have been changed in the first place, so there is a fix coming shortly to restore support for OS X 10.6.

Replay for Minesweeper

The screenshot is of an early build in 2009. The game has come quite a ways visually.

Although it doesn't visually look much different from earlier versions, 2.7 was a big update for me. I refactored much of the source code, and reorganized some parts of the project. The main new feature, replay, is one I've been wanting to add for a while. I actually did have replay working since before the last update, but it was inefficient due to the main data structure for the game, and I wanted to restructure that before finishing up replay functionality. Now that its finished, I'm quite happy with the result, I hope you enjoy it too.

Monday, January 2, 2012

Klotski on the Mac

I have finished a Klotski game for the mac. Just like for Minesweeper, I want to make a quality, minimal but elegant designed game that is fun to play and addresses the nostalgia for the original.

I have finished an initial version which is available free on the Mac App store. It contains only a few basic layouts for now, but I have plans to add more soon.

Download on the App store

Saturday, April 23, 2011

Minesweeper 2.5

Version 2.5 is recently been reviewed, approved, and ready for the Mac App Store.
- Games can be saved and loaded for records.
- The Inspector tool statistics have been reworded to be more clear.
- The clock can be clicked anytime to start a new game.
- Several long standing bugs have been fixed.

See Full Description
Download on the Mac App Store


Digging through my old projects, I uncovered this small gem. It's a very bare bones clone of Tetris for Mac. It's is very incomplete, there is no scoring, no high scores, and no levels to speak of. It is however fun, I have unintentionally wasted quite a bit of time playing. This was one of my first attempts at programming Objective-C, Cocoa, the code is not exemplary, to say the least. I'm not sure I will ever make this into a complete game, but who knows. In any case, please enjoy.

The controls:
A - Hold
Z - Rotate left (or Up)
X - Rotate right
Left/Right - Move
Down - Slow drop
Space - Instant drop

Download Now

Tuesday, February 1, 2011

Minesweeper 2.4

Version 2.4 is available now. There is now an option for chording, which is by default set to off; I hope this will be a help to those without two button mice. Also, new icon and a few graphics and interface adjustments.

See Full Description
Download on the Mac App Store