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