2 #===-- test-release.sh - Test the LLVM release candidates ------------------===#
4 # The LLVM Compiler Infrastructure
6 # This file is distributed under the University of Illinois Open Source
9 #===------------------------------------------------------------------------===#
11 # Download, build, and test the release candidate for an LLVM release.
13 #===------------------------------------------------------------------------===#
15 if [ `uname -s` = "FreeBSD" ]; then
21 # Base SVN URL for the sources.
22 Base_url="http://llvm.org/svn/llvm-project"
40 ExtraConfigureFlags=""
44 echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]"
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 " -no-openmp Disable check-out & build libomp"
68 while [ $# -gt 0 ]; do
70 -release | --release )
73 Release_no_dot="`echo $1 | sed -e 's,\.,,g'`"
75 -rc | --rc | -RC | --RC )
82 -svn-path | --svn-path )
87 RC="`echo $ExportBranch | sed -e 's,/,_,g'`"
88 echo "WARNING: Using the branch $ExportBranch instead of a release tag"
89 echo " This is intended to aid new packagers in trialing "
90 echo " builds without requiring a tag to be created first"
96 -configure-flags | --configure-flags )
98 ExtraConfigureFlags="$1"
101 NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
102 if [ -z "$NumJobs" ]; then
107 -build-dir | --build-dir | -builddir | --builddir )
111 -no-checkout | --no-checkout )
114 -test-debug | --test-debug )
117 -test-asserts | --test-asserts )
120 -no-compare-files | --no-compare-files )
123 -use-gzip | --use-gzip )
126 -use-autoconf | --use-autoconf )
144 -help | --help | -h | --h | -\? )
149 echo "unknown option: $1"
157 if [ "$use_autoconf" = "no" ]; then
158 if [ "$do_test_suite" = "yes" ]; then
159 # See llvm.org/PR26146.
160 echo Skipping test-suite build when using CMake.
161 echo It will still be exported.
162 do_test_suite="export-only"
166 # Check required arguments.
167 if [ -z "$Release" ]; then
168 echo "error: no release number specified"
171 if [ -z "$RC" ]; then
172 echo "error: no release candidate number specified"
175 if [ -z "$ExportBranch" ]; then
176 ExportBranch="tags/RELEASE_$Release_no_dot/$RC"
178 if [ -z "$Triple" ]; then
179 echo "error: no target triple specified"
183 # Figure out how many make processes to run.
184 if [ -z "$NumJobs" ]; then
185 NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
187 if [ -z "$NumJobs" ]; then
188 NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
190 if [ -z "$NumJobs" ]; then
191 NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
193 if [ -z "$NumJobs" ]; then
198 projects="llvm cfe clang-tools-extra"
199 if [ $do_rt = "yes" ]; then
200 projects="$projects compiler-rt"
202 if [ $do_libs = "yes" ]; then
203 projects="$projects libcxx libcxxabi"
204 if [ $do_libunwind = "yes" ]; then
205 projects="$projects libunwind"
208 case $do_test_suite in
210 projects="$projects test-suite"
213 if [ $do_openmp = "yes" ]; then
214 projects="$projects openmp"
217 # Go to the build directory (may be different from CWD)
218 BuildDir=$BuildDir/$RC
222 # Location of log files.
223 LogDir=$BuildDir/logs
226 # Final package name.
227 Package=clang+llvm-$Release
228 if [ $RC != "final" ]; then
231 Package=$Package-$Triple
233 # Errors to be highlighted at the end are written to this file.
234 echo -n > $LogDir/deferred_errors.log
236 function deferred_error() {
240 echo "[${Flavor} Phase${Phase}] ${Msg}" | tee -a $LogDir/deferred_errors.log
243 # Make sure that a required program is available
244 function check_program_exists() {
246 if ! type -P $program > /dev/null 2>&1 ; then
247 echo "program '$1' not found !"
252 if [ `uname -s` != "Darwin" ]; then
253 check_program_exists 'chrpath'
254 check_program_exists 'file'
255 check_program_exists 'objdump'
258 # Make sure that the URLs are valid.
259 function check_valid_urls() {
260 for proj in $projects ; do
261 echo "# Validating $proj SVN URL"
263 if ! svn ls $Base_url/$proj/$ExportBranch > /dev/null 2>&1 ; then
264 echo "$proj does not have a $ExportBranch branch/tag!"
270 # Export sources to the build directory.
271 function export_sources() {
274 for proj in $projects ; do
280 projsrc=llvm.src/tools/clang
283 projsrc=llvm.src/tools/clang/tools/extra
285 compiler-rt|libcxx|libcxxabi|libunwind|openmp)
286 projsrc=llvm.src/projects/$proj
289 if [ $do_test_suite = 'yes' ]; then
290 projsrc=llvm.src/projects/$proj
296 echo "error: unknown project $proj"
301 if [ -d $projsrc ]; then
302 echo "# Reusing $proj $Release-$RC sources in $projsrc"
305 echo "# Exporting $proj $Release-$RC sources to $projsrc"
306 if ! svn export -q $Base_url/$proj/$ExportBranch $projsrc ; then
307 echo "error: failed to export $proj project"
315 function configure_llvmCore() {
324 ConfigureFlags="--enable-optimized --disable-assertions"
329 ConfigureFlags="--enable-optimized --enable-assertions"
334 ConfigureFlags="--disable-optimized --enable-assertions"
337 echo "# Invalid flavor '$Flavor'"
343 echo "# Using C compiler: $c_compiler"
344 echo "# Using C++ compiler: $cxx_compiler"
347 echo "# Configuring llvm $Release-$RC $Flavor"
349 if [ "$use_autoconf" = "yes" ]; then
350 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
351 $BuildDir/llvm.src/configure \
352 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
353 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
354 env CC="$c_compiler" CXX="$cxx_compiler" \
355 $BuildDir/llvm.src/configure \
356 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
357 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
359 echo "#" 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 env CC="$c_compiler" CXX="$cxx_compiler" \
366 cmake -G "Unix Makefiles" \
367 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
368 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
369 $ExtraConfigureFlags $BuildDir/llvm.src \
370 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
376 function build_llvmCore() {
383 echo "# Compiling llvm $Release-$RC $Flavor"
384 echo "# ${MAKE} -j $NumJobs VERBOSE=1"
385 ${MAKE} -j $NumJobs VERBOSE=1 \
386 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
388 echo "# Installing llvm $Release-$RC $Flavor"
389 echo "# ${MAKE} install"
391 DESTDIR="${DestDir}" \
392 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
396 function test_llvmCore() {
402 if ! ( ${MAKE} -j $NumJobs -k check-all \
403 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
404 deferred_error $Phase $Flavor "check-all failed"
407 if [ "$use_autoconf" = "yes" ]; then
408 # In the cmake build, unit tests are run as part of check-all.
409 if ! ( ${MAKE} -k unittests 2>&1 | \
410 tee $LogDir/llvm.unittests-Phase$Phase-$Flavor.log ) ; then
411 deferred_error $Phase $Flavor "unittests failed"
418 # Clean RPATH. Libtool adds the build directory to the search path, which is
419 # not necessary --- and even harmful --- for the binary packages we release.
420 function clean_RPATH() {
421 if [ `uname -s` = "Darwin" ]; then
424 local InstallPath="$1"
425 for Candidate in `find $InstallPath/{bin,lib} -type f`; do
426 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
427 if rpath=`objdump -x $Candidate | grep 'RPATH'` ; then
428 rpath=`echo $rpath | sed -e's/^ *RPATH *//'`
429 if [ -n "$rpath" ]; then
430 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
431 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
438 # Create a package of the release binaries.
439 function package_release() {
441 cd $BuildDir/Phase3/Release
442 mv llvmCore-$Release-$RC.install/usr/local $Package
443 if [ "$use_gzip" = "yes" ]; then
444 tar cfz $BuildDir/$Package.tar.gz $Package
446 tar cfJ $BuildDir/$Package.tar.xz $Package
448 mv $Package llvmCore-$Release-$RC.install/usr/local
452 # Exit if any command fails
453 # Note: pipefail is necessary for running build commands through
454 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
458 if [ "$do_checkout" = "yes" ]; then
464 if [ "$do_debug" = "yes" ]; then
465 Flavors="Debug $Flavors"
467 if [ "$do_asserts" = "yes" ]; then
468 Flavors="$Flavors Release+Asserts"
471 for Flavor in $Flavors ; do
474 echo "********************************************************************************"
475 echo " Release: $Release-$RC"
476 echo " Build: $Flavor"
477 echo " System Info: "
479 echo "********************************************************************************"
484 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
485 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
487 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
488 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
490 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
491 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
493 rm -rf $llvmCore_phase1_objdir
494 rm -rf $llvmCore_phase1_destdir
496 rm -rf $llvmCore_phase2_objdir
497 rm -rf $llvmCore_phase2_destdir
499 rm -rf $llvmCore_phase3_objdir
500 rm -rf $llvmCore_phase3_destdir
502 mkdir -p $llvmCore_phase1_objdir
503 mkdir -p $llvmCore_phase1_destdir
505 mkdir -p $llvmCore_phase2_objdir
506 mkdir -p $llvmCore_phase2_destdir
508 mkdir -p $llvmCore_phase3_objdir
509 mkdir -p $llvmCore_phase3_destdir
511 ############################################################################
512 # Phase 1: Build llvmCore and clang
513 echo "# Phase 1: Building llvmCore"
514 configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir
515 build_llvmCore 1 $Flavor \
516 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
517 clean_RPATH $llvmCore_phase1_destdir/usr/local
519 ########################################################################
520 # Phase 2: Build llvmCore with newly built clang from phase 1.
521 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
522 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
523 echo "# Phase 2: Building llvmCore"
524 configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir
525 build_llvmCore 2 $Flavor \
526 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
527 clean_RPATH $llvmCore_phase2_destdir/usr/local
529 ########################################################################
530 # Phase 3: Build llvmCore with newly built clang from phase 2.
531 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
532 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
533 echo "# Phase 3: Building llvmCore"
534 configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir
535 build_llvmCore 3 $Flavor \
536 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
537 clean_RPATH $llvmCore_phase3_destdir/usr/local
539 ########################################################################
540 # Testing: Test phase 3
541 echo "# Testing - built with clang"
542 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
544 ########################################################################
545 # Compare .o files between Phase2 and Phase3 and report which ones
547 if [ "$do_compare" = "yes" ]; then
549 echo "# Comparing Phase 2 and Phase 3 files"
550 for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do
551 p3=`echo $p2 | sed -e 's,Phase2,Phase3,'`
552 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
553 # case there are build paths in the debug info. On some systems,
554 # sed adds a newline to the output, so pass $p3 through sed too.
556 <(env LC_CTYPE=C sed -e 's,Phase2,Phase3,g' $p2) \
557 <(env LC_CTYPE=C sed -e '' $p3) 16 16; then
558 echo "file `basename $p2` differs between phase 2 and phase 3"
564 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
571 echo "### Testing Finished ###"
572 if [ "$use_gzip" = "yes" ]; then
573 echo "### Package: $Package.tar.gz"
575 echo "### Package: $Package.tar.xz"
577 echo "### Logs: $LogDir"
580 if [ -s "$LogDir/deferred_errors.log" ]; then
581 cat "$LogDir/deferred_errors.log"