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 projects="llvm cfe compiler-rt libcxx libcxxabi test-suite clang-tools-extra"
23 # Base SVN URL for the sources.
24 Base_url="http://llvm.org/svn/llvm-project"
37 ExtraConfigureFlags=""
40 echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]"
42 echo " -release X.Y.Z The release version to test."
43 echo " -rc NUM The pre-release candidate number."
44 echo " -final The final release candidate."
45 echo " -triple TRIPLE The target triple for this machine."
46 echo " -j NUM Number of compile jobs to run. [default: 3]"
47 echo " -build-dir DIR Directory to perform testing in. [default: pwd]"
48 echo " -no-checkout Don't checkout the sources from SVN."
49 echo " -test-debug Test the debug build. [default: no]"
50 echo " -test-asserts Test with asserts on. [default: no]"
51 echo " -no-compare-files Don't test that phase 2 and 3 files are identical."
52 echo " -use-gzip Use gzip instead of xz."
53 echo " -configure-flags FLAGS Extra flags to pass to the configure step."
54 echo " -use-autoconf Use autoconf instead of cmake"
57 if [ `uname -s` = "Darwin" ]; then
58 # compiler-rt doesn't yet build with CMake on Darwin.
62 while [ $# -gt 0 ]; do
64 -release | --release )
67 Release_no_dot="`echo $1 | sed -e 's,\.,,g'`"
69 -rc | --rc | -RC | --RC )
80 -configure-flags | --configure-flags )
82 ExtraConfigureFlags="$1"
85 NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
86 if [ -z "$NumJobs" ]; then
91 -build-dir | --build-dir | -builddir | --builddir )
95 -no-checkout | --no-checkout )
98 -test-debug | --test-debug )
101 -test-asserts | --test-asserts )
104 -no-compare-files | --no-compare-files )
107 -use-gzip | --use-gzip )
110 -use-autoconf | --use-autoconf )
113 -help | --help | -h | --h | -\? )
118 echo "unknown option: $1"
126 # Check required arguments.
127 if [ -z "$Release" ]; then
128 echo "error: no release number specified"
131 if [ -z "$RC" ]; then
132 echo "error: no release candidate number specified"
135 if [ -z "$Triple" ]; then
136 echo "error: no target triple specified"
140 # Figure out how many make processes to run.
141 if [ -z "$NumJobs" ]; then
142 NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
144 if [ -z "$NumJobs" ]; then
145 NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
147 if [ -z "$NumJobs" ]; then
148 NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
150 if [ -z "$NumJobs" ]; then
154 # Go to the build directory (may be different from CWD)
155 BuildDir=$BuildDir/$RC
159 # Location of log files.
160 LogDir=$BuildDir/logs
163 # Final package name.
164 Package=clang+llvm-$Release
165 if [ $RC != "final" ]; then
168 Package=$Package-$Triple
170 # Make sure that a required program is available
171 function check_program_exists() {
173 if ! type -P $program > /dev/null 2>&1 ; then
174 echo "program '$1' not found !"
179 if [ `uname -s` != "Darwin" ]; then
180 check_program_exists 'chrpath'
181 check_program_exists 'file'
182 check_program_exists 'objdump'
185 # Make sure that the URLs are valid.
186 function check_valid_urls() {
187 for proj in $projects ; do
188 echo "# Validating $proj SVN URL"
190 if ! svn ls $Base_url/$proj/tags/RELEASE_$Release_no_dot/$RC > /dev/null 2>&1 ; then
191 echo "$proj $Release release candidate $RC doesn't exist!"
197 # Export sources to the build directory.
198 function export_sources() {
201 for proj in $projects ; do
202 echo "# Exporting $proj $Release-$RC sources"
203 if ! svn export -q $Base_url/$proj/tags/RELEASE_$Release_no_dot/$RC $proj.src ; then
204 echo "error: failed to export $proj project"
209 echo "# Creating symlinks"
210 cd $BuildDir/llvm.src/tools
211 if [ ! -h clang ]; then
212 ln -s ../../cfe.src clang
214 cd $BuildDir/llvm.src/tools/clang/tools
215 if [ ! -h clang-tools-extra ]; then
216 ln -s ../../../../clang-tools-extra.src extra
218 cd $BuildDir/llvm.src/projects
219 if [ ! -h test-suite ]; then
220 ln -s ../../test-suite.src test-suite
222 if [ ! -h compiler-rt ]; then
223 ln -s ../../compiler-rt.src compiler-rt
225 if [ ! -h libcxx ]; then
226 ln -s ../../libcxx.src libcxx
228 if [ ! -h libcxxabi ]; then
229 ln -s ../../libcxxabi.src libcxxabi
234 function configure_llvmCore() {
243 ConfigureFlags="--enable-optimized --disable-assertions"
248 ConfigureFlags="--enable-optimized --enable-assertions"
253 ConfigureFlags="--disable-optimized --enable-assertions"
256 echo "# Invalid flavor '$Flavor'"
262 echo "# Using C compiler: $c_compiler"
263 echo "# Using C++ compiler: $cxx_compiler"
266 echo "# Configuring llvm $Release-$RC $Flavor"
268 if [ "$use_autoconf" = "yes" ]; then
269 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
270 $BuildDir/llvm.src/configure \
271 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
272 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
273 env CC="$c_compiler" CXX="$cxx_compiler" \
274 $BuildDir/llvm.src/configure \
275 $ConfigureFlags --disable-timestamps $ExtraConfigureFlags \
276 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
278 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
279 cmake -G "Unix Makefiles" \
280 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
281 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
282 $ExtraConfigureFlags $BuildDir/llvm.src \
283 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
284 env CC="$c_compiler" CXX="$cxx_compiler" \
285 cmake -G "Unix Makefiles" \
286 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
287 -DLLVM_ENABLE_TIMESTAMPS=OFF -DLLVM_CONFIGTIME="(timestamp not enabled)" \
288 $ExtraConfigureFlags $BuildDir/llvm.src \
289 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
295 function build_llvmCore() {
302 echo "# Compiling llvm $Release-$RC $Flavor"
303 echo "# ${MAKE} -j $NumJobs VERBOSE=1"
304 ${MAKE} -j $NumJobs VERBOSE=1 \
305 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
307 echo "# Installing llvm $Release-$RC $Flavor"
308 echo "# ${MAKE} install"
310 DESTDIR="${DestDir}" \
311 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
315 function test_llvmCore() {
321 ${MAKE} -j $NumJobs -k check-all \
322 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log
324 if [ "$use_autoconf" = "yes" ]; then
325 # In the cmake build, unit tests are run as part of check-all.
326 ${MAKE} -k unittests \
327 2>&1 | tee $LogDir/llvm.unittests-Phase$Phase-$Flavor.log
333 # Clean RPATH. Libtool adds the build directory to the search path, which is
334 # not necessary --- and even harmful --- for the binary packages we release.
335 function clean_RPATH() {
336 if [ `uname -s` = "Darwin" ]; then
339 local InstallPath="$1"
340 for Candidate in `find $InstallPath/{bin,lib} -type f`; do
341 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
342 rpath=`objdump -x $Candidate | grep 'RPATH' | sed -e's/^ *RPATH *//'`
343 if [ -n "$rpath" ]; then
344 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
345 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
351 # Create a package of the release binaries.
352 function package_release() {
354 cd $BuildDir/Phase3/Release
355 mv llvmCore-$Release-$RC.install $Package
356 if [ "$use_gzip" = "yes" ]; then
357 tar cfz $BuildDir/$Package.tar.gz $Package
359 tar cfJ $BuildDir/$Package.tar.xz $Package
361 mv $Package llvmCore-$Release-$RC.install
365 # Exit if any command fails
366 # Note: pipefail is necessary for running build commands through
367 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
371 if [ "$do_checkout" = "yes" ]; then
377 if [ "$do_debug" = "yes" ]; then
378 Flavors="Debug $Flavors"
380 if [ "$do_asserts" = "yes" ]; then
381 Flavors="$Flavors Release+Asserts"
384 for Flavor in $Flavors ; do
387 echo "********************************************************************************"
388 echo " Release: $Release-$RC"
389 echo " Build: $Flavor"
390 echo " System Info: "
392 echo "********************************************************************************"
398 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
399 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
401 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
402 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
404 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
405 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
407 rm -rf $llvmCore_phase1_objdir
408 rm -rf $llvmCore_phase1_destdir
410 rm -rf $llvmCore_phase2_objdir
411 rm -rf $llvmCore_phase2_destdir
413 rm -rf $llvmCore_phase3_objdir
414 rm -rf $llvmCore_phase3_destdir
416 mkdir -p $llvmCore_phase1_objdir
417 mkdir -p $llvmCore_phase1_destdir
419 mkdir -p $llvmCore_phase2_objdir
420 mkdir -p $llvmCore_phase2_destdir
422 mkdir -p $llvmCore_phase3_objdir
423 mkdir -p $llvmCore_phase3_destdir
425 ############################################################################
426 # Phase 1: Build llvmCore and clang
427 echo "# Phase 1: Building llvmCore"
428 configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir
429 build_llvmCore 1 $Flavor \
430 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
431 clean_RPATH $llvmCore_phase1_destdir/usr/local
433 ########################################################################
434 # Phase 2: Build llvmCore with newly built clang from phase 1.
435 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
436 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
437 echo "# Phase 2: Building llvmCore"
438 configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir
439 build_llvmCore 2 $Flavor \
440 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
441 clean_RPATH $llvmCore_phase2_destdir/usr/local
443 ########################################################################
444 # Phase 3: Build llvmCore with newly built clang from phase 2.
445 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
446 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
447 echo "# Phase 3: Building llvmCore"
448 configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir
449 build_llvmCore 3 $Flavor \
450 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
451 clean_RPATH $llvmCore_phase3_destdir/usr/local
453 ########################################################################
454 # Testing: Test phase 3
455 echo "# Testing - built with clang"
456 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
458 ########################################################################
459 # Compare .o files between Phase2 and Phase3 and report which ones
461 if [ "$do_compare" = "yes" ]; then
463 echo "# Comparing Phase 2 and Phase 3 files"
464 for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do
465 p3=`echo $p2 | sed -e 's,Phase2,Phase3,'`
466 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
467 # case there are build paths in the debug info.
468 if ! cmp --ignore-initial=16 <(sed -e 's,Phase2,Phase3,g' $p2) $p3 \
469 > /dev/null 2>&1 ; then
470 echo "file `basename $p2` differs between phase 2 and phase 3"
475 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
482 echo "### Testing Finished ###"
483 if [ "$use_gzip" = "yes" ]; then
484 echo "### Package: $Package.tar.gz"
486 echo "### Package: $Package.tar.xz"
488 echo "### Logs: $LogDir"