#!/bin/sh
# Builds ITGmania 1.3.0 (github.com/itgmania/itgmania, tag v1.3.0, commit 8a3bf8884a, the
# official release's build) with only the timing harness (itgmania-1.3.0-timing-harness.patch,
# which adds lines and changes none), in ITGmania's own build container (Utils/Dockerfile-linux),
# into .build/itgmania-1.3.0-harness-<arch>/, and prints the binary's SHA-256. It builds for this
# machine's architecture, as ./verify.sh timing runs (PLATFORM=linux/amd64 or linux/arm64 for another).
#
# tests/timing/build_itgmania.sh
set -eu
KIT=$(cd "$(dirname "$0")/../.." && pwd)
SRC="$KIT/.build/itgmania-1.3.0"
case "$(uname -m)" in
x86_64 | amd64) NATIVE=linux/amd64 ;;
arm64 | aarch64) NATIVE=linux/arm64 ;;
*) NATIVE="linux/$(uname -m)" ;;
esac
PLATFORM=${PLATFORM:-$NATIVE}
ARCH=${PLATFORM#linux/}
OUT="$KIT/.build/itgmania-1.3.0-harness-$ARCH"
COMMIT=8a3bf8884acdcb69363f7f0ea592138e398c71e4
[ -d "$SRC/.git" ] || git clone -q --branch v1.3.0 --depth 1 https://github.com/itgmania/itgmania.git "$SRC"
cd "$SRC"
[ "$(git rev-parse HEAD)" = "$COMMIT" ] || { echo "$SRC isn't ITGmania 1.3.0" >&2; exit 1; }
# Submodules at the commits 1.3.0 pins (a shallow clone can't find some of them by branch).
git config -f .gitmodules --get-regexp 'submodule\..*\.path' | while read -r key sub; do
name=${key#submodule.}
name=${name%.path}
url=$(git config -f .gitmodules --get "submodule.$name.url")
sha=$(git ls-tree HEAD "$sub" | awk '{print $3}')
[ "$(git -C "$sub" rev-parse HEAD 2>/dev/null)" = "$sha" ] && continue
rm -rf "$sub"
mkdir -p "$sub"
(cd "$sub" && git init -q && git remote add origin "$url" && git fetch -q --depth 1 origin "$sha" && git checkout -q FETCH_HEAD)
done
# The release's sources, then the harness alone.
git reset -q HEAD -- src
git checkout -q -- src
git clean -qfd src
git apply "$KIT/tests/timing/itgmania-1.3.0-timing-harness.patch"
docker build --platform "$PLATFORM" -q -t itgmania-1.3.0-build -f Utils/Dockerfile-linux Utils >/dev/null
docker run --rm --platform "$PLATFORM" -v "$SRC:/src" -w /src itgmania-1.3.0-build sh -c \
"cmake -B Build-harness-$ARCH -DCMAKE_BUILD_TYPE=Release >/dev/null && cmake --build Build-harness-$ARCH -j \$(nproc) >/dev/null"
rm -rf "$OUT"
mkdir -p "$OUT"
for d in Announcers BGAnimations BackgroundEffects BackgroundTransitions Characters Courses Data NoteSkins Scripts Themes; do
cp -R "$SRC/$d" "$OUT/"
done
cp "$SRC/itgmania" "$OUT/"
if command -v sha256sum >/dev/null; then sha256sum "$OUT/itgmania"; else shasum -a 256 "$OUT/itgmania"; fi