No Description

strip-frameworks.sh 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ################################################################################
  2. #
  3. # Copyright 2015 Realm Inc.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. ################################################################################
  18. # This script strips all non-valid architectures from dynamic libraries in
  19. # the application's `Frameworks` directory.
  20. #
  21. # The following environment variables are required:
  22. #
  23. # BUILT_PRODUCTS_DIR
  24. # FRAMEWORKS_FOLDER_PATH
  25. # VALID_ARCHS
  26. # EXPANDED_CODE_SIGN_IDENTITY
  27. # Signs a framework with the provided identity
  28. code_sign() {
  29. # Use the current code_sign_identitiy
  30. echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
  31. echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements $1"
  32. /usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements "$1"
  33. }
  34. # Set working directory to product’s embedded frameworks
  35. cd "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}"
  36. if [ "$ACTION" = "install" ]; then
  37. echo "Copy .bcsymbolmap files to .xcarchive"
  38. find . -name '*.bcsymbolmap' -type f -exec mv {} "${CONFIGURATION_BUILD_DIR}" \;
  39. else
  40. # Delete *.bcsymbolmap files from framework bundle unless archiving
  41. find . -name '*.bcsymbolmap' -type f -exec rm -rf "{}" +\;
  42. fi
  43. echo "Stripping frameworks"
  44. for file in $(find . -type f -perm +111); do
  45. # Skip non-dynamic libraries
  46. if ! [[ "$(file "$file")" == *"dynamically linked shared library"* ]]; then
  47. continue
  48. fi
  49. # Get architectures for current file
  50. archs="$(lipo -info "${file}" | rev | cut -d ':' -f1 | rev)"
  51. stripped=""
  52. for arch in $archs; do
  53. if ! [[ "${VALID_ARCHS}" == *"$arch"* ]]; then
  54. # Strip non-valid architectures in-place
  55. lipo -remove "$arch" -output "$file" "$file" || exit 1
  56. stripped="$stripped $arch"
  57. fi
  58. done
  59. if [[ "$stripped" != "" ]]; then
  60. echo "Stripped $file of architectures:$stripped"
  61. if [ "${CODE_SIGNING_REQUIRED}" == "YES" ]; then
  62. code_sign "${file}"
  63. fi
  64. fi
  65. done