#!/bin/bash set -euo pipefail cd "$(dirname "$0")/.." source Scripts/product.env source Scripts/packaging-paths.sh source Scripts/version.sh structural_only=false if [[ ${1:-} == --no-launch ]]; then structural_only=true; shift; fi if [[ $# -gt 1 ]]; then echo "Usage: $0 [--no-launch] [app]" >&2 exit 2 fi app=$(packaging_app_path "${1:-build/$PRODUCT_NAME.app}") Scripts/bundle-preflight.sh "$app" work=$(mktemp -d "${TMPDIR:-/tmp}/$PRODUCT_CASK-smoke.XXXXXX") pid= cleanup() { if [[ -n $pid ]]; then if kill -0 "$pid" 2>/dev/null; then if ! kill -KILL "$pid" 2>/dev/null && kill -0 "$pid" 2>/dev/null; then echo "Could not kill smoke process $pid." >&2 exit 1 fi fi wait "$pid" 2>/dev/null || true pid= fi rm -rf "$work" } trap cleanup EXIT trap 'exit 130' INT trap 'exit 143' TERM codesign --verify --strict --deep "$app" if ! codesign -dv "$app" > "$work/signature.log" 2>&1; then /bin/cat "$work/signature.log" >&2 exit 1 fi if ! codesign -d --entitlements - --xml "$app" > "$work/entitlements.plist" 2> "$work/entitlements.log"; then /bin/cat "$work/entitlements.log" >&2 exit 1 fi Scripts/parcel-dev.sh check-bundle-signature "$work/signature.log" "$work/entitlements.plist" Scripts/parcel-dev.sh update-metadata check "$app/Contents/Info.plist" updates_enabled=$(/usr/libexec/PlistBuddy -c "Print :${PRODUCT_NAME}UpdatesEnabled" "$app/Contents/Info.plist") if [[ $updates_enabled == true ]]; then Scripts/parcel-dev.sh check-binaries "$app" "$PRODUCT_NAME" "$PWD" else Scripts/parcel-dev.sh check-binaries --sdk-only "$app" "$PRODUCT_NAME" "$PWD" fi framework="$app/Contents/Frameworks/Sparkle.framework" for component in Sparkle Autoupdate Updater.app XPCServices/Installer.xpc XPCServices/Downloader.xpc; do [[ -e $framework/Versions/B/$component ]] || { echo "Missing Sparkle component: $component" >&2; exit 1; } codesign --verify --strict "$framework/Versions/B/$component" done lipo "$framework/Versions/B/Sparkle" -verify_arch arm64 x86_64 if ! otool -l "$app/Contents/MacOS/$PRODUCT_NAME" | grep -F '@executable_path/../Frameworks' > /dev/null; then echo 'The app cannot locate its embedded frameworks.' >&2; exit 1 fi if [[ $structural_only == true ]]; then exit 0; fi ditto "$app" "$work/$PRODUCT_NAME.app" codesign --verify --strict --deep "$work/$PRODUCT_NAME.app" run_smoke() { local label=$1 log=$2 status=0 tick shift 2 DYLD_BIND_AT_LAUNCH=1 "$@" > "$log" 2>&1 & pid=$! for (( tick=0; tick<50; tick++ )); do if ! kill -0 "$pid" 2>/dev/null; then wait "$pid" 2>/dev/null || status=$? pid= if [[ $status != 0 ]]; then echo "The bundled $label failed (status $status):" >&2 /bin/cat "$log" >&2 return 1 fi return 0 fi sleep 0.1 done echo "The bundled $label timed out after 5 seconds:" >&2 /bin/cat "$log" >&2 return 1 } run_smoke CLI "$work/version.log" "$work/$PRODUCT_NAME.app/Contents/Resources/bin/$PRODUCT_CLI" --version if ! validate_version "$(<"$work/version.log")"; then echo 'The bundled CLI returned an invalid version:' >&2 /bin/cat "$work/version.log" >&2 exit 1 fi # dyld loads linked frameworks before main; bind eagerly without starting the app runtime. run_smoke app "$work/app.log" "$work/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME" --smoke