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"
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 " -no-64bit Don't test the 64-bit version. [default: yes]"
50 echo " -test-debug Test the debug build. [default: no]"
51 echo " -test-asserts Test with asserts on. [default: no]"
52 echo " -no-compare-files Don't test that phase 2 and 3 files are identical."
53 echo " -use-gzip Use gzip instead of xz."
54 echo " -build-triple TRIPLE The build triple for this machine"
55 echo " [default: use config.guess]"
58 while [ $# -gt 0 ]; do
60 -release | --release )
63 Release_no_dot="`echo $1 | sed -e 's,\.,,g'`"
65 -rc | --rc | -RC | --RC )
76 -build-triple | --build-triple )
81 NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
82 if [ -z "$NumJobs" ]; then
87 -build-dir | --build-dir | -builddir | --builddir )
91 -no-checkout | --no-checkout )
94 -no-64bit | --no-64bit )
97 -test-debug | --test-debug )
100 -test-asserts | --test-asserts )
103 -no-compare-files | --no-compare-files )
106 -use-gzip | --use-gzip )
109 -help | --help | -h | --h | -\? )
114 echo "unknown option: $1"
122 # Check required arguments.
123 if [ -z "$Release" ]; then
124 echo "error: no release number specified"
127 if [ -z "$RC" ]; then
128 echo "error: no release candidate number specified"
131 if [ -z "$Triple" ]; then
132 echo "error: no target triple specified"
136 # Figure out how many make processes to run.
137 if [ -z "$NumJobs" ]; then
138 NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
140 if [ -z "$NumJobs" ]; then
141 NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
143 if [ -z "$NumJobs" ]; then
144 NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
146 if [ -z "$NumJobs" ]; then
150 # Go to the build directory (may be different from CWD)
151 BuildDir=$BuildDir/$RC
155 # Location of log files.
156 LogDir=$BuildDir/logs
159 # Final package name.
160 Package=clang+llvm-$Release
161 if [ $RC != "final" ]; then
164 Package=$Package-$Triple
166 # Make sure that a required program is available
167 function check_program_exists() {
169 if ! type -P $program > /dev/null 2>&1 ; then
170 echo "program '$1' not found !"
175 if [ `uname -s` != "Darwin" ]; then
176 check_program_exists 'chrpath'
177 check_program_exists 'file'
178 check_program_exists 'objdump'
181 # Make sure that the URLs are valid.
182 function check_valid_urls() {
183 for proj in $projects ; do
184 echo "# Validating $proj SVN URL"
186 if ! svn ls $Base_url/$proj/tags/RELEASE_$Release_no_dot/$RC > /dev/null 2>&1 ; then
187 echo "$proj $Release release candidate $RC doesn't exist!"
193 # Export sources to the build directory.
194 function export_sources() {
197 for proj in $projects ; do
198 echo "# Exporting $proj $Release-$RC sources"
199 if ! svn export -q $Base_url/$proj/tags/RELEASE_$Release_no_dot/$RC $proj.src ; then
200 echo "error: failed to export $proj project"
205 echo "# Creating symlinks"
206 cd $BuildDir/llvm.src/tools
207 if [ ! -h clang ]; then
208 ln -s ../../cfe.src clang
210 cd $BuildDir/llvm.src/tools/clang/tools
211 if [ ! -h clang-tools-extra ]; then
212 ln -s ../../../../clang-tools-extra.src extra
214 cd $BuildDir/llvm.src/projects
215 if [ ! -h test-suite ]; then
216 ln -s ../../test-suite.src test-suite
218 if [ ! -h compiler-rt ]; then
219 ln -s ../../compiler-rt.src compiler-rt
221 if [ ! -h libcxx ]; then
222 ln -s ../../libcxx.src libcxx
224 if [ ! -h libcxxabi ]; then
225 ln -s ../../libcxxabi.src libcxxabi
230 function configure_llvmCore() {
237 Release | Release-64 )
250 echo "# Invalid flavor '$Flavor'"
256 if [ -z "$InstallDir" ]; then
257 echo "Using default install prefix"
260 PrefixArg="--prefix=$InstallDir"
263 echo "# Using C compiler: $c_compiler"
264 echo "# Using C++ compiler: $cxx_compiler"
266 build_triple_option="${BuildTriple:+--build=$BuildTriple}"
269 echo "# Configuring llvm $Release-$RC $Flavor"
270 echo "# $BuildDir/llvm.src/configure $PrefixArg \
271 --enable-optimized=$Optimized \
272 --enable-assertions=$Assertions \
273 --disable-timestamps \
274 $build_triple_option"
275 env CC="$c_compiler" CXX="$cxx_compiler" \
276 $BuildDir/llvm.src/configure $PrefixArg \
277 --enable-optimized=$Optimized \
278 --enable-assertions=$Assertions \
279 --disable-timestamps \
280 $build_triple_option \
281 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
285 function build_llvmCore() {
292 if [ "$Flavor" = "Release-64" ]; then
293 ExtraOpts="EXTRA_OPTIONS=-m64"
297 echo "# Compiling llvm $Release-$RC $Flavor"
298 echo "# ${MAKE} -j $NumJobs VERBOSE=1 $ExtraOpts"
299 ${MAKE} -j $NumJobs VERBOSE=1 $ExtraOpts \
300 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
302 echo "# Installing llvm $Release-$RC $Flavor"
303 echo "# ${MAKE} install"
305 DESTDIR="${DestDir}" \
306 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
310 function test_llvmCore() {
316 ${MAKE} -k check-all \
317 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log
318 ${MAKE} -k unittests \
319 2>&1 | tee $LogDir/llvm.unittests-Phase$Phase-$Flavor.log
323 # Clean RPATH. Libtool adds the build directory to the search path, which is
324 # not necessary --- and even harmful --- for the binary packages we release.
325 function clean_RPATH() {
326 if [ `uname -s` = "Darwin" ]; then
329 local InstallPath="$1"
330 for Candidate in `find $InstallPath/{bin,lib} -type f`; do
331 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
332 rpath=`objdump -x $Candidate | grep 'RPATH' | sed -e's/^ *RPATH *//'`
333 if [ -n "$rpath" ]; then
334 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
335 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
341 # Create a package of the release binaries.
342 function package_release() {
344 cd $BuildDir/Phase3/Release
345 mv llvmCore-$Release-$RC.install $Package
346 if [ "$use_gzip" = "yes" ]; then
347 tar cfz $BuildDir/$Package.tar.gz $Package
349 tar cfJ $BuildDir/$Package.tar.xz $Package
351 mv $Package llvmCore-$Release-$RC.install
355 # Exit if any command fails
356 # Note: pipefail is necessary for running build commands through
357 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
361 if [ "$do_checkout" = "yes" ]; then
367 if [ "$do_debug" = "yes" ]; then
368 Flavors="Debug $Flavors"
370 if [ "$do_asserts" = "yes" ]; then
371 Flavors="$Flavors Release+Asserts"
373 if [ "$do_64bit" = "yes" ]; then
374 Flavors="$Flavors Release-64"
377 for Flavor in $Flavors ; do
380 echo "********************************************************************************"
381 echo " Release: $Release-$RC"
382 echo " Build: $Flavor"
383 echo " System Info: "
385 echo "********************************************************************************"
391 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
392 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
394 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
395 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
397 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
398 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
400 rm -rf $llvmCore_phase1_objdir
401 rm -rf $llvmCore_phase1_destdir
403 rm -rf $llvmCore_phase2_objdir
404 rm -rf $llvmCore_phase2_destdir
406 rm -rf $llvmCore_phase3_objdir
407 rm -rf $llvmCore_phase3_destdir
409 mkdir -p $llvmCore_phase1_objdir
410 mkdir -p $llvmCore_phase1_destdir
412 mkdir -p $llvmCore_phase2_objdir
413 mkdir -p $llvmCore_phase2_destdir
415 mkdir -p $llvmCore_phase3_objdir
416 mkdir -p $llvmCore_phase3_destdir
418 ############################################################################
419 # Phase 1: Build llvmCore and clang
420 echo "# Phase 1: Building llvmCore"
421 configure_llvmCore 1 $Flavor \
422 $llvmCore_phase1_objdir ""
423 build_llvmCore 1 $Flavor \
424 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
425 clean_RPATH $llvmCore_phase1_destdir/usr/local
427 ########################################################################
428 # Phase 2: Build llvmCore with newly built clang from phase 1.
429 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
430 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
431 echo "# Phase 2: Building llvmCore"
432 configure_llvmCore 2 $Flavor \
433 $llvmCore_phase2_objdir ""
434 build_llvmCore 2 $Flavor \
435 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
436 clean_RPATH $llvmCore_phase2_destdir/usr/local
438 ########################################################################
439 # Phase 3: Build llvmCore with newly built clang from phase 2.
440 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
441 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
442 echo "# Phase 3: Building llvmCore"
443 configure_llvmCore 3 $Flavor \
444 $llvmCore_phase3_objdir ""
445 build_llvmCore 3 $Flavor \
446 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
447 clean_RPATH $llvmCore_phase3_destdir/usr/local
449 ########################################################################
450 # Testing: Test phase 3
451 echo "# Testing - built with clang"
452 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
454 ########################################################################
455 # Compare .o files between Phase2 and Phase3 and report which ones
457 if [ "$do_compare" = "yes" ]; then
459 echo "# Comparing Phase 2 and Phase 3 files"
460 for o in `find $llvmCore_phase2_objdir -name '*.o'` ; do
461 p3=`echo $o | sed -e 's,Phase2,Phase3,'`
462 if ! cmp --ignore-initial=16 $o $p3 > /dev/null 2>&1 ; then
463 echo "file `basename $o` differs between phase 2 and phase 3"
468 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
475 echo "### Testing Finished ###"
476 if [ "$use_gzip" = "yes" ]; then
477 echo "### Package: $Package.tar.gz"
479 echo "### Package: $Package.tar.xz"
481 echo "### Logs: $LogDir"