aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStuart Connolly <stuart02@gmail.com>2014-01-19 03:57:43 +0000
committerStuart Connolly <stuart02@gmail.com>2014-01-19 03:57:43 +0000
commit49b797222d0dda7868e5b6ce566723fe2a6248f1 (patch)
tree0468902a1a76cbc55f5ffed573c4c1f8213509b6
parent8b0f587b6aa4e16a2a7ba88cbb6f3a5165c52f45 (diff)
downloadsequelpro-49b797222d0dda7868e5b6ce566723fe2a6248f1.tar.gz
sequelpro-49b797222d0dda7868e5b6ce566723fe2a6248f1.tar.bz2
sequelpro-49b797222d0dda7868e5b6ce566723fe2a6248f1.zip
Display the short revision hash of the build alongside the revision number in the about dialog.
-rw-r--r--Resources/Plists/Info.plist2
-rwxr-xr-xScripts/build-version.pl74
-rw-r--r--Source/SPAboutController.m54
3 files changed, 108 insertions, 22 deletions
diff --git a/Resources/Plists/Info.plist b/Resources/Plists/Info.plist
index 0d62b893..d2107a25 100644
--- a/Resources/Plists/Info.plist
+++ b/Resources/Plists/Info.plist
@@ -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>
diff --git a/Scripts/build-version.pl b/Scripts/build-version.pl
index 521d26dc..e435573f 100755
--- a/Scripts/build-version.pl
+++ b/Scripts/build-version.pl
@@ -1,8 +1,6 @@
#! /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
diff --git a/Source/SPAboutController.m b/Source/SPAboutController.m
index c1a5c30a..921e0b83 100644
--- a/Source/SPAboutController.m
+++ b/Source/SPAboutController.m
@@ -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 @@ static NSString *SPLicenseFilename = @"License";
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 @@ static NSString *SPLicenseFilename = @"License";
[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