teachers-assistant

[RADIOACTIVE] oh boy did i make bad apps back in the day
git clone git://git.figbert.com/teachers-assistant.git
Log | Files | Refs

Pods-TeachersAssistant-frameworks.sh (7799B)


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