From ec5b2a22c8d69fa86a67a06b7bd2c0ee1d445a26 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Sat, 23 Aug 2014 18:03:12 -0400 Subject: [PATCH] Make sure CFBundleVersion is a semantic version number. CFBundleShortVersionString is now used to embed the Git rev info instead. --- Configurations/set-git-version-info.sh | 28 ++++++++++++++++++++++++++ Sparkle.xcodeproj/project.pbxproj | 28 +++++++++++++++++++++----- Sparkle/Sparkle-Info.plist | 2 +- 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100755 Configurations/set-git-version-info.sh diff --git a/Configurations/set-git-version-info.sh b/Configurations/set-git-version-info.sh new file mode 100755 index 00000000..8a79052c --- /dev/null +++ b/Configurations/set-git-version-info.sh @@ -0,0 +1,28 @@ +#!/bin/sh +set -e + +if ! which -s git ; then + exit 0 +fi + +if [ -z "$SRCROOT" ] || \ + [ -z "$BUILT_PRODUCTS_DIR" ] || \ + [ -z "$INFOPLIST_PATH" ] || \ + [ -z "$CURRENT_PROJECT_VERSION" ]; then + echo "$0: Must be run from Xcode!" 1>&2 + exit 1 +fi + +# Get the current Git master hash +version=$(cd "$SRCROOT" ; git show-ref --abbrev heads/master | awk '{print $1}') +if [ -z "$version" ] ; then + echo "$0: Can't find a Git hash!" 1>&2 + exit 0 +fi + +version="$CURRENT_PROJECT_VERSION git-$version" + +# and use it to set the CFBundleShortVersionString value +export PATH="$PATH:/usr/libexec" +PlistBuddy -c "Set :CFBundleShortVersionString '$version'" \ + "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index bab43f38..81175c97 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -302,6 +302,7 @@ 1420DF4E196247B500203BB0 /* Doxyfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Doxyfile; sourceTree = ""; }; 1420DF4F196247F900203BB0 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 142E0E0819A83AAC00E4312B /* SUBinaryDeltaTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUBinaryDeltaTest.m; path = Tests/SUBinaryDeltaTest.m; sourceTree = ""; }; + 14652F7919A93E5F00959E44 /* set-git-version-info.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "set-git-version-info.sh"; sourceTree = ""; }; 146EC84E19A68CF8004A50C5 /* Sparkle.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = Sparkle.podspec; sourceTree = SOURCE_ROOT; }; 14732BB1195FF6B700593899 /* .clang-format */ = {isa = PBXFileReference; lastKnownFileType = text; path = ".clang-format"; sourceTree = SOURCE_ROOT; }; 14732BB91960EEEE00593899 /* SampleAppcast.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = SampleAppcast.xml; sourceTree = ""; }; @@ -934,6 +935,7 @@ FA3AAF3A1050B273004B3130 /* ConfigUnitTestDebug.xcconfig */, FA3AAF391050B273004B3130 /* ConfigUnitTestRelease.xcconfig */, 14732BC91960F70A00593899 /* make-release-package.sh */, + 14652F7919A93E5F00959E44 /* set-git-version-info.sh */, 146EC84E19A68CF8004A50C5 /* Sparkle.podspec */, ); path = Configurations; @@ -1032,6 +1034,7 @@ 55C14BB3136EEF1500649790 /* Resources */, 55C14BB4136EEF1500649790 /* Sources */, 55C14BB5136EEF1500649790 /* Frameworks */, + 14652F7B19A945D600959E44 /* Run Script: Set Git Version Info */, ); buildRules = ( ); @@ -1106,7 +1109,7 @@ 142E0E0319A6A24100E4312B /* CopyFiles */, 8DC2EF540486A6940098B216 /* Sources */, 8DC2EF560486A6940098B216 /* Frameworks */, - 6131B1910DDCDE32005215F0 /* Run Script: Set git Version Info */, + 6131B1910DDCDE32005215F0 /* Run Script: Set Git Version Info */, 6195D4B40E40505A00D41A50 /* Run Script: Link fr_CA to fr */, 61E31A85103299750051D188 /* Run Script: Link pt to pt_BR */, ); @@ -1238,6 +1241,21 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 14652F7B19A945D600959E44 /* Run Script: Set Git Version Info */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script: Set Git Version Info"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$SRCROOT/Configurations/set-git-version-info.sh\""; + showEnvVarsInLog = 0; + }; 612279D70DB5470200AB99EA /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -1252,19 +1270,19 @@ shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n"; showEnvVarsInLog = 0; }; - 6131B1910DDCDE32005215F0 /* Run Script: Set git Version Info */ = { + 6131B1910DDCDE32005215F0 /* Run Script: Set Git Version Info */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 12; files = ( ); inputPaths = ( ); - name = "Run Script: Set git Version Info"; + name = "Run Script: Set Git Version Info"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; - shellPath = "/usr/bin/env ruby"; - shellScript = "# Xcode auto-versioning script for Subversion\n# by Axel Andersson, modified by Daniel Jalkut to add\n# \"--revision HEAD\" to the svn info line, which allows\n# the latest revision to always be used.\n\nif ENV[\"BUILT_PRODUCTS_DIR\"].nil?\n\tSTDERR.print \"#{$0}: Must be run from Xcode!\"\n\texit(1)\nend\n\n# Get the current Git master hash and use it to set the CFBundleVersion value\nENV[\"PATH\"] = \"/bin:/sw/bin:/usr/local/git/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/opt/local/bin\"\nexit(0) if `type git` == \"\"\nrev = `/usr/bin/env git show-ref --abbrev heads/master`\ninfo = \"#{ENV[\"BUILT_PRODUCTS_DIR\"]}/#{ENV[\"WRAPPER_NAME\"]}/Resources/Info.plist\"\nversion = rev.split(\" \")[0]\n\nif version.nil?\n\tSTDERR.print \"#{$0}: Can't find a Git hash!\"\n\texit(0)\nend\n\ninfo_contents = File.read(info)\nif info_contents.nil?\n\tSTDERR.print \"#{$0}: Can't read in the Info.plist file!\"\n\texit(1)\nend\n\ninfo_contents.sub!(/([\\t ]+CFBundleVersion<\\/key>\\n[\\t ]+).*?(<\\/string>)/, '\\1' + version + '\\2')\nSTDERR.print info_contents\nf = File.open(info, \"w\")\nf.write(info_contents)\nf.close"; + shellPath = /bin/sh; + shellScript = "\"$SRCROOT/Configurations/set-git-version-info.sh\""; showEnvVarsInLog = 0; }; 6195D4B40E40505A00D41A50 /* Run Script: Link fr_CA to fr */ = { diff --git a/Sparkle/Sparkle-Info.plist b/Sparkle/Sparkle-Info.plist index 1e23fec7..3d5c7f18 100644 --- a/Sparkle/Sparkle-Info.plist +++ b/Sparkle/Sparkle-Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - ${CURRENT_PROJECT_VERSION} git + ${CURRENT_PROJECT_VERSION} CFBundleSignature ???? CFBundleVersion