[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / llvm / utils / release / test-release.sh
blob9208161c7da1b8fee25cc228b9064fcbc8fde918
1 #!/usr/bin/env bash
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 #===------------------------------------------------------------------------===#
14 System=`uname -s`
15 if [ "$System" = "FreeBSD" ]; then
16 MAKE=gmake
17 else
18 MAKE=make
20 generator="Unix Makefiles"
22 Release=""
23 Release_no_dot=""
24 RC=""
25 Triple=""
26 use_gzip="no"
27 do_checkout="yes"
28 do_debug="no"
29 do_asserts="no"
30 do_compare="yes"
31 do_rt="yes"
32 do_clang_tools="yes"
33 do_libs="yes"
34 do_libcxxabi="yes"
35 do_libunwind="yes"
36 do_test_suite="yes"
37 do_openmp="yes"
38 do_bolt="no"
39 do_lld="yes"
40 do_lldb="yes"
41 do_polly="yes"
42 do_mlir="yes"
43 do_flang="yes"
44 do_silent_log="no"
45 BuildDir="`pwd`"
46 ExtraConfigureFlags=""
47 ExportBranch=""
48 git_ref=""
50 function usage() {
51 echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]"
52 echo ""
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
84 case $1 in
85 -release | --release )
86 shift
87 Release="$1"
88 Release_no_dot="`echo $1 | sed -e 's,\.,,g'`"
90 -rc | --rc | -RC | --RC )
91 shift
92 RC="rc$1"
94 -final | --final )
95 RC=final
97 -git-ref | --git-ref )
98 shift
99 Release="test"
100 Release_no_dot="test"
101 ExportBranch="$1"
102 RC="`echo $ExportBranch | sed -e 's,/,_,g'`"
103 git_ref="$1"
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"
108 -triple | --triple )
109 shift
110 Triple="$1"
112 -configure-flags | --configure-flags )
113 shift
114 ExtraConfigureFlags="$1"
116 -j* )
117 NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
118 if [ -z "$NumJobs" ]; then
119 shift
120 NumJobs="$1"
123 -use-ninja )
124 MAKE=ninja
125 generator=Ninja
127 -build-dir | --build-dir | -builddir | --builddir )
128 shift
129 BuildDir="$1"
131 -no-checkout | --no-checkout )
132 do_checkout="no"
134 -test-debug | --test-debug )
135 do_debug="yes"
137 -test-asserts | --test-asserts )
138 do_asserts="yes"
140 -no-compare-files | --no-compare-files )
141 do_compare="no"
143 -use-gzip | --use-gzip )
144 use_gzip="yes"
146 -no-rt )
147 do_rt="no"
149 -no-libs )
150 do_libs="no"
152 -no-clang-tools )
153 do_clang_tools="no"
155 -no-libcxxabi )
156 do_libcxxabi="no"
158 -no-libunwind )
159 do_libunwind="no"
161 -no-test-suite )
162 do_test_suite="no"
164 -no-openmp )
165 do_openmp="no"
167 -bolt )
168 do_bolt="yes"
170 -no-bolt )
171 do_bolt="no"
173 -no-lld )
174 do_lld="no"
176 -lldb )
177 do_lldb="yes"
179 -no-lldb )
180 do_lldb="no"
182 -no-polly )
183 do_polly="no"
185 -no-mlir )
186 do_mlir="no"
188 -no-flang )
189 do_flang="no"
191 -silent-log )
192 do_silent_log="yes"
194 -help | --help | -h | --h | -\? )
195 usage
196 exit 0
199 echo "unknown option: $1"
200 usage
201 exit 1
203 esac
204 shift
205 done
207 if [ $do_mlir = "no" ] && [ $do_flang = "yes" ]; then
208 echo "error: cannot build Flang without MLIR"
209 exit 1
212 # Check required arguments.
213 if [ -z "$Release" ]; then
214 echo "error: no release number specified"
215 exit 1
217 if [ -z "$RC" ]; then
218 echo "error: no release candidate number specified"
219 exit 1
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"
226 exit 1
229 if [ "$Release" != "test" ]; then
230 if [ -n "$git_ref" ]; then
231 echo "error: can't specify both -release and -git-ref"
232 exit 1
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
251 NumJobs=3
254 # Projects list
255 projects="llvm clang"
256 if [ $do_clang_tools = "yes" ]; then
257 projects="$projects clang-tools-extra"
259 runtimes=""
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
296 mkdir -p $BuildDir
297 cd $BuildDir
299 # Location of log files.
300 LogDir=$BuildDir/logs
301 mkdir -p $LogDir
303 # Final package name.
304 Package=clang+llvm-$Release
305 if [ $RC != "final" ]; then
306 Package=$Package-$RC
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() {
314 Phase="$1"
315 Flavor="$2"
316 Msg="$3"
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() {
322 local program="$1"
323 if ! type -P $program > /dev/null 2>&1 ; then
324 echo "program '$1' not found !"
325 exit 1
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
343 mkdir -p $SrcDir
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
357 # test suite.
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.
360 set +e
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."
365 do_test_suite="no"
367 set -e
370 cd $BuildDir
373 function configure_llvmCore() {
374 Phase="$1"
375 Flavor="$2"
376 ObjDir="$3"
378 case $Flavor in
379 Release )
380 BuildType="Release"
381 Assertions="OFF"
383 Release+Asserts )
384 BuildType="Release"
385 Assertions="ON"
387 Debug )
388 BuildType="Debug"
389 Assertions="ON"
392 echo "# Invalid flavor '$Flavor'"
393 echo ""
394 return
396 esac
398 project_list=${projects// /;}
399 runtime_list=${runtimes// /;}
400 echo "# Using C compiler: $c_compiler"
401 echo "# Using C++ compiler: $cxx_compiler"
403 cd $ObjDir
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
425 cd $BuildDir
428 function build_llvmCore() {
429 Phase="$1"
430 Flavor="$2"
431 ObjDir="$3"
432 DestDir="$4"
434 Verbose="VERBOSE=1"
435 if [ ${MAKE} = 'ninja' ]; then
436 Verbose="-v"
439 redir="/dev/stdout"
440 if [ $do_silent_log == "yes" ]; then
441 echo "# Silencing build logs because of -silent-log flag..."
442 redir="/dev/null"
445 cd $ObjDir
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
455 cd $BuildDir
458 function test_llvmCore() {
459 Phase="$1"
460 Flavor="$2"
461 ObjDir="$3"
463 KeepGoing="-k"
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.
467 KeepGoing="-k 100"
470 cd $ObjDir
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"
487 cd $BuildDir
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
494 return
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
507 done
510 # Create a package of the release binaries.
511 function package_release() {
512 cwd=`pwd`
513 cd $BuildDir/Phase3/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
517 else
518 tar cf - $Package | xz -9ce > $BuildDir/$Package.tar.xz
520 mv $Package llvmCore-$Release-$RC.install/usr/local
521 cd $cwd
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 $?``)
527 set -e
528 set -o pipefail
530 # Turn off core dumps, as some test cases can easily fill up even the largest
531 # file systems.
532 ulimit -c 0
534 if [ "$do_checkout" = "yes" ]; then
535 export_sources
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"
549 ${venv} $SandboxDir
550 $SandboxDir/bin/python $BuildDir/llvm-project/llvm/utils/lit/setup.py install
551 mkdir -p $TestSuiteBuildDir
555 Flavors="Release"
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
564 echo ""
565 echo ""
566 echo "********************************************************************************"
567 echo " Release: $Release-$RC"
568 echo " Build: $Flavor"
569 echo " System Info: "
570 echo " `uname -a`"
571 echo "********************************************************************************"
572 echo ""
574 c_compiler="$CC"
575 cxx_compiler="$CXX"
576 build_compiler="$CC"
577 [[ -z "$build_compiler" ]] && build_compiler="cc"
578 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
579 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
581 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
582 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
584 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
585 llvmCore_phase3_destdir=$BuildDir/Phase3/$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
642 # differ.
643 if [ "$do_compare" = "yes" ]; then
644 echo
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.
651 if ! cmp -s \
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) \
654 16 16; then
655 echo "file `basename $p2` differs between phase 2 and phase 3"
657 done
659 done
661 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
663 if [ "$use_gzip" = "yes" ]; then
664 echo "# Packaging the release as $Package.tar.gz"
665 else
666 echo "# Packaging the release as $Package.tar.xz"
668 package_release
670 set +e
672 # Woo hoo!
673 echo "### Testing Finished ###"
674 echo "### Logs: $LogDir"
676 echo "### Errors:"
677 if [ -s "$LogDir/deferred_errors.log" ]; then
678 cat "$LogDir/deferred_errors.log"
679 exit 1
680 else
681 echo "None."
684 exit 0