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"
39 ExtraConfigureFlags=""
43 echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]"
45 echo " -release X.Y.Z The release version to test."
46 echo " -rc NUM The pre-release candidate number."
47 echo " -final The final release candidate."
48 echo " -triple TRIPLE The target triple for this machine."
49 echo " -j NUM Number of compile jobs to run. [default: 3]"
50 echo " -build-dir DIR Directory to perform testing in. [default: pwd]"
51 echo " -no-checkout Don't checkout the sources from SVN."
52 echo " -test-debug Test the debug build. [default: no]"
53 echo " -test-asserts Test with asserts on. [default: no]"
54 echo " -no-compare-files Don't test that phase 2 and 3 files are identical."
55 echo " -use-gzip Use gzip instead of xz."
56 echo " -configure-flags FLAGS Extra flags to pass to the configure step."
57 echo " -use-autoconf Use autoconf instead of cmake"
58 echo " -svn-path DIR Use the specified DIR instead of a release."
59 echo " For example -svn-path trunk or -svn-path branches/release_37"
60 echo " -no-rt Disable check-out & build Compiler-RT"
61 echo " -no-libs Disable check-out & build libcxx/libcxxabi/libunwind"
62 echo " -no-test-suite Disable check-out & build test-suite"
63 echo " -openmp Check out and build the OpenMP run-time (experimental)"
66 if [ `uname -s` = "Darwin" ]; then
67 # compiler-rt doesn't yet build with CMake on Darwin.
71 while [ $# -gt 0 ]; do
73 -release | --release )
76 Release_no_dot="`echo $1 | sed -e 's,\.,,g'`"
78 -rc | --rc | -RC | --RC )
85 -svn-path | --svn-path )
90 RC="`echo $ExportBranch | sed -e 's,/,_,g'`"
91 echo "WARNING: Using the branch $ExportBranch instead of a release tag"
92 echo " This is intended to aid new packagers in trialing "
93 echo " builds without requiring a tag to be created first"
99 -configure-flags | --configure-flags )
101 ExtraConfigureFlags="$1"
104 NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
105 if [ -z "$NumJobs" ]; then
110 -build-dir | --build-dir | -builddir | --builddir )
114 -no-checkout | --no-checkout )
117 -test-debug | --test-debug )
120 -test-asserts | --test-asserts )
123 -no-compare-files | --no-compare-files )
126 -use-gzip | --use-gzip )
129 -use-autoconf | --use-autoconf )
144 -help | --help | -h | --h | -\? )
149 echo "unknown option: $1"
157 # Check required arguments.
158 if [ -z "$Release" ]; then
159 echo "error: no release number specified"
162 if [ -z "$RC" ]; then
163 echo "error: no release candidate number specified"
166 if [ -z "$ExportBranch" ]; then
167 ExportBranch="tags/RELEASE_$Release_no_dot/$RC"
169 if [ -z "$Triple" ]; then
170 echo "error: no target triple specified"
174 # Figure out how many make processes to run.
175 if [ -z "$NumJobs" ]; then
176 NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
178 if [ -z "$NumJobs" ]; then
179 NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
181 if [ -z "$NumJobs" ]; then
182 NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
184 if [ -z "$NumJobs" ]; then
189 projects="llvm cfe clang-tools-extra"
190 if [ $do_rt = "yes" ]; then
191 projects="$projects compiler-rt"
193 if [ $do_libs = "yes" ]; then
194 projects="$projects libcxx libcxxabi libunwind"
196 if [ $do_test_suite = "yes" ]; then
197 projects="$projects test-suite"
199 if [ $do_openmp = "yes" ]; then
200 projects="$projects openmp"
203 # Go to the build directory (may be different from CWD)
204 BuildDir=$BuildDir/$RC
208 # Location of log files.
209 LogDir=$BuildDir/logs
212 # Final package name.
213 Package=clang+llvm-$Release
214 if [ $RC != "final" ]; then
217 Package=$Package-$Triple
219 # Errors to be highlighted at the end are written to this file.
220 echo -n > $LogDir/deferred_errors.log
222 function deferred_error() {
226 echo "[${Flavor} Phase${Phase}] ${Msg}" | tee -a $LogDir/deferred_errors.log
229 # Make sure that a required program is available
230 function check_program_exists() {
232 if ! type -P $program > /dev/null 2>&1 ; then
233 echo "program '$1' not found !"
238 if [ `uname -s` != "Darwin" ]; then
239 check_program_exists 'chrpath'
240 check_program_exists 'file'
241 check_program_exists 'objdump'
244 # Make sure that the URLs are valid.
245 function check_valid_urls() {
246 for proj in $projects ; do
247 echo "# Validating $proj SVN URL"
249 if ! svn ls $Base_url/$proj/$ExportBranch > /dev/null 2>&1 ; then
250 echo "$proj does not have a $ExportBranch branch/tag!"
256 # Export sources to the build directory.
257 function export_sources() {
260 for proj in $projects ; do
261 if [ -d $proj.src ]; then
262 echo "# Reusing $proj $Release-$RC sources"
265 echo "# Exporting $proj $Release-$RC sources"
266 if ! svn export -q $Base_url/$proj/$ExportBranch $proj.src ; then
267 echo "error: failed to export $proj project"
272 echo "# Creating symlinks"
273 cd $BuildDir/llvm.src/tools
274 if [ ! -h clang ]; then
275 ln -s ../../cfe.src clang
277 cd $BuildDir/llvm.src/tools/clang/tools
278 if [ ! -h clang-tools-extra ]; then
279 ln -s ../../../../clang-tools-extra.src extra
281 cd $BuildDir/llvm.src/projects
282 if [ -d $BuildDir/test-suite.src ] && [ ! -h test-suite ]; then
283 ln -s ../../test-suite.src test-suite
285 if [ -d $BuildDir/compiler-rt.src ] && [ ! -h compiler-rt ]; then
286 ln -s ../../compiler-rt.src compiler-rt
288 if [ -d $BuildDir/libcxx.src ] && [ ! -h libcxx ]; then
289 ln -s ../../libcxx.src libcxx
291 if [ -d $BuildDir/libcxxabi.src ] && [ ! -h libcxxabi ]; then
292 ln -s ../../libcxxabi.src libcxxabi
294 if [ -d $BuildDir/libunwind.src ] && [ ! -h libunwind ]; then
295 ln -s ../../libunwind.src libunwind
301 function configure_llvmCore() {
310 ConfigureFlags="--enable-optimized --disable-assertions"
315 ConfigureFlags="--enable-optimized --enable-assertions"
320 ConfigureFlags="--disable-optimized --enable-assertions"
323 echo "# Invalid flavor '$Flavor'"
329 echo "# Using C compiler: $c_compiler"
330 echo "# Using C++ compiler: $cxx_compiler"
333 echo "# Configuring llvm $Release-$RC $Flavor"
335 if [ "$use_autoconf" = "yes" ]; then
336 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
337 $BuildDir/llvm.src/configure \
338 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
339 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
340 env CC="$c_compiler" CXX="$cxx_compiler" \
341 $BuildDir/llvm.src/configure \
342 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
343 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
345 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
346 cmake -G "Unix Makefiles" \
347 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
348 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
349 $ExtraConfigureFlags $BuildDir/llvm.src \
350 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
351 env CC="$c_compiler" CXX="$cxx_compiler" \
352 cmake -G "Unix Makefiles" \
353 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
354 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
355 $ExtraConfigureFlags $BuildDir/llvm.src \
356 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
362 function build_llvmCore() {
369 echo "# Compiling llvm $Release-$RC $Flavor"
370 echo "# ${MAKE} -j $NumJobs VERBOSE=1"
371 ${MAKE} -j $NumJobs VERBOSE=1 \
372 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
374 echo "# Installing llvm $Release-$RC $Flavor"
375 echo "# ${MAKE} install"
377 DESTDIR="${DestDir}" \
378 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
382 function test_llvmCore() {
388 if ! ( ${MAKE} -j $NumJobs -k check-all \
389 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
390 deferred_error $Phase $Flavor "check-all failed"
393 if [ "$use_autoconf" = "yes" ]; then
394 # In the cmake build, unit tests are run as part of check-all.
395 if ! ( ${MAKE} -k unittests 2>&1 | \
396 tee $LogDir/llvm.unittests-Phase$Phase-$Flavor.log ) ; then
397 deferred_error $Phase $Flavor "unittests failed"
404 # Clean RPATH. Libtool adds the build directory to the search path, which is
405 # not necessary --- and even harmful --- for the binary packages we release.
406 function clean_RPATH() {
407 if [ `uname -s` = "Darwin" ]; then
410 local InstallPath="$1"
411 for Candidate in `find $InstallPath/{bin,lib} -type f`; do
412 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
413 if rpath=`objdump -x $Candidate | grep 'RPATH'` ; then
414 rpath=`echo $rpath | sed -e's/^ *RPATH *//'`
415 if [ -n "$rpath" ]; then
416 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
417 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
424 # Create a package of the release binaries.
425 function package_release() {
427 cd $BuildDir/Phase3/Release
428 mv llvmCore-$Release-$RC.install/usr/local $Package
429 if [ "$use_gzip" = "yes" ]; then
430 tar cfz $BuildDir/$Package.tar.gz $Package
432 tar cfJ $BuildDir/$Package.tar.xz $Package
434 mv $Package llvmCore-$Release-$RC.install/usr/local
438 # Build and package the OpenMP run-time. This is still experimental and not
439 # meant for official testing in the release, but as a way for providing
440 # binaries as a convenience to those who want to try it out.
441 function build_OpenMP() {
444 rm -rf $BuildDir/Phase3/openmp
445 rm -rf $BuildDir/Phase3/openmp.install
446 mkdir -p $BuildDir/Phase3/openmp
447 cd $BuildDir/Phase3/openmp
448 clang=$BuildDir/Phase3/Release/llvmCore-$Release-$RC.install/usr/local/bin/clang
450 echo "#" cmake -DCMAKE_C_COMPILER=${clang} -DCMAKE_CXX_COMPILER=${clang}++ \
451 -DCMAKE_BUILD_TYPE=Release -DLIBOMP_MICRO_TESTS=on \
452 $BuildDir/openmp.src/runtime
453 cmake -DCMAKE_C_COMPILER=${clang} -DCMAKE_CXX_COMPILER=${clang}++ \
454 -DCMAKE_BUILD_TYPE=Release -DLIBOMP_MICRO_TESTS=on \
455 $BuildDir/openmp.src/runtime
457 echo "# Building OpenMP run-time"
458 echo "# ${MAKE} -j $NumJobs VERBOSE=1"
459 ${MAKE} -j $NumJobs VERBOSE=1
460 echo "# ${MAKE} libomp-micro-tests VERBOSE=1"
461 ${MAKE} libomp-micro-tests VERBOSE=1
462 echo "# ${MAKE} install DESTDIR=$BuildDir/Phase3/openmp.install"
463 ${MAKE} install DESTDIR=$BuildDir/Phase3/openmp.install
465 OpenMPPackage=OpenMP-$Triple
466 mv $BuildDir/Phase3/openmp.install/usr/local $BuildDir/$OpenMPPackage
468 tar cvfJ $BuildDir/$OpenMPPackage.tar.xz $OpenMPPackage
469 mv $OpenMPPackage $BuildDir/Phase3/openmp.install/usr/local
473 # Exit if any command fails
474 # Note: pipefail is necessary for running build commands through
475 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
479 if [ "$do_checkout" = "yes" ]; then
485 if [ "$do_debug" = "yes" ]; then
486 Flavors="Debug $Flavors"
488 if [ "$do_asserts" = "yes" ]; then
489 Flavors="$Flavors Release+Asserts"
492 for Flavor in $Flavors ; do
495 echo "********************************************************************************"
496 echo " Release: $Release-$RC"
497 echo " Build: $Flavor"
498 echo " System Info: "
500 echo "********************************************************************************"
505 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
506 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
508 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
509 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
511 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
512 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
514 rm -rf $llvmCore_phase1_objdir
515 rm -rf $llvmCore_phase1_destdir
517 rm -rf $llvmCore_phase2_objdir
518 rm -rf $llvmCore_phase2_destdir
520 rm -rf $llvmCore_phase3_objdir
521 rm -rf $llvmCore_phase3_destdir
523 mkdir -p $llvmCore_phase1_objdir
524 mkdir -p $llvmCore_phase1_destdir
526 mkdir -p $llvmCore_phase2_objdir
527 mkdir -p $llvmCore_phase2_destdir
529 mkdir -p $llvmCore_phase3_objdir
530 mkdir -p $llvmCore_phase3_destdir
532 ############################################################################
533 # Phase 1: Build llvmCore and clang
534 echo "# Phase 1: Building llvmCore"
535 configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir
536 build_llvmCore 1 $Flavor \
537 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
538 clean_RPATH $llvmCore_phase1_destdir/usr/local
540 ########################################################################
541 # Phase 2: Build llvmCore with newly built clang from phase 1.
542 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
543 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
544 echo "# Phase 2: Building llvmCore"
545 configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir
546 build_llvmCore 2 $Flavor \
547 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
548 clean_RPATH $llvmCore_phase2_destdir/usr/local
550 ########################################################################
551 # Phase 3: Build llvmCore with newly built clang from phase 2.
552 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
553 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
554 echo "# Phase 3: Building llvmCore"
555 configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir
556 build_llvmCore 3 $Flavor \
557 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
558 clean_RPATH $llvmCore_phase3_destdir/usr/local
560 ########################################################################
561 # Testing: Test phase 3
562 echo "# Testing - built with clang"
563 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
565 ########################################################################
566 # Compare .o files between Phase2 and Phase3 and report which ones
568 if [ "$do_compare" = "yes" ]; then
570 echo "# Comparing Phase 2 and Phase 3 files"
571 for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do
572 p3=`echo $p2 | sed -e 's,Phase2,Phase3,'`
573 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
574 # case there are build paths in the debug info. On some systems,
575 # sed adds a newline to the output, so pass $p3 through sed too.
576 if ! cmp -s <(sed -e 's,Phase2,Phase3,g' $p2) <(sed -e '' $p3) \
578 echo "file `basename $p2` differs between phase 2 and phase 3"
584 if [ $do_openmp = "yes" ]; then
588 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
595 echo "### Testing Finished ###"
596 if [ "$use_gzip" = "yes" ]; then
597 echo "### Package: $Package.tar.gz"
599 echo "### Package: $Package.tar.xz"
601 echo "### Logs: $LogDir"
604 if [ -s "$LogDir/deferred_errors.log" ]; then
605 cat "$LogDir/deferred_errors.log"