Merge branch 'master' of http://darcs.haskell.org/ghc
[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     #
109     # Install the mtl package into the bindist, because it is used by some
110     # tests.  It isn't essential that we do this (the failing tests will
111     # be treated as expected failures), but we get a bit more test
112     # coverage, and also verify that we can install a package into the
113     # bindist with Cabal.
114     #
115     bindistdir="bindisttest/install   dir"
116
117     # This is a hack to make
118     #     HADDOCK_DOCS = NO
119     # work when validating.
120     if grep -q "^HADDOCK_DOCS.*=.*NO" mk/validate.mk
121     then
122         unset WITH_HADDOCK
123         DO_HADDOCK=NO
124     else
125         WITH_HADDOCK=--with-haddock="$thisdir/$bindistdir/bin/haddock"
126         DO_HADDOCK=YES
127     fi
128
129     cd libraries/mtl
130     "$thisdir/$bindistdir/bin/ghc" --make Setup
131
132     ./Setup configure --with-ghc="$thisdir/$bindistdir/bin/ghc" ${WITH_HADDOCK+"$WITH_HADDOCK"} --global --builddir=dist-bindist --prefix="$thisdir/$bindistdir"
133     ./Setup build   --builddir=dist-bindist
134     [ "$DO_HADDOCK" = "YES" ] && ./Setup haddock --builddir=dist-bindist
135     ./Setup install --builddir=dist-bindist
136     ./Setup clean   --builddir=dist-bindist
137     rm -f Setup Setup.exe Setup.hi Setup.o
138     cd $thisdir
139 fi
140
141 fi # testsuite-only
142
143 # -----------------------------------------------------------------------------
144 # Run the testsuite
145
146 if [ "$hpc" = YES ]
147 then
148     # XXX With threads we'd need to give a different tix file to each thread
149     #     and then sum them up at the end
150     threads=1
151     HPCTIXFILE=$thisdir/testsuite/hpc_output/ghc.tix
152     export HPCTIXFILE
153     rm -f $HPCTIXFILE
154 fi
155
156 case "$speed" in
157 SLOW)
158         MAKE_TEST_TARGET=fulltest
159         BINDIST="BINDIST=YES"
160         ;;
161 NORMAL)
162         MAKE_TEST_TARGET=test
163         BINDIST="BINDIST=YES"
164         ;;
165 FAST)
166         MAKE_TEST_TARGET=test
167         BINDIST="BINDIST=NO"
168         ;;
169 esac
170
171 $make $MAKE_TEST_TARGET stage=2 $BINDIST THREADS=$threads 2>&1 | tee testlog
172
173 if [ "$hpc" = YES ]
174 then
175     utils/hpc/hpc markup --hpcdir=. --srcdir=compiler --srcdir=testsuite/hpc_output --destdir=testsuite/hpc_output testsuite/hpc_output/ghc.tix
176 fi
177
178 echo "-------------------------------------------------------------------"
179 if
180     grep '\<0 caused framework failures' testlog >/dev/null 2>/dev/null &&
181     grep '\<0 unexpected passes' testlog >/dev/null 2>/dev/null &&
182     grep '\<0 unexpected failures' testlog >/dev/null 2>/dev/null &&
183     ! grep 'Some files are written by multiple tests' testlog >/dev/null 2>/dev/null ; then
184     if [ $testsuite_only -eq 0 ] && [ $no_clean -eq 0 ]
185     then
186         cat <<EOF
187 Congratulations!  This tree has passed minimal testing.
188
189 NOTE: If you have made changes that may cause failures not tested for by
190 the minimal testing procedure, please do further testing as necessary.
191
192 When you are satisfied that you haven't broken anything, go ahead and
193 push/send your patches.
194 EOF
195         if [ -f mk/validate.mk ] && grep -q "^[^#]" mk/validate.mk
196         then
197             cat <<EOF
198
199 WARNING: You seem to have things set in mk/validate.mk. Please check
200 that it is OK before pushing.
201 EOF
202         fi
203         cat <<EOF
204 -------------------------------------------------------------------
205 EOF
206     else
207         cat <<EOF
208 I didn't find any problems, but this wasn't a complete validate run,
209 so be careful!
210
211 NOTE: If you have made changes that may cause failures not tested for by
212 the minimal testing procedure, please do further testing as necessary.
213 -------------------------------------------------------------------
214 EOF
215    fi
216 else
217     cat <<EOF
218 Oops!  Looks like you have some unexpected test results or framework failures.
219 Please fix them before pushing/sending patches.
220 -------------------------------------------------------------------
221 EOF
222     exit 1
223 fi
224