mirror of
https://github.com/nickshanks/ResKnife.git
synced 2024-11-09 08:05:27 +00:00
Automatically update version in InfoPlist.strings file.
This commit is contained in:
parent
95653088e7
commit
741aa76d84
Binary file not shown.
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# This script automatically sets the version and short version string of
|
||||
# an Xcode project from the Git repository containing the project.
|
||||
@ -18,6 +18,7 @@ hash git 2>/dev/null || { echo >&2 "Git required, not installed. Aborting build
|
||||
|
||||
# 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}"
|
||||
INFO_STRINGS="${TARGET_BUILD_DIR}/${INFOSTRINGS_PATH}"
|
||||
|
||||
# Build version (closest-tag-or-branch "-" commits-since-tag "-" short-hash dirty-flag)
|
||||
BUILD_VERSION=$(git describe --tags --always --dirty=+)
|
||||
@ -28,12 +29,22 @@ 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}"
|
||||
if [ $COMMIT_COUNT_SINCE_TAG = 0 ]; then
|
||||
SHORT_VERSION="$LATEST_TAG"
|
||||
else
|
||||
# increment final digit of tag and append "d" + commit-count-since-tag
|
||||
# e.g. commit after 1.0 is 1.1d1, commit after 1.0.0 is 1.0.1d1
|
||||
# this is the bit that requires /bin/bash
|
||||
OLD_IFS=$IFS
|
||||
IFS="."
|
||||
VERSION_PARTS=($LATEST_TAG)
|
||||
LAST_PART=$((${#VERSION_PARTS[@]}-1))
|
||||
VERSION_PARTS[$LAST_PART]=$((${VERSION_PARTS[${LAST_PART}]}+1))
|
||||
SHORT_VERSION="${VERSION_PARTS[*]}d${COMMIT_COUNT_SINCE_TAG}"
|
||||
IFS=$OLD_IFS
|
||||
fi
|
||||
|
||||
# Bundle version (commits-on-master-until-branch "." commits-on-branch)
|
||||
# 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)
|
||||
@ -52,6 +63,28 @@ defaults write "$INFO_PLIST" CFBundleBuildVersion "$BUILD_VERSION"
|
||||
defaults write "$INFO_PLIST" CFBundleShortVersionString "$SHORT_VERSION"
|
||||
defaults write "$INFO_PLIST" CFBundleVersion "$BUNDLE_VERSION"
|
||||
|
||||
# substitute version information into InfoPlist.strings
|
||||
# this only works for English, and only for the main app :-(
|
||||
if [[ "$TARGET_NAME" = "ResKnife Cocoa" && "$DEVELOPMENT_LANGUAGE" = "English" ]]; then
|
||||
# refresh the index and check if it is dirty
|
||||
LANG=C
|
||||
LC_CTYPE=C
|
||||
BUILD_YEAR=$(date +%Y)
|
||||
git update-index -q --refresh
|
||||
#DIRTY=$(git diff-index --quiet HEAD; echo $?)
|
||||
DIRTY=0; git diff-index --quiet HEAD || DIRTY=1
|
||||
BUILD_HASH=$(git rev-parse --short HEAD)
|
||||
if [ $DIRTY = 0 ]
|
||||
then BUILD_ID="$BUILD_HASH"
|
||||
else BUILD_ID="${BUILD_HASH}+"
|
||||
fi
|
||||
# there is a tool called envsubst that does does this, but I dont have it installed.
|
||||
iconv -f utf-16 -t utf-8 < "${PROJECT_DIR}/Cocoa/English.lproj/InfoPlist.strings" | sed -e "s/\$SHORT_VERSION/${SHORT_VERSION}/g" -e "s/\$BUILD_ID/${BUILD_ID}/g" -e "s/\$BUILD_YEAR/${BUILD_YEAR}/g" | iconv -f utf-8 -t utf-16 > "$INFO_STRINGS"
|
||||
# these don't work, but are supposed to be more general
|
||||
#iconv -f utf-16 -t utf-8 < "${PROJECT_DIR}/Cocoa/English.lproj/InfoPlist.strings" | sed -e "s/\$(\w+)/$ENV{$1}/" | iconv -f utf-8 -t utf-16 > "$INFO_STRINGS"
|
||||
#iconv -f utf-16 -t utf-8 < "${PROJECT_DIR}/Cocoa/English.lproj/InfoPlist.strings" | perl -p -e 's/\$\{(\w+)\}/$ENV{$1}/eg' | iconv -f utf-8 -t utf-16 > "$INFO_STRINGS"
|
||||
fi
|
||||
|
||||
# For debugging:
|
||||
#echo "BUILD VERSION: $BUILD_VERSION"
|
||||
#echo "LATEST_TAG: $LATEST_TAG"
|
||||
@ -60,3 +93,5 @@ defaults write "$INFO_PLIST" CFBundleVersion "$BUNDLE_VERSION"
|
||||
#echo "MASTER_COMMIT_COUNT: $MASTER_COMMIT_COUNT"
|
||||
#echo "BRANCH_COMMIT_COUNT: $BRANCH_COMMIT_COUNT"
|
||||
#echo "BUNDLE_VERSION: $BUNDLE_VERSION"
|
||||
#echo "INFOSTRINGS_PATH: $INFOSTRINGS_PATH"
|
||||
#echo "INFO_STRINGS: $INFO_STRINGS"
|
||||
|
Loading…
Reference in New Issue
Block a user