#!/bin/bash set -euo pipefail if [ "$#" -eq 1 ] && { [ "$1" = "--help" ] || [ "$1" = "-h" ]; }; then echo "Usage: $0 " exit 0 fi if [[ $# != 1 ]]; then echo "Usage: $0 " >&2 exit 2 fi repo_root="$(cd "$(dirname "$0")/../.." && pwd)" app="$1" signing_identity="${CUTDEX_CODESIGN_IDENTITY:--}" # Flutter's prebuilt engine carries an unused Homebrew search path. Remove it # from our copy before signing; the audit rejects any remaining external paths. engine="$app/Contents/Frameworks/FlutterMacOS.framework/Versions/A/FlutterMacOS" if /usr/bin/otool -l "$engine" | grep -F 'path /usr/local/lib/. (offset' >/dev/null; then /usr/bin/install_name_tool -delete_rpath /usr/local/lib/. "$engine" fi codesign_args=(--force --sign "$signing_identity") if [[ "$signing_identity" == "-" ]]; then codesign_args+=(--timestamp=none) else codesign_args+=(--timestamp --options runtime) fi while IFS= read -r binary; do if file "$binary" | grep -q 'Mach-O'; then codesign "${codesign_args[@]}" --preserve-metadata=entitlements "$binary" fi done < <(find "$app/Contents" -type f -print | sort) # Every nested bundle must use the same identity as the outer app. Mixing the # Xcode development signature with an ad-hoc or Developer ID signature causes # dyld to reject FlutterMacOS.framework on a clean launch. while IFS= read -r bundle; do codesign "${codesign_args[@]}" --preserve-metadata=entitlements "$bundle" done < <(find "$app/Contents" -type d \( \ -name '*.framework' -o -name '*.appex' -o -name '*.xpc' -o -name '*.app' \ \) -print | awk '{ print length, $0 }' | sort -rn | cut -d' ' -f2-) codesign "${codesign_args[@]}" \ --entitlements "$repo_root/macos/Runner/Release.entitlements" "$app"