-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildFramework.sh
More file actions
executable file
Β·276 lines (234 loc) Β· 9.67 KB
/
BuildFramework.sh
File metadata and controls
executable file
Β·276 lines (234 loc) Β· 9.67 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#!/bin/bash
# Usage Examples (Command β Output XCFramework Name):
# bash BuildFramework.sh FTMobileSDK β FTMobileSDK.xcframework
# bash BuildFramework.sh FTMobileSDK-dynamic β FTMobileSDK-Dynamic.xcframework
# bash BuildFramework.sh FTMobileSDK --disable-swizzling-resource β FTMobileSDK-DisableSwizzlingResource.xcframework
# bash BuildFramework.sh FTMobileSDK-dynamic --disable-swizzling-resource β FTMobileSDK-Dynamic-DisableSwizzlingResource.xcframework
# bash BuildFramework.sh FTMobileExtension β FTMobileExtension.xcframework
# bash BuildFramework.sh FTMobileExtension --disable-swizzling-resource β FTMobileExtension-DisableSwizzlingResource.xcframework
# bash BuildFramework.sh FTSessionReplay β FTSessionReplay.xcframework
# bash BuildFramework.sh FTSessionReplay-dynamic β FTSessionReplay-Dynamic.xcframework
# Parameter Notes:
# -dynamic: Build dynamic library (default: static library)
# --disable-swizzling-resource: Disable URLSession method swizzling (avoids swizzling conflicts)
# SDK Usage Scenarios:
# Main Project: FTMobileSDK (static/dynamic)
# Widget Extension: FTMobileExtension (static only) / FTMobileSDK-dynamic (dynamic, shared with main project)
# Output Path: Packaged SDK is saved to the "build" folder in the current directory
set -euo pipefail
# ======================== CORE ========================
SWIZZLING_MACRO="FT_DISABLE_SWIZZLING_RESOURCE"
CONFIGURATION="Release"
LIB_TYPE="static"
SCHEME_NAME=""
WORK_DIR="./build"
# ======================== [Utility Functions] ========================
# Output logs to stderr to avoid polluting path outputs
info() {
echo -e "\033[32m[INFO] $1\033[0m" >&2
}
error() {
echo -e "\033[31m[ERROR] $1\033[0m" >&2
exit 1
}
show_help() {
echo "Usage:"
echo " bash $0 <SCHEME_NAME> [--disable-swizzling-resource]"
echo ""
echo "Core Workflow (aligned with original script):"
echo " 1. Compile archive for physical iOS devices"
echo " 2. Compile archive for iOS simulators"
echo " 3. Combine two archives to generate XCFramework (dynamic libraries link dSYM files)"
echo ""
echo "Examples:"
echo " bash $0 FTMobileSDK-dynamic --disable-swizzling-resource # dynamic + disable swizzling"
echo " bash $0 FTMobileSDK # static"
}
# Check xcodebuild environment
check_env() {
if ! command -v xcodebuild &> /dev/null; then
error "β xcodebuild not found. Please install Xcode and configure command line tools"
fi
info "β
Environment check passed"
}
# Clean up old build artifacts (aligned with your script: empty build directory)
clean_build() {
local clean="$1"
info "π Cleaning up old build artifacts: ${clean}"
rm -rf "${clean}"
mkdir -p "${clean}"
}
# Parse Scheme (core: distinguish static/dynamic libraries, return framework name)
# Parameter: scheme name
# Return: framework name (stdout) + library type (static/dynamic, global variable LIB_TYPE)
parse_scheme() {
local scheme="$1"
local scheme_lower=$(echo "${scheme}" | tr '[:upper:]' '[:lower:]')
if [[ "${scheme_lower}" == *"-dynamic" ]]; then
LIB_TYPE="dynamic"
SCHEME_NAME="${scheme%-dynamic}"
else
LIB_TYPE="static"
SCHEME_NAME="${scheme}"
fi
}
# ======================== [Step 1: Compile Single Archive (aligned with your compilation logic)] ========================
# Parameter 1: Scheme name
# Parameter 2: Framework name
# Parameter 3: Compilation platform (iphoneos/iphonesimulator)
# Parameter 4: Whether to disable Swizzling (0/1)
# Parameter 5: Archive output path (e.g., ./build/ios.xcarchive)
build_archive() {
local scheme="$1"
local framework_name="$2"
local platform="$3"
local disable_swizzling="$4"
local archive_path="$5"
archive_path+="/${platform}.xcarchive"
info "π¦ Starting to compile ${platform} archive β ${archive_path} (${LIB_TYPE})"
# Distinguish static/dynamic library parameters (aligned with your script)
local mach_o_type="staticlib"
if [[ "${LIB_TYPE}" == "dynamic" ]]; then
mach_o_type="mh_dylib"
fi
# Preprocessor macros (Swizzling disable logic)
local preprocessor_defs="\$(inherited)"
if [[ "${disable_swizzling}" == "1" ]]; then
preprocessor_defs+=" ${SWIZZLING_MACRO}=1"
fi
# Execute compilation (fully aligned with your xcodebuild parameters)
xcodebuild archive \
-scheme "${scheme}" \
-configuration "${CONFIGURATION}" \
-archivePath "${archive_path}" \
-sdk "${platform}" \
SKIP_INSTALL=NO \
MACH_O_TYPE="${mach_o_type}" \
GCC_PREPROCESSOR_DEFINITIONS="${preprocessor_defs}" \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
# Verify if archive was generated successfully
if [[ ! -d "${archive_path}" ]]; then
error "β ${platform} archive compilation failed: ${archive_path} does not exist"
fi
info "β
${platform} archive compiled successfully"
}
# ======================== [Step 2: Combine XCFramework (fully replicate your logic)] ========================
# Parameter 1: Framework name
# Parameter 2: Whether to disable Swizzling (0/1)
# Parameter 3: Archive path
create_xcframework() {
local scheme="$1"
local framework_name="$2"
local ARCHIVE_PATH="$3"
local ios_framework="${ARCHIVE_PATH}/iphoneos.xcarchive/Products/Library/Frameworks/${scheme}.framework"
local sim_framework="${ARCHIVE_PATH}/iphonesimulator.xcarchive/Products/Library/Frameworks/${scheme}.framework"
local XCF_FRAMEWORK_PATH="${ARCHIVE_PATH}/${framework_name}.xcframework"
# 2. Verify framework path validity
if [[ ! -d "${ios_framework}" ]]; then
error "β Physical device Framework does not exist: ${ios_framework}"
fi
if [[ ! -d "${sim_framework}" ]]; then
error "β Simulator Framework does not exist: ${sim_framework}"
fi
# 4. Delete old XCFramework (avoid conflicts)
rm -rf "${XCF_FRAMEWORK_PATH}"
# 5. Generate XCFramework (fully replicate your branch logic)
if [[ "${LIB_TYPE}" == "dynamic" ]]; then
local ios_dsym="${ARCHIVE_PATH}/iphoneos.xcarchive/dSYMs/${scheme}.framework.dSYM"
local sim_dsym="${ARCHIVE_PATH}/iphonesimulator.xcarchive/dSYMs/${scheme}.framework.dSYM"
if [[ ! -d "${ios_dsym}" ]]; then
error "β Physical device dSYM does not exist: ${ios_dsym}"
fi
if [[ ! -d "${sim_dsym}" ]]; then
error "β Simulator dSYM does not exist: ${sim_dsym}"
fi
info "\nπ¦ Generating xcframework (with standard path dSYM)..."
# Dynamic library: use -debug-symbols parameter (your core logic)
xcodebuild -create-xcframework \
-framework "${ios_framework}" \
-debug-symbols "${ios_dsym}" \
-framework "${sim_framework}" \
-debug-symbols "${sim_dsym}" \
-output "${XCF_FRAMEWORK_PATH}"
info "β
Dynamic library XCFramework generated successfully: ${XCF_FRAMEWORK_PATH}"
else
# Static library: only combine frameworks, no dSYM files
info "\nπ¦ Generating static library xcframework..."
xcodebuild -create-xcframework \
-framework "${ios_framework}" \
-framework "${sim_framework}" \
-output "${XCF_FRAMEWORK_PATH}"
info "β
Static library xcframework generated successfully"
fi
if [[ ! -d "${XCF_FRAMEWORK_PATH}" ]]; then
error "β XCFramework generation failed: ${XCF_FRAMEWORK_PATH} does not exist"
fi
if [[ ! -f "${XCF_FRAMEWORK_PATH}/Info.plist" ]]; then
error "β Invalid XCFramework, Info.plist not found: ${XCF_FRAMEWORK_PATH}"
fi
rm -rf "${ARCHIVE_PATH}/iphoneos.xcarchive"
rm -rf "${ARCHIVE_PATH}/iphonesimulator.xcarchive"
}
# ======================== [Main Workflow (strict step-by-step: clean β parse β compile β combine)] ========================
main() {
# Initialize parameters
local scheme=""
local disable_swizzling="0"
# Parse command line parameters (compatible with legacy commands)
while [[ $# -gt 0 ]]; do
case "$1" in
--scheme)
if [[ $# -lt 2 ]]; then
error "β Missing value for --scheme"
fi
scheme="$2"
shift 2
;;
--disable-swizzling-resource)
disable_swizzling="1"
shift
;;
--help|-h)
show_help
exit 0
;;
*)
if [[ -z "${scheme}" ]]; then
scheme="$1"
shift
else
error "β Invalid parameter: $1 (Run $0 --help to view usage)"
fi
;;
esac
done
# Verify Scheme is mandatory
if [[ -z "${scheme}" ]]; then
error "β Missing Scheme name! Example: $0 FTMobileSDK-dynamic"
fi
# Step 1: Environment check + clean up old artifacts
check_env
# Step 2: Parse Scheme (get framework name + library type)
parse_scheme "${scheme}"
local framework_name="${SCHEME_NAME}"
if [[ "${LIB_TYPE}" == "dynamic" ]]; then
framework_name+="-Dynamic"
fi
if [[ "${disable_swizzling}" == "1" ]]; then
framework_name+="-DisableSwizzlingResource"
fi
# Step 3
local archive_path="$(cd "$(dirname "${WORK_DIR}/${framework_name}")" && pwd)/$(basename "${WORK_DIR}/${framework_name}")"
clean_build "${archive_path}"
info "π§ β SCHEME_NAME: ${SCHEME_NAME} | FRAMEWORK_NAME: ${framework_name} | LIB_TYPE: ${LIB_TYPE}"
# Step 4: archive
build_archive "${SCHEME_NAME}" "${framework_name}" "iphoneos" "${disable_swizzling}" "${archive_path}"
build_archive "${SCHEME_NAME}" "${framework_name}" "iphonesimulator" "${disable_swizzling}" "${archive_path}"
# Step 5: Combine archives to generate XCFramework (core: combine after compilation completes)
create_xcframework "${SCHEME_NAME}" "${framework_name}" "${archive_path}"
# Final artifact prompt
info "π Full workflow completed! Final artifact:"
info " β XCFramework: ${archive_path}/${framework_name}.xcframework"
}
# Execute main workflow
main "$@"