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
275 projsrc=llvm.src/tools/clang
278 projsrc=llvm.src/tools/clang/tools/extra
280 compiler-rt|libcxx|libcxxabi|libunwind|openmp|test-suite)
281 projsrc=llvm.src/projects/$proj
284 echo "error: unknown project $proj"
289 if [ -d $projsrc ]; then
290 echo "# Reusing $proj $Release-$RC sources in $projsrc"
293 echo "# Exporting $proj $Release-$RC sources to $projsrc"
294 if ! svn export -q $Base_url/$proj/$ExportBranch $projsrc ; then
295 echo "error: failed to export $proj project"
303 function configure_llvmCore() {
312 ConfigureFlags="--enable-optimized --disable-assertions"
317 ConfigureFlags="--enable-optimized --enable-assertions"
322 ConfigureFlags="--disable-optimized --enable-assertions"
325 echo "# Invalid flavor '$Flavor'"
331 echo "# Using C compiler: $c_compiler"
332 echo "# Using C++ compiler: $cxx_compiler"
335 echo "# Configuring llvm $Release-$RC $Flavor"
337 if [ "$use_autoconf" = "yes" ]; then
338 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
339 $BuildDir/llvm.src/configure \
340 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
341 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
342 env CC="$c_compiler" CXX="$cxx_compiler" \
343 $BuildDir/llvm.src/configure \
344 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
345 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
347 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
348 cmake -G "Unix Makefiles" \
349 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
350 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
351 $ExtraConfigureFlags $BuildDir/llvm.src \
352 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
353 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
364 function build_llvmCore() {
371 echo "# Compiling llvm $Release-$RC $Flavor"
372 echo "# ${MAKE} -j $NumJobs VERBOSE=1"
373 ${MAKE} -j $NumJobs VERBOSE=1 \
374 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
376 echo "# Installing llvm $Release-$RC $Flavor"
377 echo "# ${MAKE} install"
379 DESTDIR="${DestDir}" \
380 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
384 function test_llvmCore() {
390 if ! ( ${MAKE} -j $NumJobs -k check-all \
391 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
392 deferred_error $Phase $Flavor "check-all failed"
395 if [ "$use_autoconf" = "yes" ]; then
396 # In the cmake build, unit tests are run as part of check-all.
397 if ! ( ${MAKE} -k unittests 2>&1 | \
398 tee $LogDir/llvm.unittests-Phase$Phase-$Flavor.log ) ; then
399 deferred_error $Phase $Flavor "unittests failed"
406 # Clean RPATH. Libtool adds the build directory to the search path, which is
407 # not necessary --- and even harmful --- for the binary packages we release.
408 function clean_RPATH() {
409 if [ `uname -s` = "Darwin" ]; then
412 local InstallPath="$1"
413 for Candidate in `find $InstallPath/{bin,lib} -type f`; do
414 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
415 if rpath=`objdump -x $Candidate | grep 'RPATH'` ; then
416 rpath=`echo $rpath | sed -e's/^ *RPATH *//'`
417 if [ -n "$rpath" ]; then
418 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
419 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
426 # Create a package of the release binaries.
427 function package_release() {
429 cd $BuildDir/Phase3/Release
430 mv llvmCore-$Release-$RC.install/usr/local $Package
431 if [ "$use_gzip" = "yes" ]; then
432 tar cfz $BuildDir/$Package.tar.gz $Package
434 tar cfJ $BuildDir/$Package.tar.xz $Package
436 mv $Package llvmCore-$Release-$RC.install/usr/local
440 # Exit if any command fails
441 # Note: pipefail is necessary for running build commands through
442 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
446 if [ "$do_checkout" = "yes" ]; then
452 if [ "$do_debug" = "yes" ]; then
453 Flavors="Debug $Flavors"
455 if [ "$do_asserts" = "yes" ]; then
456 Flavors="$Flavors Release+Asserts"
459 for Flavor in $Flavors ; do
462 echo "********************************************************************************"
463 echo " Release: $Release-$RC"
464 echo " Build: $Flavor"
465 echo " System Info: "
467 echo "********************************************************************************"
472 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
473 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
475 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
476 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
478 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
479 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
481 rm -rf $llvmCore_phase1_objdir
482 rm -rf $llvmCore_phase1_destdir
484 rm -rf $llvmCore_phase2_objdir
485 rm -rf $llvmCore_phase2_destdir
487 rm -rf $llvmCore_phase3_objdir
488 rm -rf $llvmCore_phase3_destdir
490 mkdir -p $llvmCore_phase1_objdir
491 mkdir -p $llvmCore_phase1_destdir
493 mkdir -p $llvmCore_phase2_objdir
494 mkdir -p $llvmCore_phase2_destdir
496 mkdir -p $llvmCore_phase3_objdir
497 mkdir -p $llvmCore_phase3_destdir
499 ############################################################################
500 # Phase 1: Build llvmCore and clang
501 echo "# Phase 1: Building llvmCore"
502 configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir
503 build_llvmCore 1 $Flavor \
504 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
505 clean_RPATH $llvmCore_phase1_destdir/usr/local
507 ########################################################################
508 # Phase 2: Build llvmCore with newly built clang from phase 1.
509 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
510 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
511 echo "# Phase 2: Building llvmCore"
512 configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir
513 build_llvmCore 2 $Flavor \
514 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
515 clean_RPATH $llvmCore_phase2_destdir/usr/local
517 ########################################################################
518 # Phase 3: Build llvmCore with newly built clang from phase 2.
519 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
520 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
521 echo "# Phase 3: Building llvmCore"
522 configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir
523 build_llvmCore 3 $Flavor \
524 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
525 clean_RPATH $llvmCore_phase3_destdir/usr/local
527 ########################################################################
528 # Testing: Test phase 3
529 echo "# Testing - built with clang"
530 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
532 ########################################################################
533 # Compare .o files between Phase2 and Phase3 and report which ones
535 if [ "$do_compare" = "yes" ]; then
537 echo "# Comparing Phase 2 and Phase 3 files"
538 for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do
539 p3=`echo $p2 | sed -e 's,Phase2,Phase3,'`
540 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
541 # case there are build paths in the debug info. On some systems,
542 # sed adds a newline to the output, so pass $p3 through sed too.
544 <(env LC_CTYPE=C sed -e 's,Phase2,Phase3,g' $p2) \
545 <(env LC_CTYPE=C sed -e '' $p3) 16 16; then
546 echo "file `basename $p2` differs between phase 2 and phase 3"
552 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
559 echo "### Testing Finished ###"
560 if [ "$use_gzip" = "yes" ]; then
561 echo "### Package: $Package.tar.gz"
563 echo "### Package: $Package.tar.xz"
565 echo "### Logs: $LogDir"
568 if [ -s "$LogDir/deferred_errors.log" ]; then
569 cat "$LogDir/deferred_errors.log"