#!/bin/bash
# Generates debian/tests/control from control.in plus discovered C++ test binaries.
#
# Usage: bash gencontrol.sh [SEARCH_ROOT] [OUTPUT]
#   SEARCH_ROOT: directory to scan for test binaries (default: /usr/lib/libtorch-test/)
#   OUTPUT:      file to write (default: ./control)
#
# When running manually with no SEARCH_ROOT, bin:libtorch-test must be installed.
set -e
SEARCH_ROOT="${1:-/usr/lib/libtorch-test/}"
OUTPUT="${2:-control}"
DIR="$(cd "$(dirname "$0")" && pwd)"

if [ ! -d "${SEARCH_ROOT}" ]; then
	echo "ERROR: search root '${SEARCH_ROOT}' does not exist." >&2
	echo "If running manually, ensure bin:libtorch-test is installed first." >&2
	exit 1
fi

cp "${DIR}/control.in" "${OUTPUT}"
bash "${DIR}/gencontrol-cpptest.sh" "${SEARCH_ROOT}" >> "${OUTPUT}"

#bash "${DIR}/gencontrol-pytest.sh" >> "${OUTPUT}"
