ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / tools / clang / scripts / update.sh
blob798f7d2b8626f9317e8e556d390474f69cb07dd1
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=230914
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}/.."
32 ABS_CHROMIUM_TOOLS_DIR="${PWD}/${CHROMIUM_TOOLS_DIR}"
33 ABS_LIBCXX_DIR="${PWD}/${LIBCXX_DIR}"
34 ABS_LIBCXXABI_DIR="${PWD}/${LIBCXXABI_DIR}"
35 ABS_LLVM_DIR="${PWD}/${LLVM_DIR}"
36 ABS_LLVM_BUILD_DIR="${PWD}/${LLVM_BUILD_DIR}"
37 ABS_COMPILER_RT_DIR="${PWD}/${COMPILER_RT_DIR}"
39 # ${A:-a} returns $A if it's set, a else.
40 LLVM_REPO_URL=${LLVM_URL:-https://llvm.org/svn/llvm-project}
42 if [[ -z "$GYP_DEFINES" ]]; then
43 GYP_DEFINES=
45 if [[ -z "$GYP_GENERATORS" ]]; then
46 GYP_GENERATORS=
50 # Die if any command dies, error on undefined variable expansions.
51 set -eu
54 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
55 # Use a real version number rather than HEAD to make sure that
56 # --print-revision, stamp file logic, etc. all works naturally.
57 CLANG_REVISION=$(svn info "$LLVM_REPO_URL" \
58 | grep 'Last Changed Rev' | awk '{ printf $4; }')
61 # Use both the clang revision and the plugin revisions to test for updates.
62 BLINKGCPLUGIN_REVISION=\
63 $(grep 'set(LIBRARYNAME' "$THIS_DIR"/../blink_gc_plugin/CMakeLists.txt \
64 | cut -d ' ' -f 2 | tr -cd '[0-9]')
65 CLANG_AND_PLUGINS_REVISION="${CLANG_REVISION}-${BLINKGCPLUGIN_REVISION}"
68 OS="$(uname -s)"
70 # Parse command line options.
71 if_needed=
72 force_local_build=
73 run_tests=
74 bootstrap=
75 with_android=yes
76 chrome_tools="plugins;blink_gc_plugin"
77 gcc_toolchain=
78 with_patches=yes
80 if [[ "${OS}" = "Darwin" ]]; then
81 with_android=
84 while [[ $# > 0 ]]; do
85 case $1 in
86 --bootstrap)
87 bootstrap=yes
89 --if-needed)
90 if_needed=yes
92 --force-local-build)
93 force_local_build=yes
95 --print-revision)
96 echo $PACKAGE_VERSION
97 exit 0
99 --run-tests)
100 run_tests=yes
102 --without-android)
103 with_android=
105 --without-patches)
106 with_patches=
108 --with-chrome-tools)
109 shift
110 if [[ $# == 0 ]]; then
111 echo "--with-chrome-tools requires an argument."
112 exit 1
114 chrome_tools=$1
116 --gcc-toolchain)
117 shift
118 if [[ $# == 0 ]]; then
119 echo "--gcc-toolchain requires an argument."
120 exit 1
122 if [[ -x "$1/bin/gcc" ]]; then
123 gcc_toolchain=$1
124 else
125 echo "Invalid --gcc-toolchain: '$1'."
126 echo "'$1/bin/gcc' does not appear to be valid."
127 exit 1
131 --help)
132 echo "usage: $0 [--force-local-build] [--if-needed] [--run-tests] "
133 echo "--bootstrap: First build clang with CC, then with itself."
134 echo "--force-local-build: Don't try to download prebuilt binaries."
135 echo "--if-needed: Download clang only if the script thinks it is needed."
136 echo "--run-tests: Run tests after building. Only for local builds."
137 echo "--print-revision: Print current clang revision and exit."
138 echo "--without-android: Don't build ASan Android runtime library."
139 echo "--with-chrome-tools: Select which chrome tools to build." \
140 "Defaults to plugins;blink_gc_plugin."
141 echo " Example: --with-chrome-tools plugins;empty-string"
142 echo "--gcc-toolchain: Set the prefix for which GCC version should"
143 echo " be used for building. For example, to use gcc in"
144 echo " /opt/foo/bin/gcc, use '--gcc-toolchain '/opt/foo"
145 echo "--without-patches: Don't apply local patches."
146 echo
147 exit 1
150 echo "Unknown argument: '$1'."
151 echo "Use --help for help."
152 exit 1
154 esac
155 shift
156 done
158 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
159 force_local_build=yes
161 # Skip local patches when using HEAD: they probably don't apply anymore.
162 with_patches=
164 if ! [[ "$GYP_DEFINES" =~ .*OS=android.* ]]; then
165 # Only build the Android ASan rt when targetting Android.
166 with_android=
169 if [[ "${OS}" == "Linux" ]] && [[ -z ${gcc_toolchain:-''} ]]; then
170 # Set gcc_toolchain on Linux; llvm-symbolizer needs the bundled libstdc++.
171 gcc_toolchain="$(dirname $(dirname $(which gcc)))"
174 echo "LLVM_FORCE_HEAD_REVISION was set; using r${CLANG_REVISION}"
177 if [[ -n "$if_needed" ]]; then
178 if [[ "${OS}" == "Darwin" ]]; then
179 # clang is used on Mac.
180 true
181 elif [[ "$GYP_DEFINES" =~ .*(clang|tsan|asan|lsan|msan)=1.* ]]; then
182 # clang requested via $GYP_DEFINES.
183 true
184 elif [[ -d "${LLVM_BUILD_DIR}" ]]; then
185 # clang previously downloaded, remove third_party/llvm-build to prevent
186 # updating.
187 true
188 elif [[ "${OS}" == "Linux" ]]; then
189 # Temporarily use clang on linux. Leave a stamp file behind, so that
190 # this script can remove clang again on machines where it was autoinstalled.
191 mkdir -p "${LLVM_BUILD_DIR}"
192 touch "${LLVM_BUILD_DIR}/autoinstall_stamp"
193 true
194 else
195 # clang wasn't needed, not doing anything.
196 exit 0
201 # Check if there's anything to be done, exit early if not.
202 if [[ -f "${STAMP_FILE}" ]]; then
203 PREVIOUSLY_BUILT_REVISON=$(cat "${STAMP_FILE}")
204 if [[ -z "$force_local_build" ]] && \
205 [[ "${PREVIOUSLY_BUILT_REVISON}" = \
206 "${PACKAGE_VERSION}" ]]; then
207 echo "Clang already at ${PACKAGE_VERSION}"
208 exit 0
211 # To always force a new build if someone interrupts their build half way.
212 rm -f "${STAMP_FILE}"
215 if [[ -z "$force_local_build" ]]; then
216 # Check if there's a prebuilt binary and if so just fetch that. That's faster,
217 # and goma relies on having matching binary hashes on client and server too.
218 CDS_URL=https://commondatastorage.googleapis.com/chromium-browser-clang
219 CDS_FILE="clang-${PACKAGE_VERSION}.tgz"
220 CDS_OUT_DIR=$(mktemp -d -t clang_download.XXXXXX)
221 CDS_OUTPUT="${CDS_OUT_DIR}/${CDS_FILE}"
222 if [ "${OS}" = "Linux" ]; then
223 CDS_FULL_URL="${CDS_URL}/Linux_x64/${CDS_FILE}"
224 elif [ "${OS}" = "Darwin" ]; then
225 CDS_FULL_URL="${CDS_URL}/Mac/${CDS_FILE}"
227 echo Trying to download prebuilt clang
228 if which curl > /dev/null; then
229 curl -L --fail "${CDS_FULL_URL}" -o "${CDS_OUTPUT}" || \
230 rm -rf "${CDS_OUT_DIR}"
231 elif which wget > /dev/null; then
232 wget "${CDS_FULL_URL}" -O "${CDS_OUTPUT}" || rm -rf "${CDS_OUT_DIR}"
233 else
234 echo "Neither curl nor wget found. Please install one of these."
235 exit 1
237 if [ -f "${CDS_OUTPUT}" ]; then
238 rm -rf "${LLVM_BUILD_DIR}"
239 mkdir -p "${LLVM_BUILD_DIR}"
240 tar -xzf "${CDS_OUTPUT}" -C "${LLVM_BUILD_DIR}"
241 echo clang "${PACKAGE_VERSION}" unpacked
242 echo "${PACKAGE_VERSION}" > "${STAMP_FILE}"
243 rm -rf "${CDS_OUT_DIR}"
244 exit 0
245 else
246 echo Did not find prebuilt clang "${PACKAGE_VERSION}", building
250 if [[ -n "${with_android}" ]] && ! [[ -d "${ANDROID_NDK_DIR}" ]]; then
251 echo "Android NDK not found at ${ANDROID_NDK_DIR}"
252 echo "The Android NDK is needed to build a Clang whose -fsanitize=address"
253 echo "works on Android. See "
254 echo "http://code.google.com/p/chromium/wiki/AndroidBuildInstructions for how"
255 echo "to install the NDK, or pass --without-android."
256 exit 1
259 # Check that cmake and ninja are available.
260 if ! which cmake > /dev/null; then
261 echo "CMake needed to build clang; please install"
262 exit 1
264 if ! which ninja > /dev/null; then
265 echo "ninja needed to build clang, please install"
266 exit 1
269 echo Reverting previously patched files
270 for i in \
271 "${CLANG_DIR}/test/Index/crash-recovery-modules.m" \
272 "${CLANG_DIR}/unittests/libclang/LibclangTest.cpp" \
273 "${COMPILER_RT_DIR}/lib/asan/asan_rtl.cc" \
274 "${COMPILER_RT_DIR}/test/asan/TestCases/Linux/new_array_cookie_test.cc" \
275 "${LLVM_DIR}/test/DebugInfo/gmlt.ll" \
276 "${LLVM_DIR}/lib/CodeGen/SpillPlacement.cpp" \
277 "${LLVM_DIR}/lib/CodeGen/SpillPlacement.h" \
278 "${LLVM_DIR}/lib/Transforms/Instrumentation/MemorySanitizer.cpp" \
279 "${CLANG_DIR}/test/Driver/env.c" \
280 "${CLANG_DIR}/lib/Frontend/InitPreprocessor.cpp" \
281 "${CLANG_DIR}/test/Frontend/exceptions.c" \
282 "${CLANG_DIR}/test/Preprocessor/predefined-exceptions.m" \
283 "${LLVM_DIR}/test/Bindings/Go/go.test" \
284 "${CLANG_DIR}/lib/Parse/ParseExpr.cpp" \
285 "${CLANG_DIR}/lib/Parse/ParseTemplate.cpp" \
286 "${CLANG_DIR}/lib/Sema/SemaDeclCXX.cpp" \
287 "${CLANG_DIR}/lib/Sema/SemaExprCXX.cpp" \
288 "${CLANG_DIR}/test/SemaCXX/default2.cpp" \
289 "${CLANG_DIR}/test/SemaCXX/typo-correction-delayed.cpp" \
290 "${COMPILER_RT_DIR}/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc" \
291 "${COMPILER_RT_DIR}/test/tsan/signal_segv_handler.cc" \
292 ; do
293 if [[ -e "${i}" ]]; then
294 rm -f "${i}" # For unversioned files.
295 svn revert "${i}"
297 done
299 echo Remove the Clang tools shim dir
300 CHROME_TOOLS_SHIM_DIR=${ABS_LLVM_DIR}/tools/chrometools
301 rm -rfv ${CHROME_TOOLS_SHIM_DIR}
303 echo Getting LLVM r"${CLANG_REVISION}" in "${LLVM_DIR}"
304 if ! svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" \
305 "${LLVM_DIR}"; then
306 echo Checkout failed, retrying
307 rm -rf "${LLVM_DIR}"
308 svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" "${LLVM_DIR}"
311 echo Getting clang r"${CLANG_REVISION}" in "${CLANG_DIR}"
312 svn co --force "${LLVM_REPO_URL}/cfe/trunk@${CLANG_REVISION}" "${CLANG_DIR}"
314 # We have moved from building compiler-rt in the LLVM tree, to a separate
315 # directory. Nuke any previous checkout to avoid building it.
316 rm -rf "${LLVM_DIR}/projects/compiler-rt"
318 echo Getting compiler-rt r"${CLANG_REVISION}" in "${COMPILER_RT_DIR}"
319 svn co --force "${LLVM_REPO_URL}/compiler-rt/trunk@${CLANG_REVISION}" \
320 "${COMPILER_RT_DIR}"
322 # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes
323 # (i.e. this is needed for bootstrap builds).
324 if [ "${OS}" = "Darwin" ]; then
325 echo Getting libc++ r"${CLANG_REVISION}" in "${LIBCXX_DIR}"
326 svn co --force "${LLVM_REPO_URL}/libcxx/trunk@${CLANG_REVISION}" \
327 "${LIBCXX_DIR}"
330 # While we're bundling our own libc++ on OS X, we need to compile libc++abi
331 # into it too (since OS X 10.6 doesn't have libc++abi.dylib either).
332 if [ "${OS}" = "Darwin" ]; then
333 echo Getting libc++abi r"${CLANG_REVISION}" in "${LIBCXXABI_DIR}"
334 svn co --force "${LLVM_REPO_URL}/libcxxabi/trunk@${CLANG_REVISION}" \
335 "${LIBCXXABI_DIR}"
338 if [[ -n "$with_patches" ]]; then
340 # Apply patch for tests failing with --disable-pthreads (llvm.org/PR11974)
341 pushd "${CLANG_DIR}"
342 cat << 'EOF' |
343 --- third_party/llvm/tools/clang/test/Index/crash-recovery-modules.m (revision 202554)
344 +++ third_party/llvm/tools/clang/test/Index/crash-recovery-modules.m (working copy)
345 @@ -12,6 +12,8 @@
347 // REQUIRES: crash-recovery
348 // REQUIRES: shell
349 +// XFAIL: *
350 +// (PR11974)
352 @import Crash;
354 patch -p4
355 popd
357 pushd "${CLANG_DIR}"
358 cat << 'EOF' |
359 --- unittests/libclang/LibclangTest.cpp (revision 215949)
360 +++ unittests/libclang/LibclangTest.cpp (working copy)
361 @@ -431,7 +431,7 @@
362 EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU));
365 -TEST_F(LibclangReparseTest, ReparseWithModule) {
366 +TEST_F(LibclangReparseTest, DISABLED_ReparseWithModule) {
367 const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;";
368 const char *HeaderBottom = "\n};\n#endif\n";
369 const char *MFile = "#include \"HeaderFile.h\"\nint main() {"
371 patch -p0
372 popd
374 # This Go bindings test doesn't work after the bootstrap build on Linux. (PR21552)
375 pushd "${LLVM_DIR}"
376 cat << 'EOF' |
377 Index: test/Bindings/Go/go.test
378 ===================================================================
379 --- test/Bindings/Go/go.test (revision 223109)
380 +++ test/Bindings/Go/go.test (working copy)
381 @@ -1,3 +1,3 @@
382 -; RUN: llvm-go test llvm.org/llvm/bindings/go/llvm
383 +; RUN: true
385 ; REQUIRES: shell
387 patch -p0
388 popd
393 # Echo all commands.
394 set -x
396 # Set default values for CC and CXX if they're not set in the environment.
397 CC=${CC:-cc}
398 CXX=${CXX:-c++}
400 if [[ -n "${gcc_toolchain}" ]]; then
401 # Use the specified gcc installation for building.
402 CC="$gcc_toolchain/bin/gcc"
403 CXX="$gcc_toolchain/bin/g++"
404 # Set LD_LIBRARY_PATH to make auxiliary targets (tablegen, bootstrap compiler,
405 # etc.) find the .so.
406 export LD_LIBRARY_PATH="$(dirname $(${CXX} -print-file-name=libstdc++.so.6))"
409 CFLAGS=""
410 CXXFLAGS=""
411 LDFLAGS=""
413 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is
414 # needed, on OS X it requires libc++. clang only automatically links to libc++
415 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run on
416 # OS X versions as old as 10.7.
417 # TODO(thakis): Some bots are still on 10.6, so for now bundle libc++.dylib.
418 # Remove this once all bots are on 10.7+, then use --enable-libcpp=yes and
419 # change deployment_target to 10.7.
420 deployment_target=""
422 if [ "${OS}" = "Darwin" ]; then
423 # When building on 10.9, /usr/include usually doesn't exist, and while
424 # Xcode's clang automatically sets a sysroot, self-built clangs don't.
425 CFLAGS="-isysroot $(xcrun --show-sdk-path)"
426 CPPFLAGS="${CFLAGS}"
427 CXXFLAGS="-stdlib=libc++ -nostdinc++ -I${ABS_LIBCXX_DIR}/include ${CFLAGS}"
429 if [[ -n "${bootstrap}" ]]; then
430 deployment_target=10.6
434 # Build bootstrap clang if requested.
435 if [[ -n "${bootstrap}" ]]; then
436 ABS_INSTALL_DIR="${PWD}/${LLVM_BOOTSTRAP_INSTALL_DIR}"
437 echo "Building bootstrap compiler"
438 mkdir -p "${LLVM_BOOTSTRAP_DIR}"
439 pushd "${LLVM_BOOTSTRAP_DIR}"
441 cmake -GNinja \
442 -DCMAKE_BUILD_TYPE=Release \
443 -DLLVM_ENABLE_ASSERTIONS=ON \
444 -DLLVM_TARGETS_TO_BUILD=host \
445 -DLLVM_ENABLE_THREADS=OFF \
446 -DCMAKE_INSTALL_PREFIX="${ABS_INSTALL_DIR}" \
447 -DCMAKE_C_COMPILER="${CC}" \
448 -DCMAKE_CXX_COMPILER="${CXX}" \
449 -DCMAKE_C_FLAGS="${CFLAGS}" \
450 -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
451 ../llvm
453 ninja
454 if [[ -n "${run_tests}" ]]; then
455 ninja check-all
458 ninja install
459 if [[ -n "${gcc_toolchain}" ]]; then
460 # Copy that gcc's stdlibc++.so.6 to the build dir, so the bootstrap
461 # compiler can start.
462 cp -v "$(${CXX} -print-file-name=libstdc++.so.6)" \
463 "${ABS_INSTALL_DIR}/lib/"
466 popd
467 CC="${ABS_INSTALL_DIR}/bin/clang"
468 CXX="${ABS_INSTALL_DIR}/bin/clang++"
470 if [[ -n "${gcc_toolchain}" ]]; then
471 # Tell the bootstrap compiler to use a specific gcc prefix to search
472 # for standard library headers and shared object file.
473 CFLAGS="--gcc-toolchain=${gcc_toolchain}"
474 CXXFLAGS="--gcc-toolchain=${gcc_toolchain}"
477 echo "Building final compiler"
480 # Build clang (in a separate directory).
481 # The clang bots have this path hardcoded in built/scripts/slave/compile.py,
482 # so if you change it you also need to change these links.
483 mkdir -p "${LLVM_BUILD_DIR}"
484 pushd "${LLVM_BUILD_DIR}"
486 # Build libc++.dylib while some bots are still on OS X 10.6.
487 if [ "${OS}" = "Darwin" ]; then
488 rm -rf libcxxbuild
489 LIBCXXFLAGS="-O3 -std=c++11 -fstrict-aliasing"
491 # libcxx and libcxxabi both have a file stdexcept.cpp, so put their .o files
492 # into different subdirectories.
493 mkdir -p libcxxbuild/libcxx
494 pushd libcxxbuild/libcxx
495 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXX_DIR}"/src/*.cpp
496 popd
498 mkdir -p libcxxbuild/libcxxabi
499 pushd libcxxbuild/libcxxabi
500 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXXABI_DIR}"/src/*.cpp -I"${ABS_LIBCXXABI_DIR}/include"
501 popd
503 pushd libcxxbuild
504 ${CC:-cc} libcxx/*.o libcxxabi/*.o -o libc++.1.dylib -dynamiclib \
505 -nodefaultlibs -current_version 1 -compatibility_version 1 \
506 -lSystem -install_name @executable_path/libc++.dylib \
507 -Wl,-unexported_symbols_list,${ABS_LIBCXX_DIR}/lib/libc++unexp.exp \
508 -Wl,-force_symbols_not_weak_list,${ABS_LIBCXX_DIR}/lib/notweak.exp \
509 -Wl,-force_symbols_weak_list,${ABS_LIBCXX_DIR}/lib/weak.exp
510 ln -sf libc++.1.dylib libc++.dylib
511 popd
512 LDFLAGS+="-stdlib=libc++ -L${PWD}/libcxxbuild"
515 # Hook the Chromium tools into the LLVM build. Several Chromium tools have
516 # dependencies on LLVM/Clang libraries. The LLVM build detects implicit tools
517 # in the tools subdirectory, so install a shim CMakeLists.txt that forwards to
518 # the real directory for the Chromium tools.
519 # Note that the shim directory name intentionally has no _ or _. The implicit
520 # tool detection logic munges them in a weird way.
521 mkdir -v ${CHROME_TOOLS_SHIM_DIR}
522 cat > ${CHROME_TOOLS_SHIM_DIR}/CMakeLists.txt << EOF
523 # Since tools/clang isn't actually a subdirectory, use the two argument version
524 # to specify where build artifacts go. CMake doesn't allow reusing the same
525 # binary dir for multiple source dirs, so the build artifacts have to go into a
526 # subdirectory...
527 add_subdirectory(\${CHROMIUM_TOOLS_SRC} \${CMAKE_CURRENT_BINARY_DIR}/a)
529 rm -fv CMakeCache.txt
530 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
531 -DCMAKE_BUILD_TYPE=Release \
532 -DLLVM_ENABLE_ASSERTIONS=ON \
533 -DLLVM_ENABLE_THREADS=OFF \
534 -DCMAKE_C_COMPILER="${CC}" \
535 -DCMAKE_CXX_COMPILER="${CXX}" \
536 -DCMAKE_C_FLAGS="${CFLAGS}" \
537 -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
538 -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}" \
539 -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \
540 -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" \
541 -DCMAKE_INSTALL_PREFIX="${ABS_LLVM_BUILD_DIR}" \
542 -DCHROMIUM_TOOLS_SRC="${ABS_CHROMIUM_TOOLS_DIR}" \
543 -DCHROMIUM_TOOLS="${chrome_tools}" \
544 "${ABS_LLVM_DIR}"
547 if [[ -n "${gcc_toolchain}" ]]; then
548 # Copy in the right stdlibc++.so.6 so clang can start.
549 mkdir -p lib
550 cp -v "$(${CXX} ${CXXFLAGS} -print-file-name=libstdc++.so.6)" lib/
553 ninja
554 # If any Chromium tools were built, install those now.
555 if [[ -n "${chrome_tools}" ]]; then
556 ninja cr-install
559 STRIP_FLAGS=
560 if [ "${OS}" = "Darwin" ]; then
561 # See http://crbug.com/256342
562 STRIP_FLAGS=-x
564 cp libcxxbuild/libc++.1.dylib bin/
566 strip ${STRIP_FLAGS} bin/clang
567 popd
569 # Build compiler-rt out-of-tree.
570 mkdir -p "${COMPILER_RT_BUILD_DIR}"
571 pushd "${COMPILER_RT_BUILD_DIR}"
573 rm -fv CMakeCache.txt
574 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
575 -DCMAKE_BUILD_TYPE=Release \
576 -DLLVM_ENABLE_ASSERTIONS=ON \
577 -DLLVM_ENABLE_THREADS=OFF \
578 -DCMAKE_C_COMPILER="${CC}" \
579 -DCMAKE_CXX_COMPILER="${CXX}" \
580 -DLLVM_CONFIG_PATH="${ABS_LLVM_BUILD_DIR}/bin/llvm-config" \
581 "${ABS_COMPILER_RT_DIR}"
583 ninja
585 # Copy selected output to the main tree.
586 # Darwin doesn't support cp --parents, so pipe through tar instead.
587 CLANG_VERSION=$("${ABS_LLVM_BUILD_DIR}/bin/clang" --version | \
588 sed -ne 's/clang version \([0-9]\.[0-9]\.[0-9]\).*/\1/p')
589 ABS_LLVM_CLANG_LIB_DIR="${ABS_LLVM_BUILD_DIR}/lib/clang/${CLANG_VERSION}"
590 tar -c *blacklist.txt | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
591 tar -c include/sanitizer | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
592 if [[ "${OS}" = "Darwin" ]]; then
593 tar -c lib/darwin | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
594 else
595 tar -c lib/linux | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
598 popd
600 if [[ -n "${with_android}" ]]; then
601 # Make a standalone Android toolchain.
602 ${ANDROID_NDK_DIR}/build/tools/make-standalone-toolchain.sh \
603 --platform=android-14 \
604 --install-dir="${LLVM_BUILD_DIR}/android-toolchain" \
605 --system=linux-x86_64 \
606 --stl=stlport \
607 --toolchain=arm-linux-androideabi-4.9
609 # Android NDK r9d copies a broken unwind.h into the toolchain, see
610 # http://crbug.com/357890
611 rm -v "${LLVM_BUILD_DIR}"/android-toolchain/include/c++/*/unwind.h
613 # Build ASan runtime for Android in a separate build tree.
614 mkdir -p ${LLVM_BUILD_DIR}/android
615 pushd ${LLVM_BUILD_DIR}/android
616 rm -fv CMakeCache.txt
617 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
618 -DCMAKE_BUILD_TYPE=Release \
619 -DLLVM_ENABLE_ASSERTIONS=ON \
620 -DLLVM_ENABLE_THREADS=OFF \
621 -DCMAKE_C_COMPILER=${PWD}/../bin/clang \
622 -DCMAKE_CXX_COMPILER=${PWD}/../bin/clang++ \
623 -DLLVM_CONFIG_PATH=${PWD}/../bin/llvm-config \
624 -DCMAKE_C_FLAGS="--target=arm-linux-androideabi --sysroot=${PWD}/../android-toolchain/sysroot -B${PWD}/../android-toolchain" \
625 -DCMAKE_CXX_FLAGS="--target=arm-linux-androideabi --sysroot=${PWD}/../android-toolchain/sysroot -B${PWD}/../android-toolchain" \
626 -DANDROID=1 \
627 "${ABS_COMPILER_RT_DIR}"
628 ninja libclang_rt.asan-arm-android.so
630 # And copy it into the main build tree.
631 cp "$(find -name libclang_rt.asan-arm-android.so)" "${ABS_LLVM_CLANG_LIB_DIR}/lib/linux/"
632 popd
635 if [[ -n "$run_tests" ]]; then
636 # Run Chrome tool tests.
637 ninja -C "${LLVM_BUILD_DIR}" cr-check-all
638 # Run the LLVM and Clang tests.
639 ninja -C "${LLVM_BUILD_DIR}" check-all
642 # After everything is done, log success for this revision.
643 echo "${PACKAGE_VERSION}" > "${STAMP_FILE}"