Files
tidewall/tools/dist.sh
T
claudeandClaude Opus 5.5 4439d9a84f R1: Linux export pipeline (make dist, make dist-check)
make dist (tools/dist.sh) checks the official export templates against
tools/engine.sha512, installs only the Linux x86_64 ones into the
repo-local engine data, exports the "Linux" preset, checks the binary is
the verified release template, and packs
build/dist/tidewall-<version>-linux-x86_64.tar.gz with a .sha256:
tidewall.x86_64, tidewall.pck, a tidewall-server launcher that runs the
same game headless with clean SIGTERM handling, an example server.cfg,
README, VERSION, licences and asset provenance.

BuildInfo gives the version (application/config/version, now 0.9.0) and
the commit (build_commit.txt written by make dist, or .git in a
checkout). The main menu shows "Version 0.9.0 (commit)" and the server's
start log line carries version and commit.

make dist-check (tools/dist_check.sh) unpacks the package outside the
repo with HOME and XDG dirs in a temp dir and runs smoke against it
(new SMOKE_DIST mode), a whole bot match, and the exported game joining
the exported server over loopback.

A release template crashes on a call on null (exit 139) and ignores
invalid calls, so in package mode smoke's fault check expects only a
non-zero exit.

Closes #60

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 23:51:36 -05:00

97 lines
4.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# R1: exports the Linux x86_64 game, which is also the dedicated server, with the
# official Godot export templates and packs them into build/dist/tidewall-<version>-linux-x86_64.tar.gz.
#
# tools/dist.sh
#
# The templates come from tools/godot/ (git-ignored), checked against
# tools/engine.sha512 before use, and are installed into the repo-local engine data
# (.godot-home/), never the user's home. The version is project.godot's
# application/config/version; the commit is written into the export as
# build_commit.txt, which BuildInfo reads.
#
# The package holds:
# tidewall.x86_64 the engine (the official release template)
# tidewall.pck the game
# tidewall-server runs the same game headless as a dedicated server, with
# clean SIGTERM handling
# server.cfg an example server configuration
# LICENSE, LICENSE-ASSETS, README.md, PROVENANCE.md, VERSION
set -euo pipefail
repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo"
engine_version="$(cut -d. -f1-3 tools/engine.version)" # 4.7.2
engine_tag="${engine_version}.$(cut -d. -f4 tools/engine.version)" # 4.7.2.stable
templates_zip="tools/godot/Godot_v${engine_version}-stable_export_templates.tpz"
templates_dir=".godot-home/data/godot/export_templates/$engine_tag"
version="$(sed -n 's/^config\/version="\(.*\)"$/\1/p' project.godot)"
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "dist FAIL: no version in project.godot" >&2; exit 1; }
commit="$(git rev-parse --short=12 HEAD)"
if [[ -n "$(git status --porcelain --untracked-files=no)" ]]; then
commit="$commit-dirty"
fi
name="tidewall-$version-linux-x86_64"
out="build/dist"
stage="$out/stage"
package="$out/$name"
tools/godot.sh --verify >/dev/null
# The official templates, checked, then only the Linux x86_64 ones installed.
if [[ ! -f "$templates_dir/linux_release.x86_64" || "$(cat "$templates_dir/.verified" 2>/dev/null)" != "$(grep 'export_templates\.tpz$' tools/engine.sha512 | cut -d' ' -f1)" ]]; then
[[ -f "$templates_zip" ]] || { echo "dist FAIL: missing $templates_zip (see tools/godot.sh)" >&2; exit 1; }
echo "dist: checking the export templates against tools/engine.sha512" >&2
grep 'export_templates\.tpz$' tools/engine.sha512 | sha512sum --check --quiet
mkdir -p "$templates_dir"
unzip -q -o -j "$templates_zip" templates/linux_release.x86_64 templates/linux_debug.x86_64 templates/version.txt -d "$templates_dir"
[[ "$(cat "$templates_dir/version.txt")" == "$engine_tag" ]] || { echo "dist FAIL: templates are for $(cat "$templates_dir/version.txt"), not $engine_tag" >&2; exit 1; }
grep 'export_templates\.tpz$' tools/engine.sha512 | cut -d' ' -f1 >"$templates_dir/.verified"
fi
rm -rf "$stage" "$package" "$out/$name.tar.gz" "$out/$name.tar.gz.sha256"
mkdir -p "$stage" "$package"
trap 'rm -f "$repo/build_commit.txt"' EXIT
printf '%s\n' "$commit" >build_commit.txt
tools/godot.sh --import --quit >/dev/null 2>&1 || true
export_preset() {
local preset="$1" target="$2" raw
echo "dist: exporting '$preset'" >&2
if ! raw="$(tools/godot.sh --export-release "$preset" "$repo/$target" 2>&1)"; then
echo "dist FAIL: exporting '$preset' failed" >&2
tail -n 20 <<<"$raw" >&2
exit 1
fi
if grep -E '^(ERROR|SCRIPT ERROR)' <<<"$raw" >&2; then
echo "dist FAIL: errors while exporting '$preset'" >&2
exit 1
fi
[[ -f "$repo/$target" ]] || { echo "dist FAIL: '$preset' wrote no $target" >&2; exit 1; }
}
export_preset "Linux" "$stage/tidewall.x86_64"
rm -f build_commit.txt
# The exported binary must be the verified official template, unchanged.
cmp -s "$stage/tidewall.x86_64" "$templates_dir/linux_release.x86_64" || { echo "dist FAIL: the exported binary isn't the release template" >&2; exit 1; }
install -m 0755 "$stage/tidewall.x86_64" "$package/tidewall.x86_64"
install -m 0644 "$stage/tidewall.pck" "$package/tidewall.pck"
install -m 0755 packaging/dist/tidewall-server "$package/tidewall-server"
install -m 0644 LICENSE LICENSE-ASSETS "$package/"
install -m 0644 packaging/server/server.cfg "$package/server.cfg"
install -m 0644 packaging/dist/README.md "$package/README.md"
install -m 0644 assets/PROVENANCE.md "$package/PROVENANCE.md"
printf 'Tidewall %s\ncommit %s\nengine Godot %s\n' "$version" "$commit" "$(cat tools/engine.version)" >"$package/VERSION"
# Reproducible-ish archive: fixed owner, sorted names, mtimes from the commit.
stamp="$(git log -1 --format=%ct)"
tar --sort=name --owner=0 --group=0 --numeric-owner --mtime="@$stamp" \
-C "$out" -czf "$out/$name.tar.gz" "$name"
(cd "$out" && sha256sum "$name.tar.gz" >"$name.tar.gz.sha256")
rm -rf "$stage"
echo "dist: $out/$name.tar.gz ($(du -h "$out/$name.tar.gz" | cut -f1)), commit $commit"
tar -tzvf "$out/$name.tar.gz" | awk '{print " " $3 "\t" $6}'