From ebb9fa000cad9c09045219d600070e40398ee236 Mon Sep 17 00:00:00 2001 From: Chuck Houpt Date: Mon, 4 Nov 2024 09:06:03 -0500 Subject: [PATCH] Update automatic bundle-version for git - 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 --- Bartender.xcodeproj/project.pbxproj | 8 ++--- BartenderAppDelegate.m | 6 +++- Set-CFBundleVersion.sh | 53 ++++++++++++----------------- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/Bartender.xcodeproj/project.pbxproj b/Bartender.xcodeproj/project.pbxproj index 9132f45..f406820 100755 --- a/Bartender.xcodeproj/project.pbxproj +++ b/Bartender.xcodeproj/project.pbxproj @@ -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 */; }; @@ -598,8 +597,8 @@ 8D15AC2B0486D014006FF6A4 /* Resources */, 8D15AC300486D014006FF6A4 /* Sources */, 8D15AC330486D014006FF6A4 /* Frameworks */, - 206C7530278CAFE000EACDF8 /* Run Set CFBundleVersion Script */, 20B6A5542C7E3D3F00CFE58A /* Embed Frameworks */, + 206C7530278CAFE000EACDF8 /* Run Set CFBundleVersion Script */, ); buildRules = ( ); @@ -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 */, @@ -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 = ( diff --git a/BartenderAppDelegate.m b/BartenderAppDelegate.m index f761e9c..0bf1191 100644 --- a/BartenderAppDelegate.m +++ b/BartenderAppDelegate.m @@ -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"]]; diff --git a/Set-CFBundleVersion.sh b/Set-CFBundleVersion.sh index 3374db2..7ac4f4d 100755 --- a/Set-CFBundleVersion.sh +++ b/Set-CFBundleVersion.sh @@ -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"