nim_strip_archs.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh
  2. # nim_strip_archs.sh
  3. # LiveChat
  4. #
  5. # Created by 张灿 on 2018/10/18.
  6. # Copyright © 2018年 caicai. All rights reserved.
  7. # Strip invalid architectures
  8. strip_invalid_archs() {
  9. binary="$1"
  10. echo "current binary ${binary}"
  11. # Get architectures for current file
  12. archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)"
  13. stripped=""
  14. for arch in $archs; do
  15. if ! [[ "${ARCHS}" == *"$arch"* ]]; then
  16. if [ -f "$binary" ]; then
  17. # Strip non-valid architectures in-place
  18. lipo -remove "$arch" -output "$binary" "$binary" || exit 1
  19. stripped="$stripped $arch"
  20. fi
  21. fi
  22. done
  23. if [[ "$stripped" ]]; then
  24. echo "Stripped $binary of architectures:$stripped"
  25. fi
  26. }
  27. APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
  28. # This script loops through the frameworks embedded in the application and
  29. # removes unused architectures.
  30. find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
  31. do
  32. FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
  33. FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
  34. echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
  35. strip_invalid_archs "$FRAMEWORK_EXECUTABLE_PATH"
  36. done