From 5d7cb5dfe1e652cebde0bb896c0026cda69182d8 Mon Sep 17 00:00:00 2001 From: ZGaetano Date: Wed, 6 May 2026 19:41:07 -0400 Subject: [PATCH] installer: fix cmake source dir, absolute qmldir, trap timing, SVG fallback --- scripts/build-installer-mac.sh | 63 +++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/scripts/build-installer-mac.sh b/scripts/build-installer-mac.sh index b24f1f4..899a40c 100644 --- a/scripts/build-installer-mac.sh +++ b/scripts/build-installer-mac.sh @@ -30,6 +30,9 @@ set -euo pipefail +# Platform check: require macOS +[[ "$(uname)" != "Darwin" ]] && { echo "[ERROR] This script requires macOS" >&2; exit 1; } + # Color codes for output readonly COLOR_RESET='\033[0m' readonly COLOR_INFO='\033[0;36m' # Cyan @@ -49,15 +52,19 @@ error() { echo -e "${COLOR_ERROR}[ERROR]${COLOR_RESET} $*" >&2 } +# Build success flag for cleanup control +BUILD_SUCCESS=false + cleanup() { info "Cleaning up temporary files..." - if [[ -d "$TEMP_DIR" ]]; then + if [[ "$BUILD_SUCCESS" == false && -d "$TEMP_DIR" ]]; then rm -rf "$TEMP_DIR" fi } -# Trap EXIT to ensure cleanup +# Trap EXIT for cleanup, ERR for early error exit trap cleanup EXIT +trap 'exit 1' ERR # ============================================================================= # Parse CLI arguments @@ -186,7 +193,9 @@ ok "boringtun build complete" # ============================================================================= info "Step 2: Configuring CMake..." +mkdir -p "$BUILD_DIR" CMAKE_ARGS=( + "-S" "$REPO_ROOT" "-B" "$BUILD_DIR" "-DCMAKE_BUILD_TYPE=Release" ) @@ -225,7 +234,8 @@ ok "Found: $APP_BUNDLE" info "Step 5: Running macdeployqt to bundle Qt frameworks..." # Use macdeployqt without -dmg (we'll create the DMG ourselves) -macdeployqt "$APP_BUNDLE" -qmldir=app +# Use absolute path for -qmldir +macdeployqt "$APP_BUNDLE" -qmldir="$REPO_ROOT/app" ok "macdeployqt complete" # ============================================================================= @@ -276,24 +286,8 @@ mkdir -p "$OUTPUT_DIR" # Prepare background image DMG_BG_PATH="$REPO_ROOT/package/mac/dmg-background.png" -if [[ -f "$REPO_ROOT/package/mac/dmg-background.svg" ]]; then - info "Converting SVG background to PNG..." - if command -v rsvg-convert &>/dev/null; then - rsvg-convert -w 660 -h 400 "$REPO_ROOT/package/mac/dmg-background.svg" -o "$DMG_BG_PATH" - ok "SVG converted to PNG" - else - info "rsvg-convert not found; creating placeholder background" - # Create a simple dark placeholder PNG (if needed; create-dmg works without a background) - fi -fi - -# Use create-dmg -DMG_OUTPUT="$OUTPUT_DIR/DragonMoonlight-$VERSION.dmg" -rm -f "$DMG_OUTPUT" - CREATE_DMG_ARGS=( --volname "DragonMoonlight" - --volicon "$APP_BUNDLE/Contents/Resources/icon.icns" --window-pos 200 120 --window-size 660 400 --icon-size 128 @@ -302,14 +296,34 @@ CREATE_DMG_ARGS=( --app-drop-link 500 185 ) -if [[ -f "$DMG_BG_PATH" ]]; then - CREATE_DMG_ARGS+=(--background "$DMG_BG_PATH") +# Handle SVG background conversion +if [[ -f "$REPO_ROOT/package/mac/dmg-background.svg" ]]; then + info "Converting SVG background to PNG..." + if command -v rsvg-convert &>/dev/null; then + rsvg-convert -w 660 -h 400 "$REPO_ROOT/package/mac/dmg-background.svg" -o "$DMG_BG_PATH" + CREATE_DMG_ARGS+=(--background "$DMG_BG_PATH") + ok "SVG converted to PNG" + else + info "rsvg-convert not found — DMG will use plain background (brew install librsvg to add branding)" + fi fi +# Check for icon and conditionally add --volicon +if [[ -f "$APP_BUNDLE/Contents/Resources/icon.icns" ]]; then + CREATE_DMG_ARGS+=(--volicon "$APP_BUNDLE/Contents/Resources/icon.icns") +else + info "Warning: icon.icns not found; DMG will not have custom volume icon" +fi + +# Use create-dmg +DMG_OUTPUT="$OUTPUT_DIR/DragonMoonlight-$VERSION.dmg" +rm -f "$DMG_OUTPUT" + create-dmg "${CREATE_DMG_ARGS[@]}" "$DMG_OUTPUT" "$(dirname "$APP_BUNDLE")/DragonMoonlight.app" -if [[ ! -f "$DMG_OUTPUT" ]]; then - error "Failed to create DMG at $DMG_OUTPUT" +# Validate DMG is non-zero +if [[ ! -s "$DMG_OUTPUT" ]]; then + error "DMG is empty or missing: $DMG_OUTPUT" exit 1 fi @@ -327,6 +341,9 @@ ok "SHA256: $CHECKSUM" # Summary # ============================================================================= +# Mark build as successful before cleanup runs +BUILD_SUCCESS=true + echo "" ok "=== Build Complete ===" echo " Version: $VERSION"