Skip to content

Commit 1a1bbc5

Browse files
committed
Update package scripts
1 parent e57d9e8 commit 1a1bbc5

22 files changed

+720
-215
lines changed

package_version.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script creates a new project version for the package.
5+
# You can pass in a BRANCH to not use the default git branch.
6+
7+
DEFAULT_BRANCH="main"
8+
BRANCH=${1:-$DEFAULT_BRANCH}
9+
SCRIPT="scripts/package_version.sh"
10+
chmod +x $SCRIPT && bash $SCRIPT $BRANCH

scripts/build.sh

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,67 @@
11
#!/bin/bash
22

33
# Documentation:
4-
# This script builds a <TARGET> for all supported platforms.
4+
# This script builds a <TARGET> for all provided <PLATFORMS>.
5+
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
6+
# You can pass in a list of <PLATFORMS> if you want to customize the build.
7+
8+
# Usage:
9+
# build.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]
10+
# e.g. `bash scripts/build.sh MyTarget iOS macOS`
511

612
# Exit immediately if a command exits with a non-zero status
713
set -e
814

915
# Verify that all required arguments are provided
1016
if [ $# -eq 0 ]; then
11-
echo "Error: This script requires exactly one argument"
12-
echo "Usage: $0 <TARGET>"
17+
echo "Error: This script requires at least one argument"
18+
echo "Usage: $0 <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]"
19+
echo "For instance: $0 MyTarget iOS macOS"
1320
exit 1
1421
fi
1522

16-
# Create local argument variables.
23+
# Define argument variables
1724
TARGET=$1
1825

19-
# Use the script folder to refer to other scripts.
20-
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
21-
SCRIPT="$FOLDER/build_platform.sh"
26+
# Remove TARGET from arguments list
27+
shift
2228

23-
# Make the script executable
24-
chmod +x $SCRIPT
29+
# Define platforms variable
30+
if [ $# -eq 0 ]; then
31+
set -- iOS macOS tvOS watchOS xrOS
32+
fi
33+
PLATFORMS=$@
2534

26-
# A function that builds a specific platform
35+
# A function that builds $TARGET for a specific platform
2736
build_platform() {
28-
local platform=$1
29-
echo "Building for $platform..."
30-
if ! bash $SCRIPT $TARGET $platform; then
31-
echo "Failed to build $platform"
37+
38+
# Define a local $PLATFORM variable
39+
local PLATFORM=$1
40+
41+
# Build $TARGET for the $PLATFORM
42+
echo "Building $TARGET for $PLATFORM..."
43+
if ! xcodebuild -scheme $TARGET -derivedDataPath .build -destination generic/platform=$PLATFORM; then
44+
echo "Failed to build $TARGET for $PLATFORM"
3245
return 1
3346
fi
34-
echo "Successfully built $platform"
47+
48+
# Complete successfully
49+
echo "Successfully built $TARGET for $PLATFORM"
3550
}
3651

37-
# Array of platforms to build
38-
platforms=("iOS" "macOS" "tvOS" "watchOS" "xrOS")
52+
# Start script
53+
echo ""
54+
echo "Building $TARGET for [$PLATFORMS]..."
55+
echo ""
3956

40-
# Loop through platforms and build
41-
for platform in "${platforms[@]}"; do
42-
if ! build_platform "$platform"; then
57+
# Loop through all platforms and call the build function
58+
for PLATFORM in $PLATFORMS; do
59+
if ! build_platform "$PLATFORM"; then
4360
exit 1
4461
fi
4562
done
4663

47-
echo "All platforms built successfully!"
64+
# Complete successfully
65+
echo ""
66+
echo "Building $TARGET completed successfully!"
67+
echo ""

scripts/build_platform.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

scripts/chmod.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script makes all scripts in this folder executable.
5+
6+
# Usage:
7+
# scripts_chmod.sh
8+
# e.g. `bash scripts/chmod.sh`
9+
10+
# Exit immediately if a command exits with a non-zero status
11+
set -e
12+
13+
# Use the script folder to refer to other scripts.
14+
FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
15+
16+
# Find all .sh files in the FOLDER except chmod.sh
17+
find "$FOLDER" -name "*.sh" ! -name "chmod.sh" -type f | while read -r script; do
18+
chmod +x "$script"
19+
done

scripts/docc.sh

100644100755
Lines changed: 96 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,112 @@
11
#!/bin/bash
22

33
# Documentation:
4-
# This script build DocC for a <TARGET>.
5-
# The documentation ends up in to .build/docs.
4+
# This script builds DocC for a <TARGET> and certain <PLATFORMS>.
5+
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
6+
# You can pass in a list of <PLATFORMS> if you want to customize the build.
7+
# The documentation ends up in to .build/docs-<PLATFORM>.
8+
9+
# Usage:
10+
# docc.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]
11+
# e.g. `bash scripts/docc.sh MyTarget iOS macOS`
12+
13+
# Exit immediately if a command exits with a non-zero status
14+
set -e
15+
16+
# Fail if any command in a pipeline fails
17+
set -o pipefail
618

719
# Verify that all required arguments are provided
820
if [ $# -eq 0 ]; then
9-
echo "Error: This script requires exactly one argument"
10-
echo "Usage: $0 <TARGET>"
21+
echo "Error: This script requires at least one argument"
22+
echo "Usage: $0 <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]"
23+
echo "For instance: $0 MyTarget iOS macOS"
1124
exit 1
1225
fi
1326

27+
# Define argument variables
1428
TARGET=$1
1529
TARGET_LOWERCASED=$(echo "$1" | tr '[:upper:]' '[:lower:]')
1630

31+
# Remove TARGET from arguments list
32+
shift
33+
34+
# Define platforms variable
35+
if [ $# -eq 0 ]; then
36+
set -- iOS macOS tvOS watchOS xrOS
37+
fi
38+
PLATFORMS=$@
39+
40+
# Prepare the package for DocC
1741
swift package resolve;
1842

19-
xcodebuild docbuild -scheme $1 -derivedDataPath /tmp/docbuild -destination 'generic/platform=iOS';
43+
# A function that builds $TARGET for a specific platform
44+
build_platform() {
45+
46+
# Define a local $PLATFORM variable and set an exit code
47+
local PLATFORM=$1
48+
local EXIT_CODE=0
49+
50+
# Define the build folder name, based on the $PLATFORM
51+
case $PLATFORM in
52+
"iOS")
53+
DEBUG_PATH="Debug-iphoneos"
54+
;;
55+
"macOS")
56+
DEBUG_PATH="Debug"
57+
;;
58+
"tvOS")
59+
DEBUG_PATH="Debug-appletvos"
60+
;;
61+
"watchOS")
62+
DEBUG_PATH="Debug-watchos"
63+
;;
64+
"xrOS")
65+
DEBUG_PATH="Debug-xros"
66+
;;
67+
*)
68+
echo "Error: Unsupported platform '$PLATFORM'"
69+
exit 1
70+
;;
71+
esac
72+
73+
# Build $TARGET docs for the $PLATFORM
74+
echo "Building $TARGET docs for $PLATFORM..."
75+
if ! xcodebuild docbuild -scheme $TARGET -derivedDataPath .build/docbuild -destination "generic/platform=$PLATFORM"; then
76+
echo "Error: Failed to build documentation for $PLATFORM" >&2
77+
return 1
78+
fi
79+
80+
# Transform docs for static hosting
81+
if ! $(xcrun --find docc) process-archive \
82+
transform-for-static-hosting .build/docbuild/Build/Products/$DEBUG_PATH/$TARGET.doccarchive \
83+
--output-path .build/docs-$PLATFORM \
84+
--hosting-base-path "$TARGET"; then
85+
echo "Error: Failed to transform documentation for $PLATFORM" >&2
86+
return 1
87+
fi
88+
89+
# Inject a root redirect script on the root page
90+
echo "<script>window.location.href += \"/documentation/$TARGET_LOWERCASED\"</script>" > .build/docs-$PLATFORM/index.html;
91+
92+
# Complete successfully
93+
echo "Successfully built $TARGET docs for $PLATFORM"
94+
return 0
95+
}
96+
97+
# Start script
98+
echo ""
99+
echo "Building $TARGET docs for [$PLATFORMS]..."
100+
echo ""
20101

21-
$(xcrun --find docc) process-archive \
22-
transform-for-static-hosting /tmp/docbuild/Build/Products/Debug-iphoneos/$1.doccarchive \
23-
--output-path .build/docs \
24-
--hosting-base-path "$TARGET";
102+
# Loop through all platforms and call the build function
103+
for PLATFORM in $PLATFORMS; do
104+
if ! build_platform "$PLATFORM"; then
105+
exit 1
106+
fi
107+
done
25108

26-
echo "<script>window.location.href += \"/documentation/$TARGET_LOWERCASED\"</script>" > .build/docs/index.html;
109+
# Complete successfully
110+
echo ""
111+
echo "Building $TARGET docs completed successfully!"
112+
echo ""

scripts/framework.sh

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script builds DocC for a <TARGET> and certain <PLATFORMS>.
5+
# This script targets iOS, macOS, tvOS, watchOS, and xrOS by default.
6+
# You can pass in a list of <PLATFORMS> if you want to customize the build.
7+
8+
# Important:
9+
# This script doesn't work on packages, only on .xcproj projects that generate a framework.
10+
11+
# Usage:
12+
# framework.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]
13+
# e.g. `bash scripts/framework.sh MyTarget iOS macOS`
14+
15+
# Exit immediately if a command exits with a non-zero status
16+
set -e
17+
18+
# Verify that all required arguments are provided
19+
if [ $# -eq 0 ]; then
20+
echo "Error: This script requires exactly one argument"
21+
echo "Usage: $0 <TARGET>"
22+
exit 1
23+
fi
24+
25+
# Define argument variables
26+
TARGET=$1
27+
28+
# Remove TARGET from arguments list
29+
shift
30+
31+
# Define platforms variable
32+
if [ $# -eq 0 ]; then
33+
set -- iOS macOS tvOS watchOS xrOS
34+
fi
35+
PLATFORMS=$@
36+
37+
# Define local variables
38+
BUILD_FOLDER=.build
39+
BUILD_FOLDER_ARCHIVES=.build/framework_archives
40+
BUILD_FILE=$BUILD_FOLDER/$TARGET.xcframework
41+
BUILD_ZIP=$BUILD_FOLDER/$TARGET.zip
42+
43+
# Start script
44+
echo ""
45+
echo "Building $TARGET XCFramework for [$PLATFORMS]..."
46+
echo ""
47+
48+
# Delete old builds
49+
echo "Cleaning old builds..."
50+
rm -rf $BUILD_ZIP
51+
rm -rf $BUILD_FILE
52+
rm -rf $BUILD_FOLDER_ARCHIVES
53+
54+
55+
# Generate XCArchive files for all platforms
56+
echo "Generating XCArchives..."
57+
58+
# Initialize the xcframework command
59+
XCFRAMEWORK_CMD="xcodebuild -create-xcframework"
60+
61+
# Build iOS archives and append to the xcframework command
62+
if [[ " ${PLATFORMS[@]} " =~ " iOS " ]]; then
63+
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=iOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-iOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
64+
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=iOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-iOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
65+
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-iOS.xcarchive/Products/Library/Frameworks/$TARGET.framework"
66+
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-iOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework"
67+
fi
68+
69+
# Build iOS archive and append to the xcframework command
70+
if [[ " ${PLATFORMS[@]} " =~ " macOS " ]]; then
71+
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=macOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-macOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
72+
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-macOS.xcarchive/Products/Library/Frameworks/$TARGET.framework"
73+
fi
74+
75+
# Build tvOS archives and append to the xcframework command
76+
if [[ " ${PLATFORMS[@]} " =~ " tvOS " ]]; then
77+
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=tvOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
78+
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=tvOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
79+
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS.xcarchive/Products/Library/Frameworks/$TARGET.framework"
80+
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-tvOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework"
81+
fi
82+
83+
# Build watchOS archives and append to the xcframework command
84+
if [[ " ${PLATFORMS[@]} " =~ " watchOS " ]]; then
85+
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=watchOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
86+
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=watchOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
87+
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS.xcarchive/Products/Library/Frameworks/$TARGET.framework"
88+
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-watchOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework"
89+
fi
90+
91+
# Build xrOS archives and append to the xcframework command
92+
if [[ " ${PLATFORMS[@]} " =~ " xrOS " ]]; then
93+
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=xrOS" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
94+
xcodebuild archive -scheme $TARGET -configuration Release -destination "generic/platform=xrOS Simulator" -archivePath $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS-Sim SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
95+
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS.xcarchive/Products/Library/Frameworks/$TARGET.framework"
96+
XCFRAMEWORK_CMD+=" -framework $BUILD_FOLDER_ARCHIVES/$TARGET-xrOS-Sim.xcarchive/Products/Library/Frameworks/$TARGET.framework"
97+
fi
98+
99+
# Genererate XCFramework
100+
echo "Generating XCFramework..."
101+
XCFRAMEWORK_CMD+=" -output $BUILD_FILE"
102+
eval "$XCFRAMEWORK_CMD"
103+
104+
# Genererate iOS XCFramework zip
105+
echo "Generating XCFramework zip..."
106+
zip -r $BUILD_ZIP $BUILD_FILE
107+
echo ""
108+
echo "***** CHECKSUM *****"
109+
swift package compute-checksum $BUILD_ZIP
110+
echo "********************"
111+
echo ""
112+
113+
# Complete successfully
114+
echo ""
115+
echo "$TARGET XCFramework created successfully!"
116+
echo ""

scripts/git_default_branch.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
# Documentation:
4+
# This script echos the default git branch name.
5+
6+
# Usage:
7+
# git_default_branch.sh
8+
# e.g. `bash scripts/git_default_branch.sh`
9+
10+
BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
11+
echo $BRANCH

0 commit comments

Comments
 (0)