Merge pull request #5870 from fgaz/new-install/bindir-method
[cabal.git] / validate.sh
blob6e6353c63b2ff20bf16ac306745f6fccc07b9ff7
1 #!/bin/sh
2 # shellcheck disable=SC2086
4 # default config
5 #######################################################################
7 HC=ghc-8.2.2
8 CABAL=cabal
9 CABALPLAN=cabal-plan
10 JOBS=4
11 CABALTESTS=true
12 CABALINSTALLTESTS=true
13 CABALSUITETESTS=true
14 CABALONLY=false
15 DEPSONLY=false
16 VERBOSE=false
18 # Help
19 #######################################################################
21 show_usage() {
22 cat <<EOF
23 ./validate.sh - build & test
25 Usage: ./validate.sh [ -j JOBS | -l | -C | -c | -s | -w HC | -x CABAL | -y CABALPLAN | -d | -v ]
26 A script which runs all the tests.
28 Available options:
29 -j JOBS cabal v2-build -j argument (default: $JOBS)
30 -l Test Cabal-the-library only (default: $CABALONLY)
31 -C Don't run Cabal tests (default: $CABALTESTS)
32 -c Don't run cabal-install tests (default: $CABALINSTALLTESTS)
33 -s Don't run cabal-testsuite tests (default: $CABALSUITETESTS)
34 -w HC With compiler
35 -x CABAL With cabal-install
36 -y CABALPLAN With cabal-plan
37 -d Build dependencies only
38 -v Verbose
39 EOF
40 exit 0
43 # "library"
44 #######################################################################
46 OUTPUT=$(mktemp)
48 RED='\033[0;31m'
49 GREEN='\033[0;32m'
50 BLUE='\033[0;34m'
51 CYAN='\033[0;96m'
52 RESET='\033[0m' # No Color
54 JOB_START_TIME=$(date +%s)
56 timed() {
57 PRETTYCMD=$(echo "$@" | sed -E 's/\/home[^ ]*\/([^\/])/**\/\1/g')
58 echo "$BLUE>>> $PRETTYCMD $RESET"
59 start_time=$(date +%s)
61 if $VERBOSE; then
62 "$@" 2>&1
63 else
64 "$@" > "$OUTPUT" 2>&1
66 # echo "MOCK" > "$OUTPUT"
67 RET=$?
69 end_time=$(date +%s)
70 duration=$((end_time - start_time))
71 tduration=$((end_time - JOB_START_TIME))
73 if [ $RET -eq 0 ]; then
74 if ! $VERBOSE; then
75 # if output is relatively short, show everything
76 if [ "$(wc -l < "$OUTPUT")" -le 50 ]; then
77 cat "$OUTPUT"
78 else
79 echo "..."
80 tail -n 20 "$OUTPUT"
83 rm -f "$OUTPUT"
86 echo "$GREEN<<< $PRETTYCMD $RESET ($duration/$tduration sec)"
88 # bottom-margin
89 echo ""
90 else
91 if ! $VERBOSE; then
92 cat "$OUTPUT"
95 echo "$RED<<< $PRETTYCMD $RESET ($duration/$tduration sec, $RET)"
96 echo "$RED<<< $* $RESET ($duration/$tduration sec, $RET)"
97 rm -f "$OUTPUT"
98 exit 1
102 footer() {
103 JOB_END_TIME=$(date +%s)
104 tduration=$((JOB_END_TIME - JOB_START_TIME))
106 echo "$CYAN=== END ============================================ $(date +%T) === $RESET"
107 echo "$CYAN!!! Validation took $tduration seconds. $RESET"
110 # getopt
111 #######################################################################
113 while getopts 'j:lCcsw:x:y:dv' flag; do
114 case $flag in
115 j) JOBS="$OPTARG"
117 l) CABALONLY=true
119 C) CABALTESTS=false
121 c) CABALINSTALLTESTS=false
123 s) CABALSUITETESTS=false
125 w) HC="$OPTARG"
127 x) CABAL="$OPTARG"
129 y) CABALPLAN="$OPTARG"
131 d) DEPSONLY=true
133 v) VERBOSE=true
135 ?) show_usage
137 esac
138 done
140 shift $((OPTIND - 1))
142 # header
143 #######################################################################
145 if [ "xhelp" = "x$1" ]; then
146 show_usage;
149 TESTSUITEJOBS="-j$JOBS"
150 JOBS="-j$JOBS"
152 # assume compiler is GHC
153 RUNHASKELL=$(echo $HC | sed -E 's/ghc(-[0-9.]*)$/runghc\1/')
155 echo "$CYAN=== validate.sh ======================================== $(date +%T) === $RESET"
157 cat <<EOF
158 compiler: $HC
159 runhaskell $RUNHASKELL
160 cabal-install: $CABAL
161 cabal-plan: $CABALPLAN
162 jobs: $JOBS
163 Cabal tests: $CABALTESTS
164 cabal-install tests: $CABALINSTALLTESTS
165 cabal-testsuite: $CABALSUITETESTS
166 library only: $CABALONLY
167 dependencies only: $DEPSONLY
168 verbose: $VERBOSE
172 timed $HC --version
173 timed $CABAL --version
174 timed $CABALPLAN --version
176 # Basic setup
177 #######################################################################
179 # NOTE: This should match cabal-testsuite version
180 CABAL_VERSION="3.0.0.0"
182 if [ "$(uname)" = "Linux" ]; then
183 ARCH="x86_64-linux"
184 else
185 ARCH="x86_64-osx"
188 if $CABALONLY; then
189 PROJECTFILE=cabal.project.validate.libonly
190 else
191 PROJECTFILE=cabal.project.validate
194 BASEHC=$(basename $HC)
195 BUILDDIR=dist-newstyle-validate-$BASEHC
196 CABAL_TESTSUITE_BDIR="$(pwd)/$BUILDDIR/build/$ARCH/$BASEHC/cabal-testsuite-${CABAL_VERSION}"
198 CABALNEWBUILD="${CABAL} v2-build $JOBS -w $HC --builddir=$BUILDDIR --project-file=$PROJECTFILE"
199 CABALPLAN="${CABALPLAN} --builddir=$BUILDDIR"
201 # SCRIPT
202 #######################################################################
204 if ! $CABALONLY; then
206 echo "$CYAN=== make cabal-install-dev ============================= $(date +%T) === $RESET"
208 # make cabal-install-dev
209 timed ${RUNHASKELL} cabal-dev-scripts/src/Preprocessor.hs -o cabal-install/cabal-install.cabal -f CABAL_FLAG_LIB cabal-install/cabal-install.cabal.pp
211 fi # CABALONLY
213 # Dependencies
215 if $DEPSONLY; then
217 echo "$CYAN=== dependencies ====================================== $(date +%T) === $RESET"
219 timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks --dep --dry-run || exit 1
220 timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks --dep || exit 1
221 if $CABALTESTS; then
222 timed $CABALNEWBUILD Cabal --enable-tests --disable-benchmarks --dep --dry-run || exit 1
223 timed $CABALNEWBUILD Cabal --enable-tests --disable-benchmarks --dep || exit 1
226 # Unfortunately we can not install cabal-install or cabal-testsuite dependencies:
227 # that would build Cabal-lib!
229 footer
230 exit
232 fi # DEPSONLY
234 # Cabal lib
235 #######################################################################
237 echo "$CYAN=== Cabal: build ======================================= $(date +%T) === $RESET"
239 timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks --dry-run || exit 1
240 timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks --dep || exit 1
241 timed $CABALNEWBUILD Cabal:lib:Cabal --enable-tests --disable-benchmarks || exit 1
243 if $CABALTESTS; then
244 echo "$CYAN=== Cabal: test ======================================== $(date +%T) === $RESET"
246 timed $CABALNEWBUILD Cabal:tests --enable-tests --disable-benchmarks --dry-run || exit 1
247 timed $CABALNEWBUILD Cabal:tests --enable-tests --disable-benchmarks --dep || exit 1
248 timed $CABALNEWBUILD Cabal:tests --enable-tests --disable-benchmarks || exit 1
250 CMD="$($CABALPLAN list-bin Cabal:test:unit-tests) $TESTSUITEJOBS --hide-successes --with-ghc=$HC"
251 (cd Cabal && timed $CMD) || exit 1
253 CMD="$($CABALPLAN list-bin Cabal:test:check-tests) $TESTSUITEJOBS --hide-successes"
254 (cd Cabal && timed $CMD) || exit 1
256 CMD="$($CABALPLAN list-bin Cabal:test:parser-tests) $TESTSUITEJOBS --hide-successes"
257 (cd Cabal && timed $CMD) || exit 1
259 CMD=$($CABALPLAN list-bin Cabal:test:hackage-tests)
260 (cd Cabal && timed $CMD read-fields) || exit 1
261 (cd Cabal && timed $CMD parsec d) || exit 1
262 (cd Cabal && timed $CMD roundtrip k) || exit 1
264 fi # $CABALTESTS
266 if $CABALSUITETESTS; then
268 echo "$CYAN=== cabal-testsuite: build ============================= $(date +%T) === $RESET"
270 timed $CABALNEWBUILD cabal-testsuite --enable-tests --disable-benchmarks --dry-run || exit 1
271 timed $CABALNEWBUILD cabal-testsuite --enable-tests --disable-benchmarks --dep || exit 1
272 timed $CABALNEWBUILD cabal-testsuite --enable-tests --disable-benchmarks || exit 1
274 echo "$CYAN=== cabal-testsuite: Cabal test ======================== $(date +%T) === $RESET"
276 CMD="$($CABALPLAN list-bin cabal-testsuite:exe:cabal-tests) --builddir=$CABAL_TESTSUITE_BDIR $TESTSUITEJOBS --with-ghc=$HC --hide-successes"
277 (cd cabal-testsuite && timed $CMD) || exit 1
279 fi # CABALSUITETESTS (Cabal)
281 # If testing only library, stop here
282 if $CABALONLY; then
283 footer
284 exit
287 # cabal-install
288 #######################################################################
290 echo "$CYAN=== cabal-install: build =============================== $(date +%T) === $RESET"
292 timed $CABALNEWBUILD cabal-install --enable-tests --disable-benchmarks --dry-run || exit 1
294 # For some reason this sometimes fails. So we try twice.
295 CMD="$CABALNEWBUILD cabal-install --enable-tests --disable-benchmarks"
296 (timed $CMD) || (timed $CMD) || exit 1
299 if $CABALINSTALLTESTS; then
300 echo "$CYAN=== cabal-install: test ================================ $(date +%T) === $RESET"
302 # this are sorted in asc time used, quicker tests first.
303 CMD="$($CABALPLAN list-bin cabal-install:test:solver-quickcheck) $TESTSUITEJOBS --hide-successes"
304 (cd cabal-install && timed $CMD) || exit 1
306 # This doesn't work in parallel either
307 CMD="$($CABALPLAN list-bin cabal-install:test:unit-tests) -j1 --hide-successes"
308 (cd cabal-install && timed $CMD) || exit 1
310 # Only single job, otherwise we fail with "Heap exhausted"
311 CMD="$($CABALPLAN list-bin cabal-install:test:memory-usage-tests) -j1 --hide-successes"
312 (cd cabal-install && timed $CMD) || exit 1
314 # This test-suite doesn't like concurrency
315 CMD="$($CABALPLAN list-bin cabal-install:test:integration-tests2) -j1 --hide-successes --with-ghc=$HC"
316 (cd cabal-install && timed $CMD) || exit 1
318 fi # CABALINSTALLTESTS
321 if $CABALSUITETESTS; then
322 echo "$CYAN=== cabal-testsuite: cabal-install test ================ $(date +%T) === $RESET"
324 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"
325 (cd cabal-testsuite && timed $CMD) || exit 1
327 fi # CABALSUITETESTS
329 # END
330 #######################################################################
332 footer
334 #######################################################################