Skip to content
Permalink
Browse files

Display the short revision hash of the build alongside the revision n…

…umber in the about dialog.
  • Loading branch information...
stuconnolly committed Jan 19, 2014
1 parent 8b0f587 commit 49b797222d0dda7868e5b6ce566723fe2a6248f1
Showing with 108 additions and 22 deletions.
  1. +2 −0 Resources/Plists/Info.plist
  2. +57 −17 Scripts/build-version.pl
  3. +49 −5 Source/SPAboutController.m
@@ -176,6 +176,8 @@
</array>
<key>CFBundleVersion</key>
<string></string>
<key>SPVersionShortHash</key>
<string></string>
<key>FRFeedbackReporter.maxConsoleLogSize</key>
<integer>10000</integer>
<key>FRFeedbackReporter.targetURL</key>
@@ -1,7 +1,5 @@
#! /usr/bin/perl

#
# $Id$
#
# build-version.pl
# sequel-pro
@@ -32,38 +30,80 @@
#
# More info at <http://code.google.com/p/sequel-pro/>

# Updates the application/bundle's Info.plist CFBundleVersion to match that of the current
# Git revision.
# Updates the application/bundle's Info.plist CFBundleVersion to
# match that of the current Git revision.

use strict;
use warnings;

use Carp;

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

my $svn2git_migration_compensation = 480;
my $revision = `git log --oneline | wc -l` + $svn2git_migration_compensation;
my $plist_path = "$ENV{BUILT_PRODUCTS_DIR}/$ENV{INFOPLIST_PATH}";

my $version = $revision;
#
# Get the revision from Git.
#
sub _get_revision_number
{
my $svn2git_migration_compensation = 480;

($version =~ m/(\d+)[MS]*$/) && ($version = $1);
return `git log --oneline | wc -l` + $svn2git_migration_compensation;
}

die "$0: No Git revision found. Exiting..." unless $version;
#
# Get the revision short hash from Git.
#
sub _get_revision_short_hash
{
return `git log -n 1 --oneline --format=%h`;
}

open(my $plist, $plist_path) || croak "Unable to open plist file for reading: $!";
#
# Get the content of the app's Info.plist file.
#
sub _get_plist_content
{
open(my $plist, shift) || croak "Unable to open plist file for reading: $!";

my $info = join('', <$plist>);
my $content = join('', <$plist>);

close($plist);
close($plist);

$info =~ s/([\t ]+<key>CFBundleVersion<\/key>\n[\t ]+<string>).*?(<\/string>)/$1$version$2/;
return $content;
}

open($plist, '>', $plist_path) || croak "Unable to open plist file for writing: $!";
#
# Save the supplied plist content to the supplied path.
#
sub _save_plist
{
my ($plist_content, $plist_path) = @_;

open(my $plist, '>', $plist_path) || croak "Unable to open plist file for writing: $!";

print $plist $plist_content;

close($plist);
}

my $version = _get_revision_number();
my $version_hash = _get_revision_short_hash();

$version_hash =~ s/\n//;

croak "$0: Unable to determine Git revision. Exiting..." unless $version;
croak "$0: Unable to determine Git revision hash. Exiting..." unless $version_hash;

my $info = _get_plist_content($plist_path);

$info =~ s/([\t ]+<key>CFBundleVersion<\/key>\n[\t ]+<string>).*?(<\/string>)/$1$version$2/;
$info =~ s/([\t ]+<key>SPVersionShortHash<\/key>\n[\t ]+<string>).*?(<\/string>)/$1$version_hash$2/;

print $plist $info;
_save_plist($info, $plist_path);

close($plist);
printf("CFBunderVersion set to $version\n");
printf("VersionShortHash set to $version_hash");

exit 0
@@ -35,13 +35,22 @@
static NSString *SPCreditsFilename = @"Credits";
static NSString *SPLicenseFilename = @"License";

static NSString *SPAboutPanelNibName = @"AboutPanel";
static NSString *SPShortVersionHashKey = @"SPVersionShortHash";

@interface SPAboutController ()

- (void)_setVersionLabel:(BOOL)isNightly;

@end

@implementation SPAboutController

#pragma mark -

- (id)init
{
return [super initWithWindowNibName:@"AboutPanel"];
return [super initWithWindowNibName:SPAboutPanelNibName];
}

- (void)awakeFromNib
@@ -52,10 +61,9 @@ - (void)awakeFromNib
BOOL isNightly = [version hasPrefix:@"Nightly"];

// Set the application name, but only include the major version if this is not a nightly build.
[appNameVersionTextField setStringValue:(isNightly) ? @"Sequel Pro" : [NSString stringWithFormat:@"Sequel Pro %@", version]];

// Set the bundle/build version
[appBuildVersionTextField setStringValue:[NSString stringWithFormat:@"%@ %@", (isNightly) ? NSLocalizedString(@"Nightly Build", @"nightly build label") : NSLocalizedString(@"Build", @"build label") , [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
[appNameVersionTextField setStringValue:isNightly ? @"Sequel Pro" : [NSString stringWithFormat:@"Sequel Pro %@", version]];

[self _setVersionLabel:isNightly];

// Get the credits file contents
NSAttributedString *credits = [[[NSAttributedString alloc] initWithPath:[[NSBundle mainBundle] pathForResource:SPCreditsFilename ofType:@"rtf"] documentAttributes:nil] autorelease];
@@ -90,4 +98,40 @@ - (IBAction)closeApplicationLicenseSheet:(id)sender;
[appLicensePanel orderOut:self];
}

#pragma mark -
#pragma mark Private API

/**
* Set the UI version labels.
*
* @param isNightly Indicates whether or not this is a nightly build.
*/
- (void)_setVersionLabel:(BOOL)isNightly
{
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

// Get version numbers
NSString *bundleVersion = [infoDictionary objectForKey:(NSString *)kCFBundleVersionKey];
NSString *versionHash = [infoDictionary objectForKey:SPShortVersionHashKey];

BOOL hashIsEmpty = !versionHash && ![versionHash length];

NSString *textFieldString;

if (!bundleVersion && ![bundleVersion length] && hashIsEmpty) {
textFieldString = @"";
}
else {
textFieldString =
[NSString stringWithFormat:@"%@ %@%@",
isNightly ? NSLocalizedString(@"Nightly Build", @"nightly build label") : NSLocalizedString(@"Build", @"build label"),
bundleVersion,
hashIsEmpty ? @"" : [NSString stringWithFormat:@" (%@)", versionHash]];
}

NSLog(@"%@", textFieldString);

[appBuildVersionTextField setStringValue:textFieldString];
}

@end

0 comments on commit 49b7972

Please sign in to comment.
You can’t perform that action at this time.