diff options
author | Stuart Connolly <stuart02@gmail.com> | 2014-01-19 03:57:43 +0000 |
---|---|---|
committer | Stuart Connolly <stuart02@gmail.com> | 2014-01-19 03:57:43 +0000 |
commit | 49b797222d0dda7868e5b6ce566723fe2a6248f1 (patch) | |
tree | 0468902a1a76cbc55f5ffed573c4c1f8213509b6 /Scripts/build-version.pl | |
parent | 8b0f587b6aa4e16a2a7ba88cbb6f3a5165c52f45 (diff) | |
download | sequelpro-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.
Diffstat (limited to 'Scripts/build-version.pl')
-rwxr-xr-x | Scripts/build-version.pl | 74 |
1 files changed, 57 insertions, 17 deletions
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 |