-
Notifications
You must be signed in to change notification settings - Fork 4
/
build_xcframeworks.sh
executable file
·128 lines (107 loc) · 3.48 KB
/
build_xcframeworks.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
#!/bin/bash
#set -x
OPT_REPO="forcedotcom"
OPT_BRANCH="dev"
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
usage ()
{
echo "Use this script to set generate xcframeworks for Swift Package Manager"
echo "Usage: $0 -r org -b branch"
echo " where: - org is the organization of the iOS repo e.g forcedotcom"
echo " - branch is the branch to checkout e.g. dev"
exit 1
}
parse_opts ()
{
while getopts :hr:b: command_line_opt
do
case ${command_line_opt} in
h) usage ;;
r) OPT_REPO=${OPTARG} ;;
b) OPT_BRANCH=${OPTARG} ;;
esac
done
}
function header () {
local SPACER="---------------------------------------------------------------------------"
echo -e "${YELLOW}\n\n${SPACER}\n $1\n${SPACER}\n${NC}"
}
function cloneRepo () {
local repoOrg=$1
local branch=$2
local repo="[email protected]:${repoOrg}/SalesforceMobileSDK-iOS"
header "Cloning ${repo}#${branch}"
git clone --branch $branch --single-branch --depth 1 $repo
pushd SalesforceMobileSDK-iOS
./install.sh
popd
}
function buildFramework() {
local lib=$1
local destination=$2
local suffix=$3
pushd SalesforceMobileSDK-iOS
header "Building $destination archive for $lib"
xcodebuild archive \
-workspace SalesforceMobileSDK.xcworkspace \
-scheme $lib \
-destination "generic/platform=$destination" \
-archivePath ../archives/$lib-$suffix \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
popd
if [ $lib == "SmartStore" ]
then
header "Fix swiftinterface for $lib $destination"
find archives/$lib-$suffix.xcarchive -name "*.swiftinterface" -exec gsed -i "s/${lib}\.//g" {} \;
fi
}
function buildXCFramework () {
local lib=$1
pushd SalesforceMobileSDK-iOS
header "Building xcframework for $lib"
xcodebuild -create-xcframework \
-framework ../archives/$lib-iOS.xcarchive/Products/Library/Frameworks/$lib.framework \
-framework ../archives/$lib-Sim.xcarchive/Products/Library/Frameworks/$lib.framework \
-framework ../archives/$lib-visionOS.xcarchive/Products/Library/Frameworks/$lib.framework \
-framework ../archives/$lib-visionOS-Sim.xcarchive/Products/Library/Frameworks/$lib.framework \
-output ../archives/$lib.xcframework
popd
}
function zipXCFramework () {
local lib=$1
pushd archives
header "Zipping xcframework for $lib"
zip $lib.xcframework.zip $lib.xcframework -r
popd
}
function updateChecksum () {
local lib=$1
local checksum=`swift package compute-checksum archives/$lib.xcframework.zip`
header "Updating checksum for $lib"
gsed -i "s/checksum: \"[^\"]*\" \/\/ ${lib}/checksum: \"${checksum}\" \/\/ ${lib}/g" Package.swift
}
function processLib () {
local lib=$1
buildFramework $lib "iOS" "iOS"
buildFramework $lib "iOS Simulator" "Sim"
buildFramework $lib "visionOS" "visionOS"
buildFramework $lib "visionOS Simulator" "visionOS-Sim"
buildXCFramework $lib
zipXCFramework $lib
# Using path instead of url / checksum in Package.swift - so checksum calculation is not needed
# updateChecksum $lib
}
function cleanup () {
rm -rf archives/*.xcarchive
rm -rf archives/*.xcframework
rm -rf SalesforceMobileSDK-iOS
}
parse_opts "$@"
cloneRepo $OPT_REPO $OPT_BRANCH
for lib in 'SalesforceSDKCommon' 'SalesforceAnalytics' 'SalesforceSDKCore' 'SmartStore' 'MobileSync'
do
processLib $lib
done
cleanup