From 9662e44c9d3869459d7fe27f67a819f8c83e49dd Mon Sep 17 00:00:00 2001 From: Nicholas Shanks Date: Mon, 17 Feb 2014 11:26:58 +0000 Subject: [PATCH] Add automatic versioning. Only the Cocoa application target has a corresponding build script phase at present. --- Cocoa/Info.plist | 4 +- ResKnife.xcodeproj/project.pbxproj | 19 +++++++++ Scripts/build-version.sh | 62 ++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100755 Scripts/build-version.sh diff --git a/Cocoa/Info.plist b/Cocoa/Info.plist index 8d2b4aa..1ff61e4 100644 --- a/Cocoa/Info.plist +++ b/Cocoa/Info.plist @@ -48,11 +48,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.6 cvs + CFBundleSignature ResK CFBundleVersion - 19 + NSAppleScriptEnabled NSMainNibFile diff --git a/ResKnife.xcodeproj/project.pbxproj b/ResKnife.xcodeproj/project.pbxproj index d3b01bd..7976600 100644 --- a/ResKnife.xcodeproj/project.pbxproj +++ b/ResKnife.xcodeproj/project.pbxproj @@ -1604,6 +1604,7 @@ E18BF56F069FEA1300F076B8 /* Sources */, E18BF586069FEA1300F076B8 /* Frameworks */, E18BF589069FEA1300F076B8 /* Rez */, + 0EF0A9D818B18F3D00BF3F47 /* Run Versioning Script */, ); buildRules = ( ); @@ -2027,6 +2028,24 @@ }; /* End PBXRezBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 0EF0A9D818B18F3D00BF3F47 /* Run Versioning Script */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Versioning Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "${PROJECT_DIR}/Scripts/build-version.sh"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 8415918618AFE39B00306B4F /* Sources */ = { isa = PBXSourcesBuildPhase; diff --git a/Scripts/build-version.sh b/Scripts/build-version.sh new file mode 100755 index 0000000..4877f63 --- /dev/null +++ b/Scripts/build-version.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# This script automatically sets the version and short version string of +# an Xcode project from the Git repository containing the project. +# +# To use this script in Xcode, add the script's path to a "Run Script" build +# phase for your application target. + +set -o errexit +set -o nounset + +# First, check for git in $PATH +hash git 2>/dev/null || { echo >&2 "Git required, not installed. Aborting build number update script."; exit 0; } + +# Alternatively, we could use Xcode's copy of the Git binary, +# but old Xcodes don't have this. +#GIT=$(xcrun -find git) + +# Run Script build phases that operate on product files of the target that defines them should use the value of this build setting [TARGET_BUILD_DIR]. But Run Script build phases that operate on product files of other targets should use “BUILT_PRODUCTS_DIR” instead. +INFO_PLIST="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" + +# Build version (closest-tag-or-branch "-" commits-since-tag "-" short-hash dirty-flag) +BUILD_VERSION=$(git describe --tags --always --dirty=+) + +# Use the latest tag for short version (expected tag format "n[.n[.n]]") +LATEST_TAG=$(git describe --tags --abbrev=0) +COMMIT_COUNT_SINCE_TAG=$(git rev-list --count ${LATEST_TAG}..) +if [ $LATEST_TAG = "start" ] + then LATEST_TAG=0 +fi +if [ $COMMIT_COUNT_SINCE_TAG = 0 ] + then SHORT_VERSION="$LATEST_TAG" + else SHORT_VERSION="${LATEST_TAG}d${COMMIT_COUNT_SINCE_TAG}" +fi + +# Bundle version (commits-on-master-until-branch "." commits-on-branch) +# Assumes that two release branches will not diverge from the same commit on master. +if [ $(git rev-parse --abbrev-ref HEAD) = "master" ]; then + MASTER_COMMIT_COUNT=$(git rev-list --count HEAD) + BRANCH_COMMIT_COUNT=0 + BUNDLE_VERSION="$MASTER_COMMIT_COUNT" +else + MASTER_COMMIT_COUNT=$(git rev-list --count $(git rev-list master.. | tail -n 1)^) + BRANCH_COMMIT_COUNT=$(git rev-list --count master..) + if [ $BRANCH_COMMIT_COUNT = 0 ] + then BUNDLE_VERSION="$MASTER_COMMIT_COUNT" + else BUNDLE_VERSION="${MASTER_COMMIT_COUNT}.${BRANCH_COMMIT_COUNT}" + fi +fi + +defaults write "$INFO_PLIST" CFBundleBuildVersion "$BUILD_VERSION" +defaults write "$INFO_PLIST" CFBundleShortVersionString "$SHORT_VERSION" +defaults write "$INFO_PLIST" CFBundleVersion "$BUNDLE_VERSION" + +# For debugging: +#echo "BUILD VERSION: $BUILD_VERSION" +#echo "LATEST_TAG: $LATEST_TAG" +#echo "COMMIT_COUNT_SINCE_TAG: $COMMIT_COUNT_SINCE_TAG" +#echo "SHORT VERSION: $SHORT_VERSION" +#echo "MASTER_COMMIT_COUNT: $MASTER_COMMIT_COUNT" +#echo "BRANCH_COMMIT_COUNT: $BRANCH_COMMIT_COUNT" +#echo "BUNDLE_VERSION: $BUNDLE_VERSION"