Add a hack to make validating with HADDOCK_DOCS=NO work
[ghc.git] / validate
1 #!/bin/sh
2
3 # Flags:
4 #   --no-clean:       don't make clean first, just carry on from
5 #                     a previous interrupted validation run
6 #   --testsuite-only: don't build the compiler, just run
7 #                     the test suite
8 #   --hpc:            build stage2 with -fhpc, and see how much of the
9 #                     compiler the test suite covers.
10 #                     2008-07-01: 63% slower than the default.
11 #                     HTML generated here: testsuite/hpc_output/hpc_index.html
12 #   --normal:         Default settings
13 #   --fast:           Omit dyn way, omit binary distribution
14 #   --slow:           Build stage2 with -DDEBUG.
15 #                     2008-07-01: 14% slower than the default.
16
17 set -e
18
19 no_clean=0
20 testsuite_only=0
21 hpc=NO
22 speed=NORMAL
23
24 while [ $# -gt 0 ]
25 do
26     case "$1" in
27     --no-clean)
28         no_clean=1
29         ;;
30     --testsuite-only)
31         testsuite_only=1
32         ;;
33     --hpc)
34         hpc=YES
35         ;;
36     --slow)
37         speed=SLOW
38         ;;
39     --fast)
40         speed=FAST
41         ;;
42     --normal)
43         speed=NORMAL
44         ;;
45     *)
46         echo "Bad argument: $1" >&2
47         exit 1;;
48     esac
49     shift
50 done
51
52 if ! [ -d testsuite ]
53 then
54     echo 'You need the testsuite to validate' >&2
55     echo 'Run "./sync-all --testsuite get" to get it' >&2
56     exit 1
57 fi
58
59 if [ "$THREADS" = "" ]; then
60     if [ "$CPUS" = "" ]; then
61         threads=2
62     else
63         threads=$(($CPUS + 1)) # `expr $CPUS + 1`
64     fi
65 else
66     threads="$THREADS"
67 fi
68
69 if type gmake > /dev/null 2> /dev/null
70 then
71     make="gmake"
72 else
73     make="make"
74 fi
75
76 if [ $testsuite_only -eq 0 ]; then
77
78 if [ $no_clean -eq 0 ]; then
79     $make maintainer-clean NO_CLEAN_GMP=YES
80
81     INSTDIR=`pwd`/inst
82     if [ "$OSTYPE" = "cygwin" ]
83     then
84         INSTDIR=`cygpath -m "$INSTDIR"`
85     fi
86
87     /usr/bin/perl -w boot --validate --required-tag=dph
88     ./configure --prefix="$INSTDIR" $config_args
89 fi
90
91 thisdir=`utils/ghc-pwd/dist-boot/ghc-pwd`
92
93 echo "Validating=YES"       >  mk/are-validating.mk
94 echo "ValidateSpeed=$speed" >> mk/are-validating.mk
95 echo "ValidateHpc=$hpc"     >> mk/are-validating.mk
96
97 $make -j$threads
98 # For a "debug make", add "--debug=b --debug=m"
99
100 # -----------------------------------------------------------------------------
101 # Build and test a binary distribution (not --fast)
102
103 if [ $speed != "FAST" ]; then
104
105     $make binary-dist-prep
106     $make test_bindist TEST_PREP=YES
107
108     # This is a hack to make
109     #     HADDOCK_DOCS = NO
110     # work when validating.
111     if grep -q "^HADDOCK_DOCS[  ]*=[    ]*NO[   ]*$" mk/validate.mk
112     then
113         unset WITH_HADDOCK
114         DO_HADDOCK=NO
115     else
116         WITH_HADDOCK=--with-haddock="$thisdir/$bindistdir/bin/haddock"
117         DO_HADDOCK=YES
118     fi
119
120     #
121     # Install the mtl package into the bindist, because it is used by some
122     # tests.  It isn't essential that we do this (the failing tests will
123     # be treated as expected failures), but we get a bit more test
124     # coverage, and also verify that we can install a package into the
125     # bindist with Cabal.
126     #
127     bindistdir="bindisttest/install   dir"
128     cd libraries/mtl
129     "$thisdir/$bindistdir/bin/ghc" --make Setup
130
131     ./Setup configure --with-ghc="$thisdir/$bindistdir/bin/ghc" ${WITH_HADDOCK+"$WITH_HADDOCK"} --global --builddir=dist-bindist --prefix="$thisdir/$bindistdir"
132     ./Setup build   --builddir=dist-bindist
133     [ "$DO_HADDOCK" = "YES" ] && ./Setup haddock --builddir=dist-bindist
134     ./Setup install --builddir=dist-bindist
135     ./Setup clean   --builddir=dist-bindist
136     rm -f Setup Setup.exe Setup.hi Setup.o
137     cd $thisdir
138 fi
139
140 fi # testsuite-only
141
142 # -----------------------------------------------------------------------------
143 # Run the testsuite
144
145 if [ "$hpc" = YES ]
146 then
147     # XXX With threads we'd need to give a different tix file to each thread
148     #     and then sum them up at the end
149     threads=1
150     HPCTIXFILE=$thisdir/testsuite/hpc_output/ghc.tix
151     export HPCTIXFILE
152     rm -f $HPCTIXFILE
153 fi
154
155 case "$speed" in
156 SLOW)
157         MAKE_TEST_TARGET=fulltest
158         BINDIST="BINDIST=YES"
159         ;;
160 NORMAL)
161         MAKE_TEST_TARGET=test
162         BINDIST="BINDIST=YES"
163         ;;
164 FAST)
165         MAKE_TEST_TARGET=test
166         BINDIST="BINDIST=NO"
167         ;;
168 esac
169
170 $make $MAKE_TEST_TARGET stage=2 $BINDIST THREADS=$threads 2>&1 | tee testlog
171
172 if [ "$hpc" = YES ]
173 then
174     utils/hpc/hpc markup --hpcdir=. --srcdir=compiler --srcdir=testsuite/hpc_output --destdir=testsuite/hpc_output testsuite/hpc_output/ghc.tix
175 fi
176
177 echo "-------------------------------------------------------------------"
178 if
179     grep '\<0 caused framework failures' testlog >/dev/null 2>/dev/null &&
180     grep '\<0 unexpected passes' testlog >/dev/null 2>/dev/null &&
181     grep '\<0 unexpected failures' testlog >/dev/null 2>/dev/null &&
182     ! grep 'Some files are written by multiple tests' testlog >/dev/null 2>/dev/null ; then
183     if [ $testsuite_only -eq 0 ] && [ $no_clean -eq 0 ]
184     then
185         cat <<EOF
186 Congratulations!  This tree has passed minimal testing.
187
188 NOTE: If you have made changes that may cause failures not tested for by
189 the minimal testing procedure, please do further testing as necessary.
190
191 When you are satisfied that you haven't broken anything, go ahead and
192 push/send your patches.
193 EOF
194         if [ -f mk/validate.mk ] && grep -q "^[^#]" mk/validate.mk
195         then
196             cat <<EOF
197
198 WARNING: You seem to have things set in mk/validate.mk. Please check
199 that it is OK before pushing.
200 EOF
201         fi
202         cat <<EOF
203 -------------------------------------------------------------------
204 EOF
205     else
206         cat <<EOF
207 I didn't find any problems, but this wasn't a complete validate run,
208 so be careful!
209
210 NOTE: If you have made changes that may cause failures not tested for by
211 the minimal testing procedure, please do further testing as necessary.
212 -------------------------------------------------------------------
213 EOF
214    fi
215 else
216     cat <<EOF
217 Oops!  Looks like you have some unexpected test results or framework failures.
218 Please fix them before pushing/sending patches.
219 -------------------------------------------------------------------
220 EOF
221     exit 1
222 fi
223