RongCloudRTC-xcframeworks.sh 4.0 KB

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