Skip to content

Commit

Permalink
🔖 New system to manage build number & version
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Aug 10, 2023
1 parent fe92c22 commit c76ebcf
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 46 deletions.
36 changes: 10 additions & 26 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
A80521312A84878200BF7E22 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
A82521EB29E234EB00139654 /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; };
A82521ED29E235AC00139654 /* AccessibilityAccessManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessibilityAccessManager.swift; sourceTree = "<group>"; };
A8263BDD2A48FA4C00E86EAA /* CGKeyCode+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGKeyCode+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -212,6 +213,7 @@
A8E59C37297F5E9A0064D4BA /* Loop */ = {
isa = PBXGroup;
children = (
A80521312A84878200BF7E22 /* Config.xcconfig */,
A8E59C38297F5E9A0064D4BA /* LoopApp.swift */,
A8330ABB2A3AC05200673C8D /* Helpers */,
A82521EA29E2349700139654 /* About Window */,
Expand Down Expand Up @@ -243,7 +245,6 @@
buildConfigurationList = A8E59C44297F5E9B0064D4BA /* Build configuration list for PBXNativeTarget "Loop" */;
buildPhases = (
A8291D6C2A450C2700C5CB69 /* Run SwiftLint */,
A83F608129874F18005796CE /* Set Build Number */,
A8E59C31297F5E9A0064D4BA /* Sources */,
A8E59C32297F5E9A0064D4BA /* Frameworks */,
A8E59C33297F5E9A0064D4BA /* Resources */,
Expand Down Expand Up @@ -332,25 +333,6 @@
shellPath = /bin/sh;
shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftlint > /dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
A83F608129874F18005796CE /* Set Build Number */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 12;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Set Build Number";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "$SRCROOT/resources/set_build_number.sh\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down Expand Up @@ -396,6 +378,7 @@
/* Begin XCBuildConfiguration section */
A8E59C42297F5E9B0064D4BA /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = A80521312A84878200BF7E22 /* Config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
Expand Down Expand Up @@ -428,6 +411,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = "$(BUILD_NUMBER)";
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -447,6 +431,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = "$(VERSION)";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand All @@ -458,6 +443,7 @@
};
A8E59C43297F5E9B0064D4BA /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = A80521312A84878200BF7E22 /* Config.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
Expand Down Expand Up @@ -490,6 +476,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = "$(BUILD_NUMBER)";
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
Expand All @@ -503,6 +490,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = "$(VERSION)";
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
Expand All @@ -520,10 +508,9 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Loop/Preview Content\"";
DEVELOPMENT_TEAM = F679LF3JPM;
DEVELOPMENT_TEAM = 6783T5MU9D;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -536,7 +523,6 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.0.0;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.MrKai77.Loop.Debug;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -555,10 +541,9 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Loop/Preview Content\"";
DEVELOPMENT_TEAM = F679LF3JPM;
DEVELOPMENT_TEAM = 6783T5MU9D;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -571,7 +556,6 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 1.0.0;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = com.MrKai77.Loop;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
21 changes: 20 additions & 1 deletion Loop.xcodeproj/xcshareddata/xcschemes/Loop.xcscheme
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.3">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<PreActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "$SRCROOT/resources/set_build_number.sh&#10;"
shellToInvoke = "/bin/bash">
<EnvironmentBuildable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A8E59C34297F5E9A0064D4BA"
BuildableName = "Loop.app"
BlueprintName = "Loop"
ReferencedContainer = "container:Loop.xcodeproj">
</BuildableReference>
</EnvironmentBuildable>
</ActionContent>
</ExecutionAction>
</PreActions>
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
Expand Down
12 changes: 12 additions & 0 deletions Loop/Config.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Config.xcconfig
// Loop
//
// Created by Kai Azim on 2023-08-09.
//

// Using other tools to set Loop's build number and marketing version didn't work well, so I
// resorted to using this config file to edit their values. There is a script in the resources
// folder that will auto-update the build number based on the number of commits.
VERSION = 1.0.0
BUILD_NUMBER = 0
24 changes: 5 additions & 19 deletions resources/set_build_number.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
#!/bin/bash

echo "Settings build number!"
echo "--- Setting build number! ---"

git=$(sh /etc/profile; which git)
number_of_commits=$("$git" rev-list HEAD --count)
cd "$SRCROOT"

target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH"
dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.plist"
sed -i -e "/BUILD_NUMBER =/ s/= .*/= $(git rev-list --count HEAD)/" Loop/Config.xcconfig

for plist in "$target_plist" "$dsym_plist"; do
if [ -f "$plist" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${number_of_commits}" "$plist"
fi
done
rm Loop/Config.xcconfig-e

settings_root_plist="$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Settings.bundle/Root.plist"

if [ -f "$settings_root_plist" ]; then
settingsVersion="$APP_MARKETING_VERSION (${number_of_commits})"
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:1:DefaultValue $settingsVersion" "$settings_root_plist"
else
echo "Could not find: $settings_root_plist"
exit 0
fi
echo "--- Done! ---"

0 comments on commit c76ebcf

Please sign in to comment.