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 if [ `uname -s` = "Darwin" ]; then
69 # compiler-rt doesn't yet build with CMake on Darwin.
73 while [ $# -gt 0 ]; do
75 -release | --release )
78 Release_no_dot="`echo $1 | sed -e 's,\.,,g'`"
80 -rc | --rc | -RC | --RC )
87 -svn-path | --svn-path )
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"
101 -configure-flags | --configure-flags )
103 ExtraConfigureFlags="$1"
106 NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
107 if [ -z "$NumJobs" ]; then
112 -build-dir | --build-dir | -builddir | --builddir )
116 -no-checkout | --no-checkout )
119 -test-debug | --test-debug )
122 -test-asserts | --test-asserts )
125 -no-compare-files | --no-compare-files )
128 -use-gzip | --use-gzip )
131 -use-autoconf | --use-autoconf )
149 -help | --help | -h | --h | -\? )
154 echo "unknown option: $1"
162 if [ "$use_autoconf" = "no" ]; then
163 # See llvm.org/PR26146.
164 echo Skipping test-suite when using CMake.
168 # Check required arguments.
169 if [ -z "$Release" ]; then
170 echo "error: no release number specified"
173 if [ -z "$RC" ]; then
174 echo "error: no release candidate number specified"
177 if [ -z "$ExportBranch" ]; then
178 ExportBranch="tags/RELEASE_$Release_no_dot/$RC"
180 if [ -z "$Triple" ]; then
181 echo "error: no target triple specified"
185 # Figure out how many make processes to run.
186 if [ -z "$NumJobs" ]; then
187 NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
189 if [ -z "$NumJobs" ]; then
190 NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
192 if [ -z "$NumJobs" ]; then
193 NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
195 if [ -z "$NumJobs" ]; then
200 projects="llvm cfe clang-tools-extra"
201 if [ $do_rt = "yes" ]; then
202 projects="$projects compiler-rt"
204 if [ $do_libs = "yes" ]; then
205 projects="$projects libcxx libcxxabi"
206 if [ $do_libunwind = "yes" ]; then
207 projects="$projects libunwind"
210 if [ $do_test_suite = "yes" ]; then
211 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
275 if [ -d $proj.src ]; then
276 echo "# Reusing $proj $Release-$RC sources"
279 echo "# Exporting $proj $Release-$RC sources"
280 if ! svn export -q $Base_url/$proj/$ExportBranch $proj.src ; then
281 echo "error: failed to export $proj project"
286 echo "# Creating symlinks"
287 cd $BuildDir/llvm.src/tools
288 if [ ! -h clang ]; then
289 ln -s ../../cfe.src clang
292 # The autoconf and CMake builds want different symlinks here:
293 if [ "$use_autoconf" = "yes" ]; then
294 cd $BuildDir/llvm.src/tools/clang/tools
295 if [ ! -h extra ]; then
296 ln -s ../../../../clang-tools-extra.src extra
299 cd $BuildDir/cfe.src/tools
300 if [ ! -h extra ]; then
301 ln -s ../../clang-tools-extra.src extra
305 cd $BuildDir/llvm.src/projects
306 if [ -d $BuildDir/test-suite.src ] && [ ! -h test-suite ]; then
307 ln -s ../../test-suite.src test-suite
309 if [ -d $BuildDir/compiler-rt.src ] && [ ! -h compiler-rt ]; then
310 ln -s ../../compiler-rt.src compiler-rt
312 if [ -d $BuildDir/openmp.src ] && [ ! -h openmp ]; then
313 ln -s ../../openmp.src openmp
315 if [ -d $BuildDir/libcxx.src ] && [ ! -h libcxx ]; then
316 ln -s ../../libcxx.src libcxx
318 if [ -d $BuildDir/libcxxabi.src ] && [ ! -h libcxxabi ]; then
319 ln -s ../../libcxxabi.src libcxxabi
321 if [ -d $BuildDir/libunwind.src ] && [ ! -h libunwind ]; then
322 ln -s ../../libunwind.src libunwind
328 function configure_llvmCore() {
337 ConfigureFlags="--enable-optimized --disable-assertions"
342 ConfigureFlags="--enable-optimized --enable-assertions"
347 ConfigureFlags="--disable-optimized --enable-assertions"
350 echo "# Invalid flavor '$Flavor'"
356 echo "# Using C compiler: $c_compiler"
357 echo "# Using C++ compiler: $cxx_compiler"
360 echo "# Configuring llvm $Release-$RC $Flavor"
362 if [ "$use_autoconf" = "yes" ]; then
363 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
364 $BuildDir/llvm.src/configure \
365 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
366 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
367 env CC="$c_compiler" CXX="$cxx_compiler" \
368 $BuildDir/llvm.src/configure \
369 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
370 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
372 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
373 cmake -G "Unix Makefiles" \
374 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
375 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
376 $ExtraConfigureFlags $BuildDir/llvm.src \
377 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
378 env CC="$c_compiler" CXX="$cxx_compiler" \
379 cmake -G "Unix Makefiles" \
380 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
381 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
382 $ExtraConfigureFlags $BuildDir/llvm.src \
383 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
389 function build_llvmCore() {
396 echo "# Compiling llvm $Release-$RC $Flavor"
397 echo "# ${MAKE} -j $NumJobs VERBOSE=1"
398 ${MAKE} -j $NumJobs VERBOSE=1 \
399 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
401 echo "# Installing llvm $Release-$RC $Flavor"
402 echo "# ${MAKE} install"
404 DESTDIR="${DestDir}" \
405 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
409 function test_llvmCore() {
415 if ! ( ${MAKE} -j $NumJobs -k check-all \
416 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
417 deferred_error $Phase $Flavor "check-all failed"
420 if [ "$use_autoconf" = "yes" ]; then
421 # In the cmake build, unit tests are run as part of check-all.
422 if ! ( ${MAKE} -k unittests 2>&1 | \
423 tee $LogDir/llvm.unittests-Phase$Phase-$Flavor.log ) ; then
424 deferred_error $Phase $Flavor "unittests failed"
431 # Clean RPATH. Libtool adds the build directory to the search path, which is
432 # not necessary --- and even harmful --- for the binary packages we release.
433 function clean_RPATH() {
434 if [ `uname -s` = "Darwin" ]; then
437 local InstallPath="$1"
438 for Candidate in `find $InstallPath/{bin,lib} -type f`; do
439 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
440 if rpath=`objdump -x $Candidate | grep 'RPATH'` ; then
441 rpath=`echo $rpath | sed -e's/^ *RPATH *//'`
442 if [ -n "$rpath" ]; then
443 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
444 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
451 # Create a package of the release binaries.
452 function package_release() {
454 cd $BuildDir/Phase3/Release
455 mv llvmCore-$Release-$RC.install/usr/local $Package
456 if [ "$use_gzip" = "yes" ]; then
457 tar cfz $BuildDir/$Package.tar.gz $Package
459 tar cfJ $BuildDir/$Package.tar.xz $Package
461 mv $Package llvmCore-$Release-$RC.install/usr/local
465 # Exit if any command fails
466 # Note: pipefail is necessary for running build commands through
467 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
471 if [ "$do_checkout" = "yes" ]; then
477 if [ "$do_debug" = "yes" ]; then
478 Flavors="Debug $Flavors"
480 if [ "$do_asserts" = "yes" ]; then
481 Flavors="$Flavors Release+Asserts"
484 for Flavor in $Flavors ; do
487 echo "********************************************************************************"
488 echo " Release: $Release-$RC"
489 echo " Build: $Flavor"
490 echo " System Info: "
492 echo "********************************************************************************"
497 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
498 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
500 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
501 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
503 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
504 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
506 rm -rf $llvmCore_phase1_objdir
507 rm -rf $llvmCore_phase1_destdir
509 rm -rf $llvmCore_phase2_objdir
510 rm -rf $llvmCore_phase2_destdir
512 rm -rf $llvmCore_phase3_objdir
513 rm -rf $llvmCore_phase3_destdir
515 mkdir -p $llvmCore_phase1_objdir
516 mkdir -p $llvmCore_phase1_destdir
518 mkdir -p $llvmCore_phase2_objdir
519 mkdir -p $llvmCore_phase2_destdir
521 mkdir -p $llvmCore_phase3_objdir
522 mkdir -p $llvmCore_phase3_destdir
524 ############################################################################
525 # Phase 1: Build llvmCore and clang
526 echo "# Phase 1: Building llvmCore"
527 configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir
528 build_llvmCore 1 $Flavor \
529 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
530 clean_RPATH $llvmCore_phase1_destdir/usr/local
532 ########################################################################
533 # Phase 2: Build llvmCore with newly built clang from phase 1.
534 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
535 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
536 echo "# Phase 2: Building llvmCore"
537 configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir
538 build_llvmCore 2 $Flavor \
539 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
540 clean_RPATH $llvmCore_phase2_destdir/usr/local
542 ########################################################################
543 # Phase 3: Build llvmCore with newly built clang from phase 2.
544 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
545 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
546 echo "# Phase 3: Building llvmCore"
547 configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir
548 build_llvmCore 3 $Flavor \
549 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
550 clean_RPATH $llvmCore_phase3_destdir/usr/local
552 ########################################################################
553 # Testing: Test phase 3
554 echo "# Testing - built with clang"
555 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
557 ########################################################################
558 # Compare .o files between Phase2 and Phase3 and report which ones
560 if [ "$do_compare" = "yes" ]; then
562 echo "# Comparing Phase 2 and Phase 3 files"
563 for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do
564 p3=`echo $p2 | sed -e 's,Phase2,Phase3,'`
565 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
566 # case there are build paths in the debug info. On some systems,
567 # sed adds a newline to the output, so pass $p3 through sed too.
568 if ! cmp -s <(sed -e 's,Phase2,Phase3,g' $p2) <(sed -e '' $p3) \
570 echo "file `basename $p2` differs between phase 2 and phase 3"
576 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
583 echo "### Testing Finished ###"
584 if [ "$use_gzip" = "yes" ]; then
585 echo "### Package: $Package.tar.gz"
587 echo "### Package: $Package.tar.xz"
589 echo "### Logs: $LogDir"
592 if [ -s "$LogDir/deferred_errors.log" ]; then
593 cat "$LogDir/deferred_errors.log"