A Bash script to automate common cabal (v2) tasks

This commit is contained in:
Iavor Diatchki 2018-12-12 16:59:00 -08:00
parent d377f38c9d
commit 2bd9d3aecf
2 changed files with 71 additions and 41 deletions

71
cry Executable file
View File

@ -0,0 +1,71 @@
#!/bin/bash
BIN=bin
function setup_external_tools {
if [ ! -f "$BIN/test-runner" ]
then
mkdir -p "$BIN"
cabal v2-install --symlink-bindir="$BIN" test-runner
fi
}
function show_usage {
cat <<EOM
Usage: $0 COMMAND COMANND_OPTIONS
Available commands:
build Build Cryptol
haddock Generate Haddock documentation
test Run some tests
EOM
}
if [ "$#" == "0" ]
then
show_usage
exit 1
fi
COMMAND=$1
shift
case $COMMAND in
build)
echo Building Cryptol
cabal v2-build exe:cryptol;;
haddock)
echo Building Haddock documentation
cabal v2-haddock;;
test)
echo Running tests
setup_external_tools
if [ "$#" == "0" ]
then TESTS=tests
else TESTS=$*
fi
$BIN/test-runner --ext=.icry \
--exe=cabal \
-F v2-run -F -v0 -F exe:cryptol -F -- -F -b \
$TESTS
;;
help)
show_usage
exit 0;;
*)
echo Unrecognized command: $COMMAND
show_usage
exit 1;;
esac

View File

@ -1,41 +0,0 @@
#!/bin/bash
TEST_DIR=tests
ALL_TESTS=("modsys" "parser" "issues" "regression" "renamer" "mono-binds")
TESTS=()
if [ $# == 0 ]; then
declare -a TESTS
for i in ${!ALL_TESTS[*]}; do
TESTS[i]="$TEST_DIR/${ALL_TESTS[i]}"
done
else
TESTS=("$@")
fi
CRY_VERSION=$(grep Version: cryptol.cabal | awk '{print $2}')
if [ ${CRY_VERSION}x == "x" ]; then
echo Failed to guess version of Cryptol.
exit 1
fi
GHC_VERSION=$(ghc --numeric-version)
if [ ${GHC_VERSION}x == "x" ]; then
echo Failed to guess version of GHC.
exit 1
fi
echo Testing Cryptol version ${CRY_VERSION}, built using GHC ${GHC_VERSION}.
CRY=$(find dist-newstyle -name cryptol -type f \
| grep $GHC_VERSION \
| grep $CRY_VERSION)
cabal new-run cryptol-test-runner -- --exe $CRY --ignore-expected ${TESTS[*]}