#!/usr/bin/env bash set -euo pipefail bundledir="${1:-}" sparkle_framework_dir="${2:-}" sparkle_bin_link="${3:-}" sparkle_bin_real="${4:-}" if [[ -z "$bundledir" || -z "$sparkle_framework_dir" ]]; then echo "Usage: $0 [sparkle_bin_link] [sparkle_bin_real]" >&2 exit 2 fi if [[ ! -d "$sparkle_framework_dir" ]]; then echo "Sparkle.framework dir not found: $sparkle_framework_dir" >&2 exit 1 fi src_framework_dir="$sparkle_framework_dir" # Homebrew often provides /opt/homebrew/Frameworks/Sparkle.framework where Versions/* are symlinks # pointing back into the Cellar. Copying that verbatim breaks inside an app bundle. # Resolve to the real Cellar framework root via Versions/Current. if [[ -e "${sparkle_framework_dir}/Versions/Current" ]]; then current_real="$(cd "${sparkle_framework_dir}/Versions/Current" && pwd -P)" # current_real is .../Sparkle.framework/Versions/B (or similar) src_framework_dir="$(cd "${current_real}/../.." && pwd -P)" fi dst_framework="${bundledir}/Contents/Frameworks/Sparkle.framework" main_bin="${bundledir}/Contents/MacOS/strawberry" qtsparkle_dylib="${bundledir}/Contents/Frameworks/libqtsparkle-qt6.dylib" mkdir -p "${bundledir}/Contents/Frameworks" echo "Bundling Sparkle.framework -> ${dst_framework}" rm -rf "${dst_framework}" # Use ditto to preserve the framework's internal symlinks/structure. ditto "${src_framework_dir}" "${dst_framework}" # Prefer the canonical framework binary path. dst_bin="${dst_framework}/Versions/Current/Sparkle" if [[ ! -e "${dst_bin}" ]]; then echo "Error: Sparkle binary missing at ${dst_bin}" >&2 exit 1 fi sparkle_rpath="@rpath/Sparkle.framework/Versions/Current/Sparkle" # Sanity check: top-level Sparkle entry should be a symlink (not a copied Mach-O file). if [[ -e "${dst_framework}/Sparkle" && ! -L "${dst_framework}/Sparkle" ]]; then echo "Warning: ${dst_framework}/Sparkle is not a symlink (unexpected). This can confuse codesign." >&2 fi echo "Fixing Sparkle.framework install name" install_name_tool -id "${sparkle_rpath}" "${dst_bin}" echo "Ensuring main binary has Frameworks rpath" install_name_tool -add_rpath "@executable_path/../Frameworks" "${main_bin}" || true echo "Rewriting Sparkle.framework references to @rpath" # Try to rewrite a few common Homebrew Sparkle install names as well, because the # recorded install name may differ from the path returned by CMake's find_library. old_candidates=( "${sparkle_bin_link}" "${sparkle_bin_real}" "/opt/homebrew/opt/sparkle-framework/Frameworks/Sparkle.framework/Versions/A/Sparkle" "/opt/homebrew/opt/sparkle-framework/Frameworks/Sparkle.framework/Versions/B/Sparkle" "/opt/homebrew/Frameworks/Sparkle.framework/Versions/A/Sparkle" "/opt/homebrew/Frameworks/Sparkle.framework/Versions/B/Sparkle" "/usr/local/opt/sparkle-framework/Frameworks/Sparkle.framework/Versions/A/Sparkle" "/usr/local/opt/sparkle-framework/Frameworks/Sparkle.framework/Versions/B/Sparkle" "/usr/local/Frameworks/Sparkle.framework/Versions/A/Sparkle" "/usr/local/Frameworks/Sparkle.framework/Versions/B/Sparkle" ) for old in "${old_candidates[@]}"; do if [[ -n "${old}" ]]; then install_name_tool -change "${old}" "${sparkle_rpath}" "${main_bin}" || true if [[ -f "${qtsparkle_dylib}" ]]; then install_name_tool -change "${old}" "${sparkle_rpath}" "${qtsparkle_dylib}" || true fi fi done