Pods-KulexiuForStudent-frameworks.sh 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #!/bin/sh
  2. set -e
  3. set -u
  4. set -o pipefail
  5. function on_error {
  6. echo "$(realpath -mq "${0}"):$1: error: Unexpected failure"
  7. }
  8. trap 'on_error $LINENO' ERR
  9. if [ -z ${FRAMEWORKS_FOLDER_PATH+x} ]; then
  10. # If FRAMEWORKS_FOLDER_PATH is not set, then there's nowhere for us to copy
  11. # frameworks to, so exit 0 (signalling the script phase was successful).
  12. exit 0
  13. fi
  14. echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
  15. mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
  16. COCOAPODS_PARALLEL_CODE_SIGN="${COCOAPODS_PARALLEL_CODE_SIGN:-false}"
  17. SWIFT_STDLIB_PATH="${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
  18. BCSYMBOLMAP_DIR="BCSymbolMaps"
  19. # This protects against multiple targets copying the same framework dependency at the same time. The solution
  20. # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html
  21. RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????")
  22. # Copies and strips a vendored framework
  23. install_framework()
  24. {
  25. if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then
  26. local source="${BUILT_PRODUCTS_DIR}/$1"
  27. elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then
  28. local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"
  29. elif [ -r "$1" ]; then
  30. local source="$1"
  31. fi
  32. local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
  33. if [ -L "${source}" ]; then
  34. echo "Symlinked..."
  35. source="$(readlink -f "${source}")"
  36. fi
  37. if [ -d "${source}/${BCSYMBOLMAP_DIR}" ]; then
  38. # Locate and install any .bcsymbolmaps if present, and remove them from the .framework before the framework is copied
  39. find "${source}/${BCSYMBOLMAP_DIR}" -name "*.bcsymbolmap"|while read f; do
  40. echo "Installing $f"
  41. install_bcsymbolmap "$f" "$destination"
  42. rm "$f"
  43. done
  44. rmdir "${source}/${BCSYMBOLMAP_DIR}"
  45. fi
  46. # Use filter instead of exclude so missing patterns don't throw errors.
  47. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\""
  48. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}"
  49. local basename
  50. basename="$(basename -s .framework "$1")"
  51. binary="${destination}/${basename}.framework/${basename}"
  52. if ! [ -r "$binary" ]; then
  53. binary="${destination}/${basename}"
  54. elif [ -L "${binary}" ]; then
  55. echo "Destination binary is symlinked..."
  56. dirname="$(dirname "${binary}")"
  57. binary="${dirname}/$(readlink "${binary}")"
  58. fi
  59. # Strip invalid architectures so "fat" simulator / device frameworks work on device
  60. if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then
  61. strip_invalid_archs "$binary"
  62. fi
  63. # Resign the code if required by the build settings to avoid unstable apps
  64. code_sign_if_enabled "${destination}/$(basename "$1")"
  65. # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7.
  66. if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then
  67. local swift_runtime_libs
  68. swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u)
  69. for lib in $swift_runtime_libs; do
  70. echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
  71. rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
  72. code_sign_if_enabled "${destination}/${lib}"
  73. done
  74. fi
  75. }
  76. # Copies and strips a vendored dSYM
  77. install_dsym() {
  78. local source="$1"
  79. warn_missing_arch=${2:-true}
  80. if [ -r "$source" ]; then
  81. # Copy the dSYM into the targets temp dir.
  82. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${DERIVED_FILES_DIR}\""
  83. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${DERIVED_FILES_DIR}"
  84. local basename
  85. basename="$(basename -s .dSYM "$source")"
  86. binary_name="$(ls "$source/Contents/Resources/DWARF")"
  87. binary="${DERIVED_FILES_DIR}/${basename}.dSYM/Contents/Resources/DWARF/${binary_name}"
  88. # Strip invalid architectures from the dSYM.
  89. if [[ "$(file "$binary")" == *"Mach-O "*"dSYM companion"* ]]; then
  90. strip_invalid_archs "$binary" "$warn_missing_arch"
  91. fi
  92. if [[ $STRIP_BINARY_RETVAL == 0 ]]; then
  93. # Move the stripped file into its final destination.
  94. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${DERIVED_FILES_DIR}/${basename}.framework.dSYM\" \"${DWARF_DSYM_FOLDER_PATH}\""
  95. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.dSYM" "${DWARF_DSYM_FOLDER_PATH}"
  96. else
  97. # The dSYM was not stripped at all, in this case touch a fake folder so the input/output paths from Xcode do not reexecute this script because the file is missing.
  98. mkdir -p "${DWARF_DSYM_FOLDER_PATH}"
  99. touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.dSYM"
  100. fi
  101. fi
  102. }
  103. # Used as a return value for each invocation of `strip_invalid_archs` function.
  104. STRIP_BINARY_RETVAL=0
  105. # Strip invalid architectures
  106. strip_invalid_archs() {
  107. binary="$1"
  108. warn_missing_arch=${2:-true}
  109. # Get architectures for current target binary
  110. binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)"
  111. # Intersect them with the architectures we are building for
  112. intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)"
  113. # If there are no archs supported by this binary then warn the user
  114. if [[ -z "$intersected_archs" ]]; then
  115. if [[ "$warn_missing_arch" == "true" ]]; then
  116. echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)."
  117. fi
  118. STRIP_BINARY_RETVAL=1
  119. return
  120. fi
  121. stripped=""
  122. for arch in $binary_archs; do
  123. if ! [[ "${ARCHS}" == *"$arch"* ]]; then
  124. # Strip non-valid architectures in-place
  125. lipo -remove "$arch" -output "$binary" "$binary"
  126. stripped="$stripped $arch"
  127. fi
  128. done
  129. if [[ "$stripped" ]]; then
  130. echo "Stripped $binary of architectures:$stripped"
  131. fi
  132. STRIP_BINARY_RETVAL=0
  133. }
  134. # Copies the bcsymbolmap files of a vendored framework
  135. install_bcsymbolmap() {
  136. local bcsymbolmap_path="$1"
  137. local destination="${BUILT_PRODUCTS_DIR}"
  138. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}""
  139. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}"
  140. }
  141. # Signs a framework with the provided identity
  142. code_sign_if_enabled() {
  143. if [ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" -a "${CODE_SIGNING_REQUIRED:-}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then
  144. # Use the current code_sign_identity
  145. echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
  146. local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS:-} --preserve-metadata=identifier,entitlements '$1'"
  147. if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then
  148. code_sign_cmd="$code_sign_cmd &"
  149. fi
  150. echo "$code_sign_cmd"
  151. eval "$code_sign_cmd"
  152. fi
  153. }
  154. if [[ "$CONFIGURATION" == "DEV" ]]; then
  155. install_framework "${PODS_ROOT}/TXIMSDK_Plus_iOS/ImSDK_Plus.framework"
  156. install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/TXLiteAVSDK_Professional/Professional/TXSoundTouch.framework"
  157. install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/TXLiteAVSDK_Professional/Professional/TXFFmpeg.framework"
  158. fi
  159. if [[ "$CONFIGURATION" == "Debug" ]]; then
  160. install_framework "${PODS_ROOT}/TXIMSDK_Plus_iOS/ImSDK_Plus.framework"
  161. install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/TXLiteAVSDK_Professional/Professional/TXSoundTouch.framework"
  162. install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/TXLiteAVSDK_Professional/Professional/TXFFmpeg.framework"
  163. fi
  164. if [[ "$CONFIGURATION" == "Release" ]]; then
  165. install_framework "${PODS_ROOT}/TXIMSDK_Plus_iOS/ImSDK_Plus.framework"
  166. install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/TXLiteAVSDK_Professional/Professional/TXSoundTouch.framework"
  167. install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/TXLiteAVSDK_Professional/Professional/TXFFmpeg.framework"
  168. fi
  169. if [[ "$CONFIGURATION" == "TEST" ]]; then
  170. install_framework "${PODS_ROOT}/TXIMSDK_Plus_iOS/ImSDK_Plus.framework"
  171. install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/TXLiteAVSDK_Professional/Professional/TXSoundTouch.framework"
  172. install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/TXLiteAVSDK_Professional/Professional/TXFFmpeg.framework"
  173. fi
  174. if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then
  175. wait
  176. fi