You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

256 lines
14 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
5 years ago
5 years ago
6 years ago
5 years ago
5 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
5 years ago
5 years ago
6 years ago
5 years ago
5 years ago
5 years ago
6 years ago
5 years ago
6 years ago
6 years ago
5 years ago
6 years ago
6 years ago
  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="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
  18. # Used as a return value for each invocation of `strip_invalid_archs` function.
  19. STRIP_BINARY_RETVAL=0
  20. # This protects against multiple targets copying the same framework dependency at the same time. The solution
  21. # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html
  22. RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????")
  23. # Copies and strips a vendored framework
  24. install_framework()
  25. {
  26. if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then
  27. local source="${BUILT_PRODUCTS_DIR}/$1"
  28. elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then
  29. local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"
  30. elif [ -r "$1" ]; then
  31. local source="$1"
  32. fi
  33. local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
  34. if [ -L "${source}" ]; then
  35. echo "Symlinked..."
  36. source="$(readlink "${source}")"
  37. fi
  38. # Use filter instead of exclude so missing patterns don't throw errors.
  39. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\""
  40. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}"
  41. local basename
  42. basename="$(basename -s .framework "$1")"
  43. binary="${destination}/${basename}.framework/${basename}"
  44. if ! [ -r "$binary" ]; then
  45. binary="${destination}/${basename}"
  46. elif [ -L "${binary}" ]; then
  47. echo "Destination binary is symlinked..."
  48. dirname="$(dirname "${binary}")"
  49. binary="${dirname}/$(readlink "${binary}")"
  50. fi
  51. # Strip invalid architectures so "fat" simulator / device frameworks work on device
  52. if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then
  53. strip_invalid_archs "$binary"
  54. fi
  55. # Resign the code if required by the build settings to avoid unstable apps
  56. code_sign_if_enabled "${destination}/$(basename "$1")"
  57. # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7.
  58. if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then
  59. local swift_runtime_libs
  60. swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u)
  61. for lib in $swift_runtime_libs; do
  62. echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
  63. rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
  64. code_sign_if_enabled "${destination}/${lib}"
  65. done
  66. fi
  67. }
  68. # Copies and strips a vendored dSYM
  69. install_dsym() {
  70. local source="$1"
  71. if [ -r "$source" ]; then
  72. # Copy the dSYM into a the targets temp dir.
  73. 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}\""
  74. 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}"
  75. local basename
  76. basename="$(basename -s .framework.dSYM "$source")"
  77. binary="${DERIVED_FILES_DIR}/${basename}.framework.dSYM/Contents/Resources/DWARF/${basename}"
  78. # Strip invalid architectures so "fat" simulator / device frameworks work on device
  79. if [[ "$(file "$binary")" == *"Mach-O "*"dSYM companion"* ]]; then
  80. strip_invalid_archs "$binary"
  81. fi
  82. if [[ $STRIP_BINARY_RETVAL == 1 ]]; then
  83. # Move the stripped file into its final destination.
  84. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${DERIVED_FILES_DIR}/${basename}.framework.dSYM\" \"${DWARF_DSYM_FOLDER_PATH}\""
  85. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.framework.dSYM" "${DWARF_DSYM_FOLDER_PATH}"
  86. else
  87. # 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.
  88. touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.framework.dSYM"
  89. fi
  90. fi
  91. }
  92. # Copies the bcsymbolmap files of a vendored framework
  93. install_bcsymbolmap() {
  94. local bcsymbolmap_path="$1"
  95. local destination="${BUILT_PRODUCTS_DIR}"
  96. 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}""
  97. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}"
  98. }
  99. # Signs a framework with the provided identity
  100. code_sign_if_enabled() {
  101. if [ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" -a "${CODE_SIGNING_REQUIRED:-}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then
  102. # Use the current code_sign_identity
  103. echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
  104. local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS:-} --preserve-metadata=identifier,entitlements '$1'"
  105. if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then
  106. code_sign_cmd="$code_sign_cmd &"
  107. fi
  108. echo "$code_sign_cmd"
  109. eval "$code_sign_cmd"
  110. fi
  111. }
  112. # Strip invalid architectures
  113. strip_invalid_archs() {
  114. binary="$1"
  115. # Get architectures for current target binary
  116. binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)"
  117. # Intersect them with the architectures we are building for
  118. intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)"
  119. # If there are no archs supported by this binary then warn the user
  120. if [[ -z "$intersected_archs" ]]; then
  121. echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)."
  122. STRIP_BINARY_RETVAL=0
  123. return
  124. fi
  125. stripped=""
  126. for arch in $binary_archs; do
  127. if ! [[ "${ARCHS}" == *"$arch"* ]]; then
  128. # Strip non-valid architectures in-place
  129. lipo -remove "$arch" -output "$binary" "$binary"
  130. stripped="$stripped $arch"
  131. fi
  132. done
  133. if [[ "$stripped" ]]; then
  134. echo "Stripped $binary of architectures:$stripped"
  135. fi
  136. STRIP_BINARY_RETVAL=1
  137. }
  138. if [[ "$CONFIGURATION" == "Debug" ]]; then
  139. install_framework "${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework"
  140. install_framework "${BUILT_PRODUCTS_DIR}/AlamofireNetworkActivityLogger/AlamofireNetworkActivityLogger.framework"
  141. install_framework "${BUILT_PRODUCTS_DIR}/BRYXBanner/BRYXBanner.framework"
  142. install_framework "${BUILT_PRODUCTS_DIR}/CHDwifft/CHDwifft.framework"
  143. install_framework "${BUILT_PRODUCTS_DIR}/CHSlackTextViewController/CHSlackTextViewController.framework"
  144. install_framework "${BUILT_PRODUCTS_DIR}/CRToast/CRToast.framework"
  145. install_framework "${BUILT_PRODUCTS_DIR}/ChannelIO/ChannelIO.framework"
  146. install_framework "${BUILT_PRODUCTS_DIR}/DTTJailbreakDetection/DTTJailbreakDetection.framework"
  147. install_framework "${BUILT_PRODUCTS_DIR}/FLEX/FLEX.framework"
  148. install_framework "${BUILT_PRODUCTS_DIR}/GTMSessionFetcher/GTMSessionFetcher.framework"
  149. install_framework "${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework"
  150. install_framework "${BUILT_PRODUCTS_DIR}/Hero/Hero.framework"
  151. install_framework "${BUILT_PRODUCTS_DIR}/Hex/Hex.framework"
  152. install_framework "${BUILT_PRODUCTS_DIR}/IQKeyboardManagerSwift/IQKeyboardManagerSwift.framework"
  153. install_framework "${BUILT_PRODUCTS_DIR}/KeychainAccess/KeychainAccess.framework"
  154. install_framework "${BUILT_PRODUCTS_DIR}/Kingfisher/Kingfisher.framework"
  155. install_framework "${BUILT_PRODUCTS_DIR}/LGSideMenuController/LGSideMenuController.framework"
  156. install_framework "${BUILT_PRODUCTS_DIR}/Localize-Swift/Localize_Swift.framework"
  157. install_framework "${BUILT_PRODUCTS_DIR}/MBProgressHUD/MBProgressHUD.framework"
  158. install_framework "${BUILT_PRODUCTS_DIR}/MGSwipeTableCell/MGSwipeTableCell.framework"
  159. install_framework "${BUILT_PRODUCTS_DIR}/NVActivityIndicatorView/NVActivityIndicatorView.framework"
  160. install_framework "${BUILT_PRODUCTS_DIR}/ObjectMapper/ObjectMapper.framework"
  161. install_framework "${BUILT_PRODUCTS_DIR}/PMAlertController/PMAlertController.framework"
  162. install_framework "${BUILT_PRODUCTS_DIR}/PanModal/PanModal.framework"
  163. install_framework "${BUILT_PRODUCTS_DIR}/PhoneNumberKit/PhoneNumberKit.framework"
  164. install_framework "${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework"
  165. install_framework "${BUILT_PRODUCTS_DIR}/RSKImageCropper/RSKImageCropper.framework"
  166. install_framework "${BUILT_PRODUCTS_DIR}/ReSwift/ReSwift.framework"
  167. install_framework "${BUILT_PRODUCTS_DIR}/Reusable/Reusable.framework"
  168. install_framework "${BUILT_PRODUCTS_DIR}/RxCocoa/RxCocoa.framework"
  169. install_framework "${BUILT_PRODUCTS_DIR}/RxRelay/RxRelay.framework"
  170. install_framework "${BUILT_PRODUCTS_DIR}/RxSwift/RxSwift.framework"
  171. install_framework "${BUILT_PRODUCTS_DIR}/RxSwiftExt/RxSwiftExt.framework"
  172. install_framework "${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework"
  173. install_framework "${BUILT_PRODUCTS_DIR}/SVProgressHUD/SVProgressHUD.framework"
  174. install_framework "${BUILT_PRODUCTS_DIR}/SnapKit/SnapKit.framework"
  175. install_framework "${BUILT_PRODUCTS_DIR}/Socket.IO-Client-Swift/SocketIO.framework"
  176. install_framework "${BUILT_PRODUCTS_DIR}/Starscream/Starscream.framework"
  177. install_framework "${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework"
  178. install_framework "${BUILT_PRODUCTS_DIR}/SwiftyTimer/SwiftyTimer.framework"
  179. install_framework "${BUILT_PRODUCTS_DIR}/TLPhotoPicker/TLPhotoPicker.framework"
  180. install_framework "${BUILT_PRODUCTS_DIR}/VisualEffectView/VisualEffectView.framework"
  181. install_framework "${BUILT_PRODUCTS_DIR}/XLPagerTabStrip/XLPagerTabStrip.framework"
  182. install_framework "${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework"
  183. fi
  184. if [[ "$CONFIGURATION" == "Release" ]]; then
  185. install_framework "${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework"
  186. install_framework "${BUILT_PRODUCTS_DIR}/AlamofireNetworkActivityLogger/AlamofireNetworkActivityLogger.framework"
  187. install_framework "${BUILT_PRODUCTS_DIR}/BRYXBanner/BRYXBanner.framework"
  188. install_framework "${BUILT_PRODUCTS_DIR}/CHDwifft/CHDwifft.framework"
  189. install_framework "${BUILT_PRODUCTS_DIR}/CHSlackTextViewController/CHSlackTextViewController.framework"
  190. install_framework "${BUILT_PRODUCTS_DIR}/CRToast/CRToast.framework"
  191. install_framework "${BUILT_PRODUCTS_DIR}/ChannelIO/ChannelIO.framework"
  192. install_framework "${BUILT_PRODUCTS_DIR}/DTTJailbreakDetection/DTTJailbreakDetection.framework"
  193. install_framework "${BUILT_PRODUCTS_DIR}/GTMSessionFetcher/GTMSessionFetcher.framework"
  194. install_framework "${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework"
  195. install_framework "${BUILT_PRODUCTS_DIR}/Hero/Hero.framework"
  196. install_framework "${BUILT_PRODUCTS_DIR}/Hex/Hex.framework"
  197. install_framework "${BUILT_PRODUCTS_DIR}/IQKeyboardManagerSwift/IQKeyboardManagerSwift.framework"
  198. install_framework "${BUILT_PRODUCTS_DIR}/KeychainAccess/KeychainAccess.framework"
  199. install_framework "${BUILT_PRODUCTS_DIR}/Kingfisher/Kingfisher.framework"
  200. install_framework "${BUILT_PRODUCTS_DIR}/LGSideMenuController/LGSideMenuController.framework"
  201. install_framework "${BUILT_PRODUCTS_DIR}/Localize-Swift/Localize_Swift.framework"
  202. install_framework "${BUILT_PRODUCTS_DIR}/MBProgressHUD/MBProgressHUD.framework"
  203. install_framework "${BUILT_PRODUCTS_DIR}/MGSwipeTableCell/MGSwipeTableCell.framework"
  204. install_framework "${BUILT_PRODUCTS_DIR}/NVActivityIndicatorView/NVActivityIndicatorView.framework"
  205. install_framework "${BUILT_PRODUCTS_DIR}/ObjectMapper/ObjectMapper.framework"
  206. install_framework "${BUILT_PRODUCTS_DIR}/PMAlertController/PMAlertController.framework"
  207. install_framework "${BUILT_PRODUCTS_DIR}/PanModal/PanModal.framework"
  208. install_framework "${BUILT_PRODUCTS_DIR}/PhoneNumberKit/PhoneNumberKit.framework"
  209. install_framework "${BUILT_PRODUCTS_DIR}/Protobuf/Protobuf.framework"
  210. install_framework "${BUILT_PRODUCTS_DIR}/RSKImageCropper/RSKImageCropper.framework"
  211. install_framework "${BUILT_PRODUCTS_DIR}/ReSwift/ReSwift.framework"
  212. install_framework "${BUILT_PRODUCTS_DIR}/Reusable/Reusable.framework"
  213. install_framework "${BUILT_PRODUCTS_DIR}/RxCocoa/RxCocoa.framework"
  214. install_framework "${BUILT_PRODUCTS_DIR}/RxRelay/RxRelay.framework"
  215. install_framework "${BUILT_PRODUCTS_DIR}/RxSwift/RxSwift.framework"
  216. install_framework "${BUILT_PRODUCTS_DIR}/RxSwiftExt/RxSwiftExt.framework"
  217. install_framework "${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework"
  218. install_framework "${BUILT_PRODUCTS_DIR}/SVProgressHUD/SVProgressHUD.framework"
  219. install_framework "${BUILT_PRODUCTS_DIR}/SnapKit/SnapKit.framework"
  220. install_framework "${BUILT_PRODUCTS_DIR}/Socket.IO-Client-Swift/SocketIO.framework"
  221. install_framework "${BUILT_PRODUCTS_DIR}/Starscream/Starscream.framework"
  222. install_framework "${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework"
  223. install_framework "${BUILT_PRODUCTS_DIR}/SwiftyTimer/SwiftyTimer.framework"
  224. install_framework "${BUILT_PRODUCTS_DIR}/TLPhotoPicker/TLPhotoPicker.framework"
  225. install_framework "${BUILT_PRODUCTS_DIR}/VisualEffectView/VisualEffectView.framework"
  226. install_framework "${BUILT_PRODUCTS_DIR}/XLPagerTabStrip/XLPagerTabStrip.framework"
  227. install_framework "${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework"
  228. fi
  229. if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then
  230. wait
  231. fi