build.sh 1.69 KB
Newer Older
1
#!/usr/bin/env bash
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

# A simple wrapper around stack
#
# This exists mainly to make it easier to pass arguments to test and benchmark
# suites.

if [[ $# -eq 0 ]]; then
    cat <<EOF
Usage: $0 COMMAND [OPTS]

Commands:
---------

b[uild] [OPTS]                  build project

17
[c]opy [OPTS]                   copy binaries to ./bin/
18

19 20 21 22 23 24 25 26 27 28 29 30 31 32
t[est] u[nit] [OPTS]            run unit tests
t[est] e[xamples] [OPTS]        run exampes
t[est] d[octests] [OPTS]        run doctests
t[est] [OPTS]                   run all testsuites

bench [OPTS]                    run the benchmark suite

r[un] [OPTS]                    run the main program

haddock [OPTS]                  build documentation
EOF
    exit 1
fi

33
doTest() {
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
    if [[ $# -eq 0 ]]; then
        exec stack test
    fi

    case "$1" in
        u|unit|s|spec)
            exec stack test :spec --test-arguments "${*:2}"
            ;;
        e|examples)
            exec stack test :examples --test-arguments "${*:2}"
            ;;
        d|doctests)
            exec stack test :doctests --test-arguments "${*:2}"
            ;;
        *)
            exec stack test "$@"
    esac
}

53
doBench() {
54 55 56
    exec stack bench :bench --benchmark-arguments "$*"
}

57 58 59
doCopy() {
    DIR=$(dirname "$0")/bin
    mkdir -p ${DIR}
60
    exec stack build --copy-bins --local-bin-path "${DIR}" "$@"
61 62
}

63 64 65 66
case "$1" in
    b|build)
        exec stack build "${@:2}"
        ;;
67 68 69
    c|copy)
	doCopy "${@:2}"
	;;
70 71 72 73 74 75 76
    t|test)
        doTest "${@:2}"
        ;;
    bench)
        doBench "${@:2}"
        ;;
    r|run)
77
        exec stack exec copar -- "${@:2}"
78 79
        ;;
    haddock)
80
        exec stack haddock :copar "${@:2}"
81 82 83 84 85
        ;;
    *)
        echo "Unknown command $1"
        exit 1
esac