AutorÃa | Ultima modificación | Ver Log |
#!/bin/shset -eset -uset -o pipefailfunction on_error {echo "$(realpath -mq "${0}"):$1: error: Unexpected failure"}trap 'on_error $LINENO' ERRif [ -z ${FRAMEWORKS_FOLDER_PATH+x} ]; then# If FRAMEWORKS_FOLDER_PATH is not set, then there's nowhere for us to copy# frameworks to, so exit 0 (signalling the script phase was successful).exit 0fiecho "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"COCOAPODS_PARALLEL_CODE_SIGN="${COCOAPODS_PARALLEL_CODE_SIGN:-false}"SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"BCSYMBOLMAP_DIR="BCSymbolMaps"# This protects against multiple targets copying the same framework dependency at the same time. The solution# was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.htmlRSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????")# Copies and strips a vendored frameworkinstall_framework(){if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; thenlocal source="${BUILT_PRODUCTS_DIR}/$1"elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; thenlocal source="${BUILT_PRODUCTS_DIR}/$(basename "$1")"elif [ -r "$1" ]; thenlocal source="$1"filocal destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"if [ -L "${source}" ]; thenecho "Symlinked..."source="$(readlink "${source}")"fiif [ -d "${source}/${BCSYMBOLMAP_DIR}" ]; then# Locate and install any .bcsymbolmaps if present, and remove them from the .framework before the framework is copiedfind "${source}/${BCSYMBOLMAP_DIR}" -name "*.bcsymbolmap"|while read f; doecho "Installing $f"install_bcsymbolmap "$f" "$destination"rm "$f"donermdir "${source}/${BCSYMBOLMAP_DIR}"fi# Use filter instead of exclude so missing patterns don't throw errors.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}\""rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}"local basenamebasename="$(basename -s .framework "$1")"binary="${destination}/${basename}.framework/${basename}"if ! [ -r "$binary" ]; thenbinary="${destination}/${basename}"elif [ -L "${binary}" ]; thenecho "Destination binary is symlinked..."dirname="$(dirname "${binary}")"binary="${dirname}/$(readlink "${binary}")"fi# Strip invalid architectures so "fat" simulator / device frameworks work on deviceif [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; thenstrip_invalid_archs "$binary"fi# Resign the code if required by the build settings to avoid unstable appscode_sign_if_enabled "${destination}/$(basename "$1")"# Embed linked Swift runtime libraries. No longer necessary as of Xcode 7.if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; thenlocal swift_runtime_libsswift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u)for lib in $swift_runtime_libs; doecho "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\""rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}"code_sign_if_enabled "${destination}/${lib}"donefi}# Copies and strips a vendored dSYMinstall_dsym() {local source="$1"warn_missing_arch=${2:-true}if [ -r "$source" ]; then# Copy the dSYM into the targets temp dir.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}\""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}"local basenamebasename="$(basename -s .dSYM "$source")"binary_name="$(ls "$source/Contents/Resources/DWARF")"binary="${DERIVED_FILES_DIR}/${basename}.dSYM/Contents/Resources/DWARF/${binary_name}"# Strip invalid architectures from the dSYM.if [[ "$(file "$binary")" == *"Mach-O "*"dSYM companion"* ]]; thenstrip_invalid_archs "$binary" "$warn_missing_arch"fiif [[ $STRIP_BINARY_RETVAL == 0 ]]; then# Move the stripped file into its final destination.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}\""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}"else# 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.mkdir -p "${DWARF_DSYM_FOLDER_PATH}"touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.dSYM"fifi}# Used as a return value for each invocation of `strip_invalid_archs` function.STRIP_BINARY_RETVAL=0# Strip invalid architecturesstrip_invalid_archs() {binary="$1"warn_missing_arch=${2:-true}# Get architectures for current target binarybinary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)"# Intersect them with the architectures we are building forintersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)"# If there are no archs supported by this binary then warn the userif [[ -z "$intersected_archs" ]]; thenif [[ "$warn_missing_arch" == "true" ]]; thenecho "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)."fiSTRIP_BINARY_RETVAL=1returnfistripped=""for arch in $binary_archs; doif ! [[ "${ARCHS}" == *"$arch"* ]]; then# Strip non-valid architectures in-placelipo -remove "$arch" -output "$binary" "$binary"stripped="$stripped $arch"fidoneif [[ "$stripped" ]]; thenecho "Stripped $binary of architectures:$stripped"fiSTRIP_BINARY_RETVAL=0}# Copies the bcsymbolmap files of a vendored frameworkinstall_bcsymbolmap() {local bcsymbolmap_path="$1"local destination="${BUILT_PRODUCTS_DIR}"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}""rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}"}# Signs a framework with the provided identitycode_sign_if_enabled() {if [ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" -a "${CODE_SIGNING_REQUIRED:-}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then# Use the current code_sign_identityecho "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}"local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS:-} --preserve-metadata=identifier,entitlements '$1'"if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; thencode_sign_cmd="$code_sign_cmd &"fiecho "$code_sign_cmd"eval "$code_sign_cmd"fi}if [[ "$CONFIGURATION" == "Debug" ]]; theninstall_framework "${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework"install_framework "${BUILT_PRODUCTS_DIR}/AlamofireImage/AlamofireImage.framework"install_framework "${BUILT_PRODUCTS_DIR}/DeviceKit/DeviceKit.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseABTesting/FirebaseABTesting.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseCore/FirebaseCore.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseCoreDiagnostics/FirebaseCoreDiagnostics.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseCrashlytics/FirebaseCrashlytics.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseInAppMessaging/FirebaseInAppMessaging.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseInstallations/FirebaseInstallations.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseMessaging/FirebaseMessaging.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebasePerformance/FirebasePerformance.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseRemoteConfig/FirebaseRemoteConfig.framework"install_framework "${BUILT_PRODUCTS_DIR}/FloatingLabelTextFieldSwiftUI/FloatingLabelTextFieldSwiftUI.framework"install_framework "${BUILT_PRODUCTS_DIR}/GoogleDataTransport/GoogleDataTransport.framework"install_framework "${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework"install_framework "${BUILT_PRODUCTS_DIR}/Player/Player.framework"install_framework "${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework"install_framework "${BUILT_PRODUCTS_DIR}/RNCryptor/RNCryptor.framework"install_framework "${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework"install_framework "${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework"fiif [[ "$CONFIGURATION" == "Release" ]]; theninstall_framework "${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework"install_framework "${BUILT_PRODUCTS_DIR}/AlamofireImage/AlamofireImage.framework"install_framework "${BUILT_PRODUCTS_DIR}/DeviceKit/DeviceKit.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseABTesting/FirebaseABTesting.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseCore/FirebaseCore.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseCoreDiagnostics/FirebaseCoreDiagnostics.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseCrashlytics/FirebaseCrashlytics.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseInAppMessaging/FirebaseInAppMessaging.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseInstallations/FirebaseInstallations.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseMessaging/FirebaseMessaging.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebasePerformance/FirebasePerformance.framework"install_framework "${BUILT_PRODUCTS_DIR}/FirebaseRemoteConfig/FirebaseRemoteConfig.framework"install_framework "${BUILT_PRODUCTS_DIR}/FloatingLabelTextFieldSwiftUI/FloatingLabelTextFieldSwiftUI.framework"install_framework "${BUILT_PRODUCTS_DIR}/GoogleDataTransport/GoogleDataTransport.framework"install_framework "${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework"install_framework "${BUILT_PRODUCTS_DIR}/Player/Player.framework"install_framework "${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework"install_framework "${BUILT_PRODUCTS_DIR}/RNCryptor/RNCryptor.framework"install_framework "${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework"install_framework "${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework"fiif [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; thenwaitfi