Remove ssp from this test.
[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
16
17 Release=""
18 Release_no_dot=""
19 RC=""
20 do_checkout="yes"
21 do_ada="no"
22 do_fortran="yes"
23 do_64bit="yes"
24 BuildDir="`pwd`"
25
26 # Figure out how many make processes to run.
27 NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
28 if [ -z "$NumJobs" ]; then
29     NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
30 fi
31 if [ -z "$NumJobs" ]; then
32     NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
33 fi
34
35 function usage() {
36     echo "usage: `basename $0` -release X.Y -rc NUM [OPTIONS]"
37     echo ""
38     echo " -release X.Y      The release number to test."
39     echo " -rc NUM           The pre-release candidate number."
40     echo " -j NUM            Number of compile jobs to run. [default: 3]"
41     echo " -build-dir DIR    Directory to perform testing in. [default: pwd]"
42     echo " -no-checkout      Don't checkout the sources from SVN."
43     echo " -no-64bit         Don't test the 64-bit version. [default: yes]"
44     echo " -ada              Build Ada. [default: no]"
45     echo " -disable-fortran  Disable Fortran build. [default: build]"
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         -ada | --ada )
77             do_ada="yes"
78             ;;
79         -disable-fortran | --disable-fortran )
80             echo "WARNING: Do you *really* need to disable Fortran?"
81             sleep 5
82             do_fortran="no"
83             ;;
84         -help | --help | -h | --h | -\? )
85             usage
86             exit 0
87             ;;
88         * )
89             echo "unknown option: $1"
90             usage
91             exit 1
92             ;;
93     esac
94     shift
95 done
96
97 # Check required arguments.
98 if [ -z "$Release" ]; then
99     echo "No release number specified!"
100     exit 1
101 fi
102 if [ -z "$RC" ]; then
103     echo "No release candidate number specified!"
104     exit 1
105 fi
106
107 if [ -z "$NumJobs" ]; then
108     NumJobs=3
109 fi
110
111 # Location of sources.
112 llvmCore_srcdir=$BuildDir/llvmCore-$Release-rc$RC.src
113 llvmgcc42_srcdir=$BuildDir/llvmgcc42-$Release-rc$RC.src
114
115 # Location of log files.
116 LogDirName="$Release-rc$RC.logs"
117 LogDir=$BuildDir/$LogDirName
118 mkdir -p $LogDir
119
120 # SVN URLs for the sources.
121 Base_url="http://llvm.org/svn/llvm-project"
122 llvmCore_RC_url="$Base_url/llvm/tags/RELEASE_$Release_no_dot/rc$RC"
123 llvmgcc42_RC_url="$Base_url/llvm-gcc-4.2/tags/RELEASE_$Release_no_dot/rc$RC"
124 clang_RC_url="$Base_url/cfe/tags/RELEASE_$Release_no_dot/rc$RC"
125 test_suite_RC_url="$Base_url/test-suite/tags/RELEASE_$Release_no_dot/rc$RC"
126
127 # Make sure that the URLs are valid.
128 function check_valid_urls() {
129     echo "# Validating SVN URLs"
130     if ! svn ls $llvmCore_RC_url > /dev/null 2>&1 ; then
131         echo "llvm $Release release candidate $RC doesn't exist!"
132         exit 1
133     fi
134     if ! svn ls $llvmgcc42_RC_url > /dev/null 2>&1 ; then
135         echo "llvm-gcc-4.2 $Release release candidate $RC doesn't exist!"
136         exit 1
137     fi
138     if ! svn ls $clang_RC_url > /dev/null 2>&1 ; then
139         echo "clang $Release release candidate $RC doesn't exist!"
140         exit 1
141     fi
142     if ! svn ls $test_suite_RC_url > /dev/null 2>&1 ; then
143         echo "test-suite $Release release candidate $RC doesn't exist!"
144         exit 1
145     fi
146 }
147
148 # Export sources to the the build directory.
149 function export_sources() {
150     check_valid_urls
151
152     echo "# Exporting llvm $Release-RC$RC sources"
153     svn export -q $llvmCore_RC_url $llvmCore_srcdir
154     echo "# Exporting llvm-gcc-4.2 $Release-rc$RC  sources"
155     svn export -q $llvmgcc42_RC_url $llvmgcc42_srcdir
156     echo "# Exporting clang $Release-rc$RC sources"
157     svn export -q $clang_RC_url $llvmCore_srcdir/tools/clang
158     echo "# Exporting llvm test suite $Release-rc$RC sources"
159     svn export -q $test_suite_RC_url $llvmCore_srcdir/projects/llvm-test
160 }
161
162 function configure_llvmCore() {
163     Phase="$1"
164     Flavor="$2"
165     ObjDir="$3"
166     InstallDir="$4"
167     llvmgccDir="$5"
168
169     case $Flavor in
170         Release | Release-64 )
171             Optimized="yes"
172             Assertions="yes"
173             ;;
174         Release-Asserts )
175             Optimized="yes"
176             Assertions="no"
177             ;;
178         Debug )
179             Optimized="no"
180             Assertions="yes"
181             ;;
182         * )
183             echo "# Invalid flavor $Flavor!"
184             echo ""
185             return
186             ;;
187     esac
188
189     cd $ObjDir
190     echo "# Configuring llvm $Release-rc$RC $Flavor"
191     echo "# $llvmCore_srcdir/configure --prefix=$llvmCore_installdir \
192         --enable-optimized=$Optimized \
193         --enable-assertions=$Assertions \
194         --with-llvmgccdir=$llvmgccDir"
195     $llvmCore_srcdir/configure --prefix=$InstallDir \
196         --enable-optimized=$Optimized \
197         --enable-assertions=$Assertions \
198         --with-llvmgccdir=$llvmgccDir \
199         > $LogDir/llvm.configure.$Release-rc$RC-Phase$Phase-$Flavor.log 2>&1
200     cd -
201 }
202
203 function build_llvmCore() {
204     Phase="$1"
205     Flavor="$2"
206     ObjDir="$3"
207     ExtraOpts=""
208
209     CompilerFlags=""
210     if [ "$Phase" = "2" ]; then
211         CompilerFlags="CC=$llvmgccDir/bin/llvm-gcc CXX=$llvmgccDir/bin/llvm-g++"
212     fi
213     if [ "$Flavor" = "Release-64" ]; then
214         ExtraOpts="EXTRA_OPTIONS=-m64"
215     fi
216
217     cd $ObjDir
218     echo "# Compiling llvm $Release-rc$RC $Flavor"
219     echo "# make -j $NumJobs VERBOSE=1 $ExtraOpts"
220     make -j $NumJobs VERBOSE=1 $ExtraOpts $CompilerFlags \
221         > $LogDir/llvm.make.$Release-rc$RC-Phase$Phase-$Flavor.log 2>&1
222
223     echo "# Installing llvm $Release-rc$RC $Flavor"
224     echo "# make install"
225     make install \
226         > $LogDir/llvm.install.$Release-rc$RC-Phase$Phase-$Flavor.log 2>&1
227     cd -
228 }
229
230 function test_llvmCore() {
231     Phase="$1"
232     Flavor="$2"
233     ObjDir="$3"
234
235     cd $ObjDir
236     make check \
237         > $LogDir/llvm.check.$Release-rc$RC-Phase$Phase-$Flavor.log 2>&1
238     make -C tools/clang test \
239         > $LogDir/clang.check.$Release-rc$RC-Phase$Phase-$Flavor.log 2>&1
240     make unittests \
241         > $LogDir/llvm.unittests.$Release-rc$RC-Phase$Phase-$Flavor.log 2>&1
242     cd -
243 }
244
245 function configure_llvm_gcc() {
246     Phase="$1"
247     Flavor="$2"
248     ObjDir="$3"
249     InstallDir="$4"
250     llvmObjDir="$5"
251
252     languages="c,c++,objc,obj-c++"
253     if [ "$do_fortran" = "yes" ]; then
254         languages="$languages,fortran"
255     fi
256     if [ "$do_ada" = "yes" ]; then
257         languages="$languages,ada"
258     fi
259
260     cd $ObjDir
261     echo "# Configuring llvm-gcc $Release-rc$RC $Flavor"
262     echo "# $llvmgcc42_srcdir/configure --prefix=$InstallDir \
263         --program-prefix=llvm- --enable-llvm=$llvmObjDir \
264         --enable-languages=$languages \
265         --with-gxx-include-dir=/usr/include/c++/4.2.1"
266     $llvmgcc42_srcdir/configure --prefix=$InstallDir \
267         --program-prefix=llvm- --enable-llvm=$llvmObjDir \
268         --enable-languages=$languages \
269         --with-gxx-include-dir=/usr/include/c++/4.2.1 \
270         > $LogDir/llvm-gcc.configure.$Release-rc$RC-Phase$Phase-$Flavor.log 2>&1
271     cd -
272 }
273
274 function build_llvm_gcc() {
275     Phase="$1"
276     Flavor="$2"
277     ObjDir="$3"
278     llvmgccDir="$4"
279
280     CompilerFlags=""
281     if [ "$Phase" = "2" ]; then
282         CompilerFlags="CC=$llvmgccDir/bin/llvm-gcc CXX=$llvmgccDir/bin/llvm-g++"
283     fi
284
285     cd $ObjDir
286     echo "# Compiling llvm-gcc $Release-rc$RC $Flavor"
287     echo "# make -j $NumJobs bootstrap LLVM_VERSION_INFO=$Release"
288     make -j $NumJobs bootstrap LLVM_VERSION_INFO=$Release $CompilerFlags \
289         > $LogDir/llvm-gcc.make.$Release-rc$RC-Phase$Phase-$Flavor.log 2>&1
290
291     echo "# Installing llvm-gcc $Release-rc$RC $Flavor"
292     echo "# make install"
293     make install \
294         > $LogDir/llvm-gcc.install.$Release-rc$RC-Phase$Phase-$Flavor.log 2>&1
295     cd -
296 }
297
298 if [ "$do_checkout" = "yes" ]; then
299     export_sources
300 fi
301
302 (
303 Flavors="Debug Release Release-Asserts"
304 if [ "$do_64bit" = "yes" ]; then
305     Flavors="$Flavors Release-64"
306 fi
307
308 for Flavor in $Flavors ; do
309     echo ""
310     echo ""
311     echo "********************************************************************************"
312     echo "  Release:     $Release-rc$RC"
313     echo "  Build:       $Flavor"
314     echo "  System Info: "
315     echo "    `uname -a`"
316     echo "********************************************************************************"
317     echo ""
318
319     llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-rc$RC.obj
320     llvmCore_phase1_installdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-rc$RC.install
321
322     llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-rc$RC.obj
323     llvmCore_phase2_installdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-rc$RC.install
324
325     rm -rf $llvmCore_phase1_objdir
326     rm -rf $llvmCore_phase1_installdir
327     rm -rf $llvmCore_phase2_objdir
328     rm -rf $llvmCore_phase2_installdir
329
330     mkdir -p $llvmCore_phase1_objdir
331     mkdir -p $llvmCore_phase1_installdir
332     mkdir -p $llvmCore_phase2_objdir
333     mkdir -p $llvmCore_phase2_installdir
334
335     llvmgcc42_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmgcc42-$Release-rc$RC.obj
336     llvmgcc42_phase1_installdir=$BuildDir/Phase1/$Flavor/llvmgcc42-$Release-rc$RC.install
337
338     llvmgcc42_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmgcc42-$Release-rc$RC.obj
339     llvmgcc42_phase2_installdir=$BuildDir/Phase2/$Flavor/llvmgcc42-$Release-rc$RC.install
340
341     rm -rf $llvmgcc42_phase1_objdir
342     rm -rf $llvmgcc42_phase1_installdir
343     rm -rf $llvmgcc42_phase2_objdir
344     rm -rf $llvmgcc42_phase2_installdir
345
346     mkdir -p $llvmgcc42_phase1_objdir
347     mkdir -p $llvmgcc42_phase1_installdir
348     mkdir -p $llvmgcc42_phase2_objdir
349     mkdir -p $llvmgcc42_phase2_installdir
350
351     ############################################################################
352     # Phase 1: Build llvmCore and llvmgcc42
353     echo "# Phase 1: Building llvmCore"
354     configure_llvmCore 1 $Flavor \
355         $llvmCore_phase1_objdir $llvmCore_phase1_installdir \
356         $llvmgcc42_phase1_installdir
357     build_llvmCore 1 $Flavor \
358         $llvmCore_phase1_objdir
359
360     echo "# Phase 1: Building llvmgcc42"
361     configure_llvm_gcc 1 $Flavor \
362         $llvmgcc42_phase1_objdir $llvmgcc42_phase1_installdir \
363         $llvmCore_phase1_objdir
364     build_llvm_gcc 1 $Flavor \
365         $llvmgcc42_phase1_objdir $llvmgcc42_phase1_installdir
366
367     ############################################################################
368     # Phase 2: Build llvmCore with newly built llvmgcc42 from phase 1.
369     echo "# Phase 2: Building llvmCore"
370     configure_llvmCore 2 $Flavor \
371         $llvmCore_phase2_objdir $llvmCore_phase2_installdir \
372         $llvmgcc42_phase1_installdir
373     build_llvmCore 2 $Flavor \
374         $llvmCore_phase2_objdir
375
376     echo "# Phase 2: Building llvmgcc42"
377     configure_llvm_gcc 2 $Flavor \
378         $llvmgcc42_phase2_objdir $llvmgcc42_phase2_installdir \
379         $llvmCore_phase2_objdir
380     build_llvm_gcc 2 $Flavor \
381         $llvmgcc42_phase2_objdir $llvmgcc42_phase1_installdir
382
383     echo "# Testing - built with llvmgcc42"
384     test_llvmCore 2 $Flavor $llvmCore_phase2_objdir
385 done
386 ) 2>&1 | tee $LogDir/testing.$Release-rc$RC.log
387
388 # Woo hoo!
389 echo "### Testing Finished ###"
390 echo "### Logs: $LogDir"
391 exit 0