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"
38 ExtraConfigureFlags=""
42 echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]"
44 echo " -release X.Y.Z The release version to test."
45 echo " -rc NUM The pre-release candidate number."
46 echo " -final The final release candidate."
47 echo " -triple TRIPLE The target triple for this machine."
48 echo " -j NUM Number of compile jobs to run. [default: 3]"
49 echo " -build-dir DIR Directory to perform testing in. [default: pwd]"
50 echo " -no-checkout Don't checkout the sources from SVN."
51 echo " -test-debug Test the debug build. [default: no]"
52 echo " -test-asserts Test with asserts on. [default: no]"
53 echo " -no-compare-files Don't test that phase 2 and 3 files are identical."
54 echo " -use-gzip Use gzip instead of xz."
55 echo " -configure-flags FLAGS Extra flags to pass to the configure step."
56 echo " -use-autoconf Use autoconf instead of cmake"
57 echo " -svn-path DIR Use the specified DIR instead of a release."
58 echo " For example -svn-path trunk or -svn-path branches/release_37"
59 echo " -no-rt Disable check-out & build Compiler-RT"
60 echo " -no-libs Disable check-out & build libcxx/libcxxabi/libunwind"
61 echo " -no-test-suite Disable check-out & build test-suite"
64 if [ `uname -s` = "Darwin" ]; then
65 # compiler-rt doesn't yet build with CMake on Darwin.
69 while [ $# -gt 0 ]; do
71 -release | --release )
74 Release_no_dot="`echo $1 | sed -e 's,\.,,g'`"
76 -rc | --rc | -RC | --RC )
83 -svn-path | --svn-path )
88 RC="`echo $ExportBranch | sed -e 's,/,_,g'`"
89 echo "WARNING: Using the branch $ExportBranch instead of a release tag"
90 echo " This is intended to aid new packagers in trialing "
91 echo " builds without requiring a tag to be created first"
97 -configure-flags | --configure-flags )
99 ExtraConfigureFlags="$1"
102 NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
103 if [ -z "$NumJobs" ]; then
108 -build-dir | --build-dir | -builddir | --builddir )
112 -no-checkout | --no-checkout )
115 -test-debug | --test-debug )
118 -test-asserts | --test-asserts )
121 -no-compare-files | --no-compare-files )
124 -use-gzip | --use-gzip )
127 -use-autoconf | --use-autoconf )
139 -help | --help | -h | --h | -\? )
144 echo "unknown option: $1"
152 # Check required arguments.
153 if [ -z "$Release" ]; then
154 echo "error: no release number specified"
157 if [ -z "$RC" ]; then
158 echo "error: no release candidate number specified"
161 if [ -z "$ExportBranch" ]; then
162 ExportBranch="tags/RELEASE_$Release_no_dot/$RC"
164 if [ -z "$Triple" ]; then
165 echo "error: no target triple specified"
169 # Figure out how many make processes to run.
170 if [ -z "$NumJobs" ]; then
171 NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
173 if [ -z "$NumJobs" ]; then
174 NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
176 if [ -z "$NumJobs" ]; then
177 NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
179 if [ -z "$NumJobs" ]; then
184 projects="llvm cfe clang-tools-extra"
185 if [ $do_rt = "yes" ]; then
186 projects="$projects compiler-rt"
188 if [ $do_libs = "yes" ]; then
189 projects="$projects libcxx libcxxabi libunwind"
191 if [ $do_test_suite = "yes" ]; then
192 projects="$projects test-suite"
195 # Go to the build directory (may be different from CWD)
196 BuildDir=$BuildDir/$RC
200 # Location of log files.
201 LogDir=$BuildDir/logs
204 # Final package name.
205 Package=clang+llvm-$Release
206 if [ $RC != "final" ]; then
209 Package=$Package-$Triple
211 # Make sure that a required program is available
212 function check_program_exists() {
214 if ! type -P $program > /dev/null 2>&1 ; then
215 echo "program '$1' not found !"
220 if [ `uname -s` != "Darwin" ]; then
221 check_program_exists 'chrpath'
222 check_program_exists 'file'
223 check_program_exists 'objdump'
226 # Make sure that the URLs are valid.
227 function check_valid_urls() {
228 for proj in $projects ; do
229 echo "# Validating $proj SVN URL"
231 if ! svn ls $Base_url/$proj/$ExportBranch > /dev/null 2>&1 ; then
232 echo "$proj does not have a $ExportBranch branch/tag!"
238 # Export sources to the build directory.
239 function export_sources() {
242 for proj in $projects ; do
243 if [ -d $proj.src ]; then
244 echo "# Reusing $proj $Release-$RC sources"
247 echo "# Exporting $proj $Release-$RC sources"
248 if ! svn export -q $Base_url/$proj/$ExportBranch $proj.src ; then
249 echo "error: failed to export $proj project"
254 echo "# Creating symlinks"
255 cd $BuildDir/llvm.src/tools
256 if [ ! -h clang ]; then
257 ln -s ../../cfe.src clang
259 cd $BuildDir/llvm.src/tools/clang/tools
260 if [ ! -h clang-tools-extra ]; then
261 ln -s ../../../../clang-tools-extra.src extra
263 cd $BuildDir/llvm.src/projects
264 if [ -d $BuildDir/test-suite.src ] && [ ! -h test-suite ]; then
265 ln -s ../../test-suite.src test-suite
267 if [ -d $BuildDir/compiler-rt.src ] && [ ! -h compiler-rt ]; then
268 ln -s ../../compiler-rt.src compiler-rt
270 if [ -d $BuildDir/libcxx.src ] && [ ! -h libcxx ]; then
271 ln -s ../../libcxx.src libcxx
273 if [ -d $BuildDir/libcxxabi.src ] && [ ! -h libcxxabi ]; then
274 ln -s ../../libcxxabi.src libcxxabi
276 if [ -d $BuildDir/libunwind.src ] && [ ! -h libunwind ]; then
277 ln -s ../../libunwind.src libunwind
283 function configure_llvmCore() {
292 ConfigureFlags="--enable-optimized --disable-assertions"
297 ConfigureFlags="--enable-optimized --enable-assertions"
302 ConfigureFlags="--disable-optimized --enable-assertions"
305 echo "# Invalid flavor '$Flavor'"
311 echo "# Using C compiler: $c_compiler"
312 echo "# Using C++ compiler: $cxx_compiler"
315 echo "# Configuring llvm $Release-$RC $Flavor"
317 if [ "$use_autoconf" = "yes" ]; then
318 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
319 $BuildDir/llvm.src/configure \
320 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
321 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
322 env CC="$c_compiler" CXX="$cxx_compiler" \
323 $BuildDir/llvm.src/configure \
324 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
325 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
327 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
328 cmake -G "Unix Makefiles" \
329 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
330 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
331 $ExtraConfigureFlags $BuildDir/llvm.src \
332 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
333 env CC="$c_compiler" CXX="$cxx_compiler" \
334 cmake -G "Unix Makefiles" \
335 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
336 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
337 $ExtraConfigureFlags $BuildDir/llvm.src \
338 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
344 function build_llvmCore() {
351 echo "# Compiling llvm $Release-$RC $Flavor"
352 echo "# ${MAKE} -j $NumJobs VERBOSE=1"
353 ${MAKE} -j $NumJobs VERBOSE=1 \
354 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
356 echo "# Installing llvm $Release-$RC $Flavor"
357 echo "# ${MAKE} install"
359 DESTDIR="${DestDir}" \
360 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
364 function test_llvmCore() {
370 ${MAKE} -j $NumJobs -k check-all \
371 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log
373 if [ "$use_autoconf" = "yes" ]; then
374 # In the cmake build, unit tests are run as part of check-all.
375 ${MAKE} -k unittests \
376 2>&1 | tee $LogDir/llvm.unittests-Phase$Phase-$Flavor.log
382 # Clean RPATH. Libtool adds the build directory to the search path, which is
383 # not necessary --- and even harmful --- for the binary packages we release.
384 function clean_RPATH() {
385 if [ `uname -s` = "Darwin" ]; then
388 local InstallPath="$1"
389 for Candidate in `find $InstallPath/{bin,lib} -type f`; do
390 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
391 if rpath=`objdump -x $Candidate | grep 'RPATH'` ; then
392 rpath=`echo $rpath | sed -e's/^ *RPATH *//'`
393 if [ -n "$rpath" ]; then
394 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
395 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
402 # Create a package of the release binaries.
403 function package_release() {
405 cd $BuildDir/Phase3/Release
406 mv llvmCore-$Release-$RC.install/usr/local $Package
407 if [ "$use_gzip" = "yes" ]; then
408 tar cfz $BuildDir/$Package.tar.gz $Package
410 tar cfJ $BuildDir/$Package.tar.xz $Package
412 mv $Package llvmCore-$Release-$RC.install/usr/local
416 # Exit if any command fails
417 # Note: pipefail is necessary for running build commands through
418 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
422 if [ "$do_checkout" = "yes" ]; then
428 if [ "$do_debug" = "yes" ]; then
429 Flavors="Debug $Flavors"
431 if [ "$do_asserts" = "yes" ]; then
432 Flavors="$Flavors Release+Asserts"
435 for Flavor in $Flavors ; do
438 echo "********************************************************************************"
439 echo " Release: $Release-$RC"
440 echo " Build: $Flavor"
441 echo " System Info: "
443 echo "********************************************************************************"
449 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
450 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
452 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
453 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
455 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
456 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
458 rm -rf $llvmCore_phase1_objdir
459 rm -rf $llvmCore_phase1_destdir
461 rm -rf $llvmCore_phase2_objdir
462 rm -rf $llvmCore_phase2_destdir
464 rm -rf $llvmCore_phase3_objdir
465 rm -rf $llvmCore_phase3_destdir
467 mkdir -p $llvmCore_phase1_objdir
468 mkdir -p $llvmCore_phase1_destdir
470 mkdir -p $llvmCore_phase2_objdir
471 mkdir -p $llvmCore_phase2_destdir
473 mkdir -p $llvmCore_phase3_objdir
474 mkdir -p $llvmCore_phase3_destdir
476 ############################################################################
477 # Phase 1: Build llvmCore and clang
478 echo "# Phase 1: Building llvmCore"
479 configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir
480 build_llvmCore 1 $Flavor \
481 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
482 clean_RPATH $llvmCore_phase1_destdir/usr/local
484 ########################################################################
485 # Phase 2: Build llvmCore with newly built clang from phase 1.
486 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
487 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
488 echo "# Phase 2: Building llvmCore"
489 configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir
490 build_llvmCore 2 $Flavor \
491 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
492 clean_RPATH $llvmCore_phase2_destdir/usr/local
494 ########################################################################
495 # Phase 3: Build llvmCore with newly built clang from phase 2.
496 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
497 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
498 echo "# Phase 3: Building llvmCore"
499 configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir
500 build_llvmCore 3 $Flavor \
501 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
502 clean_RPATH $llvmCore_phase3_destdir/usr/local
504 ########################################################################
505 # Testing: Test phase 3
506 echo "# Testing - built with clang"
507 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
509 ########################################################################
510 # Compare .o files between Phase2 and Phase3 and report which ones
512 if [ "$do_compare" = "yes" ]; then
514 echo "# Comparing Phase 2 and Phase 3 files"
515 for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do
516 p3=`echo $p2 | sed -e 's,Phase2,Phase3,'`
517 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
518 # case there are build paths in the debug info. On some systems,
519 # sed adds a newline to the output, so pass $p3 through sed too.
520 if ! cmp -s <(sed -e 's,Phase2,Phase3,g' $p2) <(sed -e '' $p3) \
522 echo "file `basename $p2` differs between phase 2 and phase 3"
527 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
534 echo "### Testing Finished ###"
535 if [ "$use_gzip" = "yes" ]; then
536 echo "### Package: $Package.tar.gz"
538 echo "### Package: $Package.tar.xz"
540 echo "### Logs: $LogDir"