|
1
|
#!/bin/sh |
|
2
|
set -e |
|
3
|
|
|
4
|
echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" |
|
5
|
mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" |
|
6
|
|
|
7
|
SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" |
|
8
|
|
|
9
|
install_framework() |
|
10
|
{ |
|
11
|
if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then |
|
12
|
local source="${BUILT_PRODUCTS_DIR}/$1" |
|
13
|
elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then |
|
14
|
local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" |
|
15
|
elif [ -r "$1" ]; then |
|
16
|
local source="$1" |
|
17
|
fi |
|
18
|
|
|
19
|
local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" |
|
20
|
|
|
21
|
if [ -L "${source}" ]; then |
|
22
|
echo "Symlinked..." |
|
23
|
source="$(readlink "${source}")" |
|
24
|
fi |
|
25
|
|
|
26
|
# use filter instead of exclude so missing patterns dont' throw errors |
|
27
|
echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" |
|
28
|
rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" |
|
29
|
|
|
30
|
local basename |
|
31
|
basename="$(basename -s .framework "$1")" |
|
32
|
binary="${destination}/${basename}.framework/${basename}" |
|
33
|
if ! [ -r "$binary" ]; then |
|
34
|
binary="${destination}/${basename}" |
|
35
|
fi |
|
36
|
|
|
37
|
# Strip invalid architectures so "fat" simulator / device frameworks work on device |
|
38
|
if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then |
|
39
|
strip_invalid_archs "$binary" |
|
40
|
fi |
|
41
|
|
|
42
|
# Resign the code if required by the build settings to avoid unstable apps |
|
43
|
code_sign_if_enabled "${destination}/$(basename "$1")" |
|
44
|
|
|
45
|
# Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. |
|
46
|
if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then |
|
47
|
local swift_runtime_libs |
|
48
|
swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) |
|
49
|
for lib in $swift_runtime_libs; do |
|
50
|
echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" |
|
51
|
rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" |
|
52
|
code_sign_if_enabled "${destination}/${lib}" |
|
53
|
done |
|
54
|
fi |
|
55
|
} |
|
56
|
|
|
57
|
# Signs a framework with the provided identity |
|
58
|
code_sign_if_enabled() { |
|
59
|
if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then |
|
60
|
# Use the current code_sign_identitiy |
|
61
|
echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" |
|
62
|
echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements \"$1\"" |
|
63
|
/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements "$1" |
|
64
|
fi |
|
65
|
} |
|
66
|
|
|
67
|
# Strip invalid architectures |
|
68
|
strip_invalid_archs() { |
|
69
|
binary="$1" |
|
70
|
# Get architectures for current file |
|
71
|
archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)" |
|
72
|
stripped="" |
|
73
|
for arch in $archs; do |
|
74
|
if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then |
|
75
|
# Strip non-valid architectures in-place |
|
76
|
lipo -remove "$arch" -output "$binary" "$binary" || exit 1 |
|
77
|
stripped="$stripped $arch" |
|
78
|
fi |
|
79
|
done |
|
80
|
if [[ "$stripped" ]]; then |
|
81
|
echo "Stripped $binary of architectures:$stripped" |
|
82
|
fi |
|
83
|
} |
|
84
|
|