Files
psxrecomp/tools/fetch_toolchain.sh
Alex Vanderveen 3b5bf48305 Follow the RetroPortingToolKit transfer in submodule URLs and tooling
recomp-net, retcomm-rbengine (now rbengine), retcomm-toolchains (now
RetroPorting-Toolchains), the catalog and the launcher moved from
TechnicallyComputers to the RetroPortingToolKit org. GitHub still
redirects the old repo URLs, so nothing is broken today — but this repo
is what every port inherits its .gitmodules from, so the old owner
propagates into each new clone until it is fixed here.

.gitmodules now names the new URLs. The toolchain repo is updated in the
CI action default, the codegen host, fetch_toolchain.sh, toolchain_pack
and package_setup_host, and the scaffolder's recomp-net / rbengine
defaults follow.

Two things the mechanical sweep would have missed:

- render_launcher_block() held a second copy of the launcher slug split
  across two string literals, so a search for the full slug did not see
  it and every regenerated README kept the dead owner. It is now derived
  from LAUNCHER_REPO, which is the only place the slug lives.

- readme_has_launcher() matched one exact slug. Pointed at the new one
  alone it would report every port built before the transfer as missing
  its launcher section, and append a second copy to any README carrying
  neither the markers nor a "## RetComM Launcher" heading. It now
  accepts both.

The scaffolder's default GitHub owner for new ports becomes
RetroPortingToolKit. Existing ports are unaffected — they carry their
own owner in the README and remote.

psxrecomp, snesrecomp and recomp-ui did not move and still point at
mstan. Submodule paths (lib/recomp-net, lib/retcomm-rbengine) are
unchanged: they are pinned by every port and are not repo slugs.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018xfKkiEkh87zL1EpE5Ty55
2026-09-09 00:39:14 -04:00

134 lines
3.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Download and unpack a retcomm-toolchains cmake-clang-v1 pack.
#
# Usage:
# fetch_toolchain.sh --artifact <linux-x64|windows-x64|macos-arm64|macos-x64> \
# [--dl-dir DIR] [--out-dir DIR] [--repo OWNER/NAME]
#
# Prints: TOOLCHAIN_DIR=<absolute path with bin/>
# When GITHUB_ENV is set (Actions), also appends:
# TOOLCHAIN_DIR=...
# PSXRECOMP_TOOLCHAIN_DIR=...
# BPE_TOOLCHAIN_DIR=... (compat alias for existing title workflows)
#
# Env:
# GH_TOKEN / GITHUB_TOKEN — optional; used for gh or Authorization on curl
set -euo pipefail
ARTIFACT=""
DL_DIR=".cache/toolchain-dl"
OUT_DIR=".cache/toolchain-pack"
REPO="RetroPortingToolKit/RetroPorting-Toolchains"
usage() {
sed -n '2,16p' "$0" | sed 's/^# \{0,1\}//'
exit 2
}
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help) usage ;;
--artifact) ARTIFACT="${2:?}"; shift 2 ;;
--dl-dir) DL_DIR="${2:?}"; shift 2 ;;
--out-dir) OUT_DIR="${2:?}"; shift 2 ;;
--repo) REPO="${2:?}"; shift 2 ;;
*)
echo "error: unknown arg: $1" >&2
usage
;;
esac
done
if [[ -z "${ARTIFACT}" ]]; then
echo "error: --artifact is required" >&2
usage
fi
case "${ARTIFACT}" in
linux-x64)
PATTERN='cmake-clang-v1*linux*.zip'
ASSET_NAME='cmake-clang-v1-linux-x64.zip'
;;
windows-x64)
PATTERN='cmake-clang-v1*windows*.zip'
ASSET_NAME='cmake-clang-v1-windows-x64.zip'
;;
macos-arm64|macos-x64)
PATTERN='cmake-clang-v1*macos*.zip'
ASSET_NAME='cmake-clang-v1-macos-universal.zip'
;;
*)
echo "error: unknown artifact '${ARTIFACT}' (want linux-x64|windows-x64|macos-arm64|macos-x64)" >&2
exit 1
;;
esac
TOKEN="${GH_TOKEN:-${GITHUB_TOKEN:-}}"
rm -rf "${DL_DIR}" "${OUT_DIR}"
mkdir -p "${DL_DIR}" "${OUT_DIR}"
if command -v gh >/dev/null 2>&1; then
if [[ -n "${TOKEN}" ]]; then
export GH_TOKEN="${TOKEN}"
fi
gh release download -R "${REPO}" -p "${PATTERN}" -D "${DL_DIR}" --clobber
elif command -v curl >/dev/null 2>&1; then
ASSET_URL="https://github.com/${REPO}/releases/latest/download/${ASSET_NAME}"
echo "gh not on PATH; curling ${ASSET_URL}"
curl_args=(-fsSL -o "${DL_DIR}/${ASSET_NAME}")
if [[ -n "${TOKEN}" ]]; then
curl_args+=(-H "Authorization: Bearer ${TOKEN}")
fi
curl "${curl_args[@]}" "${ASSET_URL}"
else
echo "error: neither gh nor curl available to fetch toolchain pack" >&2
exit 1
fi
ZIP="$(find "${DL_DIR}" -maxdepth 1 -type f -name '*.zip' | head -n1)"
if [[ -z "${ZIP}" ]]; then
echo "error: no toolchain zip matching ${PATTERN}" >&2
ls -la "${DL_DIR}" >&2 || true
exit 1
fi
echo "Unpacking toolchain from ${ZIP}"
if command -v unzip >/dev/null 2>&1; then
unzip -q "${ZIP}" -d "${OUT_DIR}"
else
python3 -c '
import pathlib, zipfile, sys
z = next(pathlib.Path(sys.argv[1]).glob("*.zip"))
zipfile.ZipFile(z).extractall(sys.argv[2])
' "${DL_DIR}" "${OUT_DIR}"
fi
# Unwrap single top-level directory if present.
shopt -s nullglob
entries=("${OUT_DIR}"/*)
shopt -u nullglob
if [[ ${#entries[@]} -eq 1 && -d "${entries[0]}" ]]; then
TOOLCHAIN_DIR="$(cd "${entries[0]}" && pwd)"
else
TOOLCHAIN_DIR="$(cd "${OUT_DIR}" && pwd)"
fi
if [[ ! -d "${TOOLCHAIN_DIR}/bin" ]]; then
echo "error: toolchain pack missing bin/ under ${TOOLCHAIN_DIR}" >&2
find "${OUT_DIR}" -maxdepth 3 >&2 || true
exit 1
fi
echo "TOOLCHAIN_DIR=${TOOLCHAIN_DIR}"
if [[ -n "${GITHUB_ENV:-}" ]]; then
{
echo "TOOLCHAIN_DIR=${TOOLCHAIN_DIR}"
echo "PSXRECOMP_TOOLCHAIN_DIR=${TOOLCHAIN_DIR}"
echo "BPE_TOOLCHAIN_DIR=${TOOLCHAIN_DIR}"
} >>"${GITHUB_ENV}"
fi
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
echo "toolchain-dir=${TOOLCHAIN_DIR}" >>"${GITHUB_OUTPUT}"
fi