#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
RLM_DIR="$ROOT_DIR/tools/rcl-rlm"
WHEELHOUSE_DIR="$RLM_DIR/wheels"
REQUIREMENTS_FILE="$RLM_DIR/requirements.txt"

SYSTEM_PYTHON="$(command -v python3 || true)"
if [[ -z "$SYSTEM_PYTHON" ]]; then
  echo "python3 not found in PATH. Install Python to build the wheelhouse." >&2
  exit 1
fi

if [[ ! -f "$REQUIREMENTS_FILE" ]]; then
  echo "Missing $REQUIREMENTS_FILE." >&2
  exit 1
fi

mkdir -p "$WHEELHOUSE_DIR"

echo "Downloading wheels to $WHEELHOUSE_DIR"
"$SYSTEM_PYTHON" -m pip download \
  --only-binary=:all: \
  --dest "$WHEELHOUSE_DIR" \
  -r "$REQUIREMENTS_FILE"

echo "Wheelhouse ready."
