Solver DSL: Support benchmarks, internal libraries, and foreign libraries.
[cabal.git] / validate.sh
blob2ac342f534dd9f622b5441c92108fafcc13cca22
1 #!/bin/sh
2 # shellcheck disable=SC2086
4 # Help
5 if [ "$1" = "help" ]; then
6 cat <<EOF
7 This is a helper script to build and run tests locally.
8 It does about the same things as appveyor.yml, only using cabal new-build.
10 Simple usage:
12 $ HC=ghc-7.10.3 sh validate.sh
14 Multiple ghcs (serial), this takes very long.
16 $ sh validate.sh ghc-7.6.3 ghc-7.8.4 ghc-7.10.3 ghc-8.0.2 ghc-8.2.2
18 Params (with defaults)
20 JOBS=-j4 cabal new-build -j argument
21 TESTSUITEJOBS=-j3 cabal-tests -j argument
22 CABALTESTS=true Run Cabal tests
23 CABALINSTALLTESTS=true Run cabal-install tests
24 CABALSUITETESTS=true Run cabal-testsuite
25 EOF
26 exit 0
29 # Loop thru compilers if given as an argument
30 if [ $# -ne 0 ]; then
31 set -e
32 for HC in "$@"; do
33 export HC
34 sh $0
35 done
36 exit 0
39 HC=${HC-ghc-8.2.2}
40 JOBS=${JOBS--j4}
41 TESTSUITEJOBS=${TESTSUITEJOBS--j3}
43 CABALTESTS=${CABALTESTS-true}
44 CABALINSTALLTESTS=${CABALINSTALLTESTS-true}
45 CABALSUITETESTS=${CABALSUITETESTS-true}
47 CABAL_VERSION="2.3.0.0"
48 if [ "$(uname)" = "Linux" ]; then
49 ARCH="x86_64-linux"
50 else
51 ARCH="x86_64-osx"
54 BUILDDIR=dist-newstyle-validate-$HC
55 CABAL_TESTSUITE_BDIR="$(pwd)/$BUILDDIR/build/$ARCH/$HC/cabal-testsuite-${CABAL_VERSION}"
57 CABALNEWBUILD="cabal new-build $JOBS -w $HC --builddir=$BUILDDIR --project-file=cabal.project.validate"
58 CABALPLAN="cabal-plan --builddir=$BUILDDIR"
60 OUTPUT=$(mktemp)
62 RED='\033[0;31m'
63 GREEN='\033[0;32m'
64 BLUE='\033[0;34m'
65 CYAN='\033[0;96m'
66 RESET='\033[0m' # No Color
68 JOB_START_TIME=$(date +%s)
70 timed() {
71 PRETTYCMD=$(echo "$@" | sed -E 's/\/home[^ ]*\/([^\/])/**\/\1/g')
72 echo "$BLUE>>> $PRETTYCMD $RESET"
73 start_time=$(date +%s)
75 "$@" > "$OUTPUT" 2>&1
76 # echo "MOCK" > "$OUTPUT"
77 RET=$?
79 end_time=$(date +%s)
80 duration=$((end_time - start_time))
81 tduration=$((end_time - JOB_START_TIME))
83 if [ $RET -eq 0 ]; then
84 echo "$GREEN<<< $PRETTYCMD $RESET ($duration/$tduration sec)"
86 # if output is relatively short, show everything
87 if [ "$(wc -l < "$OUTPUT")" -le 20 ]; then
88 cat "$OUTPUT"
89 else
90 echo "..."
91 tail -n 5 "$OUTPUT"
94 rm -f "$OUTPUT"
96 # bottom-margin
97 echo ""
98 else
99 echo "$RED<<< $PRETTYCMD $RESET ($duration/$tduration sec, $RET)"
100 cat "$OUTPUT"
101 echo "$RED<<< $* $RESET ($duration/$tduration sec, $RET)"
102 rm -f "$OUTPUT"
103 exit 1
107 # Info
108 echo "$CYAN!!! Validating with $HC $RESET"
110 timed ghc --version
111 timed cabal --version
112 timed cabal-plan --version
115 # Cabal
116 echo "$CYAN=== Cabal: build ======================================= $(date +%T) === $RESET"
118 timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks --dry-run || exit 1
119 timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks --dep || exit 1
120 timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks || exit 1
122 # Environment files interfere with legacy Custom setup builds in sandbox
123 # https://github.com/haskell/cabal/issues/4642
124 rm -rf .ghc.environment.*
126 ## Cabal tests
127 if $CABALTESTS; then
128 echo "$CYAN=== Cabal: test ======================================== $(date +%T) === $RESET"
130 timed $CABALNEWBUILD Cabal:tests --enable-tests --disable-benchmarks --dry-run || exit 1
131 timed $CABALNEWBUILD Cabal:tests --enable-tests --disable-benchmarks || exit 1
132 rm -rf .ghc.environment.*
134 CMD="$($CABALPLAN list-bin Cabal:test:unit-tests) $TESTSUITEJOBS --hide-successes"
135 (cd Cabal && timed $CMD) || exit 1
137 CMD="$($CABALPLAN list-bin Cabal:test:check-tests) $TESTSUITEJOBS --hide-successes"
138 (cd Cabal && timed $CMD) || exit 1
140 CMD="$($CABALPLAN list-bin Cabal:test:parser-tests) $TESTSUITEJOBS --hide-successes"
141 (cd Cabal && timed $CMD) || exit 1
143 CMD=$($CABALPLAN list-bin Cabal:test:hackage-tests)
144 (cd Cabal && timed $CMD parsec d) || exit 1
145 (cd Cabal && timed $CMD roundtrip k) || exit 1
147 fi # $CABALTESTS
150 # cabal-testsuite
151 # cabal test ssuite is run first
152 echo "$CYAN=== cabal-install cabal-testsuite: build =============== $(date +%T) === $RESET"
154 timed $CABALNEWBUILD all --enable-tests --disable-benchmarks --dry-run || exit 1
156 # For some reason this sometimes fails. So we try twice.
157 CMD="$CABALNEWBUILD all --enable-tests --disable-benchmarks"
158 (timed $CMD) || (timed $CMD) || exit 1
159 rm -rf .ghc.environment.*
162 # cabal-install tests
163 if $CABALINSTALLTESTS; then
164 echo "$CYAN=== cabal-install: test ================================ $(date +%T) === $RESET"
166 # this are sorted in asc time used, quicker tests first.
167 CMD="$($CABALPLAN list-bin cabal-install:test:solver-quickcheck) $TESTSUITEJOBS --hide-successes"
168 (cd cabal-install && timed $CMD) || exit 1
170 # This doesn't work in parallel either
171 CMD="$($CABALPLAN list-bin cabal-install:test:unit-tests) -j1 --hide-successes"
172 (cd cabal-install && timed $CMD) || exit 1
174 # Only single job, otherwise we fail with "Heap exhausted"
175 CMD="$($CABALPLAN list-bin cabal-install:test:memory-usage-tests) -j1 --hide-successes"
176 (cd cabal-install && timed $CMD) || exit 1
178 # This test-suite doesn't like concurrency
179 CMD="$($CABALPLAN list-bin cabal-install:test:integration-tests2) -j1 --hide-successes"
180 (cd cabal-install && timed $CMD) || exit 1
182 fi # CABALINSTALLTESTS
185 # cabal-testsuite tests
186 if $CABALSUITETESTS; then
187 echo "$CYAN=== cabal-testsuite: test ============================== $(date +%T) === $RESET"
189 CMD="$($CABALPLAN list-bin cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR --with-cabal=$($CABALPLAN list-bin cabal-install:exe:cabal) $TESTSUITEJOBS --hide-successes"
190 (cd cabal-testsuite && timed $CMD) || exit 1
192 fi # CABALSUITETESTS
195 # Footer
196 JOB_END_TIME=$(date +%s)
197 tduration=$((JOB_END_TIME - JOB_START_TIME))
199 echo "$CYAN!!! Validation took $tduration seconds. $RESET"