Skip to content

Commit

Permalink
Update automatic bundle-version for git
Browse files Browse the repository at this point in the history
- Add git description for tracking hash and tags
- Correct build-phase deps so runs after Info.plist processing
- Simplify script to only emit warnings on failure
  • Loading branch information
chuckhoupt committed Nov 4, 2024
1 parent f3a046c commit ebb9fa0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
8 changes: 4 additions & 4 deletions Bartender.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
2067590F0FE847A800B1B7B9 /* WeighOff.png in Resources */ = {isa = PBXBuildFile; fileRef = 2067590D0FE847A800B1B7B9 /* WeighOff.png */; };
206759100FE847A800B1B7B9 /* WeighON.png in Resources */ = {isa = PBXBuildFile; fileRef = 2067590E0FE847A800B1B7B9 /* WeighON.png */; };
206759160FE9C49E00B1B7B9 /* BartenderIcons.icns in Resources */ = {isa = PBXBuildFile; fileRef = 206759150FE9C49E00B1B7B9 /* BartenderIcons.icns */; };
206C752F278CAFBE00EACDF8 /* Set-CFBundleVersion.sh in Resources */ = {isa = PBXBuildFile; fileRef = 206C752E278CAFBE00EACDF8 /* Set-CFBundleVersion.sh */; };
207458E115B4FE37008312B4 /* BCDailyDataWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 207458E015B4FE37008312B4 /* BCDailyDataWebView.m */; };
207AA6251610C8C1002FACB5 /* duplicate icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 207AA6241610C8C1002FACB5 /* duplicate icon.png */; };
208787DB16C209FB004998D1 /* FadeOutText.m in Sources */ = {isa = PBXBuildFile; fileRef = 208787DA16C209FB004998D1 /* FadeOutText.m */; };
Expand Down Expand Up @@ -598,8 +597,8 @@
8D15AC2B0486D014006FF6A4 /* Resources */,
8D15AC300486D014006FF6A4 /* Sources */,
8D15AC330486D014006FF6A4 /* Frameworks */,
206C7530278CAFE000EACDF8 /* Run Set CFBundleVersion Script */,
20B6A5542C7E3D3F00CFE58A /* Embed Frameworks */,
206C7530278CAFE000EACDF8 /* Run Set CFBundleVersion Script */,
);
buildRules = (
);
Expand Down Expand Up @@ -696,7 +695,6 @@
203BFBB9192E8AF1001B770B /* navy.png in Resources */,
203BFBB0192E8AF1001B770B /* blue.png in Resources */,
203BFBD4192E8AF1001B770B /* Markdown-BuildRule.sh in Resources */,
206C752F278CAFBE00EACDF8 /* Set-CFBundleVersion.sh in Resources */,
203BFBBB192E8AF1001B770B /* olive.png in Resources */,
203BFBB2192E8AF1001B770B /* darkgray.png in Resources */,
203BFBAF192E8AF1001B770B /* black.png in Resources */,
Expand All @@ -709,12 +707,14 @@
/* Begin PBXShellScriptBuildPhase section */
206C7530278CAFE000EACDF8 /* Run Set CFBundleVersion Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
alwaysOutOfDate = 1;
buildActionMask = 12;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)",
);
name = "Run Set CFBundleVersion Script";
outputFileListPaths = (
Expand Down
6 changes: 5 additions & 1 deletion BartenderAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];

[self.versionLabel setStringValue:[NSString stringWithFormat:@"Version %@ (%@)", [main objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [main objectForInfoDictionaryKey:@"CFBundleVersion"]] ];
[self.versionLabel setStringValue:[NSString stringWithFormat:@"Version %@ (%@) [%@]",
[main objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
[main objectForInfoDictionaryKey:@"CFBundleVersion"],
[main objectForInfoDictionaryKey:@"BCGitDescribe"]
]];

[self.copyrightLabel setStringValue: [main objectForInfoDictionaryKey:@"NSHumanReadableCopyright"]];

Expand Down
53 changes: 22 additions & 31 deletions Set-CFBundleVersion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,40 @@

# Set-CFBundleVersion.sh
#
# Sets the built-product's CFBundeVersion to the current working-directory Subversion revision.
# Sets the built-product's CFBundeVersion to the current working-directory revision.
#
# Install by adding a Run-Script Phase to the end of target's Build Phases with the script:
# Install by adding a Run-Script Phase to the end of target's Build Phases with:
#
# $SRCROOT/Set-CFBundleVersion.sh
# Script: $SRCROOT/Set-CFBundleVersion.sh
# Based on dependency analysis: False
# Input Files: $(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)
#
# Select "Run script only when installing" to limit execution to Release/Archiving.
#
# Created by Chuck Houpt on 10/23/13.
# Copyright 2013 Behavioral Cybernetics LLC. All rights reserved.
# Copyright 2013-2024 Behavioral Cybernetics LLC. All rights reserved.

set -eu

exit
set -eux

# Only run on release builds, since debug builds are by definition based on un-commmited code changes.
if [ $CONFIGURATION != 'Release' ] ; then exit ; fi

# Preemptively call svn-cleanup to avoid sqlite-errors from svnversion
svn cleanup

REVISION=$(svnversion -n)
#if [ $CONFIGURATION != 'Release' ] ; then exit ; fi

# Report problems if the working directory isn't a completely clean single-revision checkout.
# Use REPORT var to switch between warning and error ("Jerk Mode")
REPORT=warning
# REPORT=error

if [[ ! "$REVISION" =~ ^[0-9]+$ ]]
then
echo "$REPORT: working directory is not a single unmodified revision. svnversion reports: $REVISION (note: X:Y means mixed-revision, so update work-dir. 'M' means modified, so commit work-dir changes)"
[ $REPORT == 'warning' ]
elif [[ $(svn status) ]]
if [[ ! -d .git ]]
then
echo "warning: working directory is not a completely clean checkout with no extranious files. svn status reports:"
svn status
echo "warning: working dir not under version control, could not set version"
exit
fi

REVISION=$(git rev-list --count HEAD)
DESCRIBE=$(git describe --tags --long --always --dirty=-mutant)

# Emulate SVN by adding M if dirty
case $DESCRIBE in
*-mutant) REVISION="${REVISION}M" ;;
esac

# Modify CFBundleVersion in the product's compiled Info.plist

if grep --quiet 'CFBundleVersion' "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $REVISION" "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
else
/usr/libexec/PlistBuddy -c "Add :CFBundleVersion string $REVISION" "$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH"
fi
/usr/libexec/PlistBuddy -c "Add :CFBundleVersion string $REVISION" \
-c "Add :BCGitDescribe string $DESCRIBE" \
"$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH" || echo "warning: failed to setup CFBundleVersion"

0 comments on commit ebb9fa0

Please sign in to comment.