From 49b797222d0dda7868e5b6ce566723fe2a6248f1 Mon Sep 17 00:00:00 2001 From: Stuart Connolly Date: Sun, 19 Jan 2014 03:57:43 +0000 Subject: Display the short revision hash of the build alongside the revision number in the about dialog. --- Scripts/build-version.pl | 74 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 17 deletions(-) (limited to 'Scripts') 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,7 +1,5 @@ #! /usr/bin/perl -# -# $Id$ # # build-version.pl # sequel-pro @@ -32,38 +30,80 @@ # # More info at -# 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 ]+CFBundleVersion<\/key>\n[\t ]+).*?(<\/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 ]+CFBundleVersion<\/key>\n[\t ]+).*?(<\/string>)/$1$version$2/; +$info =~ s/([\t ]+SPVersionShortHash<\/key>\n[\t ]+).*?(<\/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 -- cgit v1.2.3