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"
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-libs Disable check-out & build libcxx/libcxxabi/libunwind"
69 echo " -no-libcxxabi Disable check-out & build libcxxabi"
70 echo " -no-libunwind Disable check-out & build libunwind"
71 echo " -no-test-suite Disable check-out & build test-suite"
72 echo " -no-openmp Disable check-out & build libomp"
73 echo " -no-lld Disable check-out & build lld"
74 echo " -lldb Enable check-out & build lldb"
75 echo " -no-lldb Disable check-out & build lldb (default)"
76 echo " -no-polly Disable check-out & build Polly"
77 echo " -no-mlir Disable check-out & build MLIR"
78 echo " -no-flang Disable check-out & build Flang"
81 while [ $# -gt 0 ]; do
83 -release |
--release )
86 Release_no_dot
="`echo $1 | sed -e 's,\.,,g'`"
88 -rc |
--rc |
-RC |
--RC )
95 -git-ref |
--git-ref )
100 RC
="`echo $ExportBranch | sed -e 's,/,_,g'`"
102 echo "WARNING: Using the ref $git_ref instead of a release tag"
103 echo " This is intended to aid new packagers in trialing "
104 echo " builds without requiring a tag to be created first"
110 -configure-flags |
--configure-flags )
112 ExtraConfigureFlags
="$1"
115 NumJobs
="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
116 if [ -z "$NumJobs" ]; then
125 -build-dir |
--build-dir |
-builddir |
--builddir )
129 -no-checkout |
--no-checkout )
132 -test-debug |
--test-debug )
135 -test-asserts |
--test-asserts )
138 -no-compare-files |
--no-compare-files )
141 -use-gzip |
--use-gzip )
180 -help |
--help |
-h |
--h |
-\? )
185 echo "unknown option: $1"
193 if [ $do_mlir = "no" ] && [ $do_flang = "yes" ]; then
194 echo "error: cannot build Flang without MLIR"
198 # Check required arguments.
199 if [ -z "$Release" ]; then
200 echo "error: no release number specified"
203 if [ -z "$RC" ]; then
204 echo "error: no release candidate number specified"
207 if [ -z "$ExportBranch" ]; then
208 ExportBranch
="tags/RELEASE_$Release_no_dot/$RC"
210 if [ -z "$Triple" ]; then
211 echo "error: no target triple specified"
215 if [ "$Release" != "test" ]; then
216 if [ -n "$git_ref" ]; then
217 echo "error: can't specify both -release and -git-ref"
220 git_ref
=llvmorg-
$Release
221 if [ "$RC" != "final" ]; then
222 git_ref
="$git_ref-$RC"
226 # Figure out how many make processes to run.
227 if [ -z "$NumJobs" ]; then
228 NumJobs
=`sysctl -n hw.activecpu 2> /dev/null || true`
230 if [ -z "$NumJobs" ]; then
231 NumJobs
=`sysctl -n hw.ncpu 2> /dev/null || true`
233 if [ -z "$NumJobs" ]; then
234 NumJobs
=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
236 if [ -z "$NumJobs" ]; then
241 projects
="llvm clang clang-tools-extra"
242 if [ $do_rt = "yes" ]; then
243 projects
="$projects compiler-rt"
245 if [ $do_libs = "yes" ]; then
246 projects
="$projects libcxx"
247 if [ $do_libcxxabi = "yes" ]; then
248 projects
="$projects libcxxabi"
250 if [ $do_libunwind = "yes" ]; then
251 projects
="$projects libunwind"
254 case $do_test_suite in
256 projects
="$projects test-suite"
259 if [ $do_openmp = "yes" ]; then
260 projects
="$projects openmp"
262 if [ $do_lld = "yes" ]; then
263 projects
="$projects lld"
265 if [ $do_lldb = "yes" ]; then
266 projects
="$projects lldb"
268 if [ $do_polly = "yes" ]; then
269 projects
="$projects polly"
271 if [ $do_mlir = "yes" ]; then
272 projects
="$projects mlir"
274 if [ $do_flang = "yes" ]; then
275 projects
="$projects flang"
278 # Go to the build directory (may be different from CWD)
279 BuildDir
=$BuildDir/$RC
283 # Location of log files.
284 LogDir
=$BuildDir/logs
287 # Final package name.
288 Package
=clang
+llvm-
$Release
289 if [ $RC != "final" ]; then
292 Package
=$Package-$Triple
294 # Errors to be highlighted at the end are written to this file.
295 echo -n > $LogDir/deferred_errors.log
297 function deferred_error
() {
301 echo "[${Flavor} Phase${Phase}] ${Msg}" |
tee -a $LogDir/deferred_errors.log
304 # Make sure that a required program is available
305 function check_program_exists
() {
307 if ! type -P $program > /dev
/null
2>&1 ; then
308 echo "program '$1' not found !"
313 if [ "$System" != "Darwin" -a "$System" != "SunOS" ]; then
314 check_program_exists
'chrpath'
317 if [ "$System" != "Darwin" ]; then
318 check_program_exists
'file'
319 check_program_exists
'objdump'
322 check_program_exists
${MAKE}
324 # Export sources to the build directory.
325 function export_sources
() {
326 SrcDir
=$BuildDir/llvm-project
328 echo "# Using git ref: $git_ref"
330 # GitHub allows you to download a tarball of any commit using the URL:
331 # https://github.com/$organization/$repo/archive/$ref.tar.gz
332 curl
-L https
://github.com
/llvm
/llvm-project
/archive
/$git_ref.
tar.gz | \
333 tar -C $SrcDir --strip-components=1 -xzf -
335 if [ "$do_test_suite" = "yes" ]; then
336 TestSuiteSrcDir
=$BuildDir/llvm-test-suite
337 mkdir
-p $TestSuiteSrcDir
339 # We can only use named refs, like branches and tags, that exist in
340 # both the llvm-project and test-suite repos if we want to run the
342 # If the test-suite fails to download assume we are using a ref that
343 # doesn't exist in the test suite and disable it.
345 curl
-L https
://github.com
/llvm
/test-suite
/archive
/$git_ref.
tar.gz | \
346 tar -C $TestSuiteSrcDir --strip-components=1 -xzf -
347 if [ $?
-ne -0 ]; then
348 echo "$git_ref not found in test-suite repo, test-suite disabled."
357 function configure_llvmCore
() {
376 echo "# Invalid flavor '$Flavor'"
382 project_list
=${projects// /;}
383 echo "# Using C compiler: $c_compiler"
384 echo "# Using C++ compiler: $cxx_compiler"
387 echo "# Configuring llvm $Release-$RC $Flavor"
389 echo "#" env CC
="$c_compiler" CXX
="$cxx_compiler" \
390 cmake
-G "$generator" \
391 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
392 -DLLVM_ENABLE_PROJECTS="$project_list" \
393 $ExtraConfigureFlags $BuildDir/llvm-project
/llvm \
394 2>&1 |
tee $LogDir/llvm.configure-Phase
$Phase-$Flavor.log
395 env CC
="$c_compiler" CXX
="$cxx_compiler" \
396 cmake
-G "$generator" \
397 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
398 -DLLVM_ENABLE_PROJECTS="$project_list" \
399 $ExtraConfigureFlags $BuildDir/llvm-project
/llvm \
400 2>&1 |
tee $LogDir/llvm.configure-Phase
$Phase-$Flavor.log
405 function build_llvmCore
() {
412 if [ ${MAKE} = 'ninja' ]; then
417 echo "# Compiling llvm $Release-$RC $Flavor"
418 echo "# ${MAKE} -j $NumJobs $Verbose"
419 ${MAKE} -j $NumJobs $Verbose \
420 2>&1 |
tee $LogDir/llvm.make-Phase
$Phase-$Flavor.log
422 echo "# Installing llvm $Release-$RC $Flavor"
423 echo "# ${MAKE} install"
424 DESTDIR
="${DestDir}" ${MAKE} install \
425 2>&1 |
tee $LogDir/llvm.install-Phase
$Phase-$Flavor.log
429 function test_llvmCore
() {
435 if [ ${MAKE} = 'ninja' ]; then
436 # Ninja doesn't have a documented "keep-going-forever" mode, we need to
437 # set a limit on how many jobs can fail before we give up.
442 if ! ( ${MAKE} -j $NumJobs $KeepGoing check-all \
443 2>&1 |
tee $LogDir/llvm.check-Phase
$Phase-$Flavor.log
) ; then
444 deferred_error
$Phase $Flavor "check-all failed"
447 if [ $do_test_suite = 'yes' ]; then
448 cd $TestSuiteBuildDir
449 env CC
="$c_compiler" CXX
="$cxx_compiler" \
450 cmake
$TestSuiteSrcDir -G "$generator" -DTEST_SUITE_LIT=$Lit
452 if ! ( ${MAKE} -j $NumJobs $KeepGoing check \
453 2>&1 |
tee $LogDir/llvm.check-Phase
$Phase-$Flavor.log
) ; then
454 deferred_error
$Phase $Flavor "test suite failed"
460 # Clean RPATH. Libtool adds the build directory to the search path, which is
461 # not necessary --- and even harmful --- for the binary packages we release.
462 function clean_RPATH
() {
463 if [ "$System" = "Darwin" -o "$System" = "SunOS" ]; then
466 local InstallPath
="$1"
467 for Candidate
in `find $InstallPath/{bin,lib} -type f`; do
468 if file $Candidate |
grep ELF |
egrep 'executable|shared object' > /dev
/null
2>&1 ; then
469 if rpath
=`objdump -x $Candidate | grep 'RPATH'` ; then
470 rpath
=`echo $rpath | sed -e's/^ *RPATH *//'`
471 if [ -n "$rpath" ]; then
472 newrpath
=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
473 chrpath
-r $newrpath $Candidate 2>&1 > /dev
/null
2>&1
480 # Create a package of the release binaries.
481 function package_release
() {
483 cd $BuildDir/Phase
3/Release
484 mv llvmCore-
$Release-$RC.install
/usr
/local $Package
485 if [ "$use_gzip" = "yes" ]; then
486 tar cf
- $Package |
gzip -9c > $BuildDir/$Package.
tar.gz
488 tar cf
- $Package | xz
-9ce > $BuildDir/$Package.
tar.xz
490 mv $Package llvmCore-
$Release-$RC.install
/usr
/local
494 # Exit if any command fails
495 # Note: pipefail is necessary for running build commands through
496 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
500 # Turn off core dumps, as some test cases can easily fill up even the largest
504 if [ "$do_checkout" = "yes" ]; then
508 # Setup the test-suite. Do this early so we can catch failures before
509 # we do the full 3 stage build.
510 if [ $do_test_suite = "yes" ]; then
511 check_program_exists
'python3'
512 venv
="python3 -m venv"
514 SandboxDir
="$BuildDir/sandbox"
515 Lit
=$SandboxDir/bin
/lit
516 TestSuiteBuildDir
="$BuildDir/test-suite-build"
517 TestSuiteSrcDir
="$BuildDir/llvm-test-suite"
520 $SandboxDir/bin
/python
$BuildDir/llvm-project
/llvm
/utils
/lit
/setup.py
install
521 mkdir
-p $TestSuiteBuildDir
526 if [ "$do_debug" = "yes" ]; then
527 Flavors
="Debug $Flavors"
529 if [ "$do_asserts" = "yes" ]; then
530 Flavors
="$Flavors Release+Asserts"
533 for Flavor
in $Flavors ; do
536 echo "********************************************************************************"
537 echo " Release: $Release-$RC"
538 echo " Build: $Flavor"
539 echo " System Info: "
541 echo "********************************************************************************"
546 llvmCore_phase1_objdir
=$BuildDir/Phase
1/$Flavor/llvmCore-
$Release-$RC.obj
547 llvmCore_phase1_destdir
=$BuildDir/Phase
1/$Flavor/llvmCore-
$Release-$RC.
install
549 llvmCore_phase2_objdir
=$BuildDir/Phase
2/$Flavor/llvmCore-
$Release-$RC.obj
550 llvmCore_phase2_destdir
=$BuildDir/Phase
2/$Flavor/llvmCore-
$Release-$RC.
install
552 llvmCore_phase3_objdir
=$BuildDir/Phase
3/$Flavor/llvmCore-
$Release-$RC.obj
553 llvmCore_phase3_destdir
=$BuildDir/Phase
3/$Flavor/llvmCore-
$Release-$RC.
install
555 rm -rf $llvmCore_phase1_objdir
556 rm -rf $llvmCore_phase1_destdir
558 rm -rf $llvmCore_phase2_objdir
559 rm -rf $llvmCore_phase2_destdir
561 rm -rf $llvmCore_phase3_objdir
562 rm -rf $llvmCore_phase3_destdir
564 mkdir
-p $llvmCore_phase1_objdir
565 mkdir
-p $llvmCore_phase1_destdir
567 mkdir
-p $llvmCore_phase2_objdir
568 mkdir
-p $llvmCore_phase2_destdir
570 mkdir
-p $llvmCore_phase3_objdir
571 mkdir
-p $llvmCore_phase3_destdir
573 ############################################################################
574 # Phase 1: Build llvmCore and clang
575 echo "# Phase 1: Building llvmCore"
576 configure_llvmCore
1 $Flavor $llvmCore_phase1_objdir
577 build_llvmCore
1 $Flavor \
578 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
579 clean_RPATH
$llvmCore_phase1_destdir/usr
/local
581 ########################################################################
582 # Phase 2: Build llvmCore with newly built clang from phase 1.
583 c_compiler
=$llvmCore_phase1_destdir/usr
/local
/bin
/clang
584 cxx_compiler
=$llvmCore_phase1_destdir/usr
/local
/bin
/clang
++
585 echo "# Phase 2: Building llvmCore"
586 configure_llvmCore
2 $Flavor $llvmCore_phase2_objdir
587 build_llvmCore
2 $Flavor \
588 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
589 clean_RPATH
$llvmCore_phase2_destdir/usr
/local
591 ########################################################################
592 # Phase 3: Build llvmCore with newly built clang from phase 2.
593 c_compiler
=$llvmCore_phase2_destdir/usr
/local
/bin
/clang
594 cxx_compiler
=$llvmCore_phase2_destdir/usr
/local
/bin
/clang
++
595 echo "# Phase 3: Building llvmCore"
596 configure_llvmCore
3 $Flavor $llvmCore_phase3_objdir
597 build_llvmCore
3 $Flavor \
598 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
599 clean_RPATH
$llvmCore_phase3_destdir/usr
/local
601 ########################################################################
602 # Testing: Test phase 3
603 c_compiler
=$llvmCore_phase3_destdir/usr
/local
/bin
/clang
604 cxx_compiler
=$llvmCore_phase3_destdir/usr
/local
/bin
/clang
++
605 echo "# Testing - built with clang"
606 test_llvmCore
3 $Flavor $llvmCore_phase3_objdir
608 ########################################################################
609 # Compare .o files between Phase2 and Phase3 and report which ones
611 if [ "$do_compare" = "yes" ]; then
613 echo "# Comparing Phase 2 and Phase 3 files"
614 for p2
in `find $llvmCore_phase2_objdir -name '*.o'` ; do
615 p3
=`echo $p2 | sed -e 's,Phase2,Phase3,'`
616 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
617 # case there are build paths in the debug info. Do the same sub-
618 # stitution on both files in case the string occurrs naturally.
620 <(env LC_CTYPE
=C
sed -e 's,Phase1,Phase2,g' -e 's,Phase2,Phase3,g' $p2) \
621 <(env LC_CTYPE
=C
sed -e 's,Phase1,Phase2,g' -e 's,Phase2,Phase3,g' $p3) \
623 echo "file `basename $p2` differs between phase 2 and phase 3"
629 ) 2>&1 |
tee $LogDir/testing.
$Release-$RC.log
631 if [ "$use_gzip" = "yes" ]; then
632 echo "# Packaging the release as $Package.tar.gz"
634 echo "# Packaging the release as $Package.tar.xz"
641 echo "### Testing Finished ###"
642 echo "### Logs: $LogDir"
645 if [ -s "$LogDir/deferred_errors.log" ]; then
646 cat "$LogDir/deferred_errors.log"