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