[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / utils / release / test-release.sh
blob8f691ccfb87af2e033bc8cba0d5d1a4a320921b4
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 # Base SVN URL for the sources.
23 Base_url="http://llvm.org/svn/llvm-project"
25 Release=""
26 Release_no_dot=""
27 RC=""
28 Triple=""
29 use_gzip="no"
30 do_checkout="yes"
31 do_debug="no"
32 do_asserts="no"
33 do_compare="yes"
34 do_rt="yes"
35 do_libs="yes"
36 do_libcxxabi="yes"
37 do_libunwind="yes"
38 do_test_suite="yes"
39 do_openmp="yes"
40 do_lld="yes"
41 do_lldb="no"
42 do_polly="yes"
43 BuildDir="`pwd`"
44 ExtraConfigureFlags=""
45 ExportBranch=""
47 function usage() {
48 echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]"
49 echo ""
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
78 case $1 in
79 -release | --release )
80 shift
81 Release="$1"
82 Release_no_dot="`echo $1 | sed -e 's,\.,,g'`"
84 -rc | --rc | -RC | --RC )
85 shift
86 RC="rc$1"
88 -final | --final )
89 RC=final
91 -svn-path | --svn-path )
92 shift
93 Release="test"
94 Release_no_dot="test"
95 ExportBranch="$1"
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"
101 -triple | --triple )
102 shift
103 Triple="$1"
105 -configure-flags | --configure-flags )
106 shift
107 ExtraConfigureFlags="$1"
109 -j* )
110 NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
111 if [ -z "$NumJobs" ]; then
112 shift
113 NumJobs="$1"
116 -use-ninja )
117 MAKE=ninja
118 generator=Ninja
120 -build-dir | --build-dir | -builddir | --builddir )
121 shift
122 BuildDir="$1"
124 -no-checkout | --no-checkout )
125 do_checkout="no"
127 -test-debug | --test-debug )
128 do_debug="yes"
130 -test-asserts | --test-asserts )
131 do_asserts="yes"
133 -no-compare-files | --no-compare-files )
134 do_compare="no"
136 -use-gzip | --use-gzip )
137 use_gzip="yes"
139 -no-rt )
140 do_rt="no"
142 -no-libs )
143 do_libs="no"
145 -no-libcxxabi )
146 do_libcxxabi="no"
148 -no-libunwind )
149 do_libunwind="no"
151 -no-test-suite )
152 do_test_suite="no"
154 -no-openmp )
155 do_openmp="no"
157 -no-lld )
158 do_lld="no"
160 -lldb )
161 do_lldb="yes"
163 -no-lldb )
164 do_lldb="no"
166 -no-polly )
167 do_polly="no"
169 -help | --help | -h | --h | -\? )
170 usage
171 exit 0
174 echo "unknown option: $1"
175 usage
176 exit 1
178 esac
179 shift
180 done
182 # Check required arguments.
183 if [ -z "$Release" ]; then
184 echo "error: no release number specified"
185 exit 1
187 if [ -z "$RC" ]; then
188 echo "error: no release candidate number specified"
189 exit 1
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"
196 exit 1
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
210 NumJobs=3
213 # Projects list
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
228 yes|export-only)
229 projects="$projects test-suite"
231 esac
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
247 mkdir -p $BuildDir
248 cd $BuildDir
250 # Location of log files.
251 LogDir=$BuildDir/logs
252 mkdir -p $LogDir
254 # Final package name.
255 Package=clang+llvm-$Release
256 if [ $RC != "final" ]; then
257 Package=$Package-$RC
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() {
265 Phase="$1"
266 Flavor="$2"
267 Msg="$3"
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() {
273 local program="$1"
274 if ! type -P $program > /dev/null 2>&1 ; then
275 echo "program '$1' not found !"
276 exit 1
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!"
295 exit 1
297 done
300 # Export sources to the build directory.
301 function export_sources() {
302 check_valid_urls
304 for proj in $projects ; do
305 case $proj in
306 llvm)
307 projsrc=$proj.src
309 cfe)
310 projsrc=llvm.src/tools/clang
312 lld|lldb|polly)
313 projsrc=llvm.src/tools/$proj
315 clang-tools-extra)
316 projsrc=llvm.src/tools/clang/tools/extra
318 compiler-rt|libcxx|libcxxabi|libunwind|openmp)
319 projsrc=llvm.src/projects/$proj
321 test-suite)
322 projsrc=$proj.src
325 echo "error: unknown project $proj"
326 exit 1
328 esac
330 if [ -d $projsrc ]; then
331 echo "# Reusing $proj $Release-$RC sources in $projsrc"
332 continue
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"
337 exit 1
339 done
341 cd $BuildDir
344 function configure_llvmCore() {
345 Phase="$1"
346 Flavor="$2"
347 ObjDir="$3"
349 case $Flavor in
350 Release )
351 BuildType="Release"
352 Assertions="OFF"
354 Release+Asserts )
355 BuildType="Release"
356 Assertions="ON"
358 Debug )
359 BuildType="Debug"
360 Assertions="ON"
363 echo "# Invalid flavor '$Flavor'"
364 echo ""
365 return
367 esac
369 echo "# Using C compiler: $c_compiler"
370 echo "# Using C++ compiler: $cxx_compiler"
372 cd $ObjDir
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
386 cd $BuildDir
389 function build_llvmCore() {
390 Phase="$1"
391 Flavor="$2"
392 ObjDir="$3"
393 DestDir="$4"
395 Verbose="VERBOSE=1"
396 if [ ${MAKE} = 'ninja' ]; then
397 Verbose="-v"
400 cd $ObjDir
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
410 cd $BuildDir
413 function test_llvmCore() {
414 Phase="$1"
415 Flavor="$2"
416 ObjDir="$3"
418 KeepGoing="-k"
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.
422 KeepGoing="-k 100"
425 cd $ObjDir
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"
441 cd $BuildDir
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
448 return
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
461 done
464 # Create a package of the release binaries.
465 function package_release() {
466 cwd=`pwd`
467 cd $BuildDir/Phase3/Release
468 mv llvmCore-$Release-$RC.install/usr/local $Package
469 if [ "$use_gzip" = "yes" ]; then
470 tar cfz $BuildDir/$Package.tar.gz $Package
471 else
472 tar cfJ $BuildDir/$Package.tar.xz $Package
474 mv $Package llvmCore-$Release-$RC.install/usr/local
475 cd $cwd
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 $?``)
481 set -e
482 set -o pipefail
484 if [ "$do_checkout" = "yes" ]; then
485 export_sources
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
502 Flavors="Release"
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
511 echo ""
512 echo ""
513 echo "********************************************************************************"
514 echo " Release: $Release-$RC"
515 echo " Build: $Flavor"
516 echo " System Info: "
517 echo " `uname -a`"
518 echo "********************************************************************************"
519 echo ""
521 c_compiler="$CC"
522 cxx_compiler="$CXX"
523 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
524 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
526 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
527 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
529 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
530 llvmCore_phase3_destdir=$BuildDir/Phase3/$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
587 # differ.
588 if [ "$do_compare" = "yes" ]; then
589 echo
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.
596 if ! cmp -s \
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) \
599 16 16; then
600 echo "file `basename $p2` differs between phase 2 and phase 3"
602 done
604 done
606 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
608 if [ "$use_gzip" = "yes" ]; then
609 echo "# Packaging the release as $Package.tar.gz"
610 else
611 echo "# Packaging the release as $Package.tar.xz"
613 package_release
615 set +e
617 # Woo hoo!
618 echo "### Testing Finished ###"
619 echo "### Logs: $LogDir"
621 echo "### Errors:"
622 if [ -s "$LogDir/deferred_errors.log" ]; then
623 cat "$LogDir/deferred_errors.log"
624 exit 1
625 else
626 echo "None."
629 exit 0