Support a 'final' release candidate tag.
[oota-llvm.git] / utils / release / test-release.sh
1 #!/usr/bin/env 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 if [ `uname -s` = "FreeBSD" ]; then
16     MAKE=gmake
17 else
18     MAKE=make
19 fi
20
21 projects="llvm cfe dragonegg test-suite"
22
23 # Base SVN URL for the sources.
24 Base_url="http://llvm.org/svn/llvm-project"
25
26 Release=""
27 Release_no_dot=""
28 RC=""
29 do_checkout="yes"
30 do_ada="no"
31 do_clang="yes"
32 do_dragonegg="no"
33 do_fortran="no"
34 do_objc="yes"
35 do_64bit="yes"
36 do_debug="no"
37 do_asserts="no"
38 BuildDir="`pwd`"
39
40 function usage() {
41     echo "usage: `basename $0` -release X.Y -rc NUM [OPTIONS]"
42     echo ""
43     echo " -release X.Y      The release number to test."
44     echo " -rc NUM           The pre-release candidate number."
45     echo " -final            The final release candidate."
46     echo " -j NUM            Number of compile jobs to run. [default: 3]"
47     echo " -build-dir DIR    Directory to perform testing in. [default: pwd]"
48     echo " -no-checkout      Don't checkout the sources from SVN."
49     echo " -no-64bit         Don't test the 64-bit version. [default: yes]"
50     echo " -enable-ada       Build Ada. [default: disable]"
51     echo " -disable-clang    Do not test clang. [default: enable]"
52     echo " -enable-dragonegg Test dragonegg. [default: disable]"
53     echo " -enable-fortran   Enable Fortran build. [default: disable]"
54     echo " -disable-objc     Disable ObjC build. [default: enable]"
55     echo " -test-debug       Test the debug build. [default: no]"
56     echo " -test-asserts     Test with asserts on. [default: no]"
57 }
58
59 while [ $# -gt 0 ]; do
60     case $1 in
61         -release | --release )
62             shift
63             Release="$1"
64             Release_no_dot="`echo $1 | sed -e 's,\.,,'`"
65             ;;
66         -rc | --rc | -RC | --RC )
67             shift
68             RC="rc$1"
69             ;;
70         -final | --final )
71             RC=final
72             ;;
73         -j* )
74             NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
75             if [ -z "$NumJobs" ]; then
76                 shift
77                 NumJobs="$1"
78             fi
79             ;;
80         -build-dir | --build-dir | -builddir | --builddir )
81             shift
82             BuildDir="$1"
83             ;;
84         -no-checkout | --no-checkout )
85             do_checkout="no"
86             ;;
87         -no-64bit | --no-64bit )
88             do_64bit="no"
89             ;;
90         -enable-ada | --enable-ada )
91             do_ada="yes"
92             ;;
93         -disable-clang | --disable-clang )
94             do_clang="no"
95             ;;
96         -enable-dragonegg | --enable-dragonegg )
97             do_dragonegg="yes"
98             ;;
99         -enable-fortran | --enable-fortran )
100             do_fortran="yes"
101             ;;
102         -disable-objc | --disable-objc )
103             do_objc="no"
104             ;;
105         -test-debug | --test-debug )
106             do_debug="yes"
107             ;;
108         -test-asserts | --test-asserts )
109             do_asserts="yes"
110             ;;
111         -help | --help | -h | --h | -\? )
112             usage
113             exit 0
114             ;;
115         * )
116             echo "unknown option: $1"
117             usage
118             exit 1
119             ;;
120     esac
121     shift
122 done
123
124 # Check required arguments.
125 if [ -z "$Release" ]; then
126     echo "error: no release number specified"
127     exit 1
128 fi
129 if [ -z "$RC" ]; then
130     echo "error: no release candidate number specified"
131     exit 1
132 fi
133
134 # Figure out how many make processes to run.
135 if [ -z "$NumJobs" ]; then
136     NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
137 fi
138 if [ -z "$NumJobs" ]; then
139     NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
140 fi
141 if [ -z "$NumJobs" ]; then
142     NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
143 fi
144 if [ -z "$NumJobs" ]; then
145     NumJobs=3
146 fi
147
148 # Go to the build directory (may be different from CWD)
149 BuildDir=$BuildDir/$RC
150 mkdir -p $BuildDir
151 cd $BuildDir
152
153 # Location of log files.
154 LogDir=$BuildDir/logs
155 mkdir -p $LogDir
156
157 # Find compilers.
158 if [ "$do_dragonegg" = "yes" ]; then
159     gcc_compiler="$GCC"
160     if [ -z "$gcc_compiler" ]; then
161         gcc_compiler="`which gcc`"
162         if [ -z "$gcc_compiler" ]; then
163             echo "error: cannot find gcc to use with dragonegg"
164             exit 1
165         fi
166     fi
167
168     gxx_compiler="$GXX"
169     if [ -z "$gxx_compiler" ]; then
170         gxx_compiler="`which g++`"
171         if [ -z "$gxx_compiler" ]; then
172             echo "error: cannot find g++ to use with dragonegg"
173             exit 1
174         fi
175     fi
176 fi
177
178
179 # Make sure that the URLs are valid.
180 function check_valid_urls() {
181     for proj in $projects ; do
182         echo "# Validating $proj SVN URL"
183
184         if ! svn ls $Base_url/$proj/tags/RELEASE_$Release_no_dot/$RC > /dev/null 2>&1 ; then
185             echo "llvm $Release release candidate $RC doesn't exist!"
186             exit 1
187         fi
188     done
189 }
190
191 # Export sources to the the build directory.
192 function export_sources() {
193     check_valid_urls
194
195     for proj in $projects ; do
196         echo "# Exporting $proj $Release-RC$RC sources"
197         if ! svn export -q $Base_url/$proj/tags/RELEASE_$Release_no_dot/$RC $proj.src ; then
198             echo "error: failed to export $proj project"
199             exit 1
200         fi
201     done
202
203     echo "# Creating symlinks"
204     cd $BuildDir/llvm.src/tools
205     if [ ! -h clang ]; then
206         ln -s ../../cfe.src clang
207     fi
208     cd $BuildDir/llvm.src/projects
209     if [ ! -h llvm-test ]; then
210         ln -s ../../test-suite.src llvm-test
211     fi
212     cd $BuildDir
213 }
214
215 function configure_llvmCore() {
216     Phase="$1"
217     Flavor="$2"
218     ObjDir="$3"
219     InstallDir="$4"
220
221     case $Flavor in
222         Release | Release-64 )
223             Optimized="yes"
224             Assertions="no"
225             ;;
226         Release+Asserts )
227             Optimized="yes"
228             Assertions="yes"
229             ;;
230         Debug )
231             Optimized="no"
232             Assertions="yes"
233             ;;
234         * )
235             echo "# Invalid flavor '$Flavor'"
236             echo ""
237             return
238             ;;
239     esac
240
241     echo "# Using C compiler: $c_compiler"
242     echo "# Using C++ compiler: $cxx_compiler"
243
244     cd $ObjDir
245     echo "# Configuring llvm $Release-$RC $Flavor"
246     echo "# $BuildDir/llvm.src/configure --prefix=$InstallDir \
247         --enable-optimized=$Optimized \
248         --enable-assertions=$Assertions"
249     env CC="$c_compiler" CXX="$cxx_compiler" \
250     $BuildDir/llvm.src/configure --prefix=$InstallDir \
251         --enable-optimized=$Optimized \
252         --enable-assertions=$Assertions \
253         --disable-timestamps \
254         2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
255     cd $BuildDir
256 }
257
258 function build_llvmCore() {
259     Phase="$1"
260     Flavor="$2"
261     ObjDir="$3"
262     ExtraOpts=""
263
264     if [ "$Flavor" = "Release-64" ]; then
265         ExtraOpts="EXTRA_OPTIONS=-m64"
266     fi
267
268     cd $ObjDir
269     echo "# Compiling llvm $Release-$RC $Flavor"
270     echo "# ${MAKE} -j $NumJobs VERBOSE=1 $ExtraOpts"
271     ${MAKE} -j $NumJobs VERBOSE=1 $ExtraOpts \
272         2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
273
274     echo "# Installing llvm $Release-$RC $Flavor"
275     echo "# ${MAKE} install"
276     ${MAKE} install \
277         2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
278     cd $BuildDir
279 }
280
281 function build_dragonegg() {
282     Phase="$1"
283     Flavor="$2"
284     LLVMInstallDir="$3"
285     DragonEggObjDir="$4"
286     LLVM_CONFIG=$LLVMInstallDir/bin/llvm-config
287     TOP_DIR=$BuildDir/dragonegg.src
288
289     echo "# Targeted compiler: $gcc_compiler"
290
291     cd $DragonEggObjDir
292     echo "# Compiling phase $Phase dragonegg $Release-$RC $Flavor"
293     echo -n "# CXX=$cxx_compiler TOP_DIR=$TOP_DIR GCC=$gcc_compiler "
294     echo -n "LLVM_CONFIG=$LLVM_CONFIG ${MAKE} -f $TOP_DIR/Makefile "
295     echo "-j $NumJobs VERBOSE=1"
296     CXX="$cxx_compiler" TOP_DIR="$TOP_DIR" GCC="$gcc_compiler" \
297     LLVM_CONFIG="$LLVM_CONFIG" ${MAKE} -f $TOP_DIR/Makefile \
298         -j $NumJobs VERBOSE=1 \
299             2>&1 | tee $LogDir/dragonegg-Phase$Phase-$Flavor.log
300     cd $BuildDir
301 }
302
303 function test_llvmCore() {
304     Phase="$1"
305     Flavor="$2"
306     ObjDir="$3"
307
308     cd $ObjDir
309     ${MAKE} -k check-all \
310         2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log
311     ${MAKE} -k unittests \
312         2>&1 | tee $LogDir/llvm.unittests-Phase$Phase-$Flavor.log
313     cd $BuildDir
314 }
315
316 set -e                          # Exit if any command fails
317
318 if [ "$do_checkout" = "yes" ]; then
319     export_sources
320 fi
321
322 (
323 Flavors="Release"
324 if [ "$do_debug" = "yes" ]; then
325     Flavors="Debug $Flavors"
326 fi
327 if [ "$do_asserts" = "yes" ]; then
328     Flavors="$Flavors Release+Asserts"
329 fi
330 if [ "$do_64bit" = "yes" ]; then
331     Flavors="$Flavors Release-64"
332 fi
333
334 for Flavor in $Flavors ; do
335     echo ""
336     echo ""
337     echo "********************************************************************************"
338     echo "  Release:     $Release-$RC"
339     echo "  Build:       $Flavor"
340     echo "  System Info: "
341     echo "    `uname -a`"
342     echo "********************************************************************************"
343     echo ""
344
345     c_compiler="$CC"
346     cxx_compiler="$CXX"
347
348     llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
349     llvmCore_phase1_installdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
350     dragonegg_phase1_objdir=$BuildDir/Phase1/$Flavor/DragonEgg-$Release-$RC.obj
351
352     llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
353     llvmCore_phase2_installdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
354     llvmCore_de_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-DragonEgg-$Release-$RC.obj
355     llvmCore_de_phase2_installdir=$BuildDir/Phase2/$Flavor/llvmCore-DragonEgg-$Release-$RC.install
356     dragonegg_phase2_objdir=$BuildDir/Phase2/$Flavor/DragonEgg-$Release-$RC.obj
357
358     llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
359     llvmCore_phase3_installdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
360     llvmCore_de_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-DragonEgg-$Release-$RC.obj
361     llvmCore_de_phase3_installdir=$BuildDir/Phase3/$Flavor/llvmCore-DragonEgg-$Release-$RC.install
362     dragonegg_phase3_objdir=$BuildDir/Phase3/$Flavor/DragonEgg-$Release-$RC.obj
363
364     rm -rf $llvmCore_phase1_objdir
365     rm -rf $llvmCore_phase1_installdir
366     rm -rf $dragonegg_phase1_objdir
367
368     rm -rf $llvmCore_phase2_objdir
369     rm -rf $llvmCore_phase2_installdir
370     rm -rf $llvmCore_de_phase2_objdir
371     rm -rf $llvmCore_de_phase2_installdir
372     rm -rf $dragonegg_phase2_objdir
373
374     rm -rf $llvmCore_phase3_objdir
375     rm -rf $llvmCore_phase3_installdir
376     rm -rf $llvmCore_de_phase3_objdir
377     rm -rf $llvmCore_de_phase3_installdir
378     rm -rf $dragonegg_phase3_objdir
379
380     mkdir -p $llvmCore_phase1_objdir
381     mkdir -p $llvmCore_phase1_installdir
382     mkdir -p $dragonegg_phase1_objdir
383
384     mkdir -p $llvmCore_phase2_objdir
385     mkdir -p $llvmCore_phase2_installdir
386     mkdir -p $llvmCore_de_phase2_objdir
387     mkdir -p $llvmCore_de_phase2_installdir
388     mkdir -p $dragonegg_phase2_objdir
389
390     mkdir -p $llvmCore_phase3_objdir
391     mkdir -p $llvmCore_phase3_installdir
392     mkdir -p $llvmCore_de_phase3_objdir
393     mkdir -p $llvmCore_de_phase3_installdir
394     mkdir -p $dragonegg_phase3_objdir
395
396     ############################################################################
397     # Phase 1: Build llvmCore and clang
398     echo "# Phase 1: Building llvmCore"
399     configure_llvmCore 1 $Flavor \
400         $llvmCore_phase1_objdir $llvmCore_phase1_installdir
401     build_llvmCore 1 $Flavor \
402         $llvmCore_phase1_objdir
403
404     # Test clang
405     if [ "$do_clang" = "yes" ]; then
406         ############################################################################
407         # Phase 2: Build llvmCore with newly built clang from phase 1.
408         c_compiler=$llvmCore_phase1_installdir/bin/clang
409         cxx_compiler=$llvmCore_phase1_installdir/bin/clang++
410         echo "# Phase 2: Building llvmCore"
411         configure_llvmCore 2 $Flavor \
412             $llvmCore_phase2_objdir $llvmCore_phase2_installdir
413         build_llvmCore 2 $Flavor \
414             $llvmCore_phase2_objdir
415
416         ############################################################################
417         # Phase 3: Build llvmCore with newly built clang from phase 2.
418         c_compiler=$llvmCore_phase2_installdir/bin/clang
419         cxx_compiler=$llvmCore_phase2_installdir/bin/clang++
420         echo "# Phase 3: Building llvmCore"
421         configure_llvmCore 3 $Flavor \
422             $llvmCore_phase3_objdir $llvmCore_phase3_installdir
423         build_llvmCore 3 $Flavor \
424             $llvmCore_phase3_objdir
425
426         ############################################################################
427         # Testing: Test phase 3
428         echo "# Testing - built with clang"
429         test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
430
431         ############################################################################
432         # Compare .o files between Phase2 and Phase3 and report which ones differ.
433         echo
434         echo "# Comparing Phase 2 and Phase 3 files"
435         for o in `find $llvmCore_phase2_objdir -name '*.o'` ; do
436             p3=`echo $o | sed -e 's,Phase2,Phase3,'`
437             if ! cmp --ignore-initial=16 $o $p3 > /dev/null 2>&1 ; then
438                 echo "file `basename $o` differs between phase 2 and phase 3"
439             fi
440         done
441     fi
442
443     # Test dragonegg
444     if [ "$do_dragonegg" = "yes" ]; then
445         # Build dragonegg using the targeted gcc.  This isn't necessary, but
446         # helps avoid using broken versions of gcc (which are legion), tests
447         # that the targeted gcc is basically sane and is consistent with the
448         # later phases in which the targeted gcc + dragonegg are used.
449         c_compiler="$gcc_compiler"
450         cxx_compiler="$gxx_compiler"
451         build_dragonegg 1 $Flavor $llvmCore_phase1_installdir $dragonegg_phase1_objdir
452
453         ############################################################################
454         # Phase 2: Build llvmCore with newly built dragonegg from phase 1.
455         c_compiler="$gcc_compiler -fplugin=$dragonegg_phase1_objdir/dragonegg.so"
456         cxx_compiler="$gxx_compiler -fplugin=$dragonegg_phase1_objdir/dragonegg.so"
457         echo "# Phase 2: Building llvmCore with dragonegg"
458         configure_llvmCore 2 $Flavor \
459             $llvmCore_de_phase2_objdir $llvmCore_de_phase2_installdir
460         build_llvmCore 2 $Flavor \
461             $llvmCore_de_phase2_objdir
462         build_dragonegg 2 $Flavor $llvmCore_de_phase2_installdir $dragonegg_phase2_objdir
463
464         ############################################################################
465         # Phase 3: Build llvmCore with newly built clang from phase 2.
466         c_compiler="$gcc_compiler -fplugin=$dragonegg_phase2_objdir/dragonegg.so"
467         cxx_compiler="$gxx_compiler -fplugin=$dragonegg_phase2_objdir/dragonegg.so"
468         echo "# Phase 3: Building llvmCore with dragonegg"
469         configure_llvmCore 3 $Flavor \
470             $llvmCore_de_phase3_objdir $llvmCore_de_phase3_installdir
471         build_llvmCore 3 $Flavor \
472             $llvmCore_de_phase3_objdir
473         build_dragonegg 3 $Flavor $llvmCore_de_phase3_installdir $dragonegg_phase3_objdir
474
475         ############################################################################
476         # Testing: Test phase 3
477         c_compiler="$gcc_compiler -fplugin=$dragonegg_phase3_objdir/dragonegg.so"
478         cxx_compiler="$gxx_compiler -fplugin=$dragonegg_phase3_objdir/dragonegg.so"
479         echo "# Testing - built with dragonegg"
480         test_llvmCore 3 $Flavor $llvmCore_de_phase3_objdir
481
482         ############################################################################
483         # Compare .o files between Phase2 and Phase3 and report which ones differ.
484         echo
485         echo "# Comparing Phase 2 and Phase 3 files"
486         for o in `find $llvmCore_de_phase2_objdir -name '*.o'` \
487           `find $dragonegg_phase2_objdir -name '*.o'` ; do
488             p3=`echo $o | sed -e 's,Phase2,Phase3,'`
489             if ! cmp --ignore-initial=16 $o $p3 > /dev/null 2>&1 ; then
490                 echo "file `basename $o` differs between dragonegg phase 2 and phase 3"
491             fi
492         done
493     fi
494
495     # Otherwise just test the core.
496     if [ "$do_clang" != "yes" -a "$do_dragonegg" != "yes" ]; then
497         echo "# Testing - built with system compiler"
498         test_llvmCore 1 $Flavor $llvmCore_phase1_objdir
499     fi
500 done
501 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
502
503 set +e
504
505 # Woo hoo!
506 echo "### Testing Finished ###"
507 echo "### Logs: $LogDir"
508 exit 0