Update to disable asserts. Build a phase 3 compiler, and compare phase 2 files agains...
[oota-llvm.git] / utils / release / test-release.sh
1 #!/bin/bash
2 #===-- test-release.sh - Test the LLVM release candidates ------------------===#
3 #
4 #                     The LLVM Compiler Infrastructure
5 #
6 # This file is distributed under the University of Illinois Open Source
7 # License.
8 #
9 #===------------------------------------------------------------------------===#
10 #
11 # Download, build, and test the release candidate for an LLVM release.
12 #
13 #===------------------------------------------------------------------------===#
14
15 set -e                          # Exit if any command fails
16
17 projects="llvm cfe dragonegg test-suite compiler-rt libcxx libcxxabi"
18
19 # Base SVN URL for the sources.
20 Base_url="http://llvm.org/svn/llvm-project"
21
22 Release=""
23 Release_no_dot=""
24 RC=""
25 do_checkout="yes"
26 do_ada="no"
27 do_objc="yes"
28 do_fortran="no"
29 do_64bit="yes"
30 do_debug="no"
31 do_asserts="no"
32 BuildDir="`pwd`"
33
34 function usage() {
35     echo "usage: `basename $0` -release X.Y -rc NUM [OPTIONS]"
36     echo ""
37     echo " -release X.Y      The release number to test."
38     echo " -rc NUM           The pre-release candidate number."
39     echo " -j NUM            Number of compile jobs to run. [default: 3]"
40     echo " -build-dir DIR    Directory to perform testing in. [default: pwd]"
41     echo " -no-checkout      Don't checkout the sources from SVN."
42     echo " -no-64bit         Don't test the 64-bit version. [default: yes]"
43     echo " -enable-ada       Build Ada. [default: disable]"
44     echo " -enable-fortran   Enable Fortran build. [default: disable]"
45     echo " -disable-objc     Disable ObjC build. [default: enable]"
46     echo " -test-debug       Test the debug build. [default: no]"
47     echo " -test-asserts     Test with asserts on. [default: no]"
48 }
49
50 while [ $# -gt 0 ]; do
51     case $1 in
52         -release | --release )
53             shift
54             Release="$1"
55             Release_no_dot="`echo $1 | sed -e 's,\.,,'`"
56             ;;
57         -rc | --rc | -RC | --RC )
58             shift
59             RC=$1
60             ;;
61         -j* )
62             NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
63             if [ -z "$NumJobs" ]; then
64                 shift
65                 NumJobs="$1"
66             fi
67             ;;
68         -build-dir | --build-dir | -builddir | --builddir )
69             shift
70             BuildDir="$1"
71             ;;
72         -no-checkout | --no-checkout )
73             do_checkout="no"
74             ;;
75         -no-64bit | --no-64bit )
76             do_64bit="no"
77             ;;
78         -enable-ada | --enable-ada )
79             do_ada="yes"
80             ;;
81         -enable-fortran | --enable-fortran )
82             do_fortran="yes"
83             ;;
84         -disable-objc | --disable-objc )
85             do_objc="no"
86             ;;
87         -test-debug | --test-debug )
88             do_debug="yes"
89             ;;
90         -test-asserts | --test-asserts )
91             do_asserts="yes"
92             ;;
93         -help | --help | -h | --h | -\? )
94             usage
95             exit 0
96             ;;
97         * )
98             echo "unknown option: $1"
99             usage
100             exit 1
101             ;;
102     esac
103     shift
104 done
105
106 # Check required arguments.
107 if [ -z "$Release" ]; then
108     echo "error: no release number specified"
109     exit 1
110 fi
111 if [ -z "$RC" ]; then
112     echo "error: no release candidate number specified"
113     exit 1
114 fi
115
116 # Figure out how many make processes to run.
117 if [ -z "$NumJobs" ]; then
118     NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
119 fi
120 if [ -z "$NumJobs" ]; then
121     NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
122 fi
123 if [ -z "$NumJobs" ]; then
124     NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
125 fi
126 if [ -z "$NumJobs" ]; then
127     NumJobs=3
128 fi
129
130 # Go to the build directory (may be different from CWD)
131 BuildDir=$BuildDir/rc$RC
132 mkdir -p $BuildDir
133 cd $BuildDir
134
135 # Location of log files.
136 LogDir=$BuildDir/logs
137 mkdir -p $LogDir
138
139 # Find a compilers.
140 c_compiler="`which clang`"
141 if [ -z "$c_compiler" ]; then
142     c_compiler="`which gcc`"
143     if [ -z "$c_compiler" ]; then
144         c_compiler="`which cc`"
145         if [ -z "$c_compiler" ]; then
146             echo "error: cannot find a working C compiler"
147         fi
148     fi
149 fi
150 cxx_compiler="`which clang++`"
151 if [ -z "$cxx_compiler" ]; then
152     cxx_compiler="`which g++`"
153     if [ -z "$cxx_compiler" ]; then
154         cxx_compiler="`which c++`"
155         if [ -z "$cxx_compiler" ]; then
156             echo "error: cannot find a working C++ compiler"
157         fi
158     fi
159 fi
160
161 # Make sure that the URLs are valid.
162 function check_valid_urls() {
163     for proj in $projects ; do
164         echo "# Validating $proj SVN URL"
165
166         if ! svn ls $Base_url/tags/RELEASE_$Release_no_dot/rc$RC > /dev/null 2>&1 ; then
167             echo "llvm $Release release candidate $RC doesn't exist!"
168             exit 1
169         fi
170     done
171 }
172
173 # Export sources to the the build directory.
174 function export_sources() {
175     check_valid_urls
176
177     for proj in $projects ; do
178         echo "# Exporting $proj $Release-RC$RC sources"
179         if ! svn export -q $Base_url/$proj/tags/RELEASE_$Release_no_dot/rc$RC $proj.src ; then
180             echo "error: failed to export $proj project"
181             exit 1
182         fi
183     done
184
185     echo "# Creating symlinks"
186     cd $BuildDir/llvm.src/tools
187     if [ ! -h clang ]; then
188         ln -s $BuildDir/cfe.src clang
189     fi
190     cd $BuildDir/llvm.src/projects
191     if [ ! -h llvm-test ]; then
192         ln -s $BuildDir/test-suite.src llvm-test
193     fi
194     cd $BuildDir
195 }
196
197 function configure_llvmCore() {
198     Phase="$1"
199     Flavor="$2"
200     ObjDir="$3"
201     InstallDir="$4"
202
203     case $Flavor in
204         Release | Release-64 )
205             Optimized="yes"
206             Assertions="no"
207             ;;
208         Release+Asserts )
209             Optimized="yes"
210             Assertions="yes"
211             ;;
212         Debug )
213             Optimized="no"
214             Assertions="yes"
215             ;;
216         * )
217             echo "# Invalid flavor '$Flavor'"
218             echo ""
219             return
220             ;;
221     esac
222
223     echo "# Using C compiler: $c_compiler"
224     echo "# Using C++ compiler: $cxx_compiler"
225
226     cd $ObjDir
227     echo "# Configuring llvm $Release-rc$RC $Flavor"
228     echo "# $BuildDir/llvm.src/configure --prefix=$InstallDir \
229         --enable-optimized=$Optimized \
230         --enable-assertions=$Assertions"
231     env CC=$c_compiler CXX=$cxx_compiler \
232     $BuildDir/llvm.src/configure --prefix=$InstallDir \
233         --enable-optimized=$Optimized \
234         --enable-assertions=$Assertions \
235         2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
236     cd $BuildDir
237 }
238
239 function build_llvmCore() {
240     Phase="$1"
241     Flavor="$2"
242     ObjDir="$3"
243     ExtraOpts=""
244
245     if [ "$Flavor" = "Release-64" ]; then
246         ExtraOpts="EXTRA_OPTIONS=-m64"
247     fi
248
249     cd $ObjDir
250     echo "# Compiling llvm $Release-rc$RC $Flavor"
251     echo "# make -j $NumJobs VERBOSE=1 $ExtraOpts"
252     make -j $NumJobs VERBOSE=1 $ExtraOpts \
253         2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
254
255     echo "# Installing llvm $Release-rc$RC $Flavor"
256     echo "# make install"
257     make install \
258         2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
259     cd $BuildDir
260 }
261
262 function test_llvmCore() {
263     Phase="$1"
264     Flavor="$2"
265     ObjDir="$3"
266
267     cd $ObjDir
268     make check-all \
269         2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log
270     make unittests \
271         2>&1 | tee $LogDir/llvm.unittests--Phase$Phase-$Flavor.log
272     cd $BuildDir
273 }
274
275 if [ "$do_checkout" = "yes" ]; then
276     export_sources
277 fi
278
279 (
280 Flavors="Release"
281 if [ "$do_debug" = "yes" ]; then
282     Flavors="Debug $Flavors"
283 fi
284 if [ "$do_asserts" = "yes" ]; then
285     Flavors="$Flavors Release+Asserts"
286 fi
287 if [ "$do_64bit" = "yes" ]; then
288     Flavors="$Flavors Release-64"
289 fi
290
291 for Flavor in $Flavors ; do
292     echo ""
293     echo ""
294     echo "********************************************************************************"
295     echo "  Release:     $Release-rc$RC"
296     echo "  Build:       $Flavor"
297     echo "  System Info: "
298     echo "    `uname -a`"
299     echo "********************************************************************************"
300     echo ""
301
302     llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-rc$RC.obj
303     llvmCore_phase1_installdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-rc$RC.install
304
305     llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-rc$RC.obj
306     llvmCore_phase2_installdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-rc$RC.install
307
308     llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-rc$RC.obj
309     llvmCore_phase3_installdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-rc$RC.install
310
311     rm -rf $llvmCore_phase1_objdir
312     rm -rf $llvmCore_phase1_installdir
313     rm -rf $llvmCore_phase2_objdir
314     rm -rf $llvmCore_phase2_installdir
315     rm -rf $llvmCore_phase3_objdir
316     rm -rf $llvmCore_phase3_installdir
317
318     mkdir -p $llvmCore_phase1_objdir
319     mkdir -p $llvmCore_phase1_installdir
320     mkdir -p $llvmCore_phase2_objdir
321     mkdir -p $llvmCore_phase2_installdir
322     mkdir -p $llvmCore_phase3_objdir
323     mkdir -p $llvmCore_phase3_installdir
324
325     ############################################################################
326     # Phase 1: Build llvmCore and llvmgcc42
327     echo "# Phase 1: Building llvmCore"
328     configure_llvmCore 1 $Flavor \
329         $llvmCore_phase1_objdir $llvmCore_phase1_installdir
330     build_llvmCore 1 $Flavor \
331         $llvmCore_phase1_objdir
332
333     ############################################################################
334     # Phase 2: Build llvmCore with newly built clang from phase 1.
335     c_compiler=$llvmCore_phase1_installdir/bin/clang
336     cxx_compiler=$llvmCore_phase1_installdir/bin/clang++
337     echo "# Phase 2: Building llvmCore"
338     configure_llvmCore 2 $Flavor \
339         $llvmCore_phase2_objdir $llvmCore_phase2_installdir
340     build_llvmCore 2 $Flavor \
341         $llvmCore_phase2_objdir
342
343     ############################################################################
344     # Phase 3: Build llvmCore with newly built clang from phase 2.
345     c_compiler=$llvmCore_phase2_installdir/bin/clang
346     cxx_compiler=$llvmCore_phase2_installdir/bin/clang++
347     echo "# Phase 3: Building llvmCore"
348     configure_llvmCore 3 $Flavor \
349         $llvmCore_phase3_objdir $llvmCore_phase3_installdir
350     build_llvmCore 3 $Flavor \
351         $llvmCore_phase3_objdir
352
353     ############################################################################
354     # Testing: Test phase 3
355     echo "# Testing - built with clang"
356     test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
357
358     ############################################################################
359     # Compare .o files between Phase2 and Phase3 and report which ones differ.
360     echo
361     echo "# Comparing Phase 2 and Phase 3 files"
362     for o in `find $llvmCore_phase2_objdir -name '*.o'` ; do
363         p3=`echo $o | sed -e 's,Phase2,Phase3,'`
364         if ! cmp --ignore-initial=16 $o $p3 > /dev/null 2>&1 ; then
365             echo "file `basename $o` differs between phase 2 and phase 3"
366         fi
367     done
368 done
369 ) 2>&1 | tee $LogDir/testing.$Release-rc$RC.log
370
371 # Woo hoo!
372 echo "### Testing Finished ###"
373 echo "### Logs: $LogDir"
374 exit 0