RongCloudIM-xcframeworks.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. "RongPublicService.xcframework/ios-arm64_armv7")
  52. echo ""
  53. ;;
  54. "RongPublicService.xcframework/ios-i386_x86_64-simulator")
  55. echo "simulator"
  56. ;;
  57. "RongSight.xcframework/ios-arm64_armv7")
  58. echo ""
  59. ;;
  60. "RongSight.xcframework/ios-i386_x86_64-simulator")
  61. echo "simulator"
  62. ;;
  63. esac
  64. }
  65. archs_for_slice()
  66. {
  67. case "$1" in
  68. "RongChatRoom.xcframework/ios-arm64_armv7")
  69. echo "arm64 armv7"
  70. ;;
  71. "RongChatRoom.xcframework/ios-i386_x86_64-simulator")
  72. echo "i386 x86_64"
  73. ;;
  74. "RongCustomerService.xcframework/ios-arm64_armv7")
  75. echo "arm64 armv7"
  76. ;;
  77. "RongCustomerService.xcframework/ios-i386_x86_64-simulator")
  78. echo "i386 x86_64"
  79. ;;
  80. "RongDiscussion.xcframework/ios-arm64_armv7")
  81. echo "arm64 armv7"
  82. ;;
  83. "RongDiscussion.xcframework/ios-i386_x86_64-simulator")
  84. echo "i386 x86_64"
  85. ;;
  86. "RongIMKit.xcframework/ios-arm64_armv7")
  87. echo "arm64 armv7"
  88. ;;
  89. "RongIMKit.xcframework/ios-i386_x86_64-simulator")
  90. echo "i386 x86_64"
  91. ;;
  92. "RongIMLib.xcframework/ios-arm64_armv7")
  93. echo "arm64 armv7"
  94. ;;
  95. "RongIMLib.xcframework/ios-i386_x86_64-simulator")
  96. echo "i386 x86_64"
  97. ;;
  98. "RongIMLibCore.xcframework/ios-arm64_armv7")
  99. echo "arm64 armv7"
  100. ;;
  101. "RongIMLibCore.xcframework/ios-i386_x86_64-simulator")
  102. echo "i386 x86_64"
  103. ;;
  104. "RongPublicService.xcframework/ios-arm64_armv7")
  105. echo "arm64 armv7"
  106. ;;
  107. "RongPublicService.xcframework/ios-i386_x86_64-simulator")
  108. echo "i386 x86_64"
  109. ;;
  110. "RongSight.xcframework/ios-arm64_armv7")
  111. echo "arm64 armv7"
  112. ;;
  113. "RongSight.xcframework/ios-i386_x86_64-simulator")
  114. echo "i386 x86_64"
  115. ;;
  116. esac
  117. }
  118. copy_dir()
  119. {
  120. local source="$1"
  121. local destination="$2"
  122. # Use filter instead of exclude so missing patterns don't throw errors.
  123. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" \"${source}*\" \"${destination}\""
  124. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" "${source}"/* "${destination}"
  125. }
  126. SELECT_SLICE_RETVAL=""
  127. select_slice() {
  128. local xcframework_name="$1"
  129. xcframework_name="${xcframework_name##*/}"
  130. local paths=("${@:2}")
  131. # Locate the correct slice of the .xcframework for the current architectures
  132. local target_path=""
  133. # Split archs on space so we can find a slice that has all the needed archs
  134. local target_archs=$(echo $ARCHS | tr " " "\n")
  135. local target_variant=""
  136. if [[ "$PLATFORM_NAME" == *"simulator" ]]; then
  137. target_variant="simulator"
  138. fi
  139. if [[ ! -z ${EFFECTIVE_PLATFORM_NAME+x} && "$EFFECTIVE_PLATFORM_NAME" == *"maccatalyst" ]]; then
  140. target_variant="maccatalyst"
  141. fi
  142. for i in ${!paths[@]}; do
  143. local matched_all_archs="1"
  144. local slice_archs="$(archs_for_slice "${xcframework_name}/${paths[$i]}")"
  145. local slice_variant="$(variant_for_slice "${xcframework_name}/${paths[$i]}")"
  146. for target_arch in $target_archs; do
  147. if ! [[ "${slice_variant}" == "$target_variant" ]]; then
  148. matched_all_archs="0"
  149. break
  150. fi
  151. if ! echo "${slice_archs}" | tr " " "\n" | grep -F -q -x "$target_arch"; then
  152. matched_all_archs="0"
  153. break
  154. fi
  155. done
  156. if [[ "$matched_all_archs" == "1" ]]; then
  157. # Found a matching slice
  158. echo "Selected xcframework slice ${paths[$i]}"
  159. SELECT_SLICE_RETVAL=${paths[$i]}
  160. break
  161. fi
  162. done
  163. }
  164. install_xcframework() {
  165. local basepath="$1"
  166. local name="$2"
  167. local package_type="$3"
  168. local paths=("${@:4}")
  169. # Locate the correct slice of the .xcframework for the current architectures
  170. select_slice "${basepath}" "${paths[@]}"
  171. local target_path="$SELECT_SLICE_RETVAL"
  172. if [[ -z "$target_path" ]]; then
  173. 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}})."
  174. return
  175. fi
  176. local source="$basepath/$target_path"
  177. local destination="${PODS_XCFRAMEWORKS_BUILD_DIR}/${name}"
  178. if [ ! -d "$destination" ]; then
  179. mkdir -p "$destination"
  180. fi
  181. copy_dir "$source/" "$destination"
  182. echo "Copied $source to $destination"
  183. }
  184. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongChatRoom.xcframework" "RongCloudIM/ChatRoom" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  185. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongCustomerService.xcframework" "RongCloudIM/CustomerService" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  186. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongDiscussion.xcframework" "RongCloudIM/Discussion" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  187. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongIMKit.xcframework" "RongCloudIM/IMKit" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  188. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongIMLib.xcframework" "RongCloudIM/IMLib" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  189. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongIMLibCore.xcframework" "RongCloudIM/IMLibCore" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  190. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongPublicService.xcframework" "RongCloudIM/PublicService" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"
  191. install_xcframework "${PODS_ROOT}/RongCloudIM/RongCloudIM/RongSight.xcframework" "RongCloudIM/Sight" "framework" "ios-arm64_armv7" "ios-i386_x86_64-simulator"