blob: b36d17da0d0c9791e53550f13e19ec2d7788df9a [file] [log] [blame]
Bill Wendlingf96a5bc2011-10-19 09:25:49 +00001#!/usr/bin/env bash
Bill Wendlingcedf3a22010-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 Andricca051602016-01-21 22:07:17 +000015System=`uname -s`
16if [ "$System" = "FreeBSD" ]; then
Bill Wendlingcfe82322011-10-19 08:42:07 +000017 MAKE=gmake
18else
19 MAKE=make
20fi
21
Bill Wendling9aa39432011-10-16 22:44:08 +000022# Base SVN URL for the sources.
23Base_url="http://llvm.org/svn/llvm-project"
24
Bill Wendlingcedf3a22010-09-08 18:32:31 +000025Release=""
26Release_no_dot=""
27RC=""
Bill Wendlingd6073842013-11-20 04:55:20 +000028Triple=""
Bill Wendling1585fea2013-11-24 05:29:35 +000029use_gzip="no"
Bill Wendlingcedf3a22010-09-08 18:32:31 +000030do_checkout="yes"
Bill Wendling9aa39432011-10-16 22:44:08 +000031do_debug="no"
Bill Wendling7b7d0772011-10-17 04:46:54 +000032do_asserts="no"
Bill Wendlingd70cde12012-04-02 23:27:43 +000033do_compare="yes"
Renato Golin397b0da2015-07-22 18:21:39 +000034do_rt="yes"
35do_libs="yes"
Daniel Sanders3cc4a252015-07-30 10:14:57 +000036do_libunwind="yes"
Renato Golin397b0da2015-07-22 18:21:39 +000037do_test_suite="yes"
Alexey Bataev860435c2015-12-10 05:45:58 +000038do_openmp="yes"
Dimitry Andric434fa952017-02-04 22:24:55 +000039do_lld="yes"
Daniel Sanders27ba83f2016-02-29 11:04:39 +000040do_lldb="no"
Pengxuan Zheng4a99e372017-06-20 01:04:25 +000041do_polly="yes"
Bill Wendlingcedf3a22010-09-08 18:32:31 +000042BuildDir="`pwd`"
Hans Wennborg0caeee02015-07-15 21:06:16 +000043ExtraConfigureFlags=""
Daniel Sandersc2672e52015-07-17 10:40:40 +000044ExportBranch=""
Bill Wendlingcedf3a22010-09-08 18:32:31 +000045
Bill Wendlingcedf3a22010-09-08 18:32:31 +000046function usage() {
Hans Wennborg6072d2b2015-06-22 21:13:30 +000047 echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]"
Bill Wendlingcedf3a22010-09-08 18:32:31 +000048 echo ""
Hans Wennborg6072d2b2015-06-22 21:13:30 +000049 echo " -release X.Y.Z The release version to test."
Daniel Sandersf226aaf2014-12-04 17:15:35 +000050 echo " -rc NUM The pre-release candidate number."
51 echo " -final The final release candidate."
52 echo " -triple TRIPLE The target triple for this machine."
53 echo " -j NUM Number of compile jobs to run. [default: 3]"
54 echo " -build-dir DIR Directory to perform testing in. [default: pwd]"
55 echo " -no-checkout Don't checkout the sources from SVN."
Daniel Sandersf226aaf2014-12-04 17:15:35 +000056 echo " -test-debug Test the debug build. [default: no]"
57 echo " -test-asserts Test with asserts on. [default: no]"
58 echo " -no-compare-files Don't test that phase 2 and 3 files are identical."
59 echo " -use-gzip Use gzip instead of xz."
Hans Wennborg0caeee02015-07-15 21:06:16 +000060 echo " -configure-flags FLAGS Extra flags to pass to the configure step."
Daniel Sandersc2672e52015-07-17 10:40:40 +000061 echo " -svn-path DIR Use the specified DIR instead of a release."
62 echo " For example -svn-path trunk or -svn-path branches/release_37"
Renato Golin397b0da2015-07-22 18:21:39 +000063 echo " -no-rt Disable check-out & build Compiler-RT"
64 echo " -no-libs Disable check-out & build libcxx/libcxxabi/libunwind"
Dimitry Andricd05541f2018-01-18 18:39:13 +000065 echo " -no-libcxxabi Disable check-out & build libcxxabi"
Daniel Sanders3cc4a252015-07-30 10:14:57 +000066 echo " -no-libunwind Disable check-out & build libunwind"
Renato Golin397b0da2015-07-22 18:21:39 +000067 echo " -no-test-suite Disable check-out & build test-suite"
Alexey Bataev860435c2015-12-10 05:45:58 +000068 echo " -no-openmp Disable check-out & build libomp"
Dimitry Andric434fa952017-02-04 22:24:55 +000069 echo " -no-lld Disable check-out & build lld"
Daniel Sanders27ba83f2016-02-29 11:04:39 +000070 echo " -lldb Enable check-out & build lldb"
71 echo " -no-lldb Disable check-out & build lldb (default)"
Pengxuan Zheng4a99e372017-06-20 01:04:25 +000072 echo " -no-polly Disable check-out & build Polly"
Bill Wendlingcedf3a22010-09-08 18:32:31 +000073}
74
75while [ $# -gt 0 ]; do
76 case $1 in
77 -release | --release )
78 shift
79 Release="$1"
Tom Stellard9c4c3c52014-07-21 20:20:08 +000080 Release_no_dot="`echo $1 | sed -e 's,\.,,g'`"
Bill Wendlingcedf3a22010-09-08 18:32:31 +000081 ;;
82 -rc | --rc | -RC | --RC )
83 shift
Bill Wendling957cc212011-11-28 11:45:10 +000084 RC="rc$1"
85 ;;
86 -final | --final )
87 RC=final
Bill Wendlingcedf3a22010-09-08 18:32:31 +000088 ;;
Daniel Sandersc2672e52015-07-17 10:40:40 +000089 -svn-path | --svn-path )
90 shift
91 Release="test"
92 Release_no_dot="test"
93 ExportBranch="$1"
94 RC="`echo $ExportBranch | sed -e 's,/,_,g'`"
95 echo "WARNING: Using the branch $ExportBranch instead of a release tag"
96 echo " This is intended to aid new packagers in trialing "
97 echo " builds without requiring a tag to be created first"
98 ;;
Bill Wendlingd6073842013-11-20 04:55:20 +000099 -triple | --triple )
100 shift
101 Triple="$1"
102 ;;
Hans Wennborg0caeee02015-07-15 21:06:16 +0000103 -configure-flags | --configure-flags )
Daniel Sandersf226aaf2014-12-04 17:15:35 +0000104 shift
Hans Wennborg0caeee02015-07-15 21:06:16 +0000105 ExtraConfigureFlags="$1"
Daniel Sandersf226aaf2014-12-04 17:15:35 +0000106 ;;
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000107 -j* )
108 NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
109 if [ -z "$NumJobs" ]; then
110 shift
111 NumJobs="$1"
112 fi
113 ;;
114 -build-dir | --build-dir | -builddir | --builddir )
115 shift
116 BuildDir="$1"
117 ;;
118 -no-checkout | --no-checkout )
119 do_checkout="no"
120 ;;
Bill Wendling9aa39432011-10-16 22:44:08 +0000121 -test-debug | --test-debug )
122 do_debug="yes"
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000123 ;;
Bill Wendling7b7d0772011-10-17 04:46:54 +0000124 -test-asserts | --test-asserts )
125 do_asserts="yes"
126 ;;
Bill Wendlingd70cde12012-04-02 23:27:43 +0000127 -no-compare-files | --no-compare-files )
128 do_compare="no"
129 ;;
Bill Wendling1585fea2013-11-24 05:29:35 +0000130 -use-gzip | --use-gzip )
131 use_gzip="yes"
132 ;;
Renato Golin397b0da2015-07-22 18:21:39 +0000133 -no-rt )
134 do_rt="no"
135 ;;
136 -no-libs )
137 do_libs="no"
138 ;;
Dimitry Andricd05541f2018-01-18 18:39:13 +0000139 -no-libcxxabi )
140 do_libcxxabi="no"
141 ;;
Daniel Sanders3cc4a252015-07-30 10:14:57 +0000142 -no-libunwind )
143 do_libunwind="no"
144 ;;
Renato Golin397b0da2015-07-22 18:21:39 +0000145 -no-test-suite )
146 do_test_suite="no"
147 ;;
Alexey Bataev860435c2015-12-10 05:45:58 +0000148 -no-openmp )
149 do_openmp="no"
Hans Wennborg0742a3e2015-07-29 16:29:06 +0000150 ;;
Dimitry Andric434fa952017-02-04 22:24:55 +0000151 -no-lld )
152 do_lld="no"
153 ;;
Daniel Sanders27ba83f2016-02-29 11:04:39 +0000154 -lldb )
155 do_lldb="yes"
156 ;;
157 -no-lldb )
158 do_lldb="no"
159 ;;
Pengxuan Zhengac6595c2017-01-18 01:03:29 +0000160 -no-polly )
161 do_polly="no"
162 ;;
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000163 -help | --help | -h | --h | -\? )
164 usage
165 exit 0
166 ;;
167 * )
168 echo "unknown option: $1"
169 usage
170 exit 1
171 ;;
172 esac
173 shift
174done
175
176# Check required arguments.
177if [ -z "$Release" ]; then
Bill Wendling9aa39432011-10-16 22:44:08 +0000178 echo "error: no release number specified"
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000179 exit 1
180fi
181if [ -z "$RC" ]; then
Bill Wendling9aa39432011-10-16 22:44:08 +0000182 echo "error: no release candidate number specified"
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000183 exit 1
184fi
Daniel Sandersc2672e52015-07-17 10:40:40 +0000185if [ -z "$ExportBranch" ]; then
186 ExportBranch="tags/RELEASE_$Release_no_dot/$RC"
187fi
Bill Wendlingd6073842013-11-20 04:55:20 +0000188if [ -z "$Triple" ]; then
189 echo "error: no target triple specified"
190 exit 1
191fi
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000192
Duncan Sands274090a2010-09-08 19:50:25 +0000193# Figure out how many make processes to run.
194if [ -z "$NumJobs" ]; then
195 NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
196fi
197if [ -z "$NumJobs" ]; then
198 NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
199fi
200if [ -z "$NumJobs" ]; then
201 NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
202fi
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000203if [ -z "$NumJobs" ]; then
204 NumJobs=3
205fi
206
Renato Golin397b0da2015-07-22 18:21:39 +0000207# Projects list
208projects="llvm cfe clang-tools-extra"
209if [ $do_rt = "yes" ]; then
210 projects="$projects compiler-rt"
211fi
212if [ $do_libs = "yes" ]; then
Dimitry Andricd05541f2018-01-18 18:39:13 +0000213 projects="$projects libcxx"
214 if [ $do_libcxxabi = "yes" ]; then
215 projects="$projects libcxxabi"
216 fi
Daniel Sanders3cc4a252015-07-30 10:14:57 +0000217 if [ $do_libunwind = "yes" ]; then
218 projects="$projects libunwind"
219 fi
Renato Golin397b0da2015-07-22 18:21:39 +0000220fi
Daniel Sanders20de54b2016-01-28 21:09:50 +0000221case $do_test_suite in
222 yes|export-only)
223 projects="$projects test-suite"
224 ;;
225esac
Hans Wennborg0742a3e2015-07-29 16:29:06 +0000226if [ $do_openmp = "yes" ]; then
227 projects="$projects openmp"
228fi
Dimitry Andric434fa952017-02-04 22:24:55 +0000229if [ $do_lld = "yes" ]; then
230 projects="$projects lld"
231fi
Daniel Sanders27ba83f2016-02-29 11:04:39 +0000232if [ $do_lldb = "yes" ]; then
233 projects="$projects lldb"
234fi
Pengxuan Zhengac6595c2017-01-18 01:03:29 +0000235if [ $do_polly = "yes" ]; then
236 projects="$projects polly"
237fi
Renato Golin397b0da2015-07-22 18:21:39 +0000238
Bill Wendling9aa39432011-10-16 22:44:08 +0000239# Go to the build directory (may be different from CWD)
Bill Wendling957cc212011-11-28 11:45:10 +0000240BuildDir=$BuildDir/$RC
Bill Wendling9aa39432011-10-16 22:44:08 +0000241mkdir -p $BuildDir
242cd $BuildDir
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000243
Duncan Sandsd5f631c2011-03-27 13:52:32 +0000244# Location of log files.
Bill Wendling9aa39432011-10-16 22:44:08 +0000245LogDir=$BuildDir/logs
Duncan Sandsd5f631c2011-03-27 13:52:32 +0000246mkdir -p $LogDir
247
Bill Wendlingd6073842013-11-20 04:55:20 +0000248# Final package name.
249Package=clang+llvm-$Release
250if [ $RC != "final" ]; then
251 Package=$Package-$RC
252fi
253Package=$Package-$Triple
254
Hans Wennborgfa8e3a52015-07-24 16:16:09 +0000255# Errors to be highlighted at the end are written to this file.
256echo -n > $LogDir/deferred_errors.log
257
258function deferred_error() {
259 Phase="$1"
260 Flavor="$2"
261 Msg="$3"
262 echo "[${Flavor} Phase${Phase}] ${Msg}" | tee -a $LogDir/deferred_errors.log
263}
264
Arnaud A. de Grandmaison69690e42013-11-18 10:34:59 +0000265# Make sure that a required program is available
266function check_program_exists() {
267 local program="$1"
268 if ! type -P $program > /dev/null 2>&1 ; then
269 echo "program '$1' not found !"
270 exit 1
271 fi
272}
273
Dimitry Andricca051602016-01-21 22:07:17 +0000274if [ "$System" != "Darwin" ]; then
Bill Wendlingd6073842013-11-20 04:55:20 +0000275 check_program_exists 'chrpath'
276 check_program_exists 'file'
277 check_program_exists 'objdump'
278fi
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000279
280# Make sure that the URLs are valid.
281function check_valid_urls() {
Bill Wendling9aa39432011-10-16 22:44:08 +0000282 for proj in $projects ; do
283 echo "# Validating $proj SVN URL"
284
Daniel Sandersc2672e52015-07-17 10:40:40 +0000285 if ! svn ls $Base_url/$proj/$ExportBranch > /dev/null 2>&1 ; then
286 echo "$proj does not have a $ExportBranch branch/tag!"
Bill Wendling9aa39432011-10-16 22:44:08 +0000287 exit 1
288 fi
289 done
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000290}
291
Sylvestre Ledru35521e22012-07-23 08:51:15 +0000292# Export sources to the build directory.
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000293function export_sources() {
294 check_valid_urls
295
Bill Wendling9aa39432011-10-16 22:44:08 +0000296 for proj in $projects ; do
Dimitry Andric4a5f8a12016-01-21 21:57:49 +0000297 case $proj in
298 llvm)
299 projsrc=$proj.src
300 ;;
301 cfe)
302 projsrc=llvm.src/tools/clang
303 ;;
Dimitry Andric434fa952017-02-04 22:24:55 +0000304 lld|lldb|polly)
Daniel Sanders27ba83f2016-02-29 11:04:39 +0000305 projsrc=llvm.src/tools/$proj
306 ;;
Dimitry Andric4a5f8a12016-01-21 21:57:49 +0000307 clang-tools-extra)
308 projsrc=llvm.src/tools/clang/tools/extra
309 ;;
Daniel Sanders20de54b2016-01-28 21:09:50 +0000310 compiler-rt|libcxx|libcxxabi|libunwind|openmp)
Dimitry Andric4a5f8a12016-01-21 21:57:49 +0000311 projsrc=llvm.src/projects/$proj
312 ;;
Daniel Sanders20de54b2016-01-28 21:09:50 +0000313 test-suite)
Tom Stellardeb6fd412017-06-08 21:31:59 +0000314 projsrc=$proj.src
Daniel Sanders20de54b2016-01-28 21:09:50 +0000315 ;;
Dimitry Andric4a5f8a12016-01-21 21:57:49 +0000316 *)
317 echo "error: unknown project $proj"
318 exit 1
319 ;;
320 esac
321
322 if [ -d $projsrc ]; then
323 echo "# Reusing $proj $Release-$RC sources in $projsrc"
Renato Golin397b0da2015-07-22 18:21:39 +0000324 continue
325 fi
Dimitry Andric4a5f8a12016-01-21 21:57:49 +0000326 echo "# Exporting $proj $Release-$RC sources to $projsrc"
327 if ! svn export -q $Base_url/$proj/$ExportBranch $projsrc ; then
Bill Wendling9aa39432011-10-16 22:44:08 +0000328 echo "error: failed to export $proj project"
329 exit 1
330 fi
331 done
332
Bill Wendling9aa39432011-10-16 22:44:08 +0000333 cd $BuildDir
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000334}
335
336function configure_llvmCore() {
337 Phase="$1"
338 Flavor="$2"
339 ObjDir="$3"
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000340
341 case $Flavor in
Hans Wennborg0caeee02015-07-15 21:06:16 +0000342 Release )
343 BuildType="Release"
344 Assertions="OFF"
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000345 ;;
Duncan Sands17cd9072010-09-13 13:45:33 +0000346 Release+Asserts )
Hans Wennborg0caeee02015-07-15 21:06:16 +0000347 BuildType="Release"
348 Assertions="ON"
Duncan Sands17cd9072010-09-13 13:45:33 +0000349 ;;
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000350 Debug )
Hans Wennborg0caeee02015-07-15 21:06:16 +0000351 BuildType="Debug"
352 Assertions="ON"
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000353 ;;
354 * )
Bill Wendling9aa39432011-10-16 22:44:08 +0000355 echo "# Invalid flavor '$Flavor'"
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000356 echo ""
357 return
358 ;;
359 esac
360
Bill Wendling9aa39432011-10-16 22:44:08 +0000361 echo "# Using C compiler: $c_compiler"
362 echo "# Using C++ compiler: $cxx_compiler"
363
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000364 cd $ObjDir
Bill Wendling957cc212011-11-28 11:45:10 +0000365 echo "# Configuring llvm $Release-$RC $Flavor"
Hans Wennborg0caeee02015-07-15 21:06:16 +0000366
Hans Wennborg9012baa2016-08-09 16:46:02 +0000367 echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
368 cmake -G "Unix Makefiles" \
369 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
Hans Wennborg9012baa2016-08-09 16:46:02 +0000370 $ExtraConfigureFlags $BuildDir/llvm.src \
371 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
372 env CC="$c_compiler" CXX="$cxx_compiler" \
373 cmake -G "Unix Makefiles" \
374 -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
Hans Wennborg9012baa2016-08-09 16:46:02 +0000375 $ExtraConfigureFlags $BuildDir/llvm.src \
376 2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
Hans Wennborg0caeee02015-07-15 21:06:16 +0000377
Bill Wendling9aa39432011-10-16 22:44:08 +0000378 cd $BuildDir
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000379}
380
381function build_llvmCore() {
382 Phase="$1"
383 Flavor="$2"
384 ObjDir="$3"
Dan Liew7fa38a52015-07-14 19:46:19 +0000385 DestDir="$4"
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000386
387 cd $ObjDir
Bill Wendling957cc212011-11-28 11:45:10 +0000388 echo "# Compiling llvm $Release-$RC $Flavor"
Hans Wennborg0caeee02015-07-15 21:06:16 +0000389 echo "# ${MAKE} -j $NumJobs VERBOSE=1"
390 ${MAKE} -j $NumJobs VERBOSE=1 \
Bill Wendling9aa39432011-10-16 22:44:08 +0000391 2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000392
Bill Wendling957cc212011-11-28 11:45:10 +0000393 echo "# Installing llvm $Release-$RC $Flavor"
Bill Wendlingcfe82322011-10-19 08:42:07 +0000394 echo "# ${MAKE} install"
395 ${MAKE} install \
Dan Liew7fa38a52015-07-14 19:46:19 +0000396 DESTDIR="${DestDir}" \
Bill Wendling9aa39432011-10-16 22:44:08 +0000397 2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
398 cd $BuildDir
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000399}
400
401function test_llvmCore() {
402 Phase="$1"
403 Flavor="$2"
404 ObjDir="$3"
405
406 cd $ObjDir
Hans Wennborgfa8e3a52015-07-24 16:16:09 +0000407 if ! ( ${MAKE} -j $NumJobs -k check-all \
408 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
409 deferred_error $Phase $Flavor "check-all failed"
410 fi
Hans Wennborg0caeee02015-07-15 21:06:16 +0000411
Tom Stellardeb6fd412017-06-08 21:31:59 +0000412 if [ $do_test_suite = 'yes' ]; then
Tom Stellardeb6fd412017-06-08 21:31:59 +0000413 cd $TestSuiteBuildDir
Tom Stellard2e173662017-06-15 23:05:21 +0000414 env CC="$c_compiler" CXX="$cxx_compiler" \
415 cmake $TestSuiteSrcDir -DTEST_SUITE_LIT=$Lit
Tom Stellardeb6fd412017-06-08 21:31:59 +0000416 if ! ( ${MAKE} -j $NumJobs -k check \
417 2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
418 deferred_error $Phase $Flavor "test suite failed"
419 fi
420 fi
Bill Wendling9aa39432011-10-16 22:44:08 +0000421 cd $BuildDir
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000422}
423
Arnaud A. de Grandmaison69690e42013-11-18 10:34:59 +0000424# Clean RPATH. Libtool adds the build directory to the search path, which is
425# not necessary --- and even harmful --- for the binary packages we release.
426function clean_RPATH() {
Dimitry Andricca051602016-01-21 22:07:17 +0000427 if [ "$System" = "Darwin" ]; then
Bill Wendlingd6073842013-11-20 04:55:20 +0000428 return
429 fi
Arnaud A. de Grandmaison69690e42013-11-18 10:34:59 +0000430 local InstallPath="$1"
431 for Candidate in `find $InstallPath/{bin,lib} -type f`; do
432 if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
Dimitry Andric52a143a2015-07-20 22:24:40 +0000433 if rpath=`objdump -x $Candidate | grep 'RPATH'` ; then
434 rpath=`echo $rpath | sed -e's/^ *RPATH *//'`
435 if [ -n "$rpath" ]; then
436 newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
437 chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
438 fi
Arnaud A. de Grandmaison69690e42013-11-18 10:34:59 +0000439 fi
440 fi
441 done
442}
443
Bill Wendlingd6073842013-11-20 04:55:20 +0000444# Create a package of the release binaries.
445function package_release() {
446 cwd=`pwd`
447 cd $BuildDir/Phase3/Release
Hans Wennborge38cc0b2015-07-20 20:36:21 +0000448 mv llvmCore-$Release-$RC.install/usr/local $Package
Bill Wendling1585fea2013-11-24 05:29:35 +0000449 if [ "$use_gzip" = "yes" ]; then
450 tar cfz $BuildDir/$Package.tar.gz $Package
451 else
452 tar cfJ $BuildDir/$Package.tar.xz $Package
453 fi
Hans Wennborge38cc0b2015-07-20 20:36:21 +0000454 mv $Package llvmCore-$Release-$RC.install/usr/local
Bill Wendlingd6073842013-11-20 04:55:20 +0000455 cd $cwd
456}
457
Dan Liewbbe97552015-07-07 15:50:33 +0000458# Exit if any command fails
459# Note: pipefail is necessary for running build commands through
460# a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
461set -e
462set -o pipefail
Bill Wendling06ac75c2011-10-18 17:27:12 +0000463
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000464if [ "$do_checkout" = "yes" ]; then
465 export_sources
466fi
467
Tom Stellard590a9742017-08-15 18:11:56 +0000468# Setup the test-suite. Do this early so we can catch failures before
469# we do the full 3 stage build.
470if [ $do_test_suite = "yes" ]; then
471 SandboxDir="$BuildDir/sandbox"
472 Lit=$SandboxDir/bin/lit
473 TestSuiteBuildDir="$BuildDir/test-suite-build"
474 TestSuiteSrcDir="$BuildDir/test-suite.src"
475
476 virtualenv $SandboxDir
477 $SandboxDir/bin/python $BuildDir/llvm.src/utils/lit/setup.py install
478 mkdir -p $TestSuiteBuildDir
479fi
480
Duncan Sandsd5f631c2011-03-27 13:52:32 +0000481(
Bill Wendling7b7d0772011-10-17 04:46:54 +0000482Flavors="Release"
Bill Wendling9aa39432011-10-16 22:44:08 +0000483if [ "$do_debug" = "yes" ]; then
484 Flavors="Debug $Flavors"
485fi
Bill Wendling7b7d0772011-10-17 04:46:54 +0000486if [ "$do_asserts" = "yes" ]; then
487 Flavors="$Flavors Release+Asserts"
488fi
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000489
490for Flavor in $Flavors ; do
491 echo ""
492 echo ""
493 echo "********************************************************************************"
Bill Wendling957cc212011-11-28 11:45:10 +0000494 echo " Release: $Release-$RC"
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000495 echo " Build: $Flavor"
496 echo " System Info: "
497 echo " `uname -a`"
498 echo "********************************************************************************"
499 echo ""
500
Duncan Sands9341b502011-10-20 20:10:58 +0000501 c_compiler="$CC"
502 cxx_compiler="$CXX"
Bill Wendling957cc212011-11-28 11:45:10 +0000503 llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
Dan Liew7fa38a52015-07-14 19:46:19 +0000504 llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000505
Bill Wendling957cc212011-11-28 11:45:10 +0000506 llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
Dan Liew7fa38a52015-07-14 19:46:19 +0000507 llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000508
Bill Wendling957cc212011-11-28 11:45:10 +0000509 llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
Dan Liew7fa38a52015-07-14 19:46:19 +0000510 llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
Bill Wendling7b7d0772011-10-17 04:46:54 +0000511
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000512 rm -rf $llvmCore_phase1_objdir
Dan Liew7fa38a52015-07-14 19:46:19 +0000513 rm -rf $llvmCore_phase1_destdir
Duncan Sands2efb4dd2011-10-20 11:13:04 +0000514
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000515 rm -rf $llvmCore_phase2_objdir
Dan Liew7fa38a52015-07-14 19:46:19 +0000516 rm -rf $llvmCore_phase2_destdir
Duncan Sands2efb4dd2011-10-20 11:13:04 +0000517
Bill Wendling7b7d0772011-10-17 04:46:54 +0000518 rm -rf $llvmCore_phase3_objdir
Dan Liew7fa38a52015-07-14 19:46:19 +0000519 rm -rf $llvmCore_phase3_destdir
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000520
521 mkdir -p $llvmCore_phase1_objdir
Dan Liew7fa38a52015-07-14 19:46:19 +0000522 mkdir -p $llvmCore_phase1_destdir
Duncan Sands2efb4dd2011-10-20 11:13:04 +0000523
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000524 mkdir -p $llvmCore_phase2_objdir
Dan Liew7fa38a52015-07-14 19:46:19 +0000525 mkdir -p $llvmCore_phase2_destdir
Duncan Sands2efb4dd2011-10-20 11:13:04 +0000526
Bill Wendling7b7d0772011-10-17 04:46:54 +0000527 mkdir -p $llvmCore_phase3_objdir
Dan Liew7fa38a52015-07-14 19:46:19 +0000528 mkdir -p $llvmCore_phase3_destdir
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000529
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000530 ############################################################################
Duncan Sands2efb4dd2011-10-20 11:13:04 +0000531 # Phase 1: Build llvmCore and clang
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000532 echo "# Phase 1: Building llvmCore"
Hans Wennborg923860d2015-07-14 20:15:15 +0000533 configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000534 build_llvmCore 1 $Flavor \
Dan Liew7fa38a52015-07-14 19:46:19 +0000535 $llvmCore_phase1_objdir $llvmCore_phase1_destdir
536 clean_RPATH $llvmCore_phase1_destdir/usr/local
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000537
Dan Liew7fa38a52015-07-14 19:46:19 +0000538 ########################################################################
539 # Phase 2: Build llvmCore with newly built clang from phase 1.
540 c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
541 cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
542 echo "# Phase 2: Building llvmCore"
Hans Wennborg923860d2015-07-14 20:15:15 +0000543 configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir
Dan Liew7fa38a52015-07-14 19:46:19 +0000544 build_llvmCore 2 $Flavor \
545 $llvmCore_phase2_objdir $llvmCore_phase2_destdir
546 clean_RPATH $llvmCore_phase2_destdir/usr/local
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000547
Dan Liew7fa38a52015-07-14 19:46:19 +0000548 ########################################################################
549 # Phase 3: Build llvmCore with newly built clang from phase 2.
550 c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
551 cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
552 echo "# Phase 3: Building llvmCore"
Hans Wennborg923860d2015-07-14 20:15:15 +0000553 configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir
Dan Liew7fa38a52015-07-14 19:46:19 +0000554 build_llvmCore 3 $Flavor \
555 $llvmCore_phase3_objdir $llvmCore_phase3_destdir
556 clean_RPATH $llvmCore_phase3_destdir/usr/local
Bill Wendling7b7d0772011-10-17 04:46:54 +0000557
Dan Liew7fa38a52015-07-14 19:46:19 +0000558 ########################################################################
559 # Testing: Test phase 3
Tom Stellard2e173662017-06-15 23:05:21 +0000560 c_compiler=$llvmCore_phase3_destdir/usr/local/bin/clang
561 cxx_compiler=$llvmCore_phase3_destdir/usr/local/bin/clang++
Dan Liew7fa38a52015-07-14 19:46:19 +0000562 echo "# Testing - built with clang"
563 test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
Bill Wendling7b7d0772011-10-17 04:46:54 +0000564
Dan Liew7fa38a52015-07-14 19:46:19 +0000565 ########################################################################
566 # Compare .o files between Phase2 and Phase3 and report which ones
567 # differ.
568 if [ "$do_compare" = "yes" ]; then
569 echo
570 echo "# Comparing Phase 2 and Phase 3 files"
Hans Wennborg0caeee02015-07-15 21:06:16 +0000571 for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do
572 p3=`echo $p2 | sed -e 's,Phase2,Phase3,'`
573 # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
Hans Wennborgaaacf482015-07-15 22:18:25 +0000574 # case there are build paths in the debug info. On some systems,
575 # sed adds a newline to the output, so pass $p3 through sed too.
Hans Wennborg6c52b022016-01-27 00:19:05 +0000576 if ! cmp -s \
Tom Stellardaaa40cc2017-07-24 19:28:30 +0000577 <(env LC_CTYPE=C sed -e 's,Phase2,Phase3,g' -e 's,Phase1,Phase2,g' $p2) \
Hans Wennborg6c52b022016-01-27 00:19:05 +0000578 <(env LC_CTYPE=C sed -e '' $p3) 16 16; then
Hans Wennborg0caeee02015-07-15 21:06:16 +0000579 echo "file `basename $p2` differs between phase 2 and phase 3"
Dan Liew7fa38a52015-07-14 19:46:19 +0000580 fi
581 done
Duncan Sands2efb4dd2011-10-20 11:13:04 +0000582 fi
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000583done
Hans Wennborg0742a3e2015-07-29 16:29:06 +0000584
Bill Wendling957cc212011-11-28 11:45:10 +0000585) 2>&1 | tee $LogDir/testing.$Release-$RC.log
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000586
Renato Golinc6bf7972017-05-04 16:21:30 +0000587if [ "$use_gzip" = "yes" ]; then
588 echo "# Packaging the release as $Package.tar.gz"
589else
590 echo "# Packaging the release as $Package.tar.xz"
591fi
Bill Wendlingd6073842013-11-20 04:55:20 +0000592package_release
593
Bill Wendling06ac75c2011-10-18 17:27:12 +0000594set +e
595
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000596# Woo hoo!
597echo "### Testing Finished ###"
Duncan Sandsd5f631c2011-03-27 13:52:32 +0000598echo "### Logs: $LogDir"
Hans Wennborgfa8e3a52015-07-24 16:16:09 +0000599
600echo "### Errors:"
601if [ -s "$LogDir/deferred_errors.log" ]; then
602 cat "$LogDir/deferred_errors.log"
603 exit 1
604else
605 echo "None."
606fi
607
Bill Wendlingcedf3a22010-09-08 18:32:31 +0000608exit 0