Don't add extra app list launcher page webviews.
[chromium-blink-merge.git] / tools / clang / scripts / update.sh
blob32d2ead5a66b502c77b31f922c526ca8d6c25caa
1 #!/usr/bin/env bash
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 # This script will check out llvm and clang into third_party/llvm and build it.
8 # Do NOT CHANGE this if you don't know what you're doing -- see
9 # https://code.google.com/p/chromium/wiki/UpdatingClang
10 # Reverting problematic clang rolls is safe, though.
11 CLANG_REVISION=233105
13 # This is incremented when pushing a new build of Clang at the same revision.
14 CLANG_SUB_REVISION=1
16 PACKAGE_VERSION="${CLANG_REVISION}-${CLANG_SUB_REVISION}"
18 THIS_DIR="$(dirname "${0}")"
19 LLVM_DIR="${THIS_DIR}/../../../third_party/llvm"
20 LLVM_BUILD_DIR="${LLVM_DIR}/../llvm-build/Release+Asserts"
21 COMPILER_RT_BUILD_DIR="${LLVM_DIR}/../llvm-build/compiler-rt"
22 LLVM_BOOTSTRAP_DIR="${LLVM_DIR}/../llvm-bootstrap"
23 LLVM_BOOTSTRAP_INSTALL_DIR="${LLVM_DIR}/../llvm-bootstrap-install"
24 CLANG_DIR="${LLVM_DIR}/tools/clang"
25 COMPILER_RT_DIR="${LLVM_DIR}/compiler-rt"
26 LIBCXX_DIR="${LLVM_DIR}/projects/libcxx"
27 LIBCXXABI_DIR="${LLVM_DIR}/projects/libcxxabi"
28 ANDROID_NDK_DIR="${THIS_DIR}/../../../third_party/android_tools/ndk"
29 STAMP_FILE="${LLVM_DIR}/../llvm-build/cr_build_revision"
30 CHROMIUM_TOOLS_DIR="${THIS_DIR}/.."
31 BINUTILS_DIR="${THIS_DIR}/../../../third_party/binutils"
33 ABS_CHROMIUM_TOOLS_DIR="${PWD}/${CHROMIUM_TOOLS_DIR}"
34 ABS_LIBCXX_DIR="${PWD}/${LIBCXX_DIR}"
35 ABS_LIBCXXABI_DIR="${PWD}/${LIBCXXABI_DIR}"
36 ABS_LLVM_DIR="${PWD}/${LLVM_DIR}"
37 ABS_LLVM_BUILD_DIR="${PWD}/${LLVM_BUILD_DIR}"
38 ABS_COMPILER_RT_DIR="${PWD}/${COMPILER_RT_DIR}"
39 ABS_BINUTILS_DIR="${PWD}/${BINUTILS_DIR}"
41 # ${A:-a} returns $A if it's set, a else.
42 LLVM_REPO_URL=${LLVM_URL:-https://llvm.org/svn/llvm-project}
44 CDS_URL=https://commondatastorage.googleapis.com/chromium-browser-clang
46 if [[ -z "$GYP_DEFINES" ]]; then
47 GYP_DEFINES=
49 if [[ -z "$GYP_GENERATORS" ]]; then
50 GYP_GENERATORS=
54 # Die if any command dies, error on undefined variable expansions.
55 set -eu
58 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
59 # Use a real version number rather than HEAD to make sure that
60 # --print-revision, stamp file logic, etc. all works naturally.
61 CLANG_REVISION=$(svn info "$LLVM_REPO_URL" \
62 | grep 'Last Changed Rev' | awk '{ printf $4; }')
63 PACKAGE_VERSION="${CLANG_REVISION}-0"
66 # Use both the clang revision and the plugin revisions to test for updates.
67 BLINKGCPLUGIN_REVISION=\
68 $(grep 'set(LIBRARYNAME' "$THIS_DIR"/../blink_gc_plugin/CMakeLists.txt \
69 | cut -d ' ' -f 2 | tr -cd '[0-9]')
70 CLANG_AND_PLUGINS_REVISION="${CLANG_REVISION}-${BLINKGCPLUGIN_REVISION}"
73 OS="$(uname -s)"
75 # Parse command line options.
76 if_needed=
77 force_local_build=
78 run_tests=
79 bootstrap=
80 with_android=yes
81 chrome_tools="plugins;blink_gc_plugin"
82 gcc_toolchain=
83 with_patches=yes
85 if [[ "${OS}" = "Darwin" ]]; then
86 with_android=
89 while [[ $# > 0 ]]; do
90 case $1 in
91 --bootstrap)
92 bootstrap=yes
94 --if-needed)
95 if_needed=yes
97 --force-local-build)
98 force_local_build=yes
100 --print-revision)
101 echo $PACKAGE_VERSION
102 exit 0
104 --run-tests)
105 run_tests=yes
107 --without-android)
108 with_android=
110 --without-patches)
111 with_patches=
113 --with-chrome-tools)
114 shift
115 if [[ $# == 0 ]]; then
116 echo "--with-chrome-tools requires an argument."
117 exit 1
119 chrome_tools=$1
121 --gcc-toolchain)
122 shift
123 if [[ $# == 0 ]]; then
124 echo "--gcc-toolchain requires an argument."
125 exit 1
127 if [[ -x "$1/bin/gcc" ]]; then
128 gcc_toolchain=$1
129 else
130 echo "Invalid --gcc-toolchain: '$1'."
131 echo "'$1/bin/gcc' does not appear to be valid."
132 exit 1
136 --help)
137 echo "usage: $0 [--force-local-build] [--if-needed] [--run-tests] "
138 echo "--bootstrap: First build clang with CC, then with itself."
139 echo "--force-local-build: Don't try to download prebuilt binaries."
140 echo "--if-needed: Download clang only if the script thinks it is needed."
141 echo "--run-tests: Run tests after building. Only for local builds."
142 echo "--print-revision: Print current clang revision and exit."
143 echo "--without-android: Don't build ASan Android runtime library."
144 echo "--with-chrome-tools: Select which chrome tools to build." \
145 "Defaults to plugins;blink_gc_plugin."
146 echo " Example: --with-chrome-tools plugins;empty-string"
147 echo "--gcc-toolchain: Set the prefix for which GCC version should"
148 echo " be used for building. For example, to use gcc in"
149 echo " /opt/foo/bin/gcc, use '--gcc-toolchain '/opt/foo"
150 echo "--without-patches: Don't apply local patches."
151 echo
152 exit 1
155 echo "Unknown argument: '$1'."
156 echo "Use --help for help."
157 exit 1
159 esac
160 shift
161 done
163 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
164 force_local_build=yes
166 # Skip local patches when using HEAD: they probably don't apply anymore.
167 with_patches=
169 if ! [[ "$GYP_DEFINES" =~ .*OS=android.* ]]; then
170 # Only build the Android ASan rt when targetting Android.
171 with_android=
174 LLVM_BUILD_TOOLS_DIR="${ABS_LLVM_DIR}/../llvm-build-tools"
176 if [[ "${OS}" == "Linux" ]] && [[ -z "${gcc_toolchain}" ]]; then
177 if [[ $(gcc -dumpversion) < "4.7.0" ]]; then
178 # We need a newer GCC version.
179 if [[ ! -e "${LLVM_BUILD_TOOLS_DIR}/gcc482" ]]; then
180 echo "Downloading pre-built GCC 4.8.2..."
181 mkdir -p "${LLVM_BUILD_TOOLS_DIR}"
182 curl --fail -L "${CDS_URL}/tools/gcc482.tgz" | \
183 tar zxf - -C "${LLVM_BUILD_TOOLS_DIR}"
184 echo Done
186 gcc_toolchain="${LLVM_BUILD_TOOLS_DIR}/gcc482"
187 else
188 # Always set gcc_toolchain; llvm-symbolizer needs the bundled libstdc++.
189 gcc_toolchain="$(dirname $(dirname $(which gcc)))"
193 if [[ "${OS}" == "Linux" || "${OS}" == "Darwin" ]]; then
194 if [[ $(cmake --version | grep -Eo '[0-9.]+') < "3.0" ]]; then
195 # We need a newer CMake version.
196 if [[ ! -e "${LLVM_BUILD_TOOLS_DIR}/cmake310" ]]; then
197 echo "Downloading pre-built CMake 3.10..."
198 mkdir -p "${LLVM_BUILD_TOOLS_DIR}"
199 curl --fail -L "${CDS_URL}/tools/cmake310_${OS}.tgz" | \
200 tar zxf - -C "${LLVM_BUILD_TOOLS_DIR}"
201 echo Done
203 export PATH="${LLVM_BUILD_TOOLS_DIR}/cmake310/bin:${PATH}"
207 echo "LLVM_FORCE_HEAD_REVISION was set; using r${CLANG_REVISION}"
210 if [[ -n "$if_needed" ]]; then
211 if [[ "${OS}" == "Darwin" ]]; then
212 # clang is used on Mac.
213 true
214 elif [[ "$GYP_DEFINES" =~ .*(clang|tsan|asan|lsan|msan)=1.* ]]; then
215 # clang requested via $GYP_DEFINES.
216 true
217 elif [[ -d "${LLVM_BUILD_DIR}" ]]; then
218 # clang previously downloaded, remove third_party/llvm-build to prevent
219 # updating.
220 true
221 elif [[ "${OS}" == "Linux" ]]; then
222 # Temporarily use clang on linux. Leave a stamp file behind, so that
223 # this script can remove clang again on machines where it was autoinstalled.
224 mkdir -p "${LLVM_BUILD_DIR}"
225 touch "${LLVM_BUILD_DIR}/autoinstall_stamp"
226 true
227 else
228 # clang wasn't needed, not doing anything.
229 exit 0
234 # Check if there's anything to be done, exit early if not.
235 if [[ -f "${STAMP_FILE}" ]]; then
236 PREVIOUSLY_BUILT_REVISON=$(cat "${STAMP_FILE}")
237 if [[ -z "$force_local_build" ]] && \
238 [[ "${PREVIOUSLY_BUILT_REVISON}" = \
239 "${PACKAGE_VERSION}" ]]; then
240 echo "Clang already at ${PACKAGE_VERSION}"
241 exit 0
244 # To always force a new build if someone interrupts their build half way.
245 rm -f "${STAMP_FILE}"
248 if [[ -z "$force_local_build" ]]; then
249 # Check if there's a prebuilt binary and if so just fetch that. That's faster,
250 # and goma relies on having matching binary hashes on client and server too.
251 CDS_FILE="clang-${PACKAGE_VERSION}.tgz"
252 CDS_OUT_DIR=$(mktemp -d -t clang_download.XXXXXX)
253 CDS_OUTPUT="${CDS_OUT_DIR}/${CDS_FILE}"
254 if [ "${OS}" = "Linux" ]; then
255 CDS_FULL_URL="${CDS_URL}/Linux_x64/${CDS_FILE}"
256 elif [ "${OS}" = "Darwin" ]; then
257 CDS_FULL_URL="${CDS_URL}/Mac/${CDS_FILE}"
259 echo Trying to download prebuilt clang
260 if which curl > /dev/null; then
261 curl -L --fail "${CDS_FULL_URL}" -o "${CDS_OUTPUT}" || \
262 rm -rf "${CDS_OUT_DIR}"
263 elif which wget > /dev/null; then
264 wget "${CDS_FULL_URL}" -O "${CDS_OUTPUT}" || rm -rf "${CDS_OUT_DIR}"
265 else
266 echo "Neither curl nor wget found. Please install one of these."
267 exit 1
269 if [ -f "${CDS_OUTPUT}" ]; then
270 rm -rf "${LLVM_BUILD_DIR}"
271 mkdir -p "${LLVM_BUILD_DIR}"
272 tar -xzf "${CDS_OUTPUT}" -C "${LLVM_BUILD_DIR}"
273 echo clang "${PACKAGE_VERSION}" unpacked
274 echo "${PACKAGE_VERSION}" > "${STAMP_FILE}"
275 rm -rf "${CDS_OUT_DIR}"
276 exit 0
277 else
278 echo Did not find prebuilt clang "${PACKAGE_VERSION}", building
282 if [[ -n "${with_android}" ]] && ! [[ -d "${ANDROID_NDK_DIR}" ]]; then
283 echo "Android NDK not found at ${ANDROID_NDK_DIR}"
284 echo "The Android NDK is needed to build a Clang whose -fsanitize=address"
285 echo "works on Android. See "
286 echo "http://code.google.com/p/chromium/wiki/AndroidBuildInstructions for how"
287 echo "to install the NDK, or pass --without-android."
288 exit 1
291 # Check that cmake and ninja are available.
292 if ! which cmake > /dev/null; then
293 echo "CMake needed to build clang; please install"
294 exit 1
296 if ! which ninja > /dev/null; then
297 echo "ninja needed to build clang, please install"
298 exit 1
301 echo Reverting previously patched files
302 for i in \
303 "${CLANG_DIR}/test/Index/crash-recovery-modules.m" \
304 "${CLANG_DIR}/unittests/libclang/LibclangTest.cpp" \
305 "${COMPILER_RT_DIR}/lib/asan/asan_rtl.cc" \
306 "${COMPILER_RT_DIR}/test/asan/TestCases/Linux/new_array_cookie_test.cc" \
307 "${LLVM_DIR}/test/DebugInfo/gmlt.ll" \
308 "${LLVM_DIR}/lib/CodeGen/SpillPlacement.cpp" \
309 "${LLVM_DIR}/lib/CodeGen/SpillPlacement.h" \
310 "${LLVM_DIR}/lib/Transforms/Instrumentation/MemorySanitizer.cpp" \
311 "${CLANG_DIR}/test/Driver/env.c" \
312 "${CLANG_DIR}/lib/Frontend/InitPreprocessor.cpp" \
313 "${CLANG_DIR}/test/Frontend/exceptions.c" \
314 "${CLANG_DIR}/test/Preprocessor/predefined-exceptions.m" \
315 "${LLVM_DIR}/test/Bindings/Go/go.test" \
316 "${CLANG_DIR}/lib/Parse/ParseExpr.cpp" \
317 "${CLANG_DIR}/lib/Parse/ParseTemplate.cpp" \
318 "${CLANG_DIR}/lib/Sema/SemaDeclCXX.cpp" \
319 "${CLANG_DIR}/lib/Sema/SemaExprCXX.cpp" \
320 "${CLANG_DIR}/test/SemaCXX/default2.cpp" \
321 "${CLANG_DIR}/test/SemaCXX/typo-correction-delayed.cpp" \
322 "${COMPILER_RT_DIR}/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc" \
323 "${COMPILER_RT_DIR}/test/tsan/signal_segv_handler.cc" \
324 ; do
325 if [[ -e "${i}" ]]; then
326 rm -f "${i}" # For unversioned files.
327 svn revert "${i}"
329 done
331 echo Remove the Clang tools shim dir
332 CHROME_TOOLS_SHIM_DIR=${ABS_LLVM_DIR}/tools/chrometools
333 rm -rfv ${CHROME_TOOLS_SHIM_DIR}
335 echo Getting LLVM r"${CLANG_REVISION}" in "${LLVM_DIR}"
336 if ! svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" \
337 "${LLVM_DIR}"; then
338 echo Checkout failed, retrying
339 rm -rf "${LLVM_DIR}"
340 svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" "${LLVM_DIR}"
343 echo Getting clang r"${CLANG_REVISION}" in "${CLANG_DIR}"
344 svn co --force "${LLVM_REPO_URL}/cfe/trunk@${CLANG_REVISION}" "${CLANG_DIR}"
346 # We have moved from building compiler-rt in the LLVM tree, to a separate
347 # directory. Nuke any previous checkout to avoid building it.
348 rm -rf "${LLVM_DIR}/projects/compiler-rt"
350 echo Getting compiler-rt r"${CLANG_REVISION}" in "${COMPILER_RT_DIR}"
351 svn co --force "${LLVM_REPO_URL}/compiler-rt/trunk@${CLANG_REVISION}" \
352 "${COMPILER_RT_DIR}"
354 # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes
355 # (i.e. this is needed for bootstrap builds).
356 if [ "${OS}" = "Darwin" ]; then
357 echo Getting libc++ r"${CLANG_REVISION}" in "${LIBCXX_DIR}"
358 svn co --force "${LLVM_REPO_URL}/libcxx/trunk@${CLANG_REVISION}" \
359 "${LIBCXX_DIR}"
362 # While we're bundling our own libc++ on OS X, we need to compile libc++abi
363 # into it too (since OS X 10.6 doesn't have libc++abi.dylib either).
364 if [ "${OS}" = "Darwin" ]; then
365 echo Getting libc++abi r"${CLANG_REVISION}" in "${LIBCXXABI_DIR}"
366 svn co --force "${LLVM_REPO_URL}/libcxxabi/trunk@${CLANG_REVISION}" \
367 "${LIBCXXABI_DIR}"
370 if [[ -n "$with_patches" ]]; then
372 # Apply patch for tests failing with --disable-pthreads (llvm.org/PR11974)
373 pushd "${CLANG_DIR}"
374 cat << 'EOF' |
375 --- third_party/llvm/tools/clang/test/Index/crash-recovery-modules.m (revision 202554)
376 +++ third_party/llvm/tools/clang/test/Index/crash-recovery-modules.m (working copy)
377 @@ -12,6 +12,8 @@
379 // REQUIRES: crash-recovery
380 // REQUIRES: shell
381 +// XFAIL: *
382 +// (PR11974)
384 @import Crash;
386 patch -p4
387 popd
389 pushd "${CLANG_DIR}"
390 cat << 'EOF' |
391 --- unittests/libclang/LibclangTest.cpp (revision 215949)
392 +++ unittests/libclang/LibclangTest.cpp (working copy)
393 @@ -431,7 +431,7 @@
394 EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU));
397 -TEST_F(LibclangReparseTest, ReparseWithModule) {
398 +TEST_F(LibclangReparseTest, DISABLED_ReparseWithModule) {
399 const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;";
400 const char *HeaderBottom = "\n};\n#endif\n";
401 const char *MFile = "#include \"HeaderFile.h\"\nint main() {"
403 patch -p0
404 popd
406 # This Go bindings test doesn't work after the bootstrap build on Linux. (PR21552)
407 pushd "${LLVM_DIR}"
408 cat << 'EOF' |
409 Index: test/Bindings/Go/go.test
410 ===================================================================
411 --- test/Bindings/Go/go.test (revision 223109)
412 +++ test/Bindings/Go/go.test (working copy)
413 @@ -1,3 +1,3 @@
414 -; RUN: llvm-go test llvm.org/llvm/bindings/go/llvm
415 +; RUN: true
417 ; REQUIRES: shell
419 patch -p0
420 popd
425 # Echo all commands.
426 set -x
428 # Set default values for CC and CXX if they're not set in the environment.
429 CC=${CC:-cc}
430 CXX=${CXX:-c++}
432 if [[ -n "${gcc_toolchain}" ]]; then
433 # Use the specified gcc installation for building.
434 CC="$gcc_toolchain/bin/gcc"
435 CXX="$gcc_toolchain/bin/g++"
436 # Set LD_LIBRARY_PATH to make auxiliary targets (tablegen, bootstrap compiler,
437 # etc.) find the .so.
438 export LD_LIBRARY_PATH="$(dirname $(${CXX} -print-file-name=libstdc++.so.6))"
441 CFLAGS=""
442 CXXFLAGS=""
443 LDFLAGS=""
445 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is
446 # needed, on OS X it requires libc++. clang only automatically links to libc++
447 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run on
448 # OS X versions as old as 10.7.
449 # TODO(thakis): Some bots are still on 10.6, so for now bundle libc++.dylib.
450 # Remove this once all bots are on 10.7+, then use --enable-libcpp=yes and
451 # change deployment_target to 10.7.
452 deployment_target=""
454 if [ "${OS}" = "Darwin" ]; then
455 # When building on 10.9, /usr/include usually doesn't exist, and while
456 # Xcode's clang automatically sets a sysroot, self-built clangs don't.
457 CFLAGS="-isysroot $(xcrun --show-sdk-path)"
458 CPPFLAGS="${CFLAGS}"
459 CXXFLAGS="-stdlib=libc++ -nostdinc++ -I${ABS_LIBCXX_DIR}/include ${CFLAGS}"
461 if [[ -n "${bootstrap}" ]]; then
462 deployment_target=10.6
466 # Build bootstrap clang if requested.
467 if [[ -n "${bootstrap}" ]]; then
468 ABS_INSTALL_DIR="${PWD}/${LLVM_BOOTSTRAP_INSTALL_DIR}"
469 echo "Building bootstrap compiler"
470 mkdir -p "${LLVM_BOOTSTRAP_DIR}"
471 pushd "${LLVM_BOOTSTRAP_DIR}"
473 cmake -GNinja \
474 -DCMAKE_BUILD_TYPE=Release \
475 -DLLVM_ENABLE_ASSERTIONS=ON \
476 -DLLVM_TARGETS_TO_BUILD=host \
477 -DLLVM_ENABLE_THREADS=OFF \
478 -DCMAKE_INSTALL_PREFIX="${ABS_INSTALL_DIR}" \
479 -DCMAKE_C_COMPILER="${CC}" \
480 -DCMAKE_CXX_COMPILER="${CXX}" \
481 -DCMAKE_C_FLAGS="${CFLAGS}" \
482 -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
483 ../llvm
485 ninja
486 if [[ -n "${run_tests}" ]]; then
487 ninja check-all
490 ninja install
491 if [[ -n "${gcc_toolchain}" ]]; then
492 # Copy that gcc's stdlibc++.so.6 to the build dir, so the bootstrap
493 # compiler can start.
494 cp -v "$(${CXX} -print-file-name=libstdc++.so.6)" \
495 "${ABS_INSTALL_DIR}/lib/"
498 popd
499 CC="${ABS_INSTALL_DIR}/bin/clang"
500 CXX="${ABS_INSTALL_DIR}/bin/clang++"
502 if [[ -n "${gcc_toolchain}" ]]; then
503 # Tell the bootstrap compiler to use a specific gcc prefix to search
504 # for standard library headers and shared object file.
505 CFLAGS="--gcc-toolchain=${gcc_toolchain}"
506 CXXFLAGS="--gcc-toolchain=${gcc_toolchain}"
509 echo "Building final compiler"
512 # Build clang (in a separate directory).
513 # The clang bots have this path hardcoded in built/scripts/slave/compile.py,
514 # so if you change it you also need to change these links.
515 mkdir -p "${LLVM_BUILD_DIR}"
516 pushd "${LLVM_BUILD_DIR}"
518 # Build libc++.dylib while some bots are still on OS X 10.6.
519 if [ "${OS}" = "Darwin" ]; then
520 rm -rf libcxxbuild
521 LIBCXXFLAGS="-O3 -std=c++11 -fstrict-aliasing"
523 # libcxx and libcxxabi both have a file stdexcept.cpp, so put their .o files
524 # into different subdirectories.
525 mkdir -p libcxxbuild/libcxx
526 pushd libcxxbuild/libcxx
527 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXX_DIR}"/src/*.cpp
528 popd
530 mkdir -p libcxxbuild/libcxxabi
531 pushd libcxxbuild/libcxxabi
532 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXXABI_DIR}"/src/*.cpp -I"${ABS_LIBCXXABI_DIR}/include"
533 popd
535 pushd libcxxbuild
536 ${CC:-cc} libcxx/*.o libcxxabi/*.o -o libc++.1.dylib -dynamiclib \
537 -nodefaultlibs -current_version 1 -compatibility_version 1 \
538 -lSystem -install_name @executable_path/libc++.dylib \
539 -Wl,-unexported_symbols_list,${ABS_LIBCXX_DIR}/lib/libc++unexp.exp \
540 -Wl,-force_symbols_not_weak_list,${ABS_LIBCXX_DIR}/lib/notweak.exp \
541 -Wl,-force_symbols_weak_list,${ABS_LIBCXX_DIR}/lib/weak.exp
542 ln -sf libc++.1.dylib libc++.dylib
543 popd
544 LDFLAGS+="-stdlib=libc++ -L${PWD}/libcxxbuild"
547 # Find the binutils include dir for the gold plugin.
548 BINUTILS_INCDIR=""
549 if [ "${OS}" = "Linux" ]; then
550 BINUTILS_INCDIR="${ABS_BINUTILS_DIR}/Linux_x64/Release/include"
553 # Hook the Chromium tools into the LLVM build. Several Chromium tools have
554 # dependencies on LLVM/Clang libraries. The LLVM build detects implicit tools
555 # in the tools subdirectory, so install a shim CMakeLists.txt that forwards to
556 # the real directory for the Chromium tools.
557 # Note that the shim directory name intentionally has no _ or _. The implicit
558 # tool detection logic munges them in a weird way.
559 mkdir -v ${CHROME_TOOLS_SHIM_DIR}
560 cat > ${CHROME_TOOLS_SHIM_DIR}/CMakeLists.txt << EOF
561 # Since tools/clang isn't actually a subdirectory, use the two argument version
562 # to specify where build artifacts go. CMake doesn't allow reusing the same
563 # binary dir for multiple source dirs, so the build artifacts have to go into a
564 # subdirectory...
565 add_subdirectory(\${CHROMIUM_TOOLS_SRC} \${CMAKE_CURRENT_BINARY_DIR}/a)
567 rm -fv CMakeCache.txt
568 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
569 -DCMAKE_BUILD_TYPE=Release \
570 -DLLVM_ENABLE_ASSERTIONS=ON \
571 -DLLVM_ENABLE_THREADS=OFF \
572 -DLLVM_BINUTILS_INCDIR="${BINUTILS_INCDIR}" \
573 -DCMAKE_C_COMPILER="${CC}" \
574 -DCMAKE_CXX_COMPILER="${CXX}" \
575 -DCMAKE_C_FLAGS="${CFLAGS}" \
576 -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
577 -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}" \
578 -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \
579 -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" \
580 -DCMAKE_INSTALL_PREFIX="${ABS_LLVM_BUILD_DIR}" \
581 -DCHROMIUM_TOOLS_SRC="${ABS_CHROMIUM_TOOLS_DIR}" \
582 -DCHROMIUM_TOOLS="${chrome_tools}" \
583 "${ABS_LLVM_DIR}"
586 if [[ -n "${gcc_toolchain}" ]]; then
587 # Copy in the right stdlibc++.so.6 so clang can start.
588 mkdir -p lib
589 cp -v "$(${CXX} ${CXXFLAGS} -print-file-name=libstdc++.so.6)" lib/
592 ninja
593 # If any Chromium tools were built, install those now.
594 if [[ -n "${chrome_tools}" ]]; then
595 ninja cr-install
598 STRIP_FLAGS=
599 if [ "${OS}" = "Darwin" ]; then
600 # See http://crbug.com/256342
601 STRIP_FLAGS=-x
603 cp libcxxbuild/libc++.1.dylib bin/
605 strip ${STRIP_FLAGS} bin/clang
606 popd
608 # Build compiler-rt out-of-tree.
609 mkdir -p "${COMPILER_RT_BUILD_DIR}"
610 pushd "${COMPILER_RT_BUILD_DIR}"
612 rm -fv CMakeCache.txt
613 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
614 -DCMAKE_BUILD_TYPE=Release \
615 -DLLVM_ENABLE_ASSERTIONS=ON \
616 -DLLVM_ENABLE_THREADS=OFF \
617 -DCMAKE_C_COMPILER="${CC}" \
618 -DCMAKE_CXX_COMPILER="${CXX}" \
619 -DLLVM_CONFIG_PATH="${ABS_LLVM_BUILD_DIR}/bin/llvm-config" \
620 "${ABS_COMPILER_RT_DIR}"
622 ninja
624 # Copy selected output to the main tree.
625 # Darwin doesn't support cp --parents, so pipe through tar instead.
626 CLANG_VERSION=$("${ABS_LLVM_BUILD_DIR}/bin/clang" --version | \
627 sed -ne 's/clang version \([0-9]\.[0-9]\.[0-9]\).*/\1/p')
628 ABS_LLVM_CLANG_LIB_DIR="${ABS_LLVM_BUILD_DIR}/lib/clang/${CLANG_VERSION}"
629 tar -c *blacklist.txt | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
630 tar -c include/sanitizer | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
631 if [[ "${OS}" = "Darwin" ]]; then
632 tar -c lib/darwin | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
633 else
634 tar -c lib/linux | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
637 popd
639 if [[ -n "${with_android}" ]]; then
640 # Make a standalone Android toolchain.
641 ${ANDROID_NDK_DIR}/build/tools/make-standalone-toolchain.sh \
642 --platform=android-14 \
643 --install-dir="${LLVM_BUILD_DIR}/android-toolchain" \
644 --system=linux-x86_64 \
645 --stl=stlport \
646 --toolchain=arm-linux-androideabi-4.9
648 # Android NDK r9d copies a broken unwind.h into the toolchain, see
649 # http://crbug.com/357890
650 rm -v "${LLVM_BUILD_DIR}"/android-toolchain/include/c++/*/unwind.h
652 # Build ASan runtime for Android in a separate build tree.
653 mkdir -p ${LLVM_BUILD_DIR}/android
654 pushd ${LLVM_BUILD_DIR}/android
655 rm -fv CMakeCache.txt
656 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
657 -DCMAKE_BUILD_TYPE=Release \
658 -DLLVM_ENABLE_ASSERTIONS=ON \
659 -DLLVM_ENABLE_THREADS=OFF \
660 -DCMAKE_C_COMPILER=${PWD}/../bin/clang \
661 -DCMAKE_CXX_COMPILER=${PWD}/../bin/clang++ \
662 -DLLVM_CONFIG_PATH=${PWD}/../bin/llvm-config \
663 -DCMAKE_C_FLAGS="--target=arm-linux-androideabi --sysroot=${PWD}/../android-toolchain/sysroot -B${PWD}/../android-toolchain" \
664 -DCMAKE_CXX_FLAGS="--target=arm-linux-androideabi --sysroot=${PWD}/../android-toolchain/sysroot -B${PWD}/../android-toolchain" \
665 -DANDROID=1 \
666 "${ABS_COMPILER_RT_DIR}"
667 ninja libclang_rt.asan-arm-android.so
669 # And copy it into the main build tree.
670 cp "$(find -name libclang_rt.asan-arm-android.so)" "${ABS_LLVM_CLANG_LIB_DIR}/lib/linux/"
671 popd
674 if [[ -n "$run_tests" ]]; then
675 # Run Chrome tool tests.
676 ninja -C "${LLVM_BUILD_DIR}" cr-check-all
677 # Run the LLVM and Clang tests.
678 ninja -C "${LLVM_BUILD_DIR}" check-all
681 # After everything is done, log success for this revision.
682 echo "${PACKAGE_VERSION}" > "${STAMP_FILE}"