blob: 440dee53c1b76f1a9d2758e70664ba0217b6ab0b [file] [log] [blame]
Bill Wendling495069e2011-10-19 09:25:49 +00001#!/usr/bin/env bash
Bill Wendlingb91c7122010-09-08 18:32:31 +00002#===-- test-release.sh - Test the LLVM release candidates ------------------===#
3#
4# The LLVM Compiler Infrastructure
5#
6# This file is distributed under the University of Illinois Open Source
7# License.
8#
9#===------------------------------------------------------------------------===#
10#
11# Download, build, and test the release candidate for an LLVM release.
12#
13#===------------------------------------------------------------------------===#
14
Dimitry Andricad24fed2016-01-21 22:07:17 +000015System=`uname -s`
16if [ "$System" = "FreeBSD" ]; then
Bill Wendling783993e2011-10-19 08:42:07 +000017 MAKE=gmake
18else
19 MAKE=make
20fi
21
Bill Wendling1416dc22011-10-16 22:44:08 +000022# Base SVN URL for the sources.
23Base_url="http://llvm.org/svn/llvm-project"
24
Bill Wendlingb91c7122010-09-08 18:32:31 +000025Release=""
26Release_no_dot=""
27RC=""
Bill Wendling264b48b2013-11-20 04:55:20 +000028Triple=""
Bill Wendling1fcb3902013-11-24 05:29:35 +000029use_gzip="no"
Bill Wendlingb91c7122010-09-08 18:32:31 +000030do_checkout="yes"
Bill Wendling1416dc22011-10-16 22:44:08 +000031do_debug="no"
Bill Wendlinga854f5d2011-10-17 04:46:54 +000032do_asserts="no"
Bill Wendling1adc2152012-04-02 23:27:43 +000033do_compare="yes"
Renato Golinc6f36fe2015-07-22 18:21:39 +000034do_rt="yes"
35do_libs="yes"
Dimitry Andricd05a0b82018-01-18 19:30:30 +000036do_libcxxabi="yes"
Daniel Sanders4b26be62015-07-30 10:14:57 +000037do_libunwind="yes"
Renato Golinc6f36fe2015-07-22 18:21:39 +000038do_test_suite="yes"
Alexey Bataev5ebd7ba2015-12-10 05:45:58 +000039do_openmp="yes"
Dimitry Andric68a49ae2017-02-04 22:24:55 +000040do_lld="yes"
Daniel Sanders0562fb32016-02-29 11:04:39 +000041do_lldb="no"
Pengxuan Zhenga4bbfa92017-06-20 01:04:25 +000042do_polly="yes"
Bill Wendlingb91c7122010-09-08 18:32:31 +000043BuildDir="`pwd`"
Hans Wennborgf9893932015-07-15 21:06:16 +000044ExtraConfigureFlags=""
Daniel Sandersfe6ad962015-07-17 10:40:40 +000045ExportBranch=""
Bill Wendlingb91c7122010-09-08 18:32:31 +000046
Bill Wendlingb91c7122010-09-08 18:32:31 +000047function usage() {
Hans Wennborg33d68a52015-06-22 21:13:30 +000048 echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]"
Bill Wendlingb91c7122010-09-08 18:32:31 +000049 echo ""
Hans Wennborg33d68a52015-06-22 21:13:30 +000050 echo " -release X.Y.Z The release version to test."
Daniel Sanders86bf8812014-12-04 17:15:35 +000051 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."
Daniel Sanders86bf8812014-12-04 17:15:35 +000057 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."
Hans Wennborgf9893932015-07-15 21:06:16 +000061 echo " -configure-flags FLAGS Extra flags to pass to the configure step."
Daniel Sandersfe6ad962015-07-17 10:40:40 +000062 echo " -svn-path DIR Use the specified DIR instead of a release."
63 echo " For example -svn-path trunk or -svn-path branches/release_37"
Renato Golinc6f36fe2015-07-22 18:21:39 +000064 echo " -no-rt Disable check-out & build Compiler-RT"
65 echo " -no-libs Disable check-out & build libcxx/libcxxabi/libunwind"
Dimitry Andric24f3a272018-01-18 18:39:13 +000066 echo " -no-libcxxabi Disable check-out & build libcxxabi"
Daniel Sanders4b26be62015-07-30 10:14:57 +000067 echo " -no-libunwind Disable check-out & build libunwind"
Renato Golinc6f36fe2015-07-22 18:21:39 +000068 echo " -no-test-suite Disable check-out & build test-suite"
Alexey Bataev5ebd7ba2015-12-10 05:45:58 +000069 echo " -no-openmp Disable check-out & build libomp"
Dimitry Andric68a49ae2017-02-04 22:24:55 +000070 echo " -no-lld Disable check-out & build lld"
Daniel Sanders0562fb32016-02-29 11:04:39 +000071 echo " -lldb Enable check-out & build lldb"
72 echo " -no-lldb Disable check-out & build lldb (default)"
Pengxuan Zhenga4bbfa92017-06-20 01:04:25 +000073 echo " -no-polly Disable check-out & build Polly"
Bill Wendlingb91c7122010-09-08 18:32:31 +000074}
75
76while [ $# -gt 0 ]; do
77 case $1 in
78 -release | --release )
79 shift
80 Release="$1"
Tom Stellard68923612014-07-21 20:20:08 +000081 Release_no_dot="`echo $1 | sed -e 's,\.,,g'`"
Bill Wendlingb91c7122010-09-08 18:32:31 +000082 ;;
83 -rc | --rc | -RC | --RC )
84 shift
Bill Wendling64acc572011-11-28 11:45:10 +000085 RC="rc$1"
86 ;;
87 -final | --final )
88 RC=final
Bill Wendlingb91c7122010-09-08 18:32:31 +000089 ;;
Daniel Sandersfe6ad962015-07-17 10:40:40 +000090 -svn-path | --svn-path )
91 shift
92 Release="test"
93 Release_no_dot="test"
94 ExportBranch="$1"
95 RC="`echo $ExportBranch | sed -e 's,/,_,g'`"
96 echo "WARNING: Using the branch $ExportBranch instead of a release tag"
97 echo " This is intended to aid new packagers in trialing "
98 echo " builds without requiring a tag to be created first"
99 ;;
Bill Wendling264b48b2013-11-20 04:55:20 +0000100 -triple | --triple )
101 shift
102 Triple="$1"
103 ;;
Hans Wennborgf9893932015-07-15 21:06:16 +0000104 -configure-flags | --configure-flags )
Daniel Sanders86bf8812014-12-04 17:15:35 +0000105 shift
Hans Wennborgf9893932015-07-15 21:06:16 +0000106 ExtraConfigureFlags="$1"
Daniel Sanders86bf8812014-12-04 17:15:35 +0000107 ;;
Bill Wendlingb91c7122010-09-08 18:32:31 +0000108 -j* )
109 NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
110 if [ -z "$NumJobs" ]; then
111 shift
112 NumJobs="$1"
113 fi
114 ;;
115 -build-dir | --build-dir | -builddir | --builddir )
116 shift
117 BuildDir="$1"
118 ;;
119 -no-checkout | --no-checkout )
120 do_checkout="no"
121 ;;
Bill Wendling1416dc22011-10-16 22:44:08 +0000122 -test-debug | --test-debug )
123 do_debug="yes"
Bill Wendlingb91c7122010-09-08 18:32:31 +0000124 ;;
Bill Wendlinga854f5d2011-10-17 04:46:54 +0000125 -test-asserts | --test-asserts )
126 do_asserts="yes"
127 ;;
Bill Wendling1adc2152012-04-02 23:27:43 +0000128 -no-compare-files | --no-compare-files )
129 do_compare="no"
130 ;;
Bill Wendling1fcb3902013-11-24 05:29:35 +0000131 -use-gzip | --use-gzip )
132 use_gzip="yes"
133 ;;
Renato Golinc6f36fe2015-07-22 18:21:39 +0000134 -no-rt )
135 do_rt="no"
136 ;;
137 -no-libs )
138 do_libs="no"
139 ;;
Dimitry Andric24f3a272018-01-18 18:39:13 +0000140 -no-libcxxabi )
141 do_libcxxabi="no"
142 ;;
Daniel Sanders4b26be62015-07-30 10:14:57 +0000143 -no-libunwind )
144 do_libunwind="no"
145 ;;
Renato Golinc6f36fe2015-07-22 18:21:39 +0000146 -no-test-suite )
147 do_test_suite="no"
148 ;;
Alexey Bataev5ebd7ba2015-12-10 05:45:58 +0000149 -no-openmp )
150 do_openmp="no"
Hans Wennborgc3a9cb52015-07-29 16:29:06 +0000151 ;;
Dimitry Andric68a49ae2017-02-04 22:24:55 +0000152 -no-lld )
153 do_lld="no"
154 ;;
Daniel Sanders0562fb32016-02-29 11:04:39 +0000155 -lldb )
156 do_lldb="yes"
157 ;;
158 -no-lldb )
159 do_lldb="no"
160 ;;
Pengxuan Zheng162faf42017-01-18 01:03:29 +0000161 -no-polly )
162 do_polly="no"
163 ;;
Bill Wendlingb91c7122010-09-08 18:32:31 +0000164 -help | --help | -h | --h | -\? )
165 usage
166 exit 0
167 ;;
168 * )
169 echo "unknown option: $1"
170 usage
171 exit 1
172 ;;
173 esac
174 shift
175done
176
177# Check required arguments.
178if [ -z "$Release" ]; then
Bill Wendling1416dc22011-10-16 22:44:08 +0000179 echo "error: no release number specified"
Bill Wendlingb91c7122010-09-08 18:32:31 +0000180 exit 1
181fi
182if [ -z "$RC" ]; then
Bill Wendling1416dc22011-10-16 22:44:08 +0000183 echo "error: no release candidate number specified"
Bill Wendlingb91c7122010-09-08 18:32:31 +0000184 exit 1
185fi
Daniel Sandersfe6ad962015-07-17 10:40:40 +0000186if [ -z "$ExportBranch" ]; then
187 ExportBranch="tags/RELEASE_$Release_no_dot/$RC"
188fi
Bill Wendling264b48b2013-11-20 04:55:20 +0000189if [ -z "$Triple" ]; then
190 echo "error: no target triple specified"
191 exit 1
192fi
Bill Wendlingb91c7122010-09-08 18:32:31 +0000193
Duncan Sandsd357d742010-09-08 19:50:25 +0000194# Figure out how many make processes to run.
195if [ -z "$NumJobs" ]; then
196 NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
197fi
198if [ -z "$NumJobs" ]; then
199 NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
200fi
201if [ -z "$NumJobs" ]; then
202 NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
203fi
Bill Wendlingb91c7122010-09-08 18:32:31 +0000204if [ -z "$NumJobs" ]; then
205 NumJobs=3
206fi
207
Renato Golinc6f36fe2015-07-22 18:21:39 +0000208# Projects list
209projects="llvm cfe clang-tools-extra"
210if [ $do_rt = "yes" ]; then
211 projects="$projects compiler-rt"
212fi
213if [ $do_libs = "yes" ]; then
Dimitry Andric24f3a272018-01-18 18:39:13 +0000214 projects="$projects libcxx"
215 if [ $do_libcxxabi = "yes" ]; then
216 projects="$projects libcxxabi"
217 fi
Daniel Sanders4b26be62015-07-30 10:14:57 +0000218 if [ $do_libunwind = "yes" ]; then
219 projects="$projects libunwind"
220 fi
Renato Golinc6f36fe2015-07-22 18:21:39 +0000221fi
Daniel Sanders50895702016-01-28 21:09:50 +0000222case $do_test_suite in
223 yes|export-only)
224 projects="$projects test-suite"
225 ;;
226esac
Hans Wennborgc3a9cb52015-07-29 16:29:06 +0000227if [ $do_openmp = "yes" ]; then
228 projects="$projects openmp"
229fi
Dimitry Andric68a49ae2017-02-04 22:24:55 +0000230if [ $do_lld = "yes" ]; then
231 projects="$projects lld"
232fi
Daniel Sanders0562fb32016-02-29 11:04:39 +0000233if [ $do_lldb = "yes" ]; then
234 projects="$projects lldb"
235fi
Pengxuan Zheng162faf42017-01-18 01:03:29 +0000236if [ $do_polly = "yes" ]; then
237 projects="$projects polly"
238fi
Renato Golinc6f36fe2015-07-22 18:21:39 +0000239
Bill Wendling1416dc22011-10-16 22:44:08 +0000240# Go to the build directory (may be different from CWD)
Bill Wendling64acc572011-11-28 11:45:10 +0000241BuildDir=$BuildDir/$RC
Bill Wendling1416dc22011-10-16 22:44:08 +0000242mkdir -p $BuildDir
243cd $BuildDir
Bill Wendlingb91c7122010-09-08 18:32:31 +0000244
Duncan Sandsf0bf9df2011-03-27 13:52:32 +0000245# Location of log files.
Bill Wendling1416dc22011-10-16 22:44:08 +0000246LogDir=$BuildDir/logs
Duncan Sandsf0bf9df2011-03-27 13:52:32 +0000247mkdir -p $LogDir
248
Bill Wendling264b48b2013-11-20 04:55:20 +0000249# Final package name.
250Package=clang+llvm-$Release
251if [ $RC != "final" ]; then
252 Package=$Package-$RC
253fi
254Package=$Package-$Triple
255
Hans Wennborgb8f373e2015-07-24 16:16:09 +0000256# Errors to be highlighted at the end are written to this file.
257echo -n > $LogDir/deferred_errors.log
258
259function deferred_error() {
260 Phase="$1"
261 Flavor="$2"
262 Msg="$3"
263 echo "[${Flavor} Phase${Phase}] ${Msg}" | tee -a $LogDir/deferred_errors.log
264}
265
Arnaud A. de Grandmaisonea8e1442013-11-18 10:34:59 +0000266# Make sure that a required program is available
267function check_program_exists() {
268 local program="$1"
269 if ! type -P $program > /dev/null 2>&1 ; then
270 echo "program '$1' not found !"
271 exit 1
272 fi
273}
274
Dimitry Andricad24fed2016-01-21 22:07:17 +0000275if [ "$System" != "Darwin" ]; then
Bill Wendling264b48b2013-11-20 04:55:20 +0000276 check_program_exists 'chrpath'
277 check_program_exists 'file'
278 check_program_exists 'objdump'
279fi
Bill Wendlingb91c7122010-09-08 18:32:31 +0000280
281# Make sure that the URLs are valid.
282function check_valid_urls() {
Bill Wendling1416dc22011-10-16 22:44:08 +0000283 for proj in $projects ; do
284 echo "# Validating $proj SVN URL"
285
Daniel Sandersfe6ad962015-07-17 10:40:40 +0000286 if ! svn ls $Base_url/$proj/$ExportBranch > /dev/null 2>&1 ; then
287 echo "$proj does not have a $ExportBranch branch/tag!"
Bill Wendling1416dc22011-10-16 22:44:08 +0000288 exit 1
289 fi
290 done
Bill Wendlingb91c7122010-09-08 18:32:31 +0000291}
292
Sylvestre Ledruc8e41c52012-07-23 08:51:15 +0000293# Export sources to the build directory.
Bill Wendlingb91c7122010-09-08 18:32:31 +0000294function export_sources() {
295 check_valid_urls
296
Bill Wendling1416dc22011-10-16 22:44:08 +0000297 for proj in $projects ; do
Dimitry Andric0ae89f92016-01-21 21:57:49 +0000298 case $proj in
299 llvm)
300 projsrc=$proj.src
301 ;;
302 cfe)
303 projsrc=llvm.src/tools/clang
304 ;;
Dimitry Andric68a49ae2017-02-04 22:24:55 +0000305 lld|lldb|polly)
Daniel Sanders0562fb32016-02-29 11:04:39 +0000306 projsrc=llvm.src/tools/$proj
307 ;;
Dimitry Andric0ae89f92016-01-21 21:57:49 +0000308 clang-tools-extra)
309 projsrc=llvm.src/tools/clang/tools/extra
310 ;;
Daniel Sanders50895702016-01-28 21:09:50 +0000311 compiler-rt|libcxx|libcxxabi|libunwind|openmp)
Dimitry Andric0ae89f92016-01-21 21:57:49 +0000312 projsrc=llvm.src/projects/$proj
313 ;;
Daniel Sanders50895702016-01-28 21:09:50 +0000314 test-suite)
Tom Stellarde99f33a2017-06-08 21:31:59 +0000315 projsrc=$proj.src
Daniel Sanders50895702016-01-28 21:09:50 +0000316 ;;
Dimitry Andric0ae89f92016-01-21 21:57:49 +0000317 *)
318 echo "error: unknown project $proj"
319 exit 1
320 ;;
321 esac
322
323 if [ -d $projsrc ]; then
324 echo "# Reusing $proj $Release-$RC sources in $projsrc"
Renato Golinc6f36fe2015-07-22 18:21:39 +0000325 continue
326 fi
Dimitry Andric0ae89f92016-01-21 21:57:49 +0000327 echo "# Exporting $proj $Release-$RC sources to $projsrc"
328 if ! svn export -q $Base_url/$proj/$ExportBranch $projsrc ; then
Bill Wendling1416dc22011-10-16 22:44:08 +0000329 echo "error: failed to export $proj project"
330 exit 1
331 fi
332 done
333
Bill Wendling1416dc22011-10-16 22:44:08 +0000334 cd $BuildDir
Bill Wendlingb91c7122010-09-08 18:32:31 +0000335}
336
337function configure_llvmCore() {
338 Phase="$1"
339 Flavor="$2"
340 ObjDir="$3"
Bill Wendlingb91c7122010-09-08 18:32:31 +0000341
342 case $Flavor in
Hans Wennborgf9893932015-07-15 21:06:16 +0000343 Release )
344 BuildType="Release"
345 Assertions="OFF"
Bill Wendlingb91c7122010-09-08 18:32:31 +0000346 ;;
Duncan Sands8a6e53e2010-09-13 13:45:33 +0000347 Release+Asserts )
Hans Wennborgf9893932015-07-15 21:06:16 +0000348 BuildType="Release"
349 Assertions="ON"
Duncan Sands8a6e53e2010-09-13 13:45:33 +0000350 ;;
Bill Wendlingb91c7122010-09-08 18:32:31 +0000351 Debug )
Hans Wennborgf9893932015-07-15 21:06:16 +0000352 BuildType="Debug"
353 Assertions="ON"
Bill Wendlingb91c7122010-09-08 18:32:31 +0000354 ;;
355 * )
Bill Wendling1416dc22011-10-16 22:44:08 +0000356 echo "# Invalid flavor '$Flavor'"
Bill Wendlingb91c7122010-09-08 18:32:31 +0000357 echo ""
358 return
359 ;;
360 esac
361
Bill Wendling1416dc22011-10-16 22:44:08 +0000362 echo "# Using C compiler: $c_compiler"
363 echo "# Using C++ compiler: $cxx_compiler"
364
Bill Wendlingb91c7122010-09-08 18:32:31 +0000365 cd $ObjDir
Bill Wendling64acc572011-11-28 11:45:10 +0000366 echo "# Configuring llvm $Release-$RC $Flavor"
Hans Wennborgf9893932015-07-15 21:06:16 +0000367
Hans Wennborga8ca6b62016-08-09 16:46:02 +0000368 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
369 cmake -G "Unix Makefiles" \
370 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
Hans Wennborga8ca6b62016-08-09 16:46:02 +0000371 $ExtraConfigureFlags $BuildDir/llvm.src \
372 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
373 env CC="$c_compiler" CXX="$cxx_compiler" \
374 cmake -G "Unix Makefiles" \
375 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
Hans Wennborga8ca6b62016-08-09 16:46:02 +0000376 $ExtraConfigureFlags $BuildDir/llvm.src \
377 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
Hans Wennborgf9893932015-07-15 21:06:16 +0000378
Bill Wendling1416dc22011-10-16 22:44:08 +0000379 cd $BuildDir
Bill Wendlingb91c7122010-09-08 18:32:31 +0000380}
381
382function build_llvmCore() {
383 Phase="$1"
384 Flavor="$2"
385 ObjDir="$3"
Dan Liewfb17afb2015-07-14 19:46:19 +0000386 DestDir="$4"
Bill Wendlingb91c7122010-09-08 18:32:31 +0000387
388 cd $ObjDir
Bill Wendling64acc572011-11-28 11:45:10 +0000389 echo "# Compiling llvm $Release-$RC $Flavor"
Hans Wennborgf9893932015-07-15 21:06:16 +0000390 echo "# ${MAKE} -j $NumJobs VERBOSE=1"
391 ${MAKE} -j $NumJobs VERBOSE=1 \
Bill Wendling1416dc22011-10-16 22:44:08 +0000392 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
Bill Wendlingb91c7122010-09-08 18:32:31 +0000393
Bill Wendling64acc572011-11-28 11:45:10 +0000394 echo "# Installing llvm $Release-$RC $Flavor"
Bill Wendling783993e2011-10-19 08:42:07 +0000395 echo "# ${MAKE} install"
396 ${MAKE} install \
Dan Liewfb17afb2015-07-14 19:46:19 +0000397 DESTDIR="${DestDir}" \
Bill Wendling1416dc22011-10-16 22:44:08 +0000398 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
399 cd $BuildDir
Bill Wendlingb91c7122010-09-08 18:32:31 +0000400}
401
402function test_llvmCore() {
403 Phase="$1"
404 Flavor="$2"
405 ObjDir="$3"
406
407 cd $ObjDir
Hans Wennborgb8f373e2015-07-24 16:16:09 +0000408 if ! ( ${MAKE} -j $NumJobs -k check-all \
409 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
410 deferred_error $Phase $Flavor "check-all failed"
411 fi
Hans Wennborgf9893932015-07-15 21:06:16 +0000412
Tom Stellarde99f33a2017-06-08 21:31:59 +0000413 if [ $do_test_suite = 'yes' ]; then
Tom Stellarde99f33a2017-06-08 21:31:59 +0000414 cd $TestSuiteBuildDir
Tom Stellardaa27e872017-06-15 23:05:21 +0000415 env CC="$c_compiler" CXX="$cxx_compiler" \
416 cmake $TestSuiteSrcDir -DTEST_SUITE_LIT=$Lit
Tom Stellarde99f33a2017-06-08 21:31:59 +0000417 if ! ( ${MAKE} -j $NumJobs -k check \
418 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
419 deferred_error $Phase $Flavor "test suite failed"
420 fi
421 fi
Bill Wendling1416dc22011-10-16 22:44:08 +0000422 cd $BuildDir
Bill Wendlingb91c7122010-09-08 18:32:31 +0000423}
424
Arnaud A. de Grandmaisonea8e1442013-11-18 10:34:59 +0000425# Clean RPATH. Libtool adds the build directory to the search path, which is
426# not necessary --- and even harmful --- for the binary packages we release.
427function clean_RPATH() {
Dimitry Andricad24fed2016-01-21 22:07:17 +0000428 if [ "$System" = "Darwin" ]; then
Bill Wendling264b48b2013-11-20 04:55:20 +0000429 return
430 fi
Arnaud A. de Grandmaisonea8e1442013-11-18 10:34:59 +0000431 local InstallPath="$1"
432 for Candidate in `find $InstallPath/{bin,lib} -type f`; do
433 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
Dimitry Andric85e97722015-07-20 22:24:40 +0000434 if rpath=`objdump -x $Candidate | grep 'RPATH'` ; then
435 rpath=`echo $rpath | sed -e's/^ *RPATH *//'`
436 if [ -n "$rpath" ]; then
437 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
438 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
439 fi
Arnaud A. de Grandmaisonea8e1442013-11-18 10:34:59 +0000440 fi
441 fi
442 done
443}
444
Bill Wendling264b48b2013-11-20 04:55:20 +0000445# Create a package of the release binaries.
446function package_release() {
447 cwd=`pwd`
448 cd $BuildDir/Phase3/Release
Hans Wennborgca221d02015-07-20 20:36:21 +0000449 mv llvmCore-$Release-$RC.install/usr/local $Package
Bill Wendling1fcb3902013-11-24 05:29:35 +0000450 if [ "$use_gzip" = "yes" ]; then
451 tar cfz $BuildDir/$Package.tar.gz $Package
452 else
453 tar cfJ $BuildDir/$Package.tar.xz $Package
454 fi
Hans Wennborgca221d02015-07-20 20:36:21 +0000455 mv $Package llvmCore-$Release-$RC.install/usr/local
Bill Wendling264b48b2013-11-20 04:55:20 +0000456 cd $cwd
457}
458
Dan Liew9fb48972015-07-07 15:50:33 +0000459# Exit if any command fails
460# Note: pipefail is necessary for running build commands through
461# a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
462set -e
463set -o pipefail
Bill Wendling630243a2011-10-18 17:27:12 +0000464
Bill Wendlingb91c7122010-09-08 18:32:31 +0000465if [ "$do_checkout" = "yes" ]; then
466 export_sources
467fi
468
Tom Stellard1dbfdcc2017-08-15 18:11:56 +0000469# Setup the test-suite. Do this early so we can catch failures before
470# we do the full 3 stage build.
471if [ $do_test_suite = "yes" ]; then
472 SandboxDir="$BuildDir/sandbox"
473 Lit=$SandboxDir/bin/lit
474 TestSuiteBuildDir="$BuildDir/test-suite-build"
475 TestSuiteSrcDir="$BuildDir/test-suite.src"
476
477 virtualenv $SandboxDir
478 $SandboxDir/bin/python $BuildDir/llvm.src/utils/lit/setup.py install
479 mkdir -p $TestSuiteBuildDir
480fi
481
Duncan Sandsf0bf9df2011-03-27 13:52:32 +0000482(
Bill Wendlinga854f5d2011-10-17 04:46:54 +0000483Flavors="Release"
Bill Wendling1416dc22011-10-16 22:44:08 +0000484if [ "$do_debug" = "yes" ]; then
485 Flavors="Debug $Flavors"
486fi
Bill Wendlinga854f5d2011-10-17 04:46:54 +0000487if [ "$do_asserts" = "yes" ]; then
488 Flavors="$Flavors Release+Asserts"
489fi
Bill Wendlingb91c7122010-09-08 18:32:31 +0000490
491for Flavor in $Flavors ; do
492 echo ""
493 echo ""
494 echo "********************************************************************************"
Bill Wendling64acc572011-11-28 11:45:10 +0000495 echo " Release: $Release-$RC"
Bill Wendlingb91c7122010-09-08 18:32:31 +0000496 echo " Build: $Flavor"
497 echo " System Info: "
498 echo " `uname -a`"
499 echo "********************************************************************************"
500 echo ""
501
Duncan Sandsfbc0dec2011-10-20 20:10:58 +0000502 c_compiler="$CC"
503 cxx_compiler="$CXX"
Bill Wendling64acc572011-11-28 11:45:10 +0000504 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
Dan Liewfb17afb2015-07-14 19:46:19 +0000505 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
Bill Wendlingb91c7122010-09-08 18:32:31 +0000506
Bill Wendling64acc572011-11-28 11:45:10 +0000507 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
Dan Liewfb17afb2015-07-14 19:46:19 +0000508 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
Bill Wendlingb91c7122010-09-08 18:32:31 +0000509
Bill Wendling64acc572011-11-28 11:45:10 +0000510 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
Dan Liewfb17afb2015-07-14 19:46:19 +0000511 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
Bill Wendlinga854f5d2011-10-17 04:46:54 +0000512
Bill Wendlingb91c7122010-09-08 18:32:31 +0000513 rm -rf $llvmCore_phase1_objdir
Dan Liewfb17afb2015-07-14 19:46:19 +0000514 rm -rf $llvmCore_phase1_destdir
Duncan Sandsc1aef082011-10-20 11:13:04 +0000515
Bill Wendlingb91c7122010-09-08 18:32:31 +0000516 rm -rf $llvmCore_phase2_objdir
Dan Liewfb17afb2015-07-14 19:46:19 +0000517 rm -rf $llvmCore_phase2_destdir
Duncan Sandsc1aef082011-10-20 11:13:04 +0000518
Bill Wendlinga854f5d2011-10-17 04:46:54 +0000519 rm -rf $llvmCore_phase3_objdir
Dan Liewfb17afb2015-07-14 19:46:19 +0000520 rm -rf $llvmCore_phase3_destdir
Bill Wendlingb91c7122010-09-08 18:32:31 +0000521
522 mkdir -p $llvmCore_phase1_objdir
Dan Liewfb17afb2015-07-14 19:46:19 +0000523 mkdir -p $llvmCore_phase1_destdir
Duncan Sandsc1aef082011-10-20 11:13:04 +0000524
Bill Wendlingb91c7122010-09-08 18:32:31 +0000525 mkdir -p $llvmCore_phase2_objdir
Dan Liewfb17afb2015-07-14 19:46:19 +0000526 mkdir -p $llvmCore_phase2_destdir
Duncan Sandsc1aef082011-10-20 11:13:04 +0000527
Bill Wendlinga854f5d2011-10-17 04:46:54 +0000528 mkdir -p $llvmCore_phase3_objdir
Dan Liewfb17afb2015-07-14 19:46:19 +0000529 mkdir -p $llvmCore_phase3_destdir
Bill Wendlingb91c7122010-09-08 18:32:31 +0000530
Bill Wendlingb91c7122010-09-08 18:32:31 +0000531 ############################################################################
Duncan Sandsc1aef082011-10-20 11:13:04 +0000532 # Phase 1: Build llvmCore and clang
Bill Wendlingb91c7122010-09-08 18:32:31 +0000533 echo "# Phase 1: Building llvmCore"
Hans Wennborge1bb5352015-07-14 20:15:15 +0000534 configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir
Bill Wendlingb91c7122010-09-08 18:32:31 +0000535 build_llvmCore 1 $Flavor \
Dan Liewfb17afb2015-07-14 19:46:19 +0000536 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
537 clean_RPATH $llvmCore_phase1_destdir/usr/local
Bill Wendlingb91c7122010-09-08 18:32:31 +0000538
Dan Liewfb17afb2015-07-14 19:46:19 +0000539 ########################################################################
540 # Phase 2: Build llvmCore with newly built clang from phase 1.
541 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
542 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
543 echo "# Phase 2: Building llvmCore"
Hans Wennborge1bb5352015-07-14 20:15:15 +0000544 configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir
Dan Liewfb17afb2015-07-14 19:46:19 +0000545 build_llvmCore 2 $Flavor \
546 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
547 clean_RPATH $llvmCore_phase2_destdir/usr/local
Bill Wendlingb91c7122010-09-08 18:32:31 +0000548
Dan Liewfb17afb2015-07-14 19:46:19 +0000549 ########################################################################
550 # Phase 3: Build llvmCore with newly built clang from phase 2.
551 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
552 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
553 echo "# Phase 3: Building llvmCore"
Hans Wennborge1bb5352015-07-14 20:15:15 +0000554 configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir
Dan Liewfb17afb2015-07-14 19:46:19 +0000555 build_llvmCore 3 $Flavor \
556 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
557 clean_RPATH $llvmCore_phase3_destdir/usr/local
Bill Wendlinga854f5d2011-10-17 04:46:54 +0000558
Dan Liewfb17afb2015-07-14 19:46:19 +0000559 ########################################################################
560 # Testing: Test phase 3
Tom Stellardaa27e872017-06-15 23:05:21 +0000561 c_compiler=$llvmCore_phase3_destdir/usr/local/bin/clang
562 cxx_compiler=$llvmCore_phase3_destdir/usr/local/bin/clang++
Dan Liewfb17afb2015-07-14 19:46:19 +0000563 echo "# Testing - built with clang"
564 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
Bill Wendlinga854f5d2011-10-17 04:46:54 +0000565
Dan Liewfb17afb2015-07-14 19:46:19 +0000566 ########################################################################
567 # Compare .o files between Phase2 and Phase3 and report which ones
568 # differ.
569 if [ "$do_compare" = "yes" ]; then
570 echo
571 echo "# Comparing Phase 2 and Phase 3 files"
Hans Wennborgf9893932015-07-15 21:06:16 +0000572 for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do
573 p3=`echo $p2 | sed -e 's,Phase2,Phase3,'`
574 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
Hans Wennborgdb210912015-07-15 22:18:25 +0000575 # case there are build paths in the debug info. On some systems,
576 # sed adds a newline to the output, so pass $p3 through sed too.
Hans Wennborg89b5a672016-01-27 00:19:05 +0000577 if ! cmp -s \
Tom Stellarddf6678d2017-07-24 19:28:30 +0000578 <(env LC_CTYPE=C sed -e 's,Phase2,Phase3,g' -e 's,Phase1,Phase2,g' $p2) \
Hans Wennborg89b5a672016-01-27 00:19:05 +0000579 <(env LC_CTYPE=C sed -e '' $p3) 16 16; then
Hans Wennborgf9893932015-07-15 21:06:16 +0000580 echo "file `basename $p2` differs between phase 2 and phase 3"
Dan Liewfb17afb2015-07-14 19:46:19 +0000581 fi
582 done
Duncan Sandsc1aef082011-10-20 11:13:04 +0000583 fi
Bill Wendlingb91c7122010-09-08 18:32:31 +0000584done
Hans Wennborgc3a9cb52015-07-29 16:29:06 +0000585
Bill Wendling64acc572011-11-28 11:45:10 +0000586) 2>&1 | tee $LogDir/testing.$Release-$RC.log
Bill Wendlingb91c7122010-09-08 18:32:31 +0000587
Renato Goline27523b2017-05-04 16:21:30 +0000588if [ "$use_gzip" = "yes" ]; then
589 echo "# Packaging the release as $Package.tar.gz"
590else
591 echo "# Packaging the release as $Package.tar.xz"
592fi
Bill Wendling264b48b2013-11-20 04:55:20 +0000593package_release
594
Bill Wendling630243a2011-10-18 17:27:12 +0000595set +e
596
Bill Wendlingb91c7122010-09-08 18:32:31 +0000597# Woo hoo!
598echo "### Testing Finished ###"
Duncan Sandsf0bf9df2011-03-27 13:52:32 +0000599echo "### Logs: $LogDir"
Hans Wennborgb8f373e2015-07-24 16:16:09 +0000600
601echo "### Errors:"
602if [ -s "$LogDir/deferred_errors.log" ]; then
603 cat "$LogDir/deferred_errors.log"
604 exit 1
605else
606 echo "None."
607fi
608
Bill Wendlingb91c7122010-09-08 18:32:31 +0000609exit 0