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"
46 ExtraConfigureFlags
=""
51 echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]"
53 echo " -release X.Y.Z The release version to test."
54 echo " -rc NUM The pre-release candidate number."
55 echo " -final The final release candidate."
56 echo " -triple TRIPLE The target triple for this machine."
57 echo " -j NUM Number of compile jobs to run. [default: 3]"
58 echo " -build-dir DIR Directory to perform testing in. [default: pwd]"
59 echo " -no-checkout Don't checkout the sources from SVN."
60 echo " -test-debug Test the debug build. [default: no]"
61 echo " -test-asserts Test with asserts on. [default: no]"
62 echo " -no-compare-files Don't test that phase 2 and 3 files are identical."
63 echo " -use-gzip Use gzip instead of xz."
64 echo " -use-ninja Use ninja instead of make/gmake."
65 echo " -configure-flags FLAGS Extra flags to pass to the configure step."
66 echo " -git-ref sha Use the specified git ref for testing instead of a release."
67 echo " -no-rt Disable check-out & build Compiler-RT"
68 echo " -no-clang-tools Disable check-out & build clang-tools-extra"
69 echo " -no-libs Disable check-out & build libcxx/libcxxabi/libunwind"
70 echo " -no-libcxxabi Disable check-out & build libcxxabi"
71 echo " -no-libunwind Disable check-out & build libunwind"
72 echo " -no-test-suite Disable check-out & build test-suite"
73 echo " -no-openmp Disable check-out & build libomp"
74 echo " -no-lld Disable check-out & build lld"
75 echo " -lldb Enable check-out & build lldb"
76 echo " -no-lldb Disable check-out & build lldb (default)"
77 echo " -no-polly Disable check-out & build Polly"
78 echo " -no-mlir Disable check-out & build MLIR"
79 echo " -no-flang Disable check-out & build Flang"
80 echo " -silent-log Don't output build logs to stdout"
83 while [ $# -gt 0 ]; do
85 -release |
--release )
88 Release_no_dot
="`echo $1 | sed -e 's,\.,,g'`"
90 -rc |
--rc |
-RC |
--RC )
97 -git-ref |
--git-ref )
100 Release_no_dot
="test"
102 RC
="`echo $ExportBranch | sed -e 's,/,_,g'`"
104 echo "WARNING: Using the ref $git_ref instead of a release tag"
105 echo " This is intended to aid new packagers in trialing "
106 echo " builds without requiring a tag to be created first"
112 -configure-flags |
--configure-flags )
114 ExtraConfigureFlags
="$1"
117 NumJobs
="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
118 if [ -z "$NumJobs" ]; then
127 -build-dir |
--build-dir |
-builddir |
--builddir )
131 -no-checkout |
--no-checkout )
134 -test-debug |
--test-debug )
137 -test-asserts |
--test-asserts )
140 -no-compare-files |
--no-compare-files )
143 -use-gzip |
--use-gzip )
194 -help |
--help |
-h |
--h |
-\? )
199 echo "unknown option: $1"
207 if [ $do_mlir = "no" ] && [ $do_flang = "yes" ]; then
208 echo "error: cannot build Flang without MLIR"
212 # Check required arguments.
213 if [ -z "$Release" ]; then
214 echo "error: no release number specified"
217 if [ -z "$RC" ]; then
218 echo "error: no release candidate number specified"
221 if [ -z "$ExportBranch" ]; then
222 ExportBranch
="tags/RELEASE_$Release_no_dot/$RC"
224 if [ -z "$Triple" ]; then
225 echo "error: no target triple specified"
229 if [ "$Release" != "test" ]; then
230 if [ -n "$git_ref" ]; then
231 echo "error: can't specify both -release and -git-ref"
234 git_ref
=llvmorg-
$Release
235 if [ "$RC" != "final" ]; then
236 git_ref
="$git_ref-$RC"
240 # Figure out how many make processes to run.
241 if [ -z "$NumJobs" ]; then
242 NumJobs
=`sysctl -n hw.activecpu 2> /dev/null || true`
244 if [ -z "$NumJobs" ]; then
245 NumJobs
=`sysctl -n hw.ncpu 2> /dev/null || true`
247 if [ -z "$NumJobs" ]; then
248 NumJobs
=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
250 if [ -z "$NumJobs" ]; then
255 projects
="llvm clang"
256 if [ $do_clang_tools = "yes" ]; then
257 projects
="$projects clang-tools-extra"
260 if [ $do_rt = "yes" ]; then
261 runtimes
="$runtimes compiler-rt"
263 if [ $do_libs = "yes" ]; then
264 runtimes
="$runtimes libcxx"
265 if [ $do_libcxxabi = "yes" ]; then
266 runtimes
="$runtimes libcxxabi"
268 if [ $do_libunwind = "yes" ]; then
269 runtimes
="$runtimes libunwind"
272 if [ $do_openmp = "yes" ]; then
273 projects
="$projects openmp"
275 if [ $do_bolt = "yes" ]; then
276 projects
="$projects bolt"
278 if [ $do_lld = "yes" ]; then
279 projects
="$projects lld"
281 if [ $do_lldb = "yes" ]; then
282 projects
="$projects lldb"
284 if [ $do_polly = "yes" ]; then
285 projects
="$projects polly"
287 if [ $do_mlir = "yes" ]; then
288 projects
="$projects mlir"
290 if [ $do_flang = "yes" ]; then
291 projects
="$projects flang"
294 # Go to the build directory (may be different from CWD)
295 BuildDir
=$BuildDir/$RC
299 # Location of log files.
300 LogDir
=$BuildDir/logs
303 # Final package name.
304 Package
=clang
+llvm-
$Release
305 if [ $RC != "final" ]; then
308 Package
=$Package-$Triple
310 # Errors to be highlighted at the end are written to this file.
311 echo -n > $LogDir/deferred_errors.log
313 function deferred_error
() {
317 echo "[${Flavor} Phase${Phase}] ${Msg}" |
tee -a $LogDir/deferred_errors.log
320 # Make sure that a required program is available
321 function check_program_exists
() {
323 if ! type -P $program > /dev
/null
2>&1 ; then
324 echo "program '$1' not found !"
329 if [ "$System" != "Darwin" ] && [ "$System" != "SunOS" ] && [ "$System" != "AIX" ]; then
330 check_program_exists
'chrpath'
333 if [ "$System" != "Darwin" ]; then
334 check_program_exists
'file'
335 check_program_exists
'objdump'
338 check_program_exists
${MAKE}
340 # Export sources to the build directory.
341 function export_sources
() {
342 SrcDir
=$BuildDir/llvm-project
344 echo "# Using git ref: $git_ref"
346 # GitHub allows you to download a tarball of any commit using the URL:
347 # https://github.com/$organization/$repo/archive/$ref.tar.gz
348 curl
-L https
://github.com
/llvm
/llvm-project
/archive
/$git_ref.
tar.gz | \
349 tar -C $SrcDir --strip-components=1 -xzf -
351 if [ "$do_test_suite" = "yes" ]; then
352 TestSuiteSrcDir
=$BuildDir/llvm-test-suite
353 mkdir
-p $TestSuiteSrcDir
355 # We can only use named refs, like branches and tags, that exist in
356 # both the llvm-project and test-suite repos if we want to run the
358 # If the test-suite fails to download assume we are using a ref that
359 # doesn't exist in the test suite and disable it.
361 curl
-L https
://github.com
/llvm
/test-suite
/archive
/$git_ref.
tar.gz | \
362 tar -C $TestSuiteSrcDir --strip-components=1 -xzf -
363 if [ $?
-ne -0 ]; then
364 echo "$git_ref not found in test-suite repo, test-suite disabled."
373 function configure_llvmCore
() {
392 echo "# Invalid flavor '$Flavor'"
398 project_list
=${projects// /;}
399 runtime_list
=${runtimes// /;}
400 echo "# Using C compiler: $c_compiler"
401 echo "# Using C++ compiler: $cxx_compiler"
404 echo "# Configuring llvm $Release-$RC $Flavor"
406 echo "#" env CC
="$c_compiler" CXX
="$cxx_compiler" \
407 cmake
-G "$generator" \
408 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
409 -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
410 -DLLVM_ENABLE_PROJECTS="$project_list" \
411 -DLLVM_LIT_ARGS="-j $NumJobs" \
412 -DLLVM_ENABLE_RUNTIMES="$runtime_list" \
413 $ExtraConfigureFlags $BuildDir/llvm-project
/llvm \
414 2>&1 |
tee $LogDir/llvm.configure-Phase
$Phase-$Flavor.log
415 env CC
="$c_compiler" CXX
="$cxx_compiler" \
416 cmake
-G "$generator" \
417 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
418 -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
419 -DLLVM_ENABLE_PROJECTS="$project_list" \
420 -DLLVM_LIT_ARGS="-j $NumJobs" \
421 -DLLVM_ENABLE_RUNTIMES="$runtime_list" \
422 $ExtraConfigureFlags $BuildDir/llvm-project
/llvm \
423 2>&1 |
tee $LogDir/llvm.configure-Phase
$Phase-$Flavor.log
428 function build_llvmCore
() {
435 if [ ${MAKE} = 'ninja' ]; then
440 if [ $do_silent_log == "yes" ]; then
441 echo "# Silencing build logs because of -silent-log flag..."
446 echo "# Compiling llvm $Release-$RC $Flavor"
447 echo "# ${MAKE} -j $NumJobs $Verbose"
448 ${MAKE} -j $NumJobs $Verbose \
449 2>&1 |
tee $LogDir/llvm.make-Phase
$Phase-$Flavor.log
> $redir
451 echo "# Installing llvm $Release-$RC $Flavor"
452 echo "# ${MAKE} install"
453 DESTDIR
="${DestDir}" ${MAKE} install \
454 2>&1 |
tee $LogDir/llvm.install-Phase
$Phase-$Flavor.log
> $redir
458 function test_llvmCore
() {
464 if [ ${MAKE} = 'ninja' ]; then
465 # Ninja doesn't have a documented "keep-going-forever" mode, we need to
466 # set a limit on how many jobs can fail before we give up.
471 if ! ( ${MAKE} -j $NumJobs $KeepGoing check-all \
472 2>&1 |
tee $LogDir/llvm.check-Phase
$Phase-$Flavor.log
) ; then
473 deferred_error
$Phase $Flavor "check-all failed"
476 if [ $do_test_suite = 'yes' ]; then
477 cd $TestSuiteBuildDir
478 env CC
="$c_compiler" CXX
="$cxx_compiler" \
479 cmake
$TestSuiteSrcDir -G "$generator" -DTEST_SUITE_LIT=$Lit \
480 -DTEST_SUITE_HOST_CC=$build_compiler
482 if ! ( ${MAKE} -j $NumJobs $KeepGoing check \
483 2>&1 |
tee $LogDir/llvm.check-Phase
$Phase-$Flavor.log
) ; then
484 deferred_error
$Phase $Flavor "test suite failed"
490 # Clean RPATH. Libtool adds the build directory to the search path, which is
491 # not necessary --- and even harmful --- for the binary packages we release.
492 function clean_RPATH
() {
493 if [ "$System" = "Darwin" ] ||
[ "$System" = "SunOS" ] ||
[ "$System" = "AIX" ]; then
496 local InstallPath
="$1"
497 for Candidate
in `find $InstallPath/{bin,lib} -type f`; do
498 if file $Candidate |
grep ELF |
egrep 'executable|shared object' > /dev
/null
2>&1 ; then
499 if rpath
=`objdump -x $Candidate | grep 'RPATH'` ; then
500 rpath
=`echo $rpath | sed -e's/^ *RPATH *//'`
501 if [ -n "$rpath" ]; then
502 newrpath
=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
503 chrpath
-r $newrpath $Candidate 2>&1 > /dev
/null
2>&1
510 # Create a package of the release binaries.
511 function package_release
() {
513 cd $BuildDir/Phase
3/Release
514 mv llvmCore-
$Release-$RC.install
/usr
/local $Package
515 if [ "$use_gzip" = "yes" ]; then
516 tar cf
- $Package |
gzip -9c > $BuildDir/$Package.
tar.gz
518 tar cf
- $Package | xz
-9ce > $BuildDir/$Package.
tar.xz
520 mv $Package llvmCore-
$Release-$RC.install
/usr
/local
524 # Exit if any command fails
525 # Note: pipefail is necessary for running build commands through
526 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
530 # Turn off core dumps, as some test cases can easily fill up even the largest
534 if [ "$do_checkout" = "yes" ]; then
538 # Setup the test-suite. Do this early so we can catch failures before
539 # we do the full 3 stage build.
540 if [ $do_test_suite = "yes" ]; then
541 check_program_exists
'python3'
542 venv
="python3 -m venv"
544 SandboxDir
="$BuildDir/sandbox"
545 Lit
=$SandboxDir/bin
/lit
546 TestSuiteBuildDir
="$BuildDir/test-suite-build"
547 TestSuiteSrcDir
="$BuildDir/llvm-test-suite"
550 $SandboxDir/bin
/python
$BuildDir/llvm-project
/llvm
/utils
/lit
/setup.py
install
551 mkdir
-p $TestSuiteBuildDir
556 if [ "$do_debug" = "yes" ]; then
557 Flavors
="Debug $Flavors"
559 if [ "$do_asserts" = "yes" ]; then
560 Flavors
="$Flavors Release+Asserts"
563 for Flavor
in $Flavors ; do
566 echo "********************************************************************************"
567 echo " Release: $Release-$RC"
568 echo " Build: $Flavor"
569 echo " System Info: "
571 echo "********************************************************************************"
577 [[ -z "$build_compiler" ]] && build_compiler
="cc"
578 llvmCore_phase1_objdir
=$BuildDir/Phase
1/$Flavor/llvmCore-
$Release-$RC.obj
579 llvmCore_phase1_destdir
=$BuildDir/Phase
1/$Flavor/llvmCore-
$Release-$RC.
install
581 llvmCore_phase2_objdir
=$BuildDir/Phase
2/$Flavor/llvmCore-
$Release-$RC.obj
582 llvmCore_phase2_destdir
=$BuildDir/Phase
2/$Flavor/llvmCore-
$Release-$RC.
install
584 llvmCore_phase3_objdir
=$BuildDir/Phase
3/$Flavor/llvmCore-
$Release-$RC.obj
585 llvmCore_phase3_destdir
=$BuildDir/Phase
3/$Flavor/llvmCore-
$Release-$RC.
install
587 rm -rf $llvmCore_phase1_objdir
588 rm -rf $llvmCore_phase1_destdir
590 rm -rf $llvmCore_phase2_objdir
591 rm -rf $llvmCore_phase2_destdir
593 rm -rf $llvmCore_phase3_objdir
594 rm -rf $llvmCore_phase3_destdir
596 mkdir
-p $llvmCore_phase1_objdir
597 mkdir
-p $llvmCore_phase1_destdir
599 mkdir
-p $llvmCore_phase2_objdir
600 mkdir
-p $llvmCore_phase2_destdir
602 mkdir
-p $llvmCore_phase3_objdir
603 mkdir
-p $llvmCore_phase3_destdir
605 ############################################################################
606 # Phase 1: Build llvmCore and clang
607 echo "# Phase 1: Building llvmCore"
608 configure_llvmCore
1 $Flavor $llvmCore_phase1_objdir
609 build_llvmCore
1 $Flavor \
610 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
611 clean_RPATH
$llvmCore_phase1_destdir/usr
/local
613 ########################################################################
614 # Phase 2: Build llvmCore with newly built clang from phase 1.
615 c_compiler
=$llvmCore_phase1_destdir/usr
/local
/bin
/clang
616 cxx_compiler
=$llvmCore_phase1_destdir/usr
/local
/bin
/clang
++
617 echo "# Phase 2: Building llvmCore"
618 configure_llvmCore
2 $Flavor $llvmCore_phase2_objdir
619 build_llvmCore
2 $Flavor \
620 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
621 clean_RPATH
$llvmCore_phase2_destdir/usr
/local
623 ########################################################################
624 # Phase 3: Build llvmCore with newly built clang from phase 2.
625 c_compiler
=$llvmCore_phase2_destdir/usr
/local
/bin
/clang
626 cxx_compiler
=$llvmCore_phase2_destdir/usr
/local
/bin
/clang
++
627 echo "# Phase 3: Building llvmCore"
628 configure_llvmCore
3 $Flavor $llvmCore_phase3_objdir
629 build_llvmCore
3 $Flavor \
630 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
631 clean_RPATH
$llvmCore_phase3_destdir/usr
/local
633 ########################################################################
634 # Testing: Test phase 3
635 c_compiler
=$llvmCore_phase3_destdir/usr
/local
/bin
/clang
636 cxx_compiler
=$llvmCore_phase3_destdir/usr
/local
/bin
/clang
++
637 echo "# Testing - built with clang"
638 test_llvmCore
3 $Flavor $llvmCore_phase3_objdir
640 ########################################################################
641 # Compare .o files between Phase2 and Phase3 and report which ones
643 if [ "$do_compare" = "yes" ]; then
645 echo "# Comparing Phase 2 and Phase 3 files"
646 for p2
in `find $llvmCore_phase2_objdir -name '*.o'` ; do
647 p3
=`echo $p2 | sed -e 's,Phase2,Phase3,'`
648 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
649 # case there are build paths in the debug info. Do the same sub-
650 # stitution on both files in case the string occurrs naturally.
652 <(env LC_CTYPE
=C
sed -e 's,Phase1,Phase2,g' -e 's,Phase2,Phase3,g' $p2) \
653 <(env LC_CTYPE
=C
sed -e 's,Phase1,Phase2,g' -e 's,Phase2,Phase3,g' $p3) \
655 echo "file `basename $p2` differs between phase 2 and phase 3"
661 ) 2>&1 |
tee $LogDir/testing.
$Release-$RC.log
663 if [ "$use_gzip" = "yes" ]; then
664 echo "# Packaging the release as $Package.tar.gz"
666 echo "# Packaging the release as $Package.tar.xz"
673 echo "### Testing Finished ###"
674 echo "### Logs: $LogDir"
677 if [ -s "$LogDir/deferred_errors.log" ]; then
678 cat "$LogDir/deferred_errors.log"