147 lines
5.2 KiB
Bash
Executable file
147 lines
5.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Export a single platform via Godot headless.
|
|
#
|
|
# Usage: tools/export-single.sh <platform> [version] [--debug]
|
|
# platform: macos | linux | windows | android | ios
|
|
# version: defaults to YYYYMMDD_HHMMSS
|
|
# --debug: debug build (default: release)
|
|
#
|
|
# Output: .local/build/godot/<version>/<platform>/<artifact>
|
|
#
|
|
# Requires: Godot editor CLI on PATH (`godot` on macOS, `flatpak run --user org.godotengine.Godot` on Linux),
|
|
# and export presets configured in src/game/export_presets.cfg.
|
|
#
|
|
# This script is the lowest-level single-platform export. `tools/export.sh` calls it in parallel
|
|
# across all platforms.
|
|
|
|
set -uo pipefail
|
|
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
DIM='\033[2m'
|
|
NC='\033[0m'
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
GAME_DIR="$REPO_ROOT/src/game"
|
|
PRESETS_FILE="$GAME_DIR/export_presets.cfg"
|
|
|
|
platform="${1:-}"
|
|
version=""
|
|
debug=false
|
|
|
|
shift 2>/dev/null || true
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--debug) debug=true ;;
|
|
*) version="$arg" ;;
|
|
esac
|
|
done
|
|
version="${version:-$(date +%Y%m%d_%H%M%S)}"
|
|
|
|
if [ -z "$platform" ]; then
|
|
echo -e "${RED}Usage: $0 <platform> [version] [--debug]${NC}"
|
|
echo " platforms: macos | linux | windows | android | ios"
|
|
exit 1
|
|
fi
|
|
|
|
# ── Preset & artifact resolution per platform ────────────────────────
|
|
# Preset names follow the convention "<Platform>" matching export_presets.cfg entries.
|
|
case "$platform" in
|
|
macos)
|
|
preset_name="macOS"
|
|
artifact="MagicCivilization.zip"
|
|
;;
|
|
linux)
|
|
preset_name="Linux/X11"
|
|
artifact="MagicCivilization.x86_64"
|
|
;;
|
|
windows)
|
|
preset_name="Windows Desktop"
|
|
artifact="MagicCivilization.exe"
|
|
;;
|
|
android)
|
|
preset_name="Android"
|
|
artifact="MagicCivilization.apk"
|
|
;;
|
|
ios)
|
|
preset_name="iOS"
|
|
artifact="MagicCivilization.xcodeproj" # Godot emits an Xcode project, not an ipa
|
|
;;
|
|
*)
|
|
echo -e "${RED}Unknown platform: $platform${NC}"
|
|
echo "Supported: macos, linux, windows, android, ios"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# ── Preset existence check ───────────────────────────────────────────
|
|
if [ ! -f "$PRESETS_FILE" ]; then
|
|
echo -e "${RED}Missing $PRESETS_FILE${NC}"
|
|
echo ""
|
|
echo -e "${YELLOW}Export presets have not been authored yet.${NC} To create them:"
|
|
echo " 1. Open Godot editor: ./run editor"
|
|
echo " 2. Project → Export..."
|
|
echo " 3. Add presets for: macOS, Linux/X11, Windows Desktop, Android, iOS"
|
|
echo " 4. Save (Godot writes export_presets.cfg to $GAME_DIR/)"
|
|
echo " 5. Commit the file"
|
|
echo " 6. Re-run: ./run install:$platform"
|
|
exit 2
|
|
fi
|
|
|
|
if ! grep -q "^name=\"$preset_name\"" "$PRESETS_FILE" 2>/dev/null; then
|
|
echo -e "${RED}Preset \"$preset_name\" not found in $PRESETS_FILE${NC}"
|
|
echo -e "${YELLOW}Open Godot → Project → Export → add a preset named exactly \"$preset_name\".${NC}"
|
|
exit 2
|
|
fi
|
|
|
|
# ── Godot binary resolution ──────────────────────────────────────────
|
|
# Prefer $GODOT_BIN if set (set by scripts/run/common.sh on macOS).
|
|
# Fall back to OS default.
|
|
if [ -n "${GODOT_BIN:-}" ]; then
|
|
godot_cmd="$GODOT_BIN"
|
|
elif command -v godot &>/dev/null; then
|
|
godot_cmd="godot"
|
|
elif command -v flatpak &>/dev/null && flatpak info --user org.godotengine.Godot &>/dev/null; then
|
|
godot_cmd="flatpak run --user org.godotengine.Godot"
|
|
elif command -v flatpak &>/dev/null && flatpak info org.godotengine.Godot &>/dev/null; then
|
|
godot_cmd="flatpak run org.godotengine.Godot"
|
|
else
|
|
echo -e "${RED}No Godot binary found. Run: ./run setup${NC}"
|
|
exit 3
|
|
fi
|
|
|
|
# ── Output path ──────────────────────────────────────────────────────
|
|
out_dir="$REPO_ROOT/.local/build/godot/$version/$platform"
|
|
out_path="$out_dir/$artifact"
|
|
mkdir -p "$out_dir"
|
|
|
|
# ── Export flag ──────────────────────────────────────────────────────
|
|
if $debug; then
|
|
flag="--export-debug"
|
|
mode_label="debug"
|
|
else
|
|
flag="--export-release"
|
|
mode_label="release"
|
|
fi
|
|
|
|
echo -e "${BLUE}Exporting $platform ($mode_label) → $out_path${NC}"
|
|
echo -e "${DIM}preset: $preset_name${NC}"
|
|
echo -e "${DIM}godot: $godot_cmd${NC}"
|
|
|
|
# ── Run the export ───────────────────────────────────────────────────
|
|
# shellcheck disable=SC2086
|
|
if $godot_cmd --headless --path "$GAME_DIR" "$flag" "$preset_name" "$out_path" 2>&1; then
|
|
if [ -e "$out_path" ]; then
|
|
size="$(du -h "$out_path" 2>/dev/null | cut -f1)"
|
|
echo -e "${GREEN} ✓ Exported $artifact ($size)${NC}"
|
|
exit 0
|
|
else
|
|
echo -e "${RED} ✗ Export reported success but $out_path is missing${NC}"
|
|
exit 4
|
|
fi
|
|
else
|
|
echo -e "${RED} ✗ Godot export failed${NC}"
|
|
exit 5
|
|
fi
|