forked from dplisek/GoogleMaps-SP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_xcframework.sh
executable file
·138 lines (111 loc) · 3.59 KB
/
make_xcframework.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
BUILD_DIRECTORY="Build"
CARTHAGE_XCFRAMEWORK_DIRECTORY="Carthage/Build/"
function archive_project() {
project_name=$1
framework_name=$2
# Archive iOS project.
xcodebuild archive\
-project "../$project_name.xcodeproj"\
-scheme "$framework_name"\
-configuration "Release"\
-destination "generic/platform=iOS"\
-archivePath "$framework_name.framework-iphoneos.xcarchive"\
SKIP_INSTALL=NO\
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
# Archive iOS Simulator project.
xcodebuild archive\
-project "../$project_name-Sim.xcodeproj"\
-scheme "$framework_name"\
-configuration "Simulator Release"\
-destination "generic/platform=iOS Simulator"\
-archivePath "$framework_name.framework-iphonesimulator.xcarchive"\
SKIP_INSTALL=NO\
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
}
function create_xcframework() {
project_name=$1
framework_name=$2
# Archive Xcode project.
archive_project $project_name $framework_name
# Create XCFramework from the archived project.
xcodebuild -create-xcframework\
-framework "$framework_name.framework-iphoneos.xcarchive/Products/Library/Frameworks/$framework_name.framework"\
-framework "$framework_name.framework-iphonesimulator.xcarchive/Products/Library/Frameworks/$framework_name.framework"\
-output "$framework_name.xcframework"
# Compress the XCFramework.
zip -r -X "$framework_name.xcframework.zip" "$framework_name.xcframework/"
# Save the SHA-256 checksum.
shasum -a 256 "$framework_name.xcframework.zip" >> checksum
}
function prepare() {
# Install Google Maps SDK for iOS.
carthage update
# Create Build directory if not existing.
if [ ! -d "$BUILD_DIRECTORY" ]; then
mkdir $BUILD_DIRECTORY
fi
}
function cleanup() {
rm -r *.xcframework
rm -r *.xcarchive
}
function print_completion_message() {
echo $'\n** XCFRAMEWORK CREATION FINISHED **\n'
}
function build_xcproject_project() {
prepare
cd $BUILD_DIRECTORY
create_xcframework "GoogleMaps" "GoogleMaps"
create_xcframework "GoogleMaps" "GoogleMapsBase"
create_xcframework "GoogleMaps" "GoogleMapsCore"
create_xcframework "GoogleMaps" "GoogleMapsM4B"
create_xcframework "GoogleMaps" "GooglePlaces"
cleanup
}
function create_google_xcframework() {
framework_name=$1
# Compress the XCFramework.
zip -r -X "$framework_name.xcframework.zip" "$framework_name.xcframework/"
# Save the SHA-256 checksum.
shasum -a 256 "$framework_name.xcframework.zip" >> checksum
# Move the XCFramework to build directory.
mv "$framework_name.xcframework.zip" "../../Build"
}
function package_google_xcframework() {
prepare
cd $CARTHAGE_XCFRAMEWORK_DIRECTORY
create_google_xcframework "GoogleMaps"
create_google_xcframework "GoogleMapsBase"
create_google_xcframework "GoogleMapsCore"
create_google_xcframework "GoogleMapsM4B"
create_google_xcframework "GooglePlaces"
mv "checksum" "../../Build"
}
function help() {
# Display help.
echo "Syntax: make_scframework [-x|b|h]"
echo "options:"
echo "x Create an XCFramework by building the Xcode project."
echo "g Create an XCFramework by zipping Google's prebuilt XCFramework."
echo "h Print this Help."
echo
}
while getopts ":hxg" flag; do
case "${flag}" in
h) # display Help
help
exit;;
x) # Build Xcode project
build_xcproject_project
print_completion_message
exit;;
g) # Package Google's beta Carthage XCFramework
package_google_xcframework
print_completion_message
exit;;
\?) # Invalid option
echo "Error: Invalid option"
exit;;
esac
done