暫無描述

Pods-CAISHEN-frameworks.sh 6.3KB

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