cryptol/cry
2020-07-24 14:12:41 -07:00

78 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
BIN=bin
function setup_external_tools() {
[[ -x "$BIN/test-runner" || -x "$BIN/test-runner.exe" ]] && return
cabal v2-install --install-method=copy --installdir="$BIN" test-lib
}
function show_usage() {
cat << EOM
Usage: $0 COMMAND COMANND_OPTIONS
Available commands:
run Run Cryptol
build Build Cryptol
haddock Generate Haddock documentation
test Run some tests
exe-path Print the location of the local executable
EOM
}
if [ "$#" == "0" ]; then
show_usage
exit 1
fi
COMMAND=$1
shift
case $COMMAND in
run) cabal v2-exec cryptol -- $* ;;
build)
echo Building Cryptol
# XXX: This is a workaround the fact that currently Cabal
# will not rebuild this file, even though it has TH code, that
# depends on the environment. For now, we temporarily modify the
# file, then build, then revert it back after build.
dirty_string="-- Last build $(date)"
echo "$dirty_string" >> src/GitRev.hs
if [[ -n "$RELEASE" ]]; then
sed -i.bak -e 's/^commitShortHash = .*$/commitShortHash = "UNKNOWN"/' \
-e 's/^commitHash = .*$/commitHash = "UNKNOWN"/' \
-e 's/^commitBranch = .*$/commitBranch = "UNKNOWN"/' \
-e 's/^commitDirty = .*$/commitDirty = False/' \
-e '/import qualified GitRev/d' \
src/Cryptol/Version.hs
rm -f src/Cryptol/Version.hs.bak
fi
cabal v2-build "$@" exe:cryptol
sed -i.bak "/^-- Last build/d" src/GitRev.hs
rm -f src/GitRev.hs.bak
;;
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 ;;
exe-path) cabal v2-exec which cryptol ;;
*) echo "Unrecognized command: $COMMAND" && show_usage && exit 1 ;;
esac