xref: /llvm-project/llvm/utils/release/test-release.sh (revision 51e0a997ca607f64beafb838ba1325f0465eecd4)
1#!/usr/bin/env bash
2#===-- test-release.sh - Test the LLVM release candidates ------------------===#
3#
4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7#
8#===------------------------------------------------------------------------===#
9#
10# Download, build, and test the release candidate for an LLVM release.
11#
12#===------------------------------------------------------------------------===#
13
14System=`uname -s`
15Machine=`uname -m`
16if [ "$System" = "FreeBSD" ]; then
17    MAKE=gmake
18else
19    MAKE=make
20fi
21generator="Unix Makefiles"
22
23Release=""
24Release_no_dot=""
25RC=""
26Triple=""
27use_gzip="no"
28do_checkout="yes"
29do_debug="no"
30do_asserts="no"
31do_compare="yes"
32do_rt="yes"
33do_clang_tools="yes"
34do_libs="yes"
35do_libcxxabi="yes"
36do_libunwind="yes"
37do_test_suite="yes"
38do_openmp="yes"
39do_lld="yes"
40do_lldb="yes"
41do_polly="yes"
42do_mlir="yes"
43do_flang="yes"
44do_silent_log="no"
45BuildDir="`pwd`"
46ExtraConfigureFlags=""
47ExportBranch=""
48git_ref=""
49do_cmake_cache="no"
50do_bolt="no"
51if [ "$System" = "Linux" ]; then
52    case $Machine in
53        x86_64 | arm64 | aarch64 )
54            do_bolt="yes"
55            ;;
56    esac
57fi
58
59function usage() {
60    echo "usage: `basename $0` -release X.Y.Z -rc NUM [OPTIONS]"
61    echo ""
62    echo " -release X.Y.Z       The release version to test."
63    echo " -rc NUM              The pre-release candidate number."
64    echo " -final               The final release candidate."
65    echo " -triple TRIPLE       The target triple for this machine."
66    echo " -j NUM               Number of compile jobs to run. [default: 3]"
67    echo " -build-dir DIR       Directory to perform testing in. [default: pwd]"
68    echo " -no-checkout         Don't checkout the sources from SVN."
69    echo " -test-debug          Test the debug build. [default: no]"
70    echo " -test-asserts        Test with asserts on. [default: no]"
71    echo " -no-compare-files    Don't test that phase 2 and 3 files are identical."
72    echo " -use-gzip            Use gzip instead of xz."
73    echo " -use-ninja           Use ninja instead of make/gmake."
74    echo " -configure-flags FLAGS  Extra flags to pass to the configure step."
75    echo " -git-ref sha         Use the specified git ref for testing instead of a release."
76    echo " -no-rt               Disable check-out & build Compiler-RT"
77    echo " -no-clang-tools      Disable check-out & build clang-tools-extra"
78    echo " -no-libs             Disable check-out & build libcxx/libcxxabi/libunwind"
79    echo " -no-libcxxabi        Disable check-out & build libcxxabi"
80    echo " -no-libunwind        Disable check-out & build libunwind"
81    echo " -no-test-suite       Disable check-out & build test-suite"
82    echo " -no-openmp           Disable check-out & build libomp"
83    echo " -no-lld              Disable check-out & build lld"
84    echo " -lldb                Enable check-out & build lldb"
85    echo " -no-lldb             Disable check-out & build lldb (default)"
86    echo " -no-polly            Disable check-out & build Polly"
87    echo " -no-mlir             Disable check-out & build MLIR"
88    echo " -no-flang            Disable check-out & build Flang"
89    echo " -silent-log          Don't output build logs to stdout"
90    echo " -use-cmake-cache     Build using a CMake cache file"
91}
92
93while [ $# -gt 0 ]; do
94    case $1 in
95        -release | --release )
96            shift
97            Release="$1"
98            Release_no_dot="`echo $1 | sed -e 's,\.,,g'`"
99            ;;
100        -rc | --rc | -RC | --RC )
101            shift
102            RC="rc$1"
103            ;;
104        -final | --final )
105            RC=final
106            ;;
107        -git-ref | --git-ref )
108            shift
109            Release="test"
110            Release_no_dot="test"
111            ExportBranch="$1"
112            RC="`echo $ExportBranch | sed -e 's,/,_,g'`"
113            git_ref="$1"
114            echo "WARNING: Using the ref $git_ref instead of a release tag"
115            echo "         This is intended to aid new packagers in trialing "
116            echo "         builds without requiring a tag to be created first"
117            ;;
118        -triple | --triple )
119            shift
120            Triple="$1"
121            ;;
122        -configure-flags | --configure-flags )
123            shift
124            ExtraConfigureFlags="$1"
125            ;;
126        -j* )
127            NumJobs="`echo $1 | sed -e 's,-j\([0-9]*\),\1,g'`"
128            if [ -z "$NumJobs" ]; then
129                shift
130                NumJobs="$1"
131            fi
132            ;;
133        -use-ninja )
134            MAKE=ninja
135            generator=Ninja
136            ;;
137        -build-dir | --build-dir | -builddir | --builddir )
138            shift
139            BuildDir="$1"
140            ;;
141        -no-checkout | --no-checkout )
142            do_checkout="no"
143            ;;
144        -test-debug | --test-debug )
145            do_debug="yes"
146            ;;
147        -test-asserts | --test-asserts )
148            do_asserts="yes"
149            ;;
150        -no-compare-files | --no-compare-files )
151            do_compare="no"
152            ;;
153        -use-gzip | --use-gzip )
154            use_gzip="yes"
155            ;;
156        -no-rt )
157            do_rt="no"
158            ;;
159        -no-libs )
160            do_libs="no"
161            ;;
162        -no-clang-tools )
163            do_clang_tools="no"
164            ;;
165        -no-libcxxabi )
166            do_libcxxabi="no"
167            ;;
168        -no-libunwind )
169            do_libunwind="no"
170            ;;
171        -no-test-suite )
172            do_test_suite="no"
173            ;;
174        -no-openmp )
175            do_openmp="no"
176            ;;
177        -bolt )
178            do_bolt="yes"
179            ;;
180        -no-bolt )
181            do_bolt="no"
182            ;;
183        -no-lld )
184            do_lld="no"
185            ;;
186        -lldb )
187            do_lldb="yes"
188            ;;
189        -no-lldb )
190            do_lldb="no"
191            ;;
192        -no-polly )
193            do_polly="no"
194            ;;
195        -no-mlir )
196            do_mlir="no"
197            ;;
198        -no-flang )
199            do_flang="no"
200            ;;
201        -silent-log )
202            do_silent_log="yes"
203            ;;
204        -use-cmake-cache | --use-cmake-cache )
205            do_cmake_cache="yes"
206            ;;
207        -help | --help | -h | --h | -\? )
208            usage
209            exit 0
210            ;;
211        * )
212            echo "unknown option: $1"
213            usage
214            exit 1
215            ;;
216    esac
217    shift
218done
219
220if [ $do_mlir = "no" ] && [ $do_flang = "yes" ]; then
221  echo "error: cannot build Flang without MLIR"
222  exit 1
223fi
224
225# Check required arguments.
226if [ -z "$Release" ]; then
227    echo "error: no release number specified"
228    exit 1
229fi
230if [ -z "$RC" ]; then
231    echo "error: no release candidate number specified"
232    exit 1
233fi
234if [ -z "$ExportBranch" ]; then
235    ExportBranch="tags/RELEASE_$Release_no_dot/$RC"
236fi
237if [ -z "$Triple" ]; then
238    echo "error: no target triple specified"
239    exit 1
240fi
241
242if [ "$Release" != "test" ]; then
243  if [ -n "$git_ref" ]; then
244    echo "error: can't specify both -release and -git-ref"
245    exit 1
246  fi
247  git_ref=llvmorg-$Release
248  if [ "$RC" != "final" ]; then
249    git_ref="$git_ref-$RC"
250  fi
251fi
252
253UserNumJobs="$NumJobs"
254
255# Figure out how many make processes to run.
256if [ -z "$NumJobs" ]; then
257    NumJobs=`sysctl -n hw.activecpu 2> /dev/null || true`
258fi
259if [ -z "$NumJobs" ]; then
260    NumJobs=`sysctl -n hw.ncpu 2> /dev/null || true`
261fi
262if [ -z "$NumJobs" ]; then
263    NumJobs=`grep -c processor /proc/cpuinfo 2> /dev/null || true`
264fi
265if [ -z "$NumJobs" ]; then
266    NumJobs=3
267fi
268
269if [ "$MAKE" = "ninja" ] && [ -z "$UserNumJobs" ]; then
270  # Rely on default ninja job numbers
271  J_ARG=""
272else
273  J_ARG="-j $NumJobs"
274fi
275
276# Projects list
277projects="llvm;clang"
278if [ $do_clang_tools = "yes" ]; then
279  projects="${projects:+$projects;}clang-tools-extra"
280fi
281runtimes=""
282if [ $do_rt = "yes" ]; then
283  runtimes="${runtimes:+$runtimes;}compiler-rt"
284fi
285if [ $do_libs = "yes" ]; then
286  runtimes="${runtimes:+$runtimes;}libcxx"
287  if [ $do_libcxxabi = "yes" ]; then
288    runtimes="${runtimes:+$runtimes;}libcxxabi"
289  fi
290  if [ $do_libunwind = "yes" ]; then
291    runtimes="${runtimes:+$runtimes;}libunwind"
292  fi
293fi
294if [ $do_openmp = "yes" ]; then
295  projects="${projects:+$projects;}openmp"
296fi
297if [ $do_bolt = "yes" ]; then
298  projects="${projects:+$projects;}bolt"
299fi
300if [ $do_lld = "yes" ]; then
301  projects="${projects:+$projects;}lld"
302fi
303if [ $do_lldb = "yes" ]; then
304  projects="${projects:+$projects;}lldb"
305fi
306if [ $do_polly = "yes" ]; then
307  projects="${projects:+$projects;}polly"
308fi
309if [ $do_mlir = "yes" ]; then
310  projects="${projects:+$projects;}mlir"
311fi
312if [ $do_flang = "yes" ]; then
313  projects="${projects:+$projects;}flang"
314fi
315
316# Go to the build directory (may be different from CWD)
317BuildDir=$BuildDir/$RC
318mkdir -p $BuildDir
319cd $BuildDir
320
321# Location of log files.
322LogDir=$BuildDir/logs
323mkdir -p $LogDir
324
325# Final package name.
326Package=clang+llvm-$Release
327if [ $RC != "final" ]; then
328  Package=$Package-$RC
329fi
330Package=$Package-$Triple
331
332# Errors to be highlighted at the end are written to this file.
333echo -n > $LogDir/deferred_errors.log
334
335redir="/dev/stdout"
336if [ $do_silent_log == "yes" ]; then
337  echo "# Silencing build logs because of -silent-log flag..."
338  redir="/dev/null"
339fi
340
341
342function build_with_cmake_cache() {
343(
344  CMakeBuildDir=$BuildDir/build
345  SrcDir=$BuildDir/llvm-project/
346  InstallDir=$BuildDir/install
347
348  rm -rf $CMakeBuildDir
349
350  # FIXME: Would be nice if the commands were echoed to the log file too.
351  set -x
352
353  env CC="$c_compiler" CXX="$cxx_compiler" \
354  cmake -G "$generator" -B $CMakeBuildDir -S $SrcDir/llvm \
355        -C $SrcDir/clang/cmake/caches/Release.cmake \
356	-DCLANG_BOOTSTRAP_PASSTHROUGH="LLVM_LIT_ARGS" \
357        -DLLVM_LIT_ARGS="-j $NumJobs $LitVerbose" \
358        $ExtraConfigureFlags
359        2>&1 | tee $LogDir/llvm.configure-$Flavor.log
360
361  ${MAKE} $J_ARG $Verbose -C $CMakeBuildDir stage2-check-all \
362          2>&1 | tee $LogDir/llvm.make-$Flavor.log > $redir
363
364  DESTDIR="${InstallDir}" \
365  ${MAKE} -C $CMakeBuildDir stage2-install \
366          2>&1 | tee $LogDir/llvm.install-$Flavor.log > $redir
367
368 mkdir -p $BuildDir/Release
369 pushd $BuildDir/Release
370 mv $InstallDir/usr/local $Package
371 if [ "$use_gzip" = "yes" ]; then
372    tar cf - $Package | gzip -9c > $BuildDir/$Package.tar.gz
373  else
374    tar cf - $Package | xz -9ce -T $NumJobs > $BuildDir/$Package.tar.xz
375  fi
376  mv $Package $InstallDir/usr/local
377  popd
378) 2>&1 | tee $LogDir/testing.$Release-$RC.log
379
380  exit 0
381}
382
383function deferred_error() {
384  Phase="$1"
385  Flavor="$2"
386  Msg="$3"
387  echo "[${Flavor} Phase${Phase}] ${Msg}" | tee -a $LogDir/deferred_errors.log
388}
389
390# Make sure that a required program is available
391function check_program_exists() {
392  local program="$1"
393  if ! type -P $program > /dev/null 2>&1 ; then
394    echo "program '$1' not found !"
395    exit 1
396  fi
397}
398
399if [ "$System" != "Darwin" ] && [ "$System" != "SunOS" ] && [ "$System" != "AIX" ]; then
400  check_program_exists 'chrpath'
401fi
402
403if [ "$System" != "Darwin" ]; then
404  check_program_exists 'file'
405  check_program_exists 'objdump'
406fi
407
408check_program_exists ${MAKE}
409
410# Export sources to the build directory.
411function export_sources() {
412  SrcDir=$BuildDir/llvm-project
413  mkdir -p $SrcDir
414  echo "# Using git ref: $git_ref"
415
416  # GitHub allows you to download a tarball of any commit using the URL:
417  # https://github.com/$organization/$repo/archive/$ref.tar.gz
418  curl -L https://github.com/llvm/llvm-project/archive/$git_ref.tar.gz | \
419    tar -C $SrcDir --strip-components=1 -xzf -
420
421  if [ "$do_test_suite" = "yes" ]; then
422    TestSuiteSrcDir=$BuildDir/llvm-test-suite
423    mkdir -p $TestSuiteSrcDir
424
425    # We can only use named refs, like branches and tags, that exist in
426    # both the llvm-project and test-suite repos if we want to run the
427    # test suite.
428    # If the test-suite fails to download assume we are using a ref that
429    # doesn't exist in the test suite and disable it.
430    set +e
431    curl -L https://github.com/llvm/test-suite/archive/$git_ref.tar.gz | \
432      tar -C $TestSuiteSrcDir --strip-components=1 -xzf -
433    if [ $? -ne -0 ]; then
434      echo "$git_ref not found in test-suite repo, test-suite disabled."
435      do_test_suite="no"
436    fi
437    set -e
438  fi
439
440  cd $BuildDir
441}
442
443function configure_llvmCore() {
444    Phase="$1"
445    Flavor="$2"
446    ObjDir="$3"
447
448    case $Flavor in
449        Release )
450            BuildType="Release"
451            Assertions="OFF"
452            ;;
453        Release+Asserts )
454            BuildType="Release"
455            Assertions="ON"
456            ;;
457        Debug )
458            BuildType="Debug"
459            Assertions="ON"
460            ;;
461        * )
462            echo "# Invalid flavor '$Flavor'"
463            echo ""
464            return
465            ;;
466    esac
467
468    # During the first two phases, there is no need to build any of the projects
469    # except clang, since these phases are only meant to produce a bootstrapped
470    # clang compiler, capable of building the third phase.
471    if [ "$Phase" -lt "3" ]; then
472      project_list="clang"
473    else
474      project_list="$projects"
475    fi
476    # During the first phase, there is no need to build any of the runtimes,
477    # since this phase is only meant to get a clang compiler, capable of
478    # building itself and any selected runtimes in the second phase.
479    if [ "$Phase" -lt "2" ]; then
480      runtime_list=""
481      # compiler-rt builtins is needed on AIX to have a functional Phase 1 clang.
482      if [ "$System" = "AIX" ]; then
483        runtime_list="compiler-rt"
484      fi
485    else
486      runtime_list="$runtimes"
487    fi
488
489    echo "# Using C compiler: $c_compiler"
490    echo "# Using C++ compiler: $cxx_compiler"
491
492    cd $ObjDir
493    echo "# Configuring llvm $Release-$RC $Flavor"
494
495    echo "#" env CC="$c_compiler" CXX="$cxx_compiler" \
496        cmake -G "$generator" \
497        -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
498        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
499        -DLLVM_ENABLE_PROJECTS="$project_list" \
500        -DLLVM_LIT_ARGS="-j $NumJobs $LitVerbose" \
501        -DLLVM_ENABLE_RUNTIMES="$runtime_list" \
502        $ExtraConfigureFlags $BuildDir/llvm-project/llvm \
503        2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
504    env CC="$c_compiler" CXX="$cxx_compiler" \
505        cmake -G "$generator" \
506        -DCMAKE_BUILD_TYPE=$BuildType -DLLVM_ENABLE_ASSERTIONS=$Assertions \
507        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
508        -DLLVM_ENABLE_PROJECTS="$project_list" \
509        -DLLVM_LIT_ARGS="-j $NumJobs $LitVerbose" \
510        -DLLVM_ENABLE_RUNTIMES="$runtime_list" \
511        $ExtraConfigureFlags $BuildDir/llvm-project/llvm \
512        2>&1 | tee $LogDir/llvm.configure-Phase$Phase-$Flavor.log
513
514    cd $BuildDir
515}
516
517function build_llvmCore() {
518    Phase="$1"
519    Flavor="$2"
520    ObjDir="$3"
521    DestDir="$4"
522
523    Verbose="VERBOSE=1"
524    if [ ${MAKE} = 'ninja' ]; then
525      Verbose="-v"
526    fi
527    LitVerbose="-v"
528
529    InstallTarget="install"
530    if [ "$Phase" -lt "3" ]; then
531      BuildTarget="clang"
532      InstallTarget="install-clang install-clang-resource-headers"
533      # compiler-rt builtins is needed on AIX to have a functional Phase 1 clang.
534      if [ "$System" = "AIX" ]; then
535        BuildTarget="$BuildTarget runtimes"
536        InstallTarget="$InstallTarget install-builtins"
537      fi
538    fi
539    if [ "$Phase" -eq "3" ]; then
540      # Build everything at once, with the proper parallelism and verbosity,
541      # in Phase 3.
542      BuildTarget=
543    fi
544
545    cd $ObjDir
546    echo "# Compiling llvm $Release-$RC $Flavor"
547    echo "# ${MAKE} $J_ARG $Verbose"
548    ${MAKE} $J_ARG $Verbose $BuildTarget \
549        2>&1 | tee $LogDir/llvm.make-Phase$Phase-$Flavor.log > $redir
550
551    echo "# Installing llvm $Release-$RC $Flavor"
552    echo "# ${MAKE} install"
553    DESTDIR="${DestDir}" ${MAKE} $InstallTarget \
554        2>&1 | tee $LogDir/llvm.install-Phase$Phase-$Flavor.log > $redir
555    cd $BuildDir
556}
557
558function test_llvmCore() {
559    Phase="$1"
560    Flavor="$2"
561    ObjDir="$3"
562
563    KeepGoing="-k"
564    if [ ${MAKE} = 'ninja' ]; then
565      # Ninja doesn't have a documented "keep-going-forever" mode, we need to
566      # set a limit on how many jobs can fail before we give up.
567      KeepGoing="-k 100"
568    fi
569
570    cd $ObjDir
571    if ! ( ${MAKE} $J_ARG $KeepGoing $Verbose check-all \
572        2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
573      deferred_error $Phase $Flavor "check-all failed"
574    fi
575
576    if [ $do_test_suite = 'yes' ]; then
577      cd $TestSuiteBuildDir
578      env CC="$c_compiler" CXX="$cxx_compiler" \
579          cmake $TestSuiteSrcDir -G "$generator" -DTEST_SUITE_LIT=$Lit \
580                -DTEST_SUITE_HOST_CC=$build_compiler
581
582      if ! ( ${MAKE} $J_ARG $KeepGoing $Verbose check \
583          2>&1 | tee $LogDir/llvm.check-Phase$Phase-$Flavor.log ) ; then
584        deferred_error $Phase $Flavor "test suite failed"
585      fi
586    fi
587    cd $BuildDir
588}
589
590# Clean RPATH. Libtool adds the build directory to the search path, which is
591# not necessary --- and even harmful --- for the binary packages we release.
592function clean_RPATH() {
593  if [ "$System" = "Darwin" ] || [ "$System" = "SunOS" ] || [ "$System" = "AIX" ]; then
594    return
595  fi
596  local InstallPath="$1"
597  for Candidate in `find $InstallPath/{bin,lib} -type f`; do
598    if file $Candidate | grep ELF | egrep 'executable|shared object' > /dev/null 2>&1 ; then
599      if rpath=`objdump -x $Candidate | grep 'RPATH'` ; then
600        rpath=`echo $rpath | sed -e's/^ *RPATH *//'`
601        if [ -n "$rpath" ]; then
602          newrpath=`echo $rpath | sed -e's/.*\(\$ORIGIN[^:]*\).*/\1/'`
603          chrpath -r $newrpath $Candidate 2>&1 > /dev/null 2>&1
604        fi
605      fi
606    fi
607  done
608}
609
610# Create a package of the release binaries.
611function package_release() {
612    cwd=`pwd`
613    cd $BuildDir/Phase3/Release
614    mv llvmCore-$Release-$RC.install/usr/local $Package
615    if [ "$use_gzip" = "yes" ]; then
616      tar cf - $Package | gzip -9c > $BuildDir/$Package.tar.gz
617    else
618      tar cf - $Package | xz -9ce -T $NumJobs > $BuildDir/$Package.tar.xz
619    fi
620    mv $Package llvmCore-$Release-$RC.install/usr/local
621    cd $cwd
622}
623
624# Exit if any command fails
625# Note: pipefail is necessary for running build commands through
626# a pipe (i.e. it changes the output of ``false | tee /dev/null ; echo $?``)
627set -e
628set -o pipefail
629
630# Turn off core dumps, as some test cases can easily fill up even the largest
631# file systems.
632ulimit -c 0
633
634if [ "$do_checkout" = "yes" ]; then
635    export_sources
636fi
637
638# Setup the test-suite.  Do this early so we can catch failures before
639# we do the full 3 stage build.
640if [ $do_test_suite = "yes" ]; then
641  check_program_exists 'python3'
642  venv="python3 -m venv"
643
644  SandboxDir="$BuildDir/sandbox"
645  Lit=$SandboxDir/bin/lit
646  TestSuiteBuildDir="$BuildDir/test-suite-build"
647  TestSuiteSrcDir="$BuildDir/llvm-test-suite"
648
649  ${venv} $SandboxDir
650  $SandboxDir/bin/python -m pip install $BuildDir/llvm-project/llvm/utils/lit
651  mkdir -p $TestSuiteBuildDir
652fi
653
654if [ "$do_cmake_cache" = "yes" ]; then
655  build_with_cmake_cache
656  exit 0
657fi
658
659(
660
661Flavors="Release"
662if [ "$do_debug" = "yes" ]; then
663    Flavors="Debug $Flavors"
664fi
665if [ "$do_asserts" = "yes" ]; then
666    Flavors="$Flavors Release+Asserts"
667fi
668
669for Flavor in $Flavors ; do
670    echo ""
671    echo ""
672    echo "********************************************************************************"
673    echo "  Release:     $Release-$RC"
674    echo "  Build:       $Flavor"
675    echo "  System Info: "
676    echo "    `uname -a`"
677    echo "********************************************************************************"
678    echo ""
679
680    c_compiler="$CC"
681    cxx_compiler="$CXX"
682    build_compiler="$CC"
683    [[ -z "$build_compiler" ]] && build_compiler="cc"
684    llvmCore_phase1_objdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.obj
685    llvmCore_phase1_destdir=$BuildDir/Phase1/$Flavor/llvmCore-$Release-$RC.install
686
687    llvmCore_phase2_objdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.obj
688    llvmCore_phase2_destdir=$BuildDir/Phase2/$Flavor/llvmCore-$Release-$RC.install
689
690    llvmCore_phase3_objdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.obj
691    llvmCore_phase3_destdir=$BuildDir/Phase3/$Flavor/llvmCore-$Release-$RC.install
692
693    rm -rf $llvmCore_phase1_objdir
694    rm -rf $llvmCore_phase1_destdir
695
696    rm -rf $llvmCore_phase2_objdir
697    rm -rf $llvmCore_phase2_destdir
698
699    rm -rf $llvmCore_phase3_objdir
700    rm -rf $llvmCore_phase3_destdir
701
702    mkdir -p $llvmCore_phase1_objdir
703    mkdir -p $llvmCore_phase1_destdir
704
705    mkdir -p $llvmCore_phase2_objdir
706    mkdir -p $llvmCore_phase2_destdir
707
708    mkdir -p $llvmCore_phase3_objdir
709    mkdir -p $llvmCore_phase3_destdir
710
711    ############################################################################
712    # Phase 1: Build llvmCore and clang
713    echo "# Phase 1: Building llvmCore"
714    configure_llvmCore 1 $Flavor $llvmCore_phase1_objdir
715    build_llvmCore 1 $Flavor \
716        $llvmCore_phase1_objdir $llvmCore_phase1_destdir
717    clean_RPATH $llvmCore_phase1_destdir/usr/local
718
719    ########################################################################
720    # Phase 2: Build llvmCore with newly built clang from phase 1.
721    c_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang
722    cxx_compiler=$llvmCore_phase1_destdir/usr/local/bin/clang++
723    echo "# Phase 2: Building llvmCore"
724    configure_llvmCore 2 $Flavor $llvmCore_phase2_objdir
725    build_llvmCore 2 $Flavor \
726        $llvmCore_phase2_objdir $llvmCore_phase2_destdir
727    clean_RPATH $llvmCore_phase2_destdir/usr/local
728
729    ########################################################################
730    # Phase 3: Build llvmCore with newly built clang from phase 2.
731    c_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang
732    cxx_compiler=$llvmCore_phase2_destdir/usr/local/bin/clang++
733    echo "# Phase 3: Building llvmCore"
734    configure_llvmCore 3 $Flavor $llvmCore_phase3_objdir
735    build_llvmCore 3 $Flavor \
736        $llvmCore_phase3_objdir $llvmCore_phase3_destdir
737    clean_RPATH $llvmCore_phase3_destdir/usr/local
738
739    ########################################################################
740    # Testing: Test phase 3
741    c_compiler=$llvmCore_phase3_destdir/usr/local/bin/clang
742    cxx_compiler=$llvmCore_phase3_destdir/usr/local/bin/clang++
743    echo "# Testing - built with clang"
744    test_llvmCore 3 $Flavor $llvmCore_phase3_objdir
745
746    ########################################################################
747    # Compare .o files between Phase2 and Phase3 and report which ones
748    # differ.
749    if [ "$do_compare" = "yes" ]; then
750        echo
751        echo "# Comparing Phase 2 and Phase 3 files"
752        for p2 in `find $llvmCore_phase2_objdir -name '*.o'` ; do
753            p3=`echo $p2 | sed -e 's,Phase2,Phase3,'`
754            # Substitute 'Phase2' for 'Phase3' in the Phase 2 object file in
755            # case there are build paths in the debug info. Do the same sub-
756            # stitution on both files in case the string occurrs naturally.
757            if ! cmp -s \
758                <(env LC_ALL=C sed -e 's,Phase1,Phase2,g' -e 's,Phase2,Phase3,g' $p2) \
759                <(env LC_ALL=C sed -e 's,Phase1,Phase2,g' -e 's,Phase2,Phase3,g' $p3) \
760                16 16; then
761                echo "file `basename $p2` differs between phase 2 and phase 3"
762            fi
763        done
764    fi
765done
766
767) 2>&1 | tee $LogDir/testing.$Release-$RC.log
768
769if [ "$use_gzip" = "yes" ]; then
770  echo "# Packaging the release as $Package.tar.gz"
771else
772  echo "# Packaging the release as $Package.tar.xz"
773fi
774package_release
775
776set +e
777
778# Woo hoo!
779echo "### Testing Finished ###"
780echo "### Logs: $LogDir"
781
782echo "### Errors:"
783if [ -s "$LogDir/deferred_errors.log" ]; then
784  cat "$LogDir/deferred_errors.log"
785  exit 1
786else
787  echo "None."
788fi
789
790exit 0
791