#!/usr/bin/env bash # Builds dump2png (see dump2png/main.go) inside modding/mdlp-image's Go # toolchain - dump2png has no cgo dependencies of its own, so it reuses that # image rather than needing one of its own, same reasoning as # modding/gen_animgallery.sh. # # Usage: ./build-dump2png.sh # is relative to the repository root (typically # dist/dump2png - see the root Makefile's dist_debug target and # README.md's "Debugging" section) - it's written on both sides of the # bind mount below, so an absolute or ../-escaping path won't resolve to # the same file on the host afterward. set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" REPO_ROOT="$(cd .. && pwd)" [ "$#" -eq 1 ] || { echo "usage: $0 " >&2; exit 1; } OUT_PATH="$1" case "$OUT_PATH" in /*) echo "PREFLIGHT FAIL: must be relative to the repo root, not absolute: $OUT_PATH" >&2; exit 1 ;; esac fail() { echo "PREFLIGHT FAIL: $*" >&2; exit 1; } command -v docker >/dev/null 2>&1 \ || fail "docker not found in PATH" IMAGE="${MDLP_REGISTRY_IMAGE:-questshock/mdlp}" if [ -f "$REPO_ROOT/registry.env" ]; then # shellcheck disable=SC1091 source "$REPO_ROOT/registry.env" IMAGE="${MDLP_REGISTRY_IMAGE:-$IMAGE}" fi IMAGE_TAG="$(<"$REPO_ROOT/modding/mdlp-image/VERSION")" [ -n "$IMAGE_TAG" ] || fail "modding/mdlp-image/VERSION is empty" IMAGE="$IMAGE:$IMAGE_TAG" docker image inspect "$IMAGE" >/dev/null 2>&1 \ || fail "$IMAGE not found locally - run modding/mdlp-image.sh first" docker run --rm \ -v "$REPO_ROOT:/workspace" \ -w /workspace \ -e HOST_UID="$(id -u)" \ -e HOST_GID="$(id -g)" \ "$IMAGE" \ bash -c ' set -euo pipefail # dump2png builds against ../../modding/src/hacked via its own # go.mod replace (matching that relative depth exactly, since # engine-debug-tools/ sits next to modding/ at the repo root) - # stage a patched copy (see modding/src/hacked-patches/) at that # same relative position rather than building against the # unpatched vendored source. SCRATCH_DIR="engine-debug-tools/build/dump2png-src" rm -rf "$SCRATCH_DIR" mkdir -p "$SCRATCH_DIR/engine-debug-tools" bash modding/mdlp-image/stage-hacked.sh modding "$SCRATCH_DIR/modding/src/hacked" cp -a engine-debug-tools/dump2png "$SCRATCH_DIR/engine-debug-tools/dump2png" mkdir -p "$(dirname "/workspace/$1")" (cd "$SCRATCH_DIR/engine-debug-tools/dump2png" && go build -o "/workspace/$1" .) ' _ "$OUT_PATH" echo "Built: $OUT_PATH"