#!/bin/sh
# The archive at PiPy is not featuring the test suite files
# This script is fetching the files and creates a tarball that is suited for multi-source tarball
# This might be needed for version 4.13.1 and above

UGIT=https://github.com/antlr/antlr4/
UVERSION=$(dpkg-parsechangelog --file ./changelog | grep '^Version' | cut -d' ' -f2  | cut -f1 -d-)
tarball=$(dpkg-parsechangelog --file ./changelog | awk '/^Source:/ {print $2}')_${UVERSION}.orig-test.tar.gz
set -x

tmpdir=$(mktemp -d /tmp/python3-antlr4-testsuiteXXXX)
curdir=$PWD
cd $tmpdir

git clone ${UGIT}
cd antlr4
git checkout ${UVERSION}
mv runtime/Python3/tests ../test
cd ..

tar --owner=root --group=root --mode=a+rX -caf $tarball test
mv $tarball $curdir
cd $curdir

rm -rf $tmpdir
