#!/usr/bin/env bash # Export the Linux desktop build and, unless SKIP_SMOKE=1, prove it starts under # X11. Artifacts are intentionally ignored and can be recreated at any time. set -euo pipefail root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$root_dir" GODOT_BIN="${GODOT_BIN:-/snap/bin/godot4}" if [[ ! -x "$GODOT_BIN" ]]; then GODOT_BIN="$(command -v godot4 || command -v godot || true)" fi if [[ -z "$GODOT_BIN" ]]; then echo "build-linux: Godot executable not found; set GODOT_BIN." >&2 exit 2 fi preset="Linux/X11" output="build/linux/DungeonCrawlerWorld.x86_64" godot_version="$("$GODOT_BIN" --version)" template_version="${godot_version%%.official.*}" if [[ -n "${GODOT_EXPORT_TEMPLATES_DIR:-}" ]]; then templates_dir="$GODOT_EXPORT_TEMPLATES_DIR" else # Native and Flatpak Godot use these roots. The Snap owns its isolated # user-data directory, so query it rather than incorrectly using this shell's HOME. templates_dir="$HOME/.local/share/godot/export_templates/$template_version" if [[ "$GODOT_BIN" == /snap/* ]] && command -v snap >/dev/null 2>&1; then snap_data="$(snap run --shell godot4 -c 'printf %s "$SNAP_USER_DATA"' 2>/dev/null || true)" if [[ -n "$snap_data" ]]; then templates_dir="$snap_data/.local/share/godot/export_templates/$template_version" fi elif [[ -n "${XDG_DATA_HOME:-}" ]]; then templates_dir="$XDG_DATA_HOME/godot/export_templates/$template_version" fi fi if [[ ! -f "$templates_dir/linux_release.x86_64" ]]; then echo "build-linux: missing Godot export templates for $preset at $templates_dir (expected linux_release.x86_64). Install templates matching $template_version, or set GODOT_EXPORT_TEMPLATES_DIR." >&2 exit 2 fi mkdir -p "$(dirname "$output")" rm -f "$output" "$output.pck" "$GODOT_BIN" --headless --path . --export-release "$preset" "$output" if [[ ! -x "$output" ]]; then echo "build-linux: export did not create an executable artifact at $output." >&2 exit 1 fi if [[ ! -s "$output" ]]; then echo "build-linux: Linux artifact is empty: $output." >&2 exit 1 fi if [[ "${SKIP_SMOKE:-0}" == "1" ]]; then echo "build-linux: exported $output (smoke skipped by SKIP_SMOKE=1)" exit 0 fi runner=() if [[ -z "${DISPLAY:-}" ]]; then if ! command -v xvfb-run >/dev/null 2>&1; then echo "build-linux: X11 smoke unavailable: DISPLAY is unset and xvfb-run is not installed." >&2 exit 2 fi runner=(xvfb-run --auto-servernum --server-args="-screen 0 1920x1080x24") fi smoke_log="build/linux/smoke.log" # Capture mode gives the deterministic test fixture a graceful exit. Exported # PCK resources are read-only, so the capture is only an exit seam; startup # success and an error-free log are the portable release-smoke contract. set +e timeout --foreground 8s "${runner[@]}" "./$output" -- --capture >"$smoke_log" 2>&1 smoke_status=$? set -e if [[ "$smoke_status" -ne 0 ]]; then echo "build-linux: X11 smoke failed with status $smoke_status; see $smoke_log." >&2 exit "$smoke_status" fi if grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:' "$smoke_log"; then echo "build-linux: X11 smoke reported a Godot application error; see $smoke_log." >&2 exit 1 fi echo "build-linux: exported and X11-smoke-tested $output"