2 #===-- test-release.sh - Test the LLVM release candidates ------------------===#
4 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # See https://llvm.org/LICENSE.txt for license information.
6 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 #===------------------------------------------------------------------------===#
10 # Download, build, and test the release candidate for an LLVM release.
12 #===------------------------------------------------------------------------===#
15 if [ "$System" = "FreeBSD" ]; then
20 generator
="Unix Makefiles"
22 # Base SVN URL for the sources.
23 Base_url
="http://llvm.org/svn/llvm-project"
44 ExtraConfigureFlags
=""
48 echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]"
50 echo " -release X.Y.Z The release version to test."
51 echo " -rc NUM The pre-release candidate number."
52 echo " -final The final release candidate."
53 echo " -triple TRIPLE The target triple for this machine."
54 echo " -j NUM Number of compile jobs to run. [default: 3]"
55 echo " -build-dir DIR Directory to perform testing in. [default: pwd]"
56 echo " -no-checkout Don't checkout the sources from SVN."
57 echo " -test-debug Test the debug build. [default: no]"
58 echo " -test-asserts Test with asserts on. [default: no]"
59 echo " -no-compare-files Don't test that phase 2 and 3 files are identical."
60 echo " -use-gzip Use gzip instead of xz."
61 echo " -use-ninja Use ninja instead of make/gmake."
62 echo " -configure-flags FLAGS Extra flags to pass to the configure step."
63 echo " -svn-path DIR Use the specified DIR instead of a release."
64 echo " For example -svn-path trunk or -svn-path branches/release_37"
65 echo " -no-rt Disable check-out & build Compiler-RT"
66 echo " -no-libs Disable check-out & build libcxx/libcxxabi/libunwind"
67 echo " -no-libcxxabi Disable check-out & build libcxxabi"
68 echo " -no-libunwind Disable check-out & build libunwind"
69 echo " -no-test-suite Disable check-out & build test-suite"
70 echo " -no-openmp Disable check-out & build libomp"
71 echo " -no-lld Disable check-out & build lld"
72 echo " -lldb Enable check-out & build lldb"
73 echo " -no-lldb Disable check-out & build lldb (default)"
74 echo " -no-polly Disable check-out & build Polly"
77 while [ $# -gt 0 ]; do
79 -release |
--release )
82 Release_no_dot
="`echo $1 | sed -e 's,\.,,g'`"
84 -rc |
--rc |
-RC |
--RC )
91 -svn-path |
--svn-path )
96 RC
="`echo $ExportBranch | sed -e 's,/,_,g'`"
97 echo "WARNING: Using the branch $ExportBranch instead of a release tag"
98 echo " This is intended to aid new packagers in trialing "
99 echo " builds without requiring a tag to be created first"
105 -configure-flags |
--configure-flags )
107 ExtraConfigureFlags
="$1"
110 NumJobs
="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
111 if [ -z "$NumJobs" ]; then
120 -build-dir |
--build-dir |
-builddir |
--builddir )
124 -no-checkout |
--no-checkout )
127 -test-debug |
--test-debug )
130 -test-asserts |
--test-asserts )
133 -no-compare-files |
--no-compare-files )
136 -use-gzip |
--use-gzip )
169 -help |
--help |
-h |
--h |
-\? )
174 echo "unknown option: $1"
182 # Check required arguments.
183 if [ -z "$Release" ]; then
184 echo "error: no release number specified"
187 if [ -z "$RC" ]; then
188 echo "error: no release candidate number specified"
191 if [ -z "$ExportBranch" ]; then
192 ExportBranch
="tags/RELEASE_$Release_no_dot/$RC"
194 if [ -z "$Triple" ]; then
195 echo "error: no target triple specified"
199 # Figure out how many make processes to run.
200 if [ -z "$NumJobs" ]; then
201 NumJobs
=`sysctl -n hw.activecpu 2> /dev/null || true`
203 if [ -z "$NumJobs" ]; then
204 NumJobs
=`sysctl -n hw.ncpu 2> /dev/null || true`
206 if [ -z "$NumJobs" ]; then
207 NumJobs
=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
209 if [ -z "$NumJobs" ]; then
214 projects
="llvm cfe clang-tools-extra"
215 if [ $do_rt = "yes" ]; then
216 projects
="$projects compiler-rt"
218 if [ $do_libs = "yes" ]; then
219 projects
="$projects libcxx"
220 if [ $do_libcxxabi = "yes" ]; then
221 projects
="$projects libcxxabi"
223 if [ $do_libunwind = "yes" ]; then
224 projects
="$projects libunwind"
227 case $do_test_suite in
229 projects
="$projects test-suite"
232 if [ $do_openmp = "yes" ]; then
233 projects
="$projects openmp"
235 if [ $do_lld = "yes" ]; then
236 projects
="$projects lld"
238 if [ $do_lldb = "yes" ]; then
239 projects
="$projects lldb"
241 if [ $do_polly = "yes" ]; then
242 projects
="$projects polly"
245 # Go to the build directory (may be different from CWD)
246 BuildDir
=$BuildDir/$RC
250 # Location of log files.
251 LogDir
=$BuildDir/logs
254 # Final package name.
255 Package
=clang
+llvm-
$Release
256 if [ $RC != "final" ]; then
259 Package
=$Package-$Triple
261 # Errors to be highlighted at the end are written to this file.
262 echo -n > $LogDir/deferred_errors.log
264 function deferred_error
() {
268 echo "[${Flavor} Phase${Phase}] ${Msg}" |
tee -a $LogDir/deferred_errors.log
271 # Make sure that a required program is available
272 function check_program_exists
() {
274 if ! type -P $program > /dev
/null
2>&1 ; then
275 echo "program '$1' not found !"
280 if [ "$System" != "Darwin" ]; then
281 check_program_exists
'chrpath'
282 check_program_exists
'file'
283 check_program_exists
'objdump'
286 check_program_exists
${MAKE}
288 # Make sure that the URLs are valid.
289 function check_valid_urls
() {
290 for proj
in $projects ; do
291 echo "# Validating $proj SVN URL"
293 if ! svn
ls $Base_url/$proj/$ExportBranch > /dev
/null
2>&1 ; then
294 echo "$proj does not have a $ExportBranch branch/tag!"
300 # Export sources to the build directory.
301 function export_sources
() {
304 for proj
in $projects ; do
310 projsrc
=llvm.src
/tools
/clang
313 projsrc
=llvm.src
/tools
/$proj
316 projsrc
=llvm.src
/tools
/clang
/tools
/extra
318 compiler-rt|libcxx|libcxxabi|libunwind|openmp
)
319 projsrc
=llvm.src
/projects
/$proj
325 echo "error: unknown project $proj"
330 if [ -d $projsrc ]; then
331 echo "# Reusing $proj $Release-$RC sources in $projsrc"
334 echo "# Exporting $proj $Release-$RC sources to $projsrc"
335 if ! svn
export -q $Base_url/$proj/$ExportBranch $projsrc ; then
336 echo "error: failed to export $proj project"
344 function configure_llvmCore
() {
363 echo "# Invalid flavor '$Flavor'"
369 echo "# Using C compiler: $c_compiler"
370 echo "# Using C++ compiler: $cxx_compiler"
373 echo "# Configuring llvm $Release-$RC $Flavor"
375 echo "#" env CC
="$c_compiler" CXX
="$cxx_compiler" \
376 cmake
-G "$generator" \
377 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
378 $ExtraConfigureFlags $BuildDir/llvm.src \
379 2>&1 |
tee $LogDir/llvm.configure-Phase
$Phase-$Flavor.log
380 env CC
="$c_compiler" CXX
="$cxx_compiler" \
381 cmake
-G "$generator" \
382 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
383 $ExtraConfigureFlags $BuildDir/llvm.src \
384 2>&1 |
tee $LogDir/llvm.configure-Phase
$Phase-$Flavor.log
389 function build_llvmCore
() {
396 if [ ${MAKE} = 'ninja' ]; then
401 echo "# Compiling llvm $Release-$RC $Flavor"
402 echo "# ${MAKE} -j $NumJobs $Verbose"
403 ${MAKE} -j $NumJobs $Verbose \
404 2>&1 |
tee $LogDir/llvm.make-Phase
$Phase-$Flavor.log
406 echo "# Installing llvm $Release-$RC $Flavor"
407 echo "# ${MAKE} install"
408 DESTDIR
="${DestDir}" ${MAKE} install \
409 2>&1 |
tee $LogDir/llvm.install-Phase
$Phase-$Flavor.log
413 function test_llvmCore
() {
419 if [ ${MAKE} = 'ninja' ]; then
420 # Ninja doesn't have a documented "keep-going-forever" mode, we need to
421 # set a limit on how many jobs can fail before we give up.
426 if ! ( ${MAKE} -j $NumJobs $KeepGoing check-all \
427 2>&1 |
tee $LogDir/llvm.check-Phase
$Phase-$Flavor.log
) ; then
428 deferred_error
$Phase $Flavor "check-all failed"
431 if [ $do_test_suite = 'yes' ]; then
432 cd $TestSuiteBuildDir
433 env CC
="$c_compiler" CXX
="$cxx_compiler" \
434 cmake
$TestSuiteSrcDir -G "$generator" -DTEST_SUITE_LIT=$Lit
436 if ! ( ${MAKE} -j $NumJobs $KeepGoing check \
437 2>&1 |
tee $LogDir/llvm.check-Phase
$Phase-$Flavor.log
) ; then
438 deferred_error
$Phase $Flavor "test suite failed"
444 # Clean RPATH. Libtool adds the build directory to the search path, which is
445 # not necessary --- and even harmful --- for the binary packages we release.
446 function clean_RPATH
() {
447 if [ "$System" = "Darwin" ]; then
450 local InstallPath
="$1"
451 for Candidate
in `find $InstallPath/{bin,lib} -type f`; do
452 if file $Candidate |
grep ELF |
egrep 'executable|shared object' > /dev
/null
2>&1 ; then
453 if rpath
=`objdump -x $Candidate | grep 'RPATH'` ; then
454 rpath
=`echo $rpath | sed -e's/^ *RPATH *//'`
455 if [ -n "$rpath" ]; then
456 newrpath
=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
457 chrpath
-r $newrpath $Candidate 2>&1 > /dev
/null
2>&1
464 # Create a package of the release binaries.
465 function package_release
() {
467 cd $BuildDir/Phase
3/Release
468 mv llvmCore-
$Release-$RC.install
/usr
/local $Package
469 if [ "$use_gzip" = "yes" ]; then
470 tar cfz
$BuildDir/$Package.
tar.gz
$Package
472 tar cfJ
$BuildDir/$Package.
tar.xz
$Package
474 mv $Package llvmCore-
$Release-$RC.install
/usr
/local
478 # Exit if any command fails
479 # Note: pipefail is necessary for running build commands through
480 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
484 if [ "$do_checkout" = "yes" ]; then
488 # Setup the test-suite. Do this early so we can catch failures before
489 # we do the full 3 stage build.
490 if [ $do_test_suite = "yes" ]; then
491 SandboxDir
="$BuildDir/sandbox"
492 Lit
=$SandboxDir/bin
/lit
493 TestSuiteBuildDir
="$BuildDir/test-suite-build"
494 TestSuiteSrcDir
="$BuildDir/test-suite.src"
496 virtualenv
$SandboxDir
497 $SandboxDir/bin
/python
$BuildDir/llvm.src
/utils
/lit
/setup.py
install
498 mkdir
-p $TestSuiteBuildDir
503 if [ "$do_debug" = "yes" ]; then
504 Flavors
="Debug $Flavors"
506 if [ "$do_asserts" = "yes" ]; then
507 Flavors
="$Flavors Release+Asserts"
510 for Flavor
in $Flavors ; do
513 echo "********************************************************************************"
514 echo " Release: $Release-$RC"
515 echo " Build: $Flavor"
516 echo " System Info: "
518 echo "********************************************************************************"
523 llvmCore_phase1_objdir
=$BuildDir/Phase
1/$Flavor/llvmCore-
$Release-$RC.obj
524 llvmCore_phase1_destdir
=$BuildDir/Phase
1/$Flavor/llvmCore-
$Release-$RC.
install
526 llvmCore_phase2_objdir
=$BuildDir/Phase
2/$Flavor/llvmCore-
$Release-$RC.obj
527 llvmCore_phase2_destdir
=$BuildDir/Phase
2/$Flavor/llvmCore-
$Release-$RC.
install
529 llvmCore_phase3_objdir
=$BuildDir/Phase
3/$Flavor/llvmCore-
$Release-$RC.obj
530 llvmCore_phase3_destdir
=$BuildDir/Phase
3/$Flavor/llvmCore-
$Release-$RC.
install
532 rm -rf $llvmCore_phase1_objdir
533 rm -rf $llvmCore_phase1_destdir
535 rm -rf $llvmCore_phase2_objdir
536 rm -rf $llvmCore_phase2_destdir
538 rm -rf $llvmCore_phase3_objdir
539 rm -rf $llvmCore_phase3_destdir
541 mkdir
-p $llvmCore_phase1_objdir
542 mkdir
-p $llvmCore_phase1_destdir
544 mkdir
-p $llvmCore_phase2_objdir
545 mkdir
-p $llvmCore_phase2_destdir
547 mkdir
-p $llvmCore_phase3_objdir
548 mkdir
-p $llvmCore_phase3_destdir
550 ############################################################################
551 # Phase 1: Build llvmCore and clang
552 echo "# Phase 1: Building llvmCore"
553 configure_llvmCore
1 $Flavor $llvmCore_phase1_objdir
554 build_llvmCore
1 $Flavor \
555 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
556 clean_RPATH
$llvmCore_phase1_destdir/usr
/local
558 ########################################################################
559 # Phase 2: Build llvmCore with newly built clang from phase 1.
560 c_compiler
=$llvmCore_phase1_destdir/usr
/local
/bin
/clang
561 cxx_compiler
=$llvmCore_phase1_destdir/usr
/local
/bin
/clang
++
562 echo "# Phase 2: Building llvmCore"
563 configure_llvmCore
2 $Flavor $llvmCore_phase2_objdir
564 build_llvmCore
2 $Flavor \
565 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
566 clean_RPATH
$llvmCore_phase2_destdir/usr
/local
568 ########################################################################
569 # Phase 3: Build llvmCore with newly built clang from phase 2.
570 c_compiler
=$llvmCore_phase2_destdir/usr
/local
/bin
/clang
571 cxx_compiler
=$llvmCore_phase2_destdir/usr
/local
/bin
/clang
++
572 echo "# Phase 3: Building llvmCore"
573 configure_llvmCore
3 $Flavor $llvmCore_phase3_objdir
574 build_llvmCore
3 $Flavor \
575 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
576 clean_RPATH
$llvmCore_phase3_destdir/usr
/local
578 ########################################################################
579 # Testing: Test phase 3
580 c_compiler
=$llvmCore_phase3_destdir/usr
/local
/bin
/clang
581 cxx_compiler
=$llvmCore_phase3_destdir/usr
/local
/bin
/clang
++
582 echo "# Testing - built with clang"
583 test_llvmCore
3 $Flavor $llvmCore_phase3_objdir
585 ########################################################################
586 # Compare .o files between Phase2 and Phase3 and report which ones
588 if [ "$do_compare" = "yes" ]; then
590 echo "# Comparing Phase 2 and Phase 3 files"
591 for p2
in `find $llvmCore_phase2_objdir -name '*.o'` ; do
592 p3
=`echo $p2 | sed -e 's,Phase2,Phase3,'`
593 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
594 # case there are build paths in the debug info. Do the same sub-
595 # stitution on both files in case the string occurrs naturally.
597 <(env LC_CTYPE
=C
sed -e 's,Phase1,Phase2,g' -e 's,Phase2,Phase3,g' $p2) \
598 <(env LC_CTYPE
=C
sed -e 's,Phase1,Phase2,g' -e 's,Phase2,Phase3,g' $p3) \
600 echo "file `basename $p2` differs between phase 2 and phase 3"
606 ) 2>&1 |
tee $LogDir/testing.
$Release-$RC.log
608 if [ "$use_gzip" = "yes" ]; then
609 echo "# Packaging the release as $Package.tar.gz"
611 echo "# Packaging the release as $Package.tar.xz"
618 echo "### Testing Finished ###"
619 echo "### Logs: $LogDir"
622 if [ -s "$LogDir/deferred_errors.log" ]; then
623 cat "$LogDir/deferred_errors.log"