RongCloudRTC-xcframeworks.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. "RongRTCLib.xcframework/ios-arm64_armv7")
  16. echo ""
  17. ;;
  18. "RongRTCLib.xcframework/ios-x86_64-simulator")
  19. echo "simulator"
  20. ;;
  21. esac
  22. }
  23. archs_for_slice()
  24. {
  25. case "$1" in
  26. "RongRTCLib.xcframework/ios-arm64_armv7")
  27. echo "arm64 armv7"
  28. ;;
  29. "RongRTCLib.xcframework/ios-x86_64-simulator")
  30. echo "x86_64"
  31. ;;
  32. esac
  33. }
  34. copy_dir()
  35. {
  36. local source="$1"
  37. local destination="$2"
  38. # Use filter instead of exclude so missing patterns don't throw errors.
  39. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" \"${source}*\" \"${destination}\""
  40. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" "${source}"/* "${destination}"
  41. }
  42. SELECT_SLICE_RETVAL=""
  43. select_slice() {
  44. local xcframework_name="$1"
  45. xcframework_name="${xcframework_name##*/}"
  46. local paths=("${@:2}")
  47. # Locate the correct slice of the .xcframework for the current architectures
  48. local target_path=""
  49. # Split archs on space so we can find a slice that has all the needed archs
  50. local target_archs=$(echo $ARCHS | tr " " "\n")
  51. local target_variant=""
  52. if [[ "$PLATFORM_NAME" == *"simulator" ]]; then
  53. target_variant="simulator"
  54. fi
  55. if [[ ! -z ${EFFECTIVE_PLATFORM_NAME+x} && "$EFFECTIVE_PLATFORM_NAME" == *"maccatalyst" ]]; then
  56. target_variant="maccatalyst"
  57. fi
  58. for i in ${!paths[@]}; do
  59. local matched_all_archs="1"
  60. local slice_archs="$(archs_for_slice "${xcframework_name}/${paths[$i]}")"
  61. local slice_variant="$(variant_for_slice "${xcframework_name}/${paths[$i]}")"
  62. for target_arch in $target_archs; do
  63. if ! [[ "${slice_variant}" == "$target_variant" ]]; then
  64. matched_all_archs="0"
  65. break
  66. fi
  67. if ! echo "${slice_archs}" | tr " " "\n" | grep -F -q -x "$target_arch"; then
  68. matched_all_archs="0"
  69. break
  70. fi
  71. done
  72. if [[ "$matched_all_archs" == "1" ]]; then
  73. # Found a matching slice
  74. echo "Selected xcframework slice ${paths[$i]}"
  75. SELECT_SLICE_RETVAL=${paths[$i]}
  76. break
  77. fi
  78. done
  79. }
  80. install_xcframework() {
  81. local basepath="$1"
  82. local name="$2"
  83. local package_type="$3"
  84. local paths=("${@:4}")
  85. # Locate the correct slice of the .xcframework for the current architectures
  86. select_slice "${basepath}" "${paths[@]}"
  87. local target_path="$SELECT_SLICE_RETVAL"
  88. if [[ -z "$target_path" ]]; then
  89. 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}})."
  90. return
  91. fi
  92. local source="$basepath/$target_path"
  93. local destination="${PODS_XCFRAMEWORKS_BUILD_DIR}/${name}"
  94. if [ ! -d "$destination" ]; then
  95. mkdir -p "$destination"
  96. fi
  97. copy_dir "$source/" "$destination"
  98. echo "Copied $source to $destination"
  99. }
  100. install_xcframework "${PODS_ROOT}/RongCloudRTC/RongCloudRTC/RongRTCLib.xcframework" "RongCloudRTC/RongRTCLib" "framework" "ios-arm64_armv7" "ios-x86_64-simulator"