LuckyWorld/scripts/mac_build.sh

237 lines
8.2 KiB
Bash
Raw Normal View History

#!/bin/bash
# Get the user's home directory
USER_HOME="$HOME"
# Set up Unreal Engine paths
UE_ROOT="/Users/Shared/Epic Games/UE_5.5"
UE_EDITOR="$UE_ROOT/Engine/Binaries/Mac/UnrealEditor.app/Contents/MacOS/UnrealEditor"
UE_UAT="$UE_ROOT/Engine/Build/BatchFiles/RunUAT.command"
# Set up project paths
PROJECT_ROOT="$(pwd)"
2025-04-10 07:17:18 -05:00
PROJECT_FILE="$PROJECT_ROOT/LuckyWorld.uproject"
ARCHIVE_DIR="$PROJECT_ROOT/Builds"
# Check for entitlements file
if [ -f "$PROJECT_ROOT/LuckyWorld.entitlements" ]; then
ENTITLEMENTS_FILE="$PROJECT_ROOT/LuckyWorld.entitlements"
else
echo "Warning: No entitlements file found. This might affect notarization."
ENTITLEMENTS_FILE=""
fi
# For debugging: print paths and config
echo "Project root: $PROJECT_ROOT"
echo "Project file: $PROJECT_FILE"
echo "Archive directory: $ARCHIVE_DIR"
echo "Entitlements file: $ENTITLEMENTS_FILE"
# Clean up previous build artifacts
2025-04-10 07:17:18 -05:00
rm -rf DerivedDataCache Intermediate Binaries Saved
# Generate project files
2025-04-10 07:17:18 -05:00
"$UE_ROOT/Engine/Build/BatchFiles/Mac/GenerateProjectFiles.sh" -project="$PROJECT_FILE" -game -engine
# Run the build command
"$UE_UAT" -ScriptsForProject="$PROJECT_FILE" Turnkey \
-command=VerifySdk \
-platform=Mac \
-UpdateIfNeeded \
-EditorIO \
-EditorIOPort=59484 \
-project="$PROJECT_FILE" \
BuildCookRun \
-nop4 \
-utf8output \
-cook \
-project="$PROJECT_FILE" \
2025-04-10 07:17:18 -05:00
-target=LuckyWorld \
-unrealexe="$UE_EDITOR" \
-platform=Mac \
-installed \
-stage \
-archive \
-package \
-build \
-iterativecooking \
-pak \
-iostore \
-compressed \
-prereqs \
-archivedirectory="$ARCHIVE_DIR" \
-CrashReporter \
-clientconfig=Shipping \
# -nocompile \
# -nocompileuat \
# -nocompileeditor \
# -skipbuildeditor \
BUILD_EXIT_CODE=$?
echo ""
echo "🦾 Build process completed with exit code: $BUILD_EXIT_CODE"
# Debug check for where the app might be
echo "📂 Checking potential build output locations:"
echo "Saved directory contents (if exists):"
ls -la Saved 2>/dev/null || echo "Saved directory not found"
echo "Saved/StagedBuilds directory contents (if exists):"
ls -la Saved/StagedBuilds 2>/dev/null || echo "Saved/StagedBuilds directory not found"
echo "Builds directory contents:"
ls -la "$ARCHIVE_DIR" 2>/dev/null || echo "Builds directory not found"
echo "Builds/Mac directory contents (if exists):"
ls -la "$ARCHIVE_DIR/Mac" 2>/dev/null || echo "Builds/Mac directory not found"
# Find the app, regardless of build success
echo "🔍 Searching for .app bundles in Saved and Builds directories:"
APP_PATH=""
for search_dir in "$ARCHIVE_DIR" "$ARCHIVE_DIR/Mac" "Saved/StagedBuilds" "Saved/StagedBuilds/Mac" "Saved"; do
if [ -d "$search_dir" ]; then
echo "Searching in $search_dir"
APP_FOUND=$(find "$search_dir" -name "*.app" -type d | head -n 1)
if [ -n "$APP_FOUND" ]; then
APP_PATH="$APP_FOUND"
echo "Found app bundle at: $APP_PATH"
break
fi
fi
done
if [ -z "$APP_PATH" ]; then
echo "❌ No app bundle found. Build may have failed or output location is unexpected."
# Set a fake path for debug tests
if [ -n "$CI" ]; then
echo "This is a CI environment, continuing with error checks..."
else
echo "Exiting with error code from build"
exit $BUILD_EXIT_CODE
fi
else
echo "🦾 Build completed. Application path:"
echo "$APP_PATH"
echo ""
echo "🔍 Binary files that will need signing:"
DYLIB_COUNT=$(find "$APP_PATH" -name "*.dylib" | wc -l)
SO_COUNT=$(find "$APP_PATH" -name "*.so" | wc -l)
FRAMEWORKS=$(find "$APP_PATH" -path "*.framework/*" -type f -perm +111 | wc -l)
EXECUTABLES=$(find "$APP_PATH" -type f -perm +111 -not -path "*.framework/*" -not -name "*.dylib" -not -name "*.so" | wc -l)
echo "- $DYLIB_COUNT .dylib libraries"
echo "- $SO_COUNT .so libraries"
echo "- $FRAMEWORKS framework executables"
echo "- $EXECUTABLES other executables"
echo "Total binary files: $((DYLIB_COUNT + SO_COUNT + FRAMEWORKS + EXECUTABLES))"
echo ""
echo "🔍 Checking for PhysX and other special libraries (often need special handling):"
find "$APP_PATH" -name "*PhysX*" -o -name "*APEX*"
fi
# Update bundle ID in project settings
echo ""
echo "🔧 Checking for bundle ID in UE config..."
CONFIG_FILE="$PROJECT_ROOT/Config/DefaultGame.ini"
if [ -f "$CONFIG_FILE" ]; then
if grep -q "\[/Script/MacTargetPlatform\.MacTargetSettings\]" "$CONFIG_FILE" && grep -q "BundleIdentifier=com.luckyrobots.luckyworld" "$CONFIG_FILE"; then
echo "Bundle ID already correctly set in project config ✅"
else
echo "⚠️ Warning: Bundle ID may not be correctly set in DefaultGame.ini"
echo "Please ensure [/Script/MacTargetPlatform.MacTargetSettings] section exists with BundleIdentifier=com.luckyrobots.luckyworld"
fi
else
echo "⚠️ Config file not found at $CONFIG_FILE"
fi
# Post-build process - set bundle ID
echo ""
echo "🔧 Performing post-build fix for bundle ID..."
# First verify that APP_PATH is defined and exists
if [ -z "$APP_PATH" ]; then
echo "⚠️ APP_PATH is not defined, trying to find the app bundle again..."
# Try to find the app bundle in common locations
for search_dir in "$ARCHIVE_DIR" "$ARCHIVE_DIR/Mac" "Saved/StagedBuilds" "Saved/StagedBuilds/Mac" "Saved"; do
if [ -d "$search_dir" ]; then
APP_FOUND=$(find "$search_dir" -name "*.app" -type d | head -n 1)
if [ -n "$APP_FOUND" ]; then
APP_PATH="$APP_FOUND"
echo "✅ Found app bundle at: $APP_PATH"
break
fi
fi
done
if [ -z "$APP_PATH" ]; then
echo "❌ ERROR: Could not find any app bundle. Skipping bundle ID fix."
# Don't exit, just skip this part
APP_PATH=""
fi
fi
if [ -n "$APP_PATH" ] && [ -d "$APP_PATH" ]; then
INFO_PLIST="$APP_PATH/Contents/Info.plist"
if [ -f "$INFO_PLIST" ]; then
CURRENT_BUNDLE_ID=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$INFO_PLIST" 2>/dev/null)
echo "Current bundle ID: $CURRENT_BUNDLE_ID"
if [ $? -ne 0 ] || [ "$CURRENT_BUNDLE_ID" != "com.luckyrobots.luckyworld" ]; then
echo "Bundle ID mismatch or not set - fixing it!"
echo "Setting bundle identifier to com.luckyrobots.luckyworld"
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier com.luckyrobots.luckyworld" "$INFO_PLIST"
UPDATED_ID=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$INFO_PLIST" 2>/dev/null)
if [ $? -eq 0 ]; then
echo "Updated bundle ID: $UPDATED_ID"
else
echo "⚠️ Failed to update bundle ID"
fi
else
echo "Bundle ID is already correct: com.luckyrobots.luckyworld"
fi
# Set the application name to "LuckyWorld" instead of "LuckyWorld-Mac-Shipping"
echo "Setting application name to LuckyWorld..."
/usr/libexec/PlistBuddy -c "Set :CFBundleName LuckyWorld" "$INFO_PLIST"
UPDATED_NAME=$(/usr/libexec/PlistBuddy -c "Print :CFBundleName" "$INFO_PLIST" 2>/dev/null)
if [ $? -eq 0 ]; then
echo "Updated app name: $UPDATED_NAME"
else
echo "⚠️ Failed to update app name"
fi
# Find and repair nested app bundles as well (like CrashReportClient.app)
echo "Checking for nested app bundles..."
NESTED_APPS=$(find "$APP_PATH" -name "*.app" -type d 2>/dev/null)
if [ -n "$NESTED_APPS" ]; then
echo "Found nested app bundles, fixing their bundle IDs:"
echo "$NESTED_APPS" | while read -r NESTED_APP; do
if [ -f "$NESTED_APP/Contents/Info.plist" ]; then
NESTED_NAME=$(basename "$NESTED_APP" .app)
NESTED_BUNDLE_ID="com.luckyrobots.luckyworld.$NESTED_NAME"
echo "Setting nested bundle ID to $NESTED_BUNDLE_ID for $NESTED_APP"
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $NESTED_BUNDLE_ID" "$NESTED_APP/Contents/Info.plist"
# Verify the change
UPDATED_ID=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$NESTED_APP/Contents/Info.plist" 2>/dev/null)
if [ $? -eq 0 ]; then
echo "Updated nested app bundle ID: $UPDATED_ID"
else
echo "⚠️ Failed to update nested app bundle ID for $NESTED_APP"
fi
fi
done
else
echo "No nested app bundles found."
fi
else
echo "⚠️ Info.plist not found at $INFO_PLIST"
fi
else
echo "⚠️ App bundle not found or APP_PATH is not valid. Skipping bundle ID fix."
fi