TXLiteAVSDK_Professional-xcframeworks.sh 4.6 KB

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