Pods-XenonDemo-frameworks.sh 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. if [ -z ${FRAMEWORKS_FOLDER_PATH+x} ]; then
  10. # If FRAMEWORKS_FOLDER_PATH is not set, then there's nowhere for us to copy
  11. # frameworks to, so exit 0 (signalling the script phase was successful).
  12. exit 0
  13. fi
  14. echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
  15. mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
  16. COCOAPODS_PARALLEL_CODE_SIGN="${COCOAPODS_PARALLEL_CODE_SIGN:-false}"
  17. SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
  18. BCSYMBOLMAP_DIR="BCSymbolMaps"
  19. # This protects against multiple targets copying the same framework dependency at the same time. The solution
  20. # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html
  21. RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????")
  22. # Copies and strips a vendored framework
  23. install_framework()
  24. {
  25. if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then
  26. local source="${BUILT_PRODUCTS_DIR}/$1"
  27. elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then
  28. local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"
  29. elif [ -r "$1" ]; then
  30. local source="$1"
  31. fi
  32. local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
  33. if [ -L "${source}" ]; then
  34. echo "Symlinked..."
  35. source="$(readlink "${source}")"
  36. fi
  37. if [ -d "${source}/${BCSYMBOLMAP_DIR}" ]; then
  38. # Locate and install any .bcsymbolmaps if present, and remove them from the .framework before the framework is copied
  39. find "${source}/${BCSYMBOLMAP_DIR}" -name "*.bcsymbolmap"|while read f; do
  40. echo "Installing $f"
  41. install_bcsymbolmap "$f" "$destination"
  42. rm "$f"
  43. done
  44. rmdir "${source}/${BCSYMBOLMAP_DIR}"
  45. fi
  46. # Use filter instead of exclude so missing patterns don't throw errors.
  47. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\""
  48. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}"
  49. local basename
  50. basename="$(basename -s .framework "$1")"
  51. binary="${destination}/${basename}.framework/${basename}"
  52. if ! [ -r "$binary" ]; then
  53. binary="${destination}/${basename}"
  54. elif [ -L "${binary}" ]; then
  55. echo "Destination binary is symlinked..."
  56. dirname="$(dirname "${binary}")"
  57. binary="${dirname}/$(readlink "${binary}")"
  58. fi
  59. # Strip invalid architectures so "fat" simulator / device frameworks work on device
  60. if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then
  61. strip_invalid_archs "$binary"
  62. fi
  63. # Resign the code if required by the build settings to avoid unstable apps
  64. code_sign_if_enabled "${destination}/$(basename "$1")"
  65. # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7.
  66. if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then
  67. local swift_runtime_libs
  68. swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u)
  69. for lib in $swift_runtime_libs; do
  70. echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""
  71. rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"
  72. code_sign_if_enabled "${destination}/${lib}"
  73. done
  74. fi
  75. }
  76. # Copies and strips a vendored dSYM
  77. install_dsym() {
  78. local source="$1"
  79. warn_missing_arch=${2:-true}
  80. if [ -r "$source" ]; then
  81. # Copy the dSYM into the targets temp dir.
  82. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${DERIVED_FILES_DIR}\""
  83. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${DERIVED_FILES_DIR}"
  84. local basename
  85. basename="$(basename -s .dSYM "$source")"
  86. binary_name="$(ls "$source/Contents/Resources/DWARF")"
  87. binary="${DERIVED_FILES_DIR}/${basename}.dSYM/Contents/Resources/DWARF/${binary_name}"
  88. # Strip invalid architectures from the dSYM.
  89. if [[ "$(file "$binary")" == *"Mach-O "*"dSYM companion"* ]]; then
  90. strip_invalid_archs "$binary" "$warn_missing_arch"
  91. fi
  92. if [[ $STRIP_BINARY_RETVAL == 0 ]]; then
  93. # Move the stripped file into its final destination.
  94. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${DERIVED_FILES_DIR}/${basename}.framework.dSYM\" \"${DWARF_DSYM_FOLDER_PATH}\""
  95. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.dSYM" "${DWARF_DSYM_FOLDER_PATH}"
  96. else
  97. # The dSYM was not stripped at all, in this case touch a fake folder so the input/output paths from Xcode do not reexecute this script because the file is missing.
  98. touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.dSYM"
  99. fi
  100. fi
  101. }
  102. # Used as a return value for each invocation of `strip_invalid_archs` function.
  103. STRIP_BINARY_RETVAL=0
  104. # Strip invalid architectures
  105. strip_invalid_archs() {
  106. binary="$1"
  107. warn_missing_arch=${2:-true}
  108. # Get architectures for current target binary
  109. binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)"
  110. # Intersect them with the architectures we are building for
  111. intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)"
  112. # If there are no archs supported by this binary then warn the user
  113. if [[ -z "$intersected_archs" ]]; then
  114. if [[ "$warn_missing_arch" == "true" ]]; then
  115. echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)."
  116. fi
  117. STRIP_BINARY_RETVAL=1
  118. return
  119. fi
  120. stripped=""
  121. for arch in $binary_archs; do
  122. if ! [[ "${ARCHS}" == *"$arch"* ]]; then
  123. # Strip non-valid architectures in-place
  124. lipo -remove "$arch" -output "$binary" "$binary"
  125. stripped="$stripped $arch"
  126. fi
  127. done
  128. if [[ "$stripped" ]]; then
  129. echo "Stripped $binary of architectures:$stripped"
  130. fi
  131. STRIP_BINARY_RETVAL=0
  132. }
  133. # Copies the bcsymbolmap files of a vendored framework
  134. install_bcsymbolmap() {
  135. local bcsymbolmap_path="$1"
  136. local destination="${BUILT_PRODUCTS_DIR}"
  137. echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}""
  138. rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}"
  139. }
  140. # Signs a framework with the provided identity
  141. code_sign_if_enabled() {
  142. if [ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" -a "${CODE_SIGNING_REQUIRED:-}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then
  143. # Use the current code_sign_identity
  144. echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
  145. local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS:-} --preserve-metadata=identifier,entitlements '$1'"
  146. if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then
  147. code_sign_cmd="$code_sign_cmd &"
  148. fi
  149. echo "$code_sign_cmd"
  150. eval "$code_sign_cmd"
  151. fi
  152. }
  153. if [[ "$CONFIGURATION" == "Debug" ]]; then
  154. install_framework "${BUILT_PRODUCTS_DIR}/JSONModel/JSONModel.framework"
  155. install_framework "${BUILT_PRODUCTS_DIR}/MBProgressHUD/MBProgressHUD.framework"
  156. fi
  157. if [[ "$CONFIGURATION" == "Release" ]]; then
  158. install_framework "${BUILT_PRODUCTS_DIR}/JSONModel/JSONModel.framework"
  159. install_framework "${BUILT_PRODUCTS_DIR}/MBProgressHUD/MBProgressHUD.framework"
  160. fi
  161. if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then
  162. wait
  163. fi