feat(switch): embed build-info metadata in artifacts

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Andrew Quenehen
2026-08-01 04:31:57 -03:00
parent 8982952fa4
commit 6ad8c8d73d
3 changed files with 142 additions and 12 deletions
+50 -12
View File
@@ -3,41 +3,79 @@
#
# Usage:
# scripts/build_switch.sh --loose [path/to/game.love]
# scripts/build_switch.sh --fused [--version X.Y.Z]
#
# Additional modes (fused NRO) are added in later tasks.
# Loose mode copies pinned love.nro + game.love. Fused mode builds a single
# gen1recomp-<ver>-switch.nro via devkitPro nacptool/elf2nro (requires tools).
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
WORK="$ROOT/.bazinga/work"
DIST="$ROOT/dist/switch"
LOOSE=0
FUSED=0
GAME_LOVE=""
VERSION="$(git -C "$ROOT" rev-parse --short HEAD 2>/dev/null || echo dev)"
say() { printf '\033[1;32m==>\033[0m %s\n' "$*"; }
fail() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; }
while [ $# -gt 0 ]; do
case "$1" in
--loose) LOOSE=1; shift ;;
--fused) FUSED=1; shift ;;
--version) VERSION="$2"; shift 2 ;;
-h|--help)
sed -n '2,8p' "$0" | sed 's/^# \{0,1\}//'
sed -n '2,10p' "$0" | sed 's/^# \{0,1\}//'
exit 0
;;
*)
if [ -z "$GAME_LOVE" ]; then
GAME_LOVE="$1"
else
echo "unknown argument: $1" >&2
exit 2
fail "unknown argument: $1"
fi
shift
;;
esac
done
if [ "$LOOSE" -eq 1 ]; then
if [ -n "$GAME_LOVE" ]; then
exec "$ROOT/scripts/switch/assemble_loose.sh" "$GAME_LOVE"
else
exec "$ROOT/scripts/switch/assemble_loose.sh"
fi
if [ "$LOOSE" -eq 1 ] && [ "$FUSED" -eq 1 ]; then
fail "choose one of --loose or --fused"
fi
echo "error: specify --loose (fused build not implemented yet)" >&2
exit 2
pack_game_love() {
mkdir -p "$WORK" "$DIST"
local build_info="$WORK/build-info.json"
"$ROOT/scripts/switch/write_build_info.sh" "$build_info" "$VERSION"
local love_out="$WORK/game.love"
local listing="$WORK/love-listing.txt"
"$ROOT/scripts/pack_love.sh" \
--output "$love_out" \
--listing "$listing" \
--build-info "$build_info" >/dev/null
cp "$build_info" "$DIST/build-info.json"
cp "$build_info" "$DIST/gen1recomp-${VERSION}-build-info.json"
printf '%s' "$love_out"
}
if [ "$LOOSE" -eq 1 ]; then
if [ -z "$GAME_LOVE" ]; then
GAME_LOVE="$(pack_game_love)"
else
pack_game_love >/dev/null
fi
exec "$ROOT/scripts/switch/assemble_loose.sh" "$GAME_LOVE"
fi
if [ "$FUSED" -eq 1 ]; then
GAME_LOVE="$(pack_game_love)"
OUT_NRO="$DIST/gen1recomp-${VERSION}-switch.nro"
"$ROOT/scripts/switch/build_fused.sh" "$GAME_LOVE" "$VERSION" "$OUT_NRO"
cp "$WORK/build-info.json" "$DIST/gen1recomp-${VERSION}-build-info.json"
say "done. See $DIST/"
exit 0
fi
fail "specify --loose or --fused"
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Verify pinned love-nx binaries against the manifest checksums.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
LOVE_NX_TAG="11.5-nx1"
LOVE_NX_DIR="$ROOT/.bazinga/love-nx/$LOVE_NX_TAG"
MANIFEST="$ROOT/scripts/switch/love-nx-11.5-nx1.sha256"
fail() { printf 'error: %s\n' "$*" >&2; exit 1; }
read_manifest_hash() {
local name="$1"
local line hash
line="$(grep -E "^${name}[[:space:]]+" "$MANIFEST" | head -1 || true)"
[ -n "$line" ] || fail "manifest missing entry for $name"
hash="$(printf '%s' "$line" | awk '{print $2}')"
case "$hash" in
TBD_*|"") fail "manifest hash for $name is not filled in ($hash)" ;;
esac
printf '%s' "$hash"
}
verify_file() {
local name="$1"
local path="$LOVE_NX_DIR/$name"
local expected actual
expected="$(read_manifest_hash "$name")"
[ -f "$path" ] || fail "missing pinned $name at $path — fetch per docs/switch-development.md"
actual="$(shasum -a 256 "$path" | awk '{print $1}')"
[ "$actual" = "$expected" ] \
|| fail "$name checksum mismatch (expected $expected, got $actual)"
}
verify_file love.nro
verify_file love.elf
+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# Write build-info.json for Switch artifacts.
#
# Usage: scripts/switch/write_build_info.sh OUTPUT.json [VERSION]
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
LOVE_NX_TAG="11.5-nx1"
MANIFEST="$ROOT/scripts/switch/love-nx-11.5-nx1.sha256"
OUTPUT="${1:-}"
VERSION="${2:-}"
fail() { printf 'error: %s\n' "$*" >&2; exit 1; }
[ -n "$OUTPUT" ] || fail "usage: $0 OUTPUT.json [VERSION]"
[ -f "$MANIFEST" ] || fail "missing love-nx manifest: $MANIFEST"
if [ -z "$VERSION" ]; then
VERSION="$(git -C "$ROOT" rev-parse --short HEAD 2>/dev/null || echo dev)"
fi
GIT_COMMIT="$(git -C "$ROOT" rev-parse HEAD 2>/dev/null || echo unknown)"
GIT_SHORT="$(git -C "$ROOT" rev-parse --short HEAD 2>/dev/null || echo dev)"
BUILT_AT="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
read_manifest_hash() {
local name="$1"
local line hash
line="$(grep -E "^${name}[[:space:]]+" "$MANIFEST" | head -1 || true)"
[ -n "$line" ] || fail "manifest missing entry for $name"
hash="$(printf '%s' "$line" | awk '{print $2}')"
case "$hash" in
TBD_*|"") fail "manifest hash for $name is not filled in ($hash)" ;;
esac
printf '%s' "$hash"
}
LOVE_NRO_SHA="$(read_manifest_hash love.nro)"
LOVE_ELF_SHA="$(read_manifest_hash love.elf)"
mkdir -p "$(dirname "$OUTPUT")"
cat > "$OUTPUT" <<EOF
{
"version": "$VERSION",
"gitCommit": "$GIT_SHORT",
"gitCommitFull": "$GIT_COMMIT",
"loveNxTag": "$LOVE_NX_TAG",
"loveNxChecksums": {
"love.nro": "$LOVE_NRO_SHA",
"love.elf": "$LOVE_ELF_SHA"
},
"builtAt": "$BUILT_AT"
}
EOF