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