Skip to content

Commit d390d66

Browse files
committed
Update package scripts
1 parent bc60db5 commit d390d66

13 files changed

+452
-171
lines changed

scripts/build.sh

+39-21
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,65 @@
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+
6+
# Usage:
7+
# build.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]
8+
# e.g. `bash scripts/build.sh MyTarget iOS macOS`
59

610
# Exit immediately if a command exits with a non-zero status
711
set -e
812

913
# Verify that all required arguments are provided
1014
if [ $# -eq 0 ]; then
11-
echo "Error: This script requires exactly one argument"
12-
echo "Usage: $0 <TARGET>"
15+
echo "Error: This script requires at least one argument"
16+
echo "Usage: $0 <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]"
17+
echo "For instance: $0 MyTarget iOS macOS"
1318
exit 1
1419
fi
1520

16-
# Create local argument variables.
21+
# Define argument variables
1722
TARGET=$1
1823

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"
24+
# Remove TARGET from arguments list
25+
shift
2226

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

26-
# A function that builds a specific platform
33+
# A function that builds $TARGET for a specific platform
2734
build_platform() {
28-
local platform=$1
29-
echo "Building for $platform..."
30-
if ! bash $SCRIPT $TARGET $platform; then
31-
echo "Failed to build $platform"
35+
36+
# Define a local $PLATFORM variable
37+
local PLATFORM=$1
38+
39+
# Build $TARGET for the $PLATFORM
40+
echo "Building $TARGET for $PLATFORM..."
41+
if ! xcodebuild -scheme $TARGET -derivedDataPath .build -destination generic/platform=$PLATFORM; then
42+
echo "Failed to build $TARGET for $PLATFORM"
3243
return 1
3344
fi
34-
echo "Successfully built $platform"
45+
46+
# Complete successfully
47+
echo "Successfully built $TARGET for $PLATFORM"
3548
}
3649

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

40-
# Loop through platforms and build
41-
for platform in "${platforms[@]}"; do
42-
if ! build_platform "$platform"; then
55+
# Loop through all platforms and call the build function
56+
for PLATFORM in $PLATFORMS; do
57+
if ! build_platform "$PLATFORM"; then
4358
exit 1
4459
fi
4560
done
4661

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

scripts/build_platform.sh

-16
This file was deleted.

scripts/docc.sh

100644100755
+83-10
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,99 @@
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> for all provided <PLATFORMS>.
5+
# The documentation ends up in to .build/docs-<PLATFORM>.
6+
7+
# Usage:
8+
# docc.sh <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]
9+
# e.g. `bash scripts/docc.sh MyTarget iOS macOS`
10+
11+
# Exit immediately if a command exits with a non-zero status
12+
set -e
613

714
# Verify that all required arguments are provided
815
if [ $# -eq 0 ]; then
9-
echo "Error: This script requires exactly one argument"
10-
echo "Usage: $0 <TARGET>"
16+
echo "Error: This script requires at least one argument"
17+
echo "Usage: $0 <TARGET> [<PLATFORMS> default:iOS macOS tvOS watchOS xrOS]"
18+
echo "For instance: $0 MyTarget iOS macOS"
1119
exit 1
1220
fi
1321

22+
# Define argument variables
1423
TARGET=$1
1524
TARGET_LOWERCASED=$(echo "$1" | tr '[:upper:]' '[:lower:]')
1625

26+
# Remove TARGET from arguments list
27+
shift
28+
29+
# Define platforms variable
30+
if [ $# -eq 0 ]; then
31+
set -- iOS macOS tvOS watchOS xrOS
32+
fi
33+
PLATFORMS=$@
34+
35+
# Prepare the package for DocC
1736
swift package resolve;
1837

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

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";
89+
# Loop through all platforms and call the build function
90+
for PLATFORM in $PLATFORMS; do
91+
if ! build_platform "$PLATFORM"; then
92+
exit 1
93+
fi
94+
done
2595

26-
echo "<script>window.location.href += \"/documentation/$TARGET_LOWERCASED\"</script>" > .build/docs/index.html;
96+
# Complete successfully
97+
echo ""
98+
echo "Building $TARGET docs completed successfully!"
99+
echo ""

scripts/framework.sh

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

0 commit comments

Comments
 (0)