-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathembed-rock-runtime-frameworks.sh
More file actions
executable file
·77 lines (66 loc) · 2.5 KB
/
Copy pathembed-rock-runtime-frameworks.sh
File metadata and controls
executable file
·77 lines (66 loc) · 2.5 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
#!/usr/bin/env bash
#
# Run Script Build Phase invoked by the "Brownfield Apple App" target after
# the standard "Embed Frameworks" phase.
#
# When the host RN project is RockApp, the dynamic BrownfieldLib.dylib
# produced by `rock package:ios` has @rpath load commands for
# React.framework and ReactNativeDependencies.framework. They must be
# embedded in the .app bundle or the app crashes on launch with
# "Library not loaded: @rpath/React.framework/React".
#
# `prepareXCFrameworks.js --appName RockApp` drops these xcframeworks into
# `package/`. For Vanilla / Expo flavors they are absent (React core is
# statically linked into BrownfieldLib), so this script is a no-op then.
set -euo pipefail
PACKAGE_DIR="${SRCROOT}/package"
DEST_DIR="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
EXTRA_XCFRAMEWORKS=(
"React.xcframework"
"ReactNativeDependencies.xcframework"
)
if [[ "${PLATFORM_NAME}" == iphonesimulator* || "${PLATFORM_NAME}" == macosx* ]]; then
PRIMARY_SLICE="ios-arm64_x86_64-simulator"
FALLBACK_SLICES=("ios-arm64-simulator")
else
PRIMARY_SLICE="ios-arm64"
FALLBACK_SLICES=("ios-arm64_x86_64-maccatalyst")
fi
resolve_slice_dir() {
local xcframework_path="$1"
for candidate in "${PRIMARY_SLICE}" "${FALLBACK_SLICES[@]}"; do
if [[ -d "${xcframework_path}/${candidate}" ]]; then
echo "${xcframework_path}/${candidate}"
return 0
fi
done
return 1
}
mkdir -p "${DEST_DIR}"
for xcframework in "${EXTRA_XCFRAMEWORKS[@]}"; do
XC_PATH="${PACKAGE_DIR}/${xcframework}"
if [[ ! -d "${XC_PATH}" ]]; then
echo "note: ${xcframework} not present in ${PACKAGE_DIR}, skipping (expected for Vanilla/Expo flavors)"
continue
fi
framework_name="$(basename "${xcframework}" .xcframework)"
if ! slice_dir="$(resolve_slice_dir "${XC_PATH}")"; then
echo "warning: no compatible slice for platform ${PLATFORM_NAME} in ${xcframework}; skipping"
continue
fi
src_framework="${slice_dir}/${framework_name}.framework"
if [[ ! -d "${src_framework}" ]]; then
echo "warning: ${src_framework} is missing; skipping"
continue
fi
dest_framework="${DEST_DIR}/${framework_name}.framework"
echo "Embedding ${framework_name}.framework from ${slice_dir}"
rm -rf "${dest_framework}"
cp -R "${src_framework}" "${dest_framework}"
if [[ "${EXPANDED_CODE_SIGN_IDENTITY:-}" != "" ]]; then
/usr/bin/codesign --force --sign "${EXPANDED_CODE_SIGN_IDENTITY}" \
${OTHER_CODE_SIGN_FLAGS:-} \
--preserve-metadata=identifier,entitlements,flags \
"${dest_framework}"
fi
done