Aucune description

Pods-Tania-TaniaUITests-frameworks.sh 8.7KB

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