RongCloudIM-xcframeworks.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. # This protects against multiple targets copying the same framework dependency at the same time. The solution
  10. # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html
  11. RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????")
  12. variant_for_slice()
  13. {
  14. case "$1" in
  15. "RongChatRoom.xcframework/ios-arm64_armv7")
  16. echo ""
  17. ;;
  18. "RongChatRoom.xcframework/ios-i386_x86_64-simulator")
  19. echo "simulator"
  20. ;;
  21. "RongCustomerService.xcframework/ios-arm64_armv7")
  22. echo ""
  23. ;;
  24. "RongCustomerService.xcframework/ios-i386_x86_64-simulator")
  25. echo "simulator"
  26. ;;
  27. "RongDiscussion.xcframework/ios-arm64_armv7")
  28. echo ""
  29. ;;
  30. "RongDiscussion.xcframework/ios-i386_x86_64-simulator")
  31. echo "simulator"
  32. ;;
  33. "RongIMKit.xcframework/ios-arm64_armv7")
  34. echo ""
  35. ;;
  36. "RongIMKit.xcframework/ios-i386_x86_64-simulator")
  37. echo "simulator"
  38. ;;
  39. "RongIMLib.xcframework/ios-arm64_armv7")
  40. echo ""
  41. ;;
  42. "RongIMLib.xcframework/ios-i386_x86_64-simulator")
  43. echo "simulator"
  44. ;;
  45. "RongIMLibCore.xcframework/ios-arm64_armv7")
  46. echo ""
  47. ;;
  48. "RongIMLibCore.xcframework/ios-i386_x86_64-simulator")
  49. echo "simulator"
  50. ;;
  51. "RongLocation.xcframework/ios-arm64_armv7")
  52. echo ""
  53. ;;
  54. "RongLocation.xcframework/ios-i386_x86_64-simulator")
  55. echo "simulator"
  56. ;;
  57. "RongPublicService.xcframework/ios-arm64_armv7")
  58. echo ""
  59. ;;
  60. "RongPublicService.xcframework/ios-i386_x86_64-simulator")
  61. echo "simulator"
  62. ;;
  63. "RongSight.xcframework/ios-arm64_armv7")
  64. echo ""
  65. ;;
  66. "RongSight.xcframework/ios-i386_x86_64-simulator")
  67. echo "simulator"
  68. ;;
  69. esac
  70. }
  71. archs_for_slice()
  72. {
  73. case "$1" in
  74. "RongChatRoom.xcframework/ios-arm64_armv7")
  75. echo "arm64 armv7"
  76. ;;
  77. "RongChatRoom.xcframework/ios-i386_x86_64-simulator")
  78. echo "i386 x86_64"
  79. ;;
  80. "RongCustomerService.xcframework/ios-arm64_armv7")
  81. echo "arm64 armv7"
  82. ;;
  83. "RongCustomerService.xcframework/ios-i386_x86_64-simulator")
  84. echo "i386 x86_64"
  85. ;;
  86. "RongDiscussion.xcframework/ios-arm64_armv7")
  87. echo "arm64 armv7"
  88. ;;
  89. "RongDiscussion.xcframework/ios-i386_x86_64-simulator")
  90. echo "i386 x86_64"
  91. ;;
  92. "RongIMKit.xcframework/ios-arm64_armv7")
  93. echo "arm64 armv7"
  94. ;;
  95. "RongIMKit.xcframework/ios-i386_x86_64-simulator")
  96. echo "i386 x86_64"
  97. ;;
  98. "RongIMLib.xcframework/ios-arm64_armv7")
  99. echo "arm64 armv7"
  100. ;;
  101. "RongIMLib.xcframework/ios-i386_x86_64-simulator")
  102. echo "i386 x86_64"
  103. ;;
  104. "RongIMLibCore.xcframework/ios-arm64_armv7")
  105. echo "arm64 armv7"
  106. ;;
  107. "RongIMLibCore.xcframework/ios-i386_x86_64-simulator")
  108. echo "i386 x86_64"
  109. ;;
  110. "RongLocation.xcframework/ios-arm64_armv7")
  111. echo "arm64 armv7"
  112. ;;
  113. "RongLocation.xcframework/ios-i386_x86_64-simulator")
  114. echo "i386 x86_64"
  115. ;;
  116. "RongPublicService.xcframework/ios-arm64_armv7")
  117. echo "arm64 armv7"
  118. ;;
  119. "RongPublicService.xcframework/ios-i386_x86_64-simulator")
  120. echo "i386 x86_64"
  121. ;;
  122. "RongSight.xcframework/ios-arm64_armv7")
  123. echo "arm64 armv7"
  124. ;;
  125. "RongSight.xcframework/ios-i386_x86_64-simulator")
  126. echo "i386 x86_64"
  127. ;;
  128. esac
  129. }
  130. copy_dir()
  131. {
  132. local source="$1"
  133. local destination="$2"
  134. # Use filter instead of exclude so missing patterns don't throw errors.
  135. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" \"${source}*\" \"${destination}\""
  136. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" "${source}"/* "${destination}"
  137. }
  138. SELECT_SLICE_RETVAL=""
  139. select_slice() {
  140. local xcframework_name="$1"
  141. xcframework_name="${xcframework_name##*/}"
  142. local paths=("${@:2}")
  143. # Locate the correct slice of the .xcframework for the current architectures
  144. local target_path=""
  145. # Split archs on space so we can find a slice that has all the needed archs
  146. local target_archs=$(echo $ARCHS | tr " " "\n")
  147. local target_variant=""
  148. if [[ "$PLATFORM_NAME" == *"simulator" ]]; then
  149. target_variant="simulator"
  150. fi
  151. if [[ ! -z ${EFFECTIVE_PLATFORM_NAME+x} && "$EFFECTIVE_PLATFORM_NAME" == *"maccatalyst" ]]; then
  152. target_variant="maccatalyst"
  153. fi
  154. for i in ${!paths[@]}; do
  155. local matched_all_archs="1"
  156. local slice_archs="$(archs_for_slice "${xcframework_name}/${paths[$i]}")"
  157. local slice_variant="$(variant_for_slice "${xcframework_name}/${paths[$i]}")"
  158. for target_arch in $target_archs; do
  159. if ! [[ "${slice_variant}" == "$target_variant" ]]; then
  160. matched_all_archs="0"
  161. break
  162. fi
  163. if ! echo "${slice_archs}" | tr " " "\n" | grep -F -q -x "$target_arch"; then
  164. matched_all_archs="0"
  165. break
  166. fi
  167. done
  168. if [[ "$matched_all_archs" == "1" ]]; then
  169. # Found a matching slice
  170. echo "Selected xcframework slice ${paths[$i]}"
  171. SELECT_SLICE_RETVAL=${paths[$i]}
  172. break
  173. fi
  174. done
  175. }
  176. install_xcframework() {
  177. local basepath="$1"
  178. local name="$2"
  179. local package_type="$3"
  180. local paths=("${@:4}")
  181. # Locate the correct slice of the .xcframework for the current architectures
  182. select_slice "${basepath}" "${paths[@]}"
  183. local target_path="$SELECT_SLICE_RETVAL"
  184. if [[ -z "$target_path" ]]; then
  185. echo "warning: [CP] $(basename ${basepath}): Unable to find matching slice in '${paths[@]}' for the current build architectures ($ARCHS) and platform (${EFFECTIVE_PLATFORM_NAME-${PLATFORM_NAME}})."
  186. return
  187. fi
  188. local source="$basepath/$target_path"
  189. local destination="${PODS_XCFRAMEWORKS_BUILD_DIR}/${name}"
  190. if [ ! -d "$destination" ]; then
  191. mkdir -p "$destination"
  192. fi
  193. copy_dir "$source/" "$destination"
  194. echo "Copied $source to $destination"
  195. }
  196. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongChatRoom.xcframework" "RongCloudIM/ChatRoom" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  197. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongCustomerService.xcframework" "RongCloudIM/CustomerService" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  198. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongDiscussion.xcframework" "RongCloudIM/Discussion" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  199. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongIMKit.xcframework" "RongCloudIM/IMKit" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  200. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongIMLib.xcframework" "RongCloudIM/IMLib" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  201. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongIMLibCore.xcframework" "RongCloudIM/IMLibCore" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  202. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongLocation.xcframework" "RongCloudIM/Location" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  203. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongPublicService.xcframework" "RongCloudIM/PublicService" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  204. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongSight.xcframework" "RongCloudIM/Sight" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"