1#!/usr/bin/env bash 2#===-- test-release.sh - Test the LLVM release candidates ------------------===# 3# 4# The LLVM Compiler Infrastructure 5# 6# This file is distributed under the University of Illinois Open Source 7# License. 8# 9#===------------------------------------------------------------------------===# 10# 11# Download, build, and test the release candidate for an LLVM release. 12# 13#===------------------------------------------------------------------------===# 14 15if [ `uname -s` = "FreeBSD" ]; then 16 MAKE=gmake 17else 18 MAKE=make 19fi 20 21# Base SVN URL for the sources. 22Base_url="http://llvm.org/svn/llvm-project" 23 24Release="" 25Release_no_dot="" 26RC="" 27Triple="" 28use_gzip="no" 29do_checkout="yes" 30do_debug="no" 31do_asserts="no" 32do_compare="yes" 33do_rt="yes" 34do_libs="yes" 35do_libunwind="yes" 36do_test_suite="yes" 37do_openmp="yes" 38BuildDir="`pwd`" 39use_autoconf="no" 40ExtraConfigureFlags="" 41ExportBranch="" 42 43function usage() { 44 echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]" 45 echo "" 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" 66} 67 68if [ `uname -s` = "Darwin" ]; then 69 # compiler-rt doesn't yet build with CMake on Darwin. 70 use_autoconf="yes" 71fi 72 73while [ $# -gt 0 ]; do 74 case $1 in 75 -release | --release ) 76 shift 77 Release="$1" 78 Release_no_dot="`echo $1 | sed -e 's,\.,,g'`" 79 ;; 80 -rc | --rc | -RC | --RC ) 81 shift 82 RC="rc$1" 83 ;; 84 -final | --final ) 85 RC=final 86 ;; 87 -svn-path | --svn-path ) 88 shift 89 Release="test" 90 Release_no_dot="test" 91 ExportBranch="$1" 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" 96 ;; 97 -triple | --triple ) 98 shift 99 Triple="$1" 100 ;; 101 -configure-flags | --configure-flags ) 102 shift 103 ExtraConfigureFlags="$1" 104 ;; 105 -j* ) 106 NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`" 107 if [ -z "$NumJobs" ]; then 108 shift 109 NumJobs="$1" 110 fi 111 ;; 112 -build-dir | --build-dir | -builddir | --builddir ) 113 shift 114 BuildDir="$1" 115 ;; 116 -no-checkout | --no-checkout ) 117 do_checkout="no" 118 ;; 119 -test-debug | --test-debug ) 120 do_debug="yes" 121 ;; 122 -test-asserts | --test-asserts ) 123 do_asserts="yes" 124 ;; 125 -no-compare-files | --no-compare-files ) 126 do_compare="no" 127 ;; 128 -use-gzip | --use-gzip ) 129 use_gzip="yes" 130 ;; 131 -use-autoconf | --use-autoconf ) 132 use_autoconf="yes" 133 ;; 134 -no-rt ) 135 do_rt="no" 136 ;; 137 -no-libs ) 138 do_libs="no" 139 ;; 140 -no-libunwind ) 141 do_libunwind="no" 142 ;; 143 -no-test-suite ) 144 do_test_suite="no" 145 ;; 146 -no-openmp ) 147 do_openmp="no" 148 ;; 149 -help | --help | -h | --h | -\? ) 150 usage 151 exit 0 152 ;; 153 * ) 154 echo "unknown option: $1" 155 usage 156 exit 1 157 ;; 158 esac 159 shift 160done 161 162# Check required arguments. 163if [ -z "$Release" ]; then 164 echo "error: no release number specified" 165 exit 1 166fi 167if [ -z "$RC" ]; then 168 echo "error: no release candidate number specified" 169 exit 1 170fi 171if [ -z "$ExportBranch" ]; then 172 ExportBranch="tags/RELEASE_$Release_no_dot/$RC" 173fi 174if [ -z "$Triple" ]; then 175 echo "error: no target triple specified" 176 exit 1 177fi 178 179# Figure out how many make processes to run. 180if [ -z "$NumJobs" ]; then 181 NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true` 182fi 183if [ -z "$NumJobs" ]; then 184 NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true` 185fi 186if [ -z "$NumJobs" ]; then 187 NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true` 188fi 189if [ -z "$NumJobs" ]; then 190 NumJobs=3 191fi 192 193# Projects list 194projects="llvm cfe clang-tools-extra" 195if [ $do_rt = "yes" ]; then 196 projects="$projects compiler-rt" 197fi 198if [ $do_libs = "yes" ]; then 199 projects="$projects libcxx libcxxabi" 200 if [ $do_libunwind = "yes" ]; then 201 projects="$projects libunwind" 202 fi 203fi 204if [ $do_test_suite = "yes" ]; then 205 projects="$projects test-suite" 206fi 207if [ $do_openmp = "yes" ]; then 208 projects="$projects openmp" 209fi 210 211# Go to the build directory (may be different from CWD) 212BuildDir=$BuildDir/$RC 213mkdir -p $BuildDir 214cd $BuildDir 215 216# Location of log files. 217LogDir=$BuildDir/logs 218mkdir -p $LogDir 219 220# Final package name. 221Package=clang+llvm-$Release 222if [ $RC != "final" ]; then 223 Package=$Package-$RC 224fi 225Package=$Package-$Triple 226 227# Errors to be highlighted at the end are written to this file. 228echo -n > $LogDir/deferred_errors.log 229 230function deferred_error() { 231 Phase="$1" 232 Flavor="$2" 233 Msg="$3" 234 echo "[${Flavor} Phase${Phase}] ${Msg}" | tee -a $LogDir/deferred_errors.log 235} 236 237# Make sure that a required program is available 238function check_program_exists() { 239 local program="$1" 240 if ! type -P $program > /dev/null 2>&1 ; then 241 echo "program '$1' not found !" 242 exit 1 243 fi 244} 245 246if [ `uname -s` != "Darwin" ]; then 247 check_program_exists 'chrpath' 248 check_program_exists 'file' 249 check_program_exists 'objdump' 250fi 251 252# Make sure that the URLs are valid. 253function check_valid_urls() { 254 for proj in $projects ; do 255 echo "# Validating $proj SVN URL" 256 257 if ! svn ls $Base_url/$proj/$ExportBranch > /dev/null 2>&1 ; then 258 echo "$proj does not have a $ExportBranch branch/tag!" 259 exit 1 260 fi 261 done 262} 263 264# Export sources to the build directory. 265function export_sources() { 266 check_valid_urls 267 268 for proj in $projects ; do 269 if [ -d $proj.src ]; then 270 echo "# Reusing $proj $Release-$RC sources" 271 continue 272 fi 273 echo "# Exporting $proj $Release-$RC sources" 274 if ! svn export -q $Base_url/$proj/$ExportBranch $proj.src ; then 275 echo "error: failed to export $proj project" 276 exit 1 277 fi 278 done 279 280 echo "# Creating symlinks" 281 cd $BuildDir/llvm.src/tools 282 if [ ! -h clang ]; then 283 ln -s ../../cfe.src clang 284 fi 285 cd $BuildDir/llvm.src/tools/clang/tools 286 if [ ! -h extra ]; then 287 ln -s ../../../../clang-tools-extra.src extra 288 fi 289 cd $BuildDir/llvm.src/projects 290 if [ -d $BuildDir/test-suite.src ] && [ ! -h test-suite ]; then 291 ln -s ../../test-suite.src test-suite 292 fi 293 if [ -d $BuildDir/compiler-rt.src ] && [ ! -h compiler-rt ]; then 294 ln -s ../../compiler-rt.src compiler-rt 295 fi 296 if [ -d $BuildDir/openmp.src ] && [ ! -h openmp ]; then 297 ln -s ../../openmp.src openmp 298 fi 299 if [ -d $BuildDir/libcxx.src ] && [ ! -h libcxx ]; then 300 ln -s ../../libcxx.src libcxx 301 fi 302 if [ -d $BuildDir/libcxxabi.src ] && [ ! -h libcxxabi ]; then 303 ln -s ../../libcxxabi.src libcxxabi 304 fi 305 if [ -d $BuildDir/libunwind.src ] && [ ! -h libunwind ]; then 306 ln -s ../../libunwind.src libunwind 307 fi 308 309 cd $BuildDir 310} 311 312function configure_llvmCore() { 313 Phase="$1" 314 Flavor="$2" 315 ObjDir="$3" 316 317 case $Flavor in 318 Release ) 319 BuildType="Release" 320 Assertions="OFF" 321 ConfigureFlags="--enable-optimized --disable-assertions" 322 ;; 323 Release+Asserts ) 324 BuildType="Release" 325 Assertions="ON" 326 ConfigureFlags="--enable-optimized --enable-assertions" 327 ;; 328 Debug ) 329 BuildType="Debug" 330 Assertions="ON" 331 ConfigureFlags="--disable-optimized --enable-assertions" 332 ;; 333 * ) 334 echo "# Invalid flavor '$Flavor'" 335 echo "" 336 return 337 ;; 338 esac 339 340 echo "# Using C compiler: $c_compiler" 341 echo "# Using C++ compiler: $cxx_compiler" 342 343 cd $ObjDir 344 echo "# Configuring llvm $Release-$RC $Flavor" 345 346 if [ "$use_autoconf" = "yes" ]; then 347 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \ 348 $BuildDir/llvm.src/configure \ 349 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \ 350 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log 351 env CC="$c_compiler" CXX="$cxx_compiler" \ 352 $BuildDir/llvm.src/configure \ 353 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \ 354 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log 355 else 356 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \ 357 cmake -G "Unix Makefiles" \ 358 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \ 359 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \ 360 $ExtraConfigureFlags $BuildDir/llvm.src \ 361 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log 362 env CC="$c_compiler" CXX="$cxx_compiler" \ 363 cmake -G "Unix Makefiles" \ 364 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \ 365 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \ 366 $ExtraConfigureFlags $BuildDir/llvm.src \ 367 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log 368 fi 369 370 cd $BuildDir 371} 372 373function build_llvmCore() { 374 Phase="$1" 375 Flavor="$2" 376 ObjDir="$3" 377 DestDir="$4" 378 379 cd $ObjDir 380 echo "# Compiling llvm $Release-$RC $Flavor" 381 echo "# ${MAKE} -j $NumJobs VERBOSE=1" 382 ${MAKE} -j $NumJobs VERBOSE=1 \ 383 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log 384 385 echo "# Installing llvm $Release-$RC $Flavor" 386 echo "# ${MAKE} install" 387 ${MAKE} install \ 388 DESTDIR="${DestDir}" \ 389 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log 390 cd $BuildDir 391} 392 393function test_llvmCore() { 394 Phase="$1" 395 Flavor="$2" 396 ObjDir="$3" 397 398 cd $ObjDir 399 if ! ( ${MAKE} -j $NumJobs -k check-all \ 400 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then 401 deferred_error $Phase $Flavor "check-all failed" 402 fi 403 404 if [ "$use_autoconf" = "yes" ]; then 405 # In the cmake build, unit tests are run as part of check-all. 406 if ! ( ${MAKE} -k unittests 2>&1 | \ 407 tee $LogDir/llvm.unittests-Phase$Phase-$Flavor.log ) ; then 408 deferred_error $Phase $Flavor "unittests failed" 409 fi 410 fi 411 412 cd $BuildDir 413} 414 415# Clean RPATH. Libtool adds the build directory to the search path, which is 416# not necessary --- and even harmful --- for the binary packages we release. 417function clean_RPATH() { 418 if [ `uname -s` = "Darwin" ]; then 419 return 420 fi 421 local InstallPath="$1" 422 for Candidate in `find $InstallPath/{bin,lib} -type f`; do 423 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then 424 if rpath=`objdump -x $Candidate | grep 'RPATH'` ; then 425 rpath=`echo $rpath | sed -e's/^ *RPATH *//'` 426 if [ -n "$rpath" ]; then 427 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'` 428 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1 429 fi 430 fi 431 fi 432 done 433} 434 435# Create a package of the release binaries. 436function package_release() { 437 cwd=`pwd` 438 cd $BuildDir/Phase3/Release 439 mv llvmCore-$Release-$RC.install/usr/local $Package 440 if [ "$use_gzip" = "yes" ]; then 441 tar cfz $BuildDir/$Package.tar.gz $Package 442 else 443 tar cfJ $BuildDir/$Package.tar.xz $Package 444 fi 445 mv $Package llvmCore-$Release-$RC.install/usr/local 446 cd $cwd 447} 448 449# Exit if any command fails 450# Note: pipefail is necessary for running build commands through 451# a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``) 452set -e 453set -o pipefail 454 455if [ "$do_checkout" = "yes" ]; then 456 export_sources 457fi 458 459( 460Flavors="Release" 461if [ "$do_debug" = "yes" ]; then 462 Flavors="Debug $Flavors" 463fi 464if [ "$do_asserts" = "yes" ]; then 465 Flavors="$Flavors Release+Asserts" 466fi 467 468for Flavor in $Flavors ; do 469 echo "" 470 echo "" 471 echo "********************************************************************************" 472 echo " Release: $Release-$RC" 473 echo " Build: $Flavor" 474 echo " System Info: " 475 echo " `uname -a`" 476 echo "********************************************************************************" 477 echo "" 478 479 c_compiler="$CC" 480 cxx_compiler="$CXX" 481 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj 482 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install 483 484 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj 485 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install 486 487 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj 488 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install 489 490 rm -rf $llvmCore_phase1_objdir 491 rm -rf $llvmCore_phase1_destdir 492 493 rm -rf $llvmCore_phase2_objdir 494 rm -rf $llvmCore_phase2_destdir 495 496 rm -rf $llvmCore_phase3_objdir 497 rm -rf $llvmCore_phase3_destdir 498 499 mkdir -p $llvmCore_phase1_objdir 500 mkdir -p $llvmCore_phase1_destdir 501 502 mkdir -p $llvmCore_phase2_objdir 503 mkdir -p $llvmCore_phase2_destdir 504 505 mkdir -p $llvmCore_phase3_objdir 506 mkdir -p $llvmCore_phase3_destdir 507 508 ############################################################################ 509 # Phase 1: Build llvmCore and clang 510 echo "# Phase 1: Building llvmCore" 511 configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir 512 build_llvmCore 1 $Flavor \ 513 $llvmCore_phase1_objdir $llvmCore_phase1_destdir 514 clean_RPATH $llvmCore_phase1_destdir/usr/local 515 516 ######################################################################## 517 # Phase 2: Build llvmCore with newly built clang from phase 1. 518 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang 519 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++ 520 echo "# Phase 2: Building llvmCore" 521 configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir 522 build_llvmCore 2 $Flavor \ 523 $llvmCore_phase2_objdir $llvmCore_phase2_destdir 524 clean_RPATH $llvmCore_phase2_destdir/usr/local 525 526 ######################################################################## 527 # Phase 3: Build llvmCore with newly built clang from phase 2. 528 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang 529 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++ 530 echo "# Phase 3: Building llvmCore" 531 configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir 532 build_llvmCore 3 $Flavor \ 533 $llvmCore_phase3_objdir $llvmCore_phase3_destdir 534 clean_RPATH $llvmCore_phase3_destdir/usr/local 535 536 ######################################################################## 537 # Testing: Test phase 3 538 echo "# Testing - built with clang" 539 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir 540 541 ######################################################################## 542 # Compare .o files between Phase2 and Phase3 and report which ones 543 # differ. 544 if [ "$do_compare" = "yes" ]; then 545 echo 546 echo "# Comparing Phase 2 and Phase 3 files" 547 for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do 548 p3=`echo $p2 | sed -e 's,Phase2,Phase3,'` 549 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in 550 # case there are build paths in the debug info. On some systems, 551 # sed adds a newline to the output, so pass $p3 through sed too. 552 if ! cmp -s <(sed -e 's,Phase2,Phase3,g' $p2) <(sed -e '' $p3) \ 553 16 16 ; then 554 echo "file `basename $p2` differs between phase 2 and phase 3" 555 fi 556 done 557 fi 558done 559 560) 2>&1 | tee $LogDir/testing.$Release-$RC.log 561 562package_release 563 564set +e 565 566# Woo hoo! 567echo "### Testing Finished ###" 568if [ "$use_gzip" = "yes" ]; then 569 echo "### Package: $Package.tar.gz" 570else 571 echo "### Package: $Package.tar.xz" 572fi 573echo "### Logs: $LogDir" 574 575echo "### Errors:" 576if [ -s "$LogDir/deferred_errors.log" ]; then 577 cat "$LogDir/deferred_errors.log" 578 exit 1 579else 580 echo "None." 581fi 582 583exit 0 584