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 # See llvm.org/PR26146.
159 echo Skipping test-suite when using CMake.
163 # Check required arguments.
164 if [ -z "$Release" ]; then
165 echo "error: no release number specified"
168 if [ -z "$RC" ]; then
169 echo "error: no release candidate number specified"
172 if [ -z "$ExportBranch" ]; then
173 ExportBranch="tags/RELEASE_$Release_no_dot/$RC"
175 if [ -z "$Triple" ]; then
176 echo "error: no target triple specified"
180 # Figure out how many make processes to run.
181 if [ -z "$NumJobs" ]; then
182 NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
184 if [ -z "$NumJobs" ]; then
185 NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
187 if [ -z "$NumJobs" ]; then
188 NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
190 if [ -z "$NumJobs" ]; then
195 projects="llvm cfe clang-tools-extra"
196 if [ $do_rt = "yes" ]; then
197 projects="$projects compiler-rt"
199 if [ $do_libs = "yes" ]; then
200 projects="$projects libcxx libcxxabi"
201 if [ $do_libunwind = "yes" ]; then
202 projects="$projects libunwind"
205 if [ $do_test_suite = "yes" ]; then
206 projects="$projects test-suite"
208 if [ $do_openmp = "yes" ]; then
209 projects="$projects openmp"
212 # Go to the build directory (may be different from CWD)
213 BuildDir=$BuildDir/$RC
217 # Location of log files.
218 LogDir=$BuildDir/logs
221 # Final package name.
222 Package=clang+llvm-$Release
223 if [ $RC != "final" ]; then
226 Package=$Package-$Triple
228 # Errors to be highlighted at the end are written to this file.
229 echo -n > $LogDir/deferred_errors.log
231 function deferred_error() {
235 echo "[${Flavor} Phase${Phase}] ${Msg}" | tee -a $LogDir/deferred_errors.log
238 # Make sure that a required program is available
239 function check_program_exists() {
241 if ! type -P $program > /dev/null 2>&1 ; then
242 echo "program '$1' not found !"
247 if [ `uname -s` != "Darwin" ]; then
248 check_program_exists 'chrpath'
249 check_program_exists 'file'
250 check_program_exists 'objdump'
253 # Make sure that the URLs are valid.
254 function check_valid_urls() {
255 for proj in $projects ; do
256 echo "# Validating $proj SVN URL"
258 if ! svn ls $Base_url/$proj/$ExportBranch > /dev/null 2>&1 ; then
259 echo "$proj does not have a $ExportBranch branch/tag!"
265 # Export sources to the build directory.
266 function export_sources() {
269 for proj in $projects ; do
270 if [ -d $proj.src ]; then
271 echo "# Reusing $proj $Release-$RC sources"
274 echo "# Exporting $proj $Release-$RC sources"
275 if ! svn export -q $Base_url/$proj/$ExportBranch $proj.src ; then
276 echo "error: failed to export $proj project"
281 echo "# Creating symlinks"
282 cd $BuildDir/llvm.src/tools
283 if [ ! -h clang ]; then
284 ln -s ../../cfe.src clang
287 # The autoconf and CMake builds want different symlinks here:
288 if [ "$use_autoconf" = "yes" ]; then
289 cd $BuildDir/llvm.src/tools/clang/tools
290 if [ ! -h extra ]; then
291 ln -s ../../../../clang-tools-extra.src extra
294 cd $BuildDir/cfe.src/tools
295 if [ ! -h extra ]; then
296 ln -s ../../clang-tools-extra.src extra
300 cd $BuildDir/llvm.src/projects
301 if [ -d $BuildDir/test-suite.src ] && [ ! -h test-suite ]; then
302 ln -s ../../test-suite.src test-suite
304 if [ -d $BuildDir/compiler-rt.src ] && [ ! -h compiler-rt ]; then
305 ln -s ../../compiler-rt.src compiler-rt
307 if [ -d $BuildDir/openmp.src ] && [ ! -h openmp ]; then
308 ln -s ../../openmp.src openmp
310 if [ -d $BuildDir/libcxx.src ] && [ ! -h libcxx ]; then
311 ln -s ../../libcxx.src libcxx
313 if [ -d $BuildDir/libcxxabi.src ] && [ ! -h libcxxabi ]; then
314 ln -s ../../libcxxabi.src libcxxabi
316 if [ -d $BuildDir/libunwind.src ] && [ ! -h libunwind ]; then
317 ln -s ../../libunwind.src libunwind
323 function configure_llvmCore() {
332 ConfigureFlags="--enable-optimized --disable-assertions"
337 ConfigureFlags="--enable-optimized --enable-assertions"
342 ConfigureFlags="--disable-optimized --enable-assertions"
345 echo "# Invalid flavor '$Flavor'"
351 echo "# Using C compiler: $c_compiler"
352 echo "# Using C++ compiler: $cxx_compiler"
355 echo "# Configuring llvm $Release-$RC $Flavor"
357 if [ "$use_autoconf" = "yes" ]; then
358 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
359 $BuildDir/llvm.src/configure \
360 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
361 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
362 env CC="$c_compiler" CXX="$cxx_compiler" \
363 $BuildDir/llvm.src/configure \
364 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
365 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
367 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
368 cmake -G "Unix Makefiles" \
369 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
370 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
371 $ExtraConfigureFlags $BuildDir/llvm.src \
372 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
373 env CC="$c_compiler" CXX="$cxx_compiler" \
374 cmake -G "Unix Makefiles" \
375 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
376 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
377 $ExtraConfigureFlags $BuildDir/llvm.src \
378 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
384 function build_llvmCore() {
391 echo "# Compiling llvm $Release-$RC $Flavor"
392 echo "# ${MAKE} -j $NumJobs VERBOSE=1"
393 ${MAKE} -j $NumJobs VERBOSE=1 \
394 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
396 echo "# Installing llvm $Release-$RC $Flavor"
397 echo "# ${MAKE} install"
399 DESTDIR="${DestDir}" \
400 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
404 function test_llvmCore() {
410 if ! ( ${MAKE} -j $NumJobs -k check-all \
411 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
412 deferred_error $Phase $Flavor "check-all failed"
415 if [ "$use_autoconf" = "yes" ]; then
416 # In the cmake build, unit tests are run as part of check-all.
417 if ! ( ${MAKE} -k unittests 2>&1 | \
418 tee $LogDir/llvm.unittests-Phase$Phase-$Flavor.log ) ; then
419 deferred_error $Phase $Flavor "unittests failed"
426 # Clean RPATH. Libtool adds the build directory to the search path, which is
427 # not necessary --- and even harmful --- for the binary packages we release.
428 function clean_RPATH() {
429 if [ `uname -s` = "Darwin" ]; then
432 local InstallPath="$1"
433 for Candidate in `find $InstallPath/{bin,lib} -type f`; do
434 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
435 if rpath=`objdump -x $Candidate | grep 'RPATH'` ; then
436 rpath=`echo $rpath | sed -e's/^ *RPATH *//'`
437 if [ -n "$rpath" ]; then
438 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
439 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
446 # Create a package of the release binaries.
447 function package_release() {
449 cd $BuildDir/Phase3/Release
450 mv llvmCore-$Release-$RC.install/usr/local $Package
451 if [ "$use_gzip" = "yes" ]; then
452 tar cfz $BuildDir/$Package.tar.gz $Package
454 tar cfJ $BuildDir/$Package.tar.xz $Package
456 mv $Package llvmCore-$Release-$RC.install/usr/local
460 # Exit if any command fails
461 # Note: pipefail is necessary for running build commands through
462 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
466 if [ "$do_checkout" = "yes" ]; then
472 if [ "$do_debug" = "yes" ]; then
473 Flavors="Debug $Flavors"
475 if [ "$do_asserts" = "yes" ]; then
476 Flavors="$Flavors Release+Asserts"
479 for Flavor in $Flavors ; do
482 echo "********************************************************************************"
483 echo " Release: $Release-$RC"
484 echo " Build: $Flavor"
485 echo " System Info: "
487 echo "********************************************************************************"
492 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
493 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
495 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
496 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
498 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
499 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
501 rm -rf $llvmCore_phase1_objdir
502 rm -rf $llvmCore_phase1_destdir
504 rm -rf $llvmCore_phase2_objdir
505 rm -rf $llvmCore_phase2_destdir
507 rm -rf $llvmCore_phase3_objdir
508 rm -rf $llvmCore_phase3_destdir
510 mkdir -p $llvmCore_phase1_objdir
511 mkdir -p $llvmCore_phase1_destdir
513 mkdir -p $llvmCore_phase2_objdir
514 mkdir -p $llvmCore_phase2_destdir
516 mkdir -p $llvmCore_phase3_objdir
517 mkdir -p $llvmCore_phase3_destdir
519 ############################################################################
520 # Phase 1: Build llvmCore and clang
521 echo "# Phase 1: Building llvmCore"
522 configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir
523 build_llvmCore 1 $Flavor \
524 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
525 clean_RPATH $llvmCore_phase1_destdir/usr/local
527 ########################################################################
528 # Phase 2: Build llvmCore with newly built clang from phase 1.
529 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
530 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
531 echo "# Phase 2: Building llvmCore"
532 configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir
533 build_llvmCore 2 $Flavor \
534 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
535 clean_RPATH $llvmCore_phase2_destdir/usr/local
537 ########################################################################
538 # Phase 3: Build llvmCore with newly built clang from phase 2.
539 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
540 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
541 echo "# Phase 3: Building llvmCore"
542 configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir
543 build_llvmCore 3 $Flavor \
544 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
545 clean_RPATH $llvmCore_phase3_destdir/usr/local
547 ########################################################################
548 # Testing: Test phase 3
549 echo "# Testing - built with clang"
550 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
552 ########################################################################
553 # Compare .o files between Phase2 and Phase3 and report which ones
555 if [ "$do_compare" = "yes" ]; then
557 echo "# Comparing Phase 2 and Phase 3 files"
558 for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do
559 p3=`echo $p2 | sed -e 's,Phase2,Phase3,'`
560 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
561 # case there are build paths in the debug info. On some systems,
562 # sed adds a newline to the output, so pass $p3 through sed too.
563 if ! cmp -s <(sed -e 's,Phase2,Phase3,g' $p2) <(sed -e '' $p3) \
565 echo "file `basename $p2` differs between phase 2 and phase 3"
571 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
578 echo "### Testing Finished ###"
579 if [ "$use_gzip" = "yes" ]; then
580 echo "### Package: $Package.tar.gz"
582 echo "### Package: $Package.tar.xz"
584 echo "### Logs: $LogDir"
587 if [ -s "$LogDir/deferred_errors.log" ]; then
588 cat "$LogDir/deferred_errors.log"