Overhaul the 'test-release' script.
[oota-llvm.git] / utils / release / test-release.sh
1 #!/bin/bash
2 #===-- 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
15 set -e                          # Exit if any command fails
16
17 projects="llvm cfe dragonegg test-suite compiler-rt libcxx libcxxabi"
18
19 # Base SVN URL for the sources.
20 Base_url="http://llvm.org/svn/llvm-project"
21
22 Release=""
23 Release_no_dot=""
24 RC=""
25 do_checkout="yes"
26 do_ada="no"
27 do_objc="yes"
28 do_fortran="no"
29 do_64bit="yes"
30 do_debug="no"
31 BuildDir="`pwd`"
32
33 function usage() {
34     echo "usage: `basename $0` -release X.Y -rc NUM [OPTIONS]"
35     echo ""
36     echo " -release X.Y      The release number to test."
37     echo " -rc NUM           The pre-release candidate number."
38     echo " -j NUM            Number of compile jobs to run. [default: 3]"
39     echo " -build-dir DIR    Directory to perform testing in. [default: pwd]"
40     echo " -no-checkout      Don't checkout the sources from SVN."
41     echo " -no-64bit         Don't test the 64-bit version. [default: yes]"
42     echo " -enable-ada       Build Ada. [default: disable]"
43     echo " -enable-fortran   Enable Fortran build. [default: disable]"
44     echo " -disable-objc     Disable ObjC build. [default: enable]"
45     echo " -test-debug       Test the debug build. [default: no]"
46 }
47
48 while [ $# -gt 0 ]; do
49     case $1 in
50         -release | --release )
51             shift
52             Release="$1"
53             Release_no_dot="`echo $1 | sed -e 's,\.,,'`"
54             ;;
55         -rc | --rc | -RC | --RC )
56             shift
57             RC=$1
58             ;;
59         -j* )
60             NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
61             if [ -z "$NumJobs" ]; then
62                 shift
63                 NumJobs="$1"
64             fi
65             ;;
66         -build-dir | --build-dir | -builddir | --builddir )
67             shift
68             BuildDir="$1"
69             ;;
70         -no-checkout | --no-checkout )
71             do_checkout="no"
72             ;;
73         -no-64bit | --no-64bit )
74             do_64bit="no"
75             ;;
76         -enable-ada | --enable-ada )
77             do_ada="yes"
78             ;;
79         -enable-fortran | --enable-fortran )
80             do_fortran="yes"
81             ;;
82         -disable-objc | --disable-objc )
83             do_objc="no"
84             ;;
85         -test-debug | --test-debug )
86             do_debug="yes"
87             ;;
88         -help | --help | -h | --h | -\? )
89             usage
90             exit 0
91             ;;
92         * )
93             echo "unknown option: $1"
94             usage
95             exit 1
96             ;;
97     esac
98     shift
99 done
100
101 # Check required arguments.
102 if [ -z "$Release" ]; then
103     echo "error: no release number specified"
104     exit 1
105 fi
106 if [ -z "$RC" ]; then
107     echo "error: no release candidate number specified"
108     exit 1
109 fi
110
111 # Figure out how many make processes to run.
112 if [ -z "$NumJobs" ]; then
113     NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
114 fi
115 if [ -z "$NumJobs" ]; then
116     NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
117 fi
118 if [ -z "$NumJobs" ]; then
119     NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
120 fi
121 if [ -z "$NumJobs" ]; then
122     NumJobs=3
123 fi
124
125 # Go to the build directory (may be different from CWD)
126 BuildDir=$BuildDir/rc$RC
127 mkdir -p $BuildDir
128 cd $BuildDir
129
130 # Location of log files.
131 LogDir=$BuildDir/logs
132 mkdir -p $LogDir
133
134 # Find a compilers.
135 c_compiler="`which clang`"
136 if [ -z "$c_compiler" ]; then
137     c_compiler="`which gcc`"
138     if [ -z "$c_compiler" ]; then
139         c_compiler="`which cc`"
140         if [ -z "$c_compiler" ]; then
141             echo "error: cannot find a working C compiler"
142         fi
143     fi
144 fi
145 cxx_compiler="`which clang++`"
146 if [ -z "$cxx_compiler" ]; then
147     cxx_compiler="`which g++`"
148     if [ -z "$cxx_compiler" ]; then
149         cxx_compiler="`which c++`"
150         if [ -z "$cxx_compiler" ]; then
151             echo "error: cannot find a working C++ compiler"
152         fi
153     fi
154 fi
155
156 # Make sure that the URLs are valid.
157 function check_valid_urls() {
158     for proj in $projects ; do
159         echo "# Validating $proj SVN URL"
160
161         if ! svn ls $Base_url/tags/RELEASE_$Release_no_dot/rc$RC > /dev/null 2>&1 ; then
162             echo "llvm $Release release candidate $RC doesn't exist!"
163             exit 1
164         fi
165     done
166 }
167
168 # Export sources to the the build directory.
169 function export_sources() {
170     check_valid_urls
171
172     for proj in $projects ; do
173         echo "# Exporting $proj $Release-RC$RC sources"
174         if ! svn export -q $Base_url/$proj/tags/RELEASE_$Release_no_dot/rc$RC $proj.src ; then
175             echo "error: failed to export $proj project"
176             exit 1
177         fi
178     done
179
180     echo "# Creating symlinks"
181     cd $BuildDir/llvm.src/tools
182     if [ ! -h clang ]; then
183         ln -s $BuildDir/cfe.src clang
184     fi
185     cd $BuildDir/llvm.src/projects
186     if [ ! -h llvm-test ]; then
187         ln -s $BuildDir/test-suite.src llvm-test
188     fi
189     cd $BuildDir
190 }
191
192 function configure_llvmCore() {
193     Phase="$1"
194     Flavor="$2"
195     ObjDir="$3"
196     InstallDir="$4"
197
198     case $Flavor in
199         Release | Release-64 )
200             Optimized="yes"
201             Assertions="no"
202             ;;
203         Release+Asserts )
204             Optimized="yes"
205             Assertions="yes"
206             ;;
207         Debug )
208             Optimized="no"
209             Assertions="yes"
210             ;;
211         * )
212             echo "# Invalid flavor '$Flavor'"
213             echo ""
214             return
215             ;;
216     esac
217
218     echo "# Using C compiler: $c_compiler"
219     echo "# Using C++ compiler: $cxx_compiler"
220
221     cd $ObjDir
222     echo "# Configuring llvm $Release-rc$RC $Flavor"
223     echo "# $BuildDir/llvm.src/configure --prefix=$InstallDir \
224         --enable-optimized=$Optimized \
225         --enable-assertions=$Assertions"
226     env CC=$c_compiler CXX=$cxx_compiler \
227     $BuildDir/llvm.src/configure --prefix=$InstallDir \
228         --enable-optimized=$Optimized \
229         --enable-assertions=$Assertions \
230         2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
231     cd $BuildDir
232 }
233
234 function build_llvmCore() {
235     Phase="$1"
236     Flavor="$2"
237     ObjDir="$3"
238     ExtraOpts=""
239
240     if [ "$Flavor" = "Release-64" ]; then
241         ExtraOpts="EXTRA_OPTIONS=-m64"
242     fi
243
244     cd $ObjDir
245     echo "# Compiling llvm $Release-rc$RC $Flavor"
246     echo "# make -j $NumJobs VERBOSE=1 $ExtraOpts"
247     make -j $NumJobs VERBOSE=1 $ExtraOpts \
248         2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log
249
250     echo "# Installing llvm $Release-rc$RC $Flavor"
251     echo "# make install"
252     make install \
253         2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log
254     cd $BuildDir
255 }
256
257 function test_llvmCore() {
258     Phase="$1"
259     Flavor="$2"
260     ObjDir="$3"
261
262     cd $ObjDir
263     make check-all \
264         2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log
265     make unittests \
266         2>&1 | tee $LogDir/llvm.unittests--Phase$Phase-$Flavor.log
267     cd $BuildDir
268 }
269
270 if [ "$do_checkout" = "yes" ]; then
271     export_sources
272 fi
273
274 (
275 Flavors="Release Release+Asserts"
276 if [ "$do_debug" = "yes" ]; then
277     Flavors="Debug $Flavors"
278 fi
279 if [ "$do_64bit" = "yes" ]; then
280     Flavors="$Flavors Release-64"
281 fi
282
283 for Flavor in $Flavors ; do
284     echo ""
285     echo ""
286     echo "********************************************************************************"
287     echo "  Release:     $Release-rc$RC"
288     echo "  Build:       $Flavor"
289     echo "  System Info: "
290     echo "    `uname -a`"
291     echo "********************************************************************************"
292     echo ""
293
294     llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-rc$RC.obj
295     llvmCore_phase1_installdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-rc$RC.install
296
297     llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-rc$RC.obj
298     llvmCore_phase2_installdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-rc$RC.install
299
300     rm -rf $llvmCore_phase1_objdir
301     rm -rf $llvmCore_phase1_installdir
302     rm -rf $llvmCore_phase2_objdir
303     rm -rf $llvmCore_phase2_installdir
304
305     mkdir -p $llvmCore_phase1_objdir
306     mkdir -p $llvmCore_phase1_installdir
307     mkdir -p $llvmCore_phase2_objdir
308     mkdir -p $llvmCore_phase2_installdir
309
310     ############################################################################
311     # Phase 1: Build llvmCore and llvmgcc42
312     echo "# Phase 1: Building llvmCore"
313     configure_llvmCore 1 $Flavor \
314         $llvmCore_phase1_objdir $llvmCore_phase1_installdir
315     build_llvmCore 1 $Flavor \
316         $llvmCore_phase1_objdir
317
318     ############################################################################
319     # Phase 2: Build llvmCore with newly built clang from phase 1.
320     c_compiler=$llvmCore_phase1_installdir/bin/clang
321     cxx_compiler=$llvmCore_phase1_installdir/bin/clang++
322     echo "# Phase 2: Building llvmCore"
323     configure_llvmCore 2 $Flavor \
324         $llvmCore_phase2_objdir $llvmCore_phase2_installdir
325     build_llvmCore 2 $Flavor \
326         $llvmCore_phase2_objdir
327
328     echo "# Testing - built with clang"
329     test_llvmCore 2 $Flavor $llvmCore_phase2_objdir
330 done
331 ) 2>&1 | tee $LogDir/testing.$Release-rc$RC.log
332
333 # Woo hoo!
334 echo "### Testing Finished ###"
335 echo "### Logs: $LogDir"
336 exit 0