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