[InstCombine] Signed saturation patterns
[llvm-core.git] / utils / release / test-release.sh
blobe00a41d373684c66f6e758f0c667e6ea4f8f75a0
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" -a "$System" != "SunOS" ]; then
281 check_program_exists 'chrpath'
284 if [ "$System" != "Darwin" ]; then
285 check_program_exists 'file'
286 check_program_exists 'objdump'
289 check_program_exists ${MAKE}
291 # Make sure that the URLs are valid.
292 function check_valid_urls() {
293 for proj in $projects ; do
294 echo "# Validating $proj SVN URL"
296 if ! svn ls $Base_url/$proj/$ExportBranch > /dev/null 2>&1 ; then
297 echo "$proj does not have a $ExportBranch branch/tag!"
298 exit 1
300 done
303 # Export sources to the build directory.
304 function export_sources() {
305 check_valid_urls
307 for proj in $projects ; do
308 case $proj in
309 llvm)
310 projsrc=$proj.src
312 cfe)
313 projsrc=llvm.src/tools/clang
315 lld|lldb|polly)
316 projsrc=llvm.src/tools/$proj
318 clang-tools-extra)
319 projsrc=llvm.src/tools/clang/tools/extra
321 compiler-rt|libcxx|libcxxabi|libunwind|openmp)
322 projsrc=llvm.src/projects/$proj
324 test-suite)
325 projsrc=$proj.src
328 echo "error: unknown project $proj"
329 exit 1
331 esac
333 if [ -d $projsrc ]; then
334 echo "# Reusing $proj $Release-$RC sources in $projsrc"
335 continue
337 echo "# Exporting $proj $Release-$RC sources to $projsrc"
338 if ! svn export -q $Base_url/$proj/$ExportBranch $projsrc ; then
339 echo "error: failed to export $proj project"
340 exit 1
342 done
344 cd $BuildDir
347 function configure_llvmCore() {
348 Phase="$1"
349 Flavor="$2"
350 ObjDir="$3"
352 case $Flavor in
353 Release )
354 BuildType="Release"
355 Assertions="OFF"
357 Release+Asserts )
358 BuildType="Release"
359 Assertions="ON"
361 Debug )
362 BuildType="Debug"
363 Assertions="ON"
366 echo "# Invalid flavor '$Flavor'"
367 echo ""
368 return
370 esac
372 echo "# Using C compiler: $c_compiler"
373 echo "# Using C++ compiler: $cxx_compiler"
375 cd $ObjDir
376 echo "# Configuring llvm $Release-$RC $Flavor"
378 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
379 cmake -G "$generator" \
380 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
381 $ExtraConfigureFlags $BuildDir/llvm.src \
382 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
383 env CC="$c_compiler" CXX="$cxx_compiler" \
384 cmake -G "$generator" \
385 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
386 $ExtraConfigureFlags $BuildDir/llvm.src \
387 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
389 cd $BuildDir
392 function build_llvmCore() {
393 Phase="$1"
394 Flavor="$2"
395 ObjDir="$3"
396 DestDir="$4"
398 Verbose="VERBOSE=1"
399 if [ ${MAKE} = 'ninja' ]; then
400 Verbose="-v"
403 cd $ObjDir
404 echo "# Compiling llvm $Release-$RC $Flavor"
405 echo "# ${MAKE} -j $NumJobs $Verbose"
406 ${MAKE} -j $NumJobs $Verbose \
407 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
409 echo "# Installing llvm $Release-$RC $Flavor"
410 echo "# ${MAKE} install"
411 DESTDIR="${DestDir}" ${MAKE} install \
412 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
413 cd $BuildDir
416 function test_llvmCore() {
417 Phase="$1"
418 Flavor="$2"
419 ObjDir="$3"
421 KeepGoing="-k"
422 if [ ${MAKE} = 'ninja' ]; then
423 # Ninja doesn't have a documented "keep-going-forever" mode, we need to
424 # set a limit on how many jobs can fail before we give up.
425 KeepGoing="-k 100"
428 cd $ObjDir
429 if ! ( ${MAKE} -j $NumJobs $KeepGoing check-all \
430 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
431 deferred_error $Phase $Flavor "check-all failed"
434 if [ $do_test_suite = 'yes' ]; then
435 cd $TestSuiteBuildDir
436 env CC="$c_compiler" CXX="$cxx_compiler" \
437 cmake $TestSuiteSrcDir -G "$generator" -DTEST_SUITE_LIT=$Lit
439 if ! ( ${MAKE} -j $NumJobs $KeepGoing check \
440 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
441 deferred_error $Phase $Flavor "test suite failed"
444 cd $BuildDir
447 # Clean RPATH. Libtool adds the build directory to the search path, which is
448 # not necessary --- and even harmful --- for the binary packages we release.
449 function clean_RPATH() {
450 if [ "$System" = "Darwin" -o "$System" = "SunOS" ]; then
451 return
453 local InstallPath="$1"
454 for Candidate in `find $InstallPath/{bin,lib} -type f`; do
455 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
456 if rpath=`objdump -x $Candidate | grep 'RPATH'` ; then
457 rpath=`echo $rpath | sed -e's/^ *RPATH *//'`
458 if [ -n "$rpath" ]; then
459 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
460 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
464 done
467 # Create a package of the release binaries.
468 function package_release() {
469 cwd=`pwd`
470 cd $BuildDir/Phase3/Release
471 mv llvmCore-$Release-$RC.install/usr/local $Package
472 if [ "$use_gzip" = "yes" ]; then
473 tar cfz $BuildDir/$Package.tar.gz $Package
474 else
475 tar cfJ $BuildDir/$Package.tar.xz $Package
477 mv $Package llvmCore-$Release-$RC.install/usr/local
478 cd $cwd
481 # Exit if any command fails
482 # Note: pipefail is necessary for running build commands through
483 # a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
484 set -e
485 set -o pipefail
487 if [ "$do_checkout" = "yes" ]; then
488 export_sources
491 # Setup the test-suite. Do this early so we can catch failures before
492 # we do the full 3 stage build.
493 if [ $do_test_suite = "yes" ]; then
494 SandboxDir="$BuildDir/sandbox"
495 Lit=$SandboxDir/bin/lit
496 TestSuiteBuildDir="$BuildDir/test-suite-build"
497 TestSuiteSrcDir="$BuildDir/test-suite.src"
499 virtualenv $SandboxDir
500 $SandboxDir/bin/python $BuildDir/llvm.src/utils/lit/setup.py install
501 mkdir -p $TestSuiteBuildDir
505 Flavors="Release"
506 if [ "$do_debug" = "yes" ]; then
507 Flavors="Debug $Flavors"
509 if [ "$do_asserts" = "yes" ]; then
510 Flavors="$Flavors Release+Asserts"
513 for Flavor in $Flavors ; do
514 echo ""
515 echo ""
516 echo "********************************************************************************"
517 echo " Release: $Release-$RC"
518 echo " Build: $Flavor"
519 echo " System Info: "
520 echo " `uname -a`"
521 echo "********************************************************************************"
522 echo ""
524 c_compiler="$CC"
525 cxx_compiler="$CXX"
526 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
527 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
529 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
530 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
532 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
533 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
535 rm -rf $llvmCore_phase1_objdir
536 rm -rf $llvmCore_phase1_destdir
538 rm -rf $llvmCore_phase2_objdir
539 rm -rf $llvmCore_phase2_destdir
541 rm -rf $llvmCore_phase3_objdir
542 rm -rf $llvmCore_phase3_destdir
544 mkdir -p $llvmCore_phase1_objdir
545 mkdir -p $llvmCore_phase1_destdir
547 mkdir -p $llvmCore_phase2_objdir
548 mkdir -p $llvmCore_phase2_destdir
550 mkdir -p $llvmCore_phase3_objdir
551 mkdir -p $llvmCore_phase3_destdir
553 ############################################################################
554 # Phase 1: Build llvmCore and clang
555 echo "# Phase 1: Building llvmCore"
556 configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir
557 build_llvmCore 1 $Flavor \
558 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
559 clean_RPATH $llvmCore_phase1_destdir/usr/local
561 ########################################################################
562 # Phase 2: Build llvmCore with newly built clang from phase 1.
563 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
564 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
565 echo "# Phase 2: Building llvmCore"
566 configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir
567 build_llvmCore 2 $Flavor \
568 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
569 clean_RPATH $llvmCore_phase2_destdir/usr/local
571 ########################################################################
572 # Phase 3: Build llvmCore with newly built clang from phase 2.
573 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
574 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
575 echo "# Phase 3: Building llvmCore"
576 configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir
577 build_llvmCore 3 $Flavor \
578 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
579 clean_RPATH $llvmCore_phase3_destdir/usr/local
581 ########################################################################
582 # Testing: Test phase 3
583 c_compiler=$llvmCore_phase3_destdir/usr/local/bin/clang
584 cxx_compiler=$llvmCore_phase3_destdir/usr/local/bin/clang++
585 echo "# Testing - built with clang"
586 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
588 ########################################################################
589 # Compare .o files between Phase2 and Phase3 and report which ones
590 # differ.
591 if [ "$do_compare" = "yes" ]; then
592 echo
593 echo "# Comparing Phase 2 and Phase 3 files"
594 for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do
595 p3=`echo $p2 | sed -e 's,Phase2,Phase3,'`
596 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
597 # case there are build paths in the debug info. Do the same sub-
598 # stitution on both files in case the string occurrs naturally.
599 if ! cmp -s \
600 <(env LC_CTYPE=C sed -e 's,Phase1,Phase2,g' -e 's,Phase2,Phase3,g' $p2) \
601 <(env LC_CTYPE=C sed -e 's,Phase1,Phase2,g' -e 's,Phase2,Phase3,g' $p3) \
602 16 16; then
603 echo "file `basename $p2` differs between phase 2 and phase 3"
605 done
607 done
609 ) 2>&1 | tee $LogDir/testing.$Release-$RC.log
611 if [ "$use_gzip" = "yes" ]; then
612 echo "# Packaging the release as $Package.tar.gz"
613 else
614 echo "# Packaging the release as $Package.tar.xz"
616 package_release
618 set +e
620 # Woo hoo!
621 echo "### Testing Finished ###"
622 echo "### Logs: $LogDir"
624 echo "### Errors:"
625 if [ -s "$LogDir/deferred_errors.log" ]; then
626 cat "$LogDir/deferred_errors.log"
627 exit 1
628 else
629 echo "None."
632 exit 0