Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: tools/clang/scripts/update.sh

Issue 2858873005: [infra] Roll clang to match the version used by Flutter (Closed)
Patch Set: Fix Mac Android build Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
5
6 # This script will check out llvm and clang into third_party/llvm and build it.
7
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=241602
12
13 # This is incremented when pushing a new build of Clang at the same revision.
14 CLANG_SUB_REVISION=3
15
16 PACKAGE_VERSION="${CLANG_REVISION}-${CLANG_SUB_REVISION}"
17
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"
32
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}"
40
41 # ${A:-a} returns $A if it's set, a else.
42 LLVM_REPO_URL=${LLVM_URL:-https://llvm.org/svn/llvm-project}
43
44 CDS_URL=https://commondatastorage.googleapis.com/chromium-browser-clang
45
46 if [[ -z "$GYP_DEFINES" ]]; then
47 GYP_DEFINES=
48 fi
49 if [[ -z "$GYP_GENERATORS" ]]; then
50 GYP_GENERATORS=
51 fi
52 if [[ -z "$LLVM_DOWNLOAD_GOLD_PLUGIN" ]]; then
53 LLVM_DOWNLOAD_GOLD_PLUGIN=
54 fi
55
56
57 # Die if any command dies, error on undefined variable expansions.
58 set -eu
59
60
61 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
62 # Use a real revision number rather than HEAD to make sure that the stamp file
63 # logic works.
64 CLANG_REVISION=$(svn info "$LLVM_REPO_URL" \
65 | grep 'Revision:' | awk '{ printf $2; }')
66 PACKAGE_VERSION="${CLANG_REVISION}-0"
67 fi
68
69 OS="$(uname -s)"
70
71 # Parse command line options.
72 if_needed=
73 force_local_build=
74 run_tests=
75 bootstrap=
76 with_android=yes
77 chrome_tools="plugins;blink_gc_plugin"
78 gcc_toolchain=
79 with_patches=yes
80
81 if [[ "${OS}" = "Darwin" ]]; then
82 with_android=
83 fi
84
85 while [[ $# > 0 ]]; do
86 case $1 in
87 --bootstrap)
88 bootstrap=yes
89 ;;
90 --if-needed)
91 if_needed=yes
92 ;;
93 --force-local-build)
94 force_local_build=yes
95 ;;
96 --print-revision)
97 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
98 svn info "$LLVM_DIR" | grep 'Revision:' | awk '{ printf $2; }'
99 else
100 echo $PACKAGE_VERSION
101 fi
102 exit 0
103 ;;
104 --run-tests)
105 run_tests=yes
106 ;;
107 --without-android)
108 with_android=
109 ;;
110 --without-patches)
111 with_patches=
112 ;;
113 --with-chrome-tools)
114 shift
115 if [[ $# == 0 ]]; then
116 echo "--with-chrome-tools requires an argument."
117 exit 1
118 fi
119 chrome_tools=$1
120 ;;
121 --gcc-toolchain)
122 shift
123 if [[ $# == 0 ]]; then
124 echo "--gcc-toolchain requires an argument."
125 exit 1
126 fi
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
133 fi
134 ;;
135
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
153 ;;
154 *)
155 echo "Unknown argument: '$1'."
156 echo "Use --help for help."
157 exit 1
158 ;;
159 esac
160 shift
161 done
162
163 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
164 force_local_build=yes
165
166 # Skip local patches when using HEAD: they probably don't apply anymore.
167 with_patches=
168
169 if ! [[ "$GYP_DEFINES" =~ .*OS=android.* ]]; then
170 # Only build the Android ASan rt when targetting Android.
171 with_android=
172 fi
173
174 LLVM_BUILD_TOOLS_DIR="${ABS_LLVM_DIR}/../llvm-build-tools"
175
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
185 fi
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)))"
190 fi
191 fi
192
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
202 fi
203 export PATH="${LLVM_BUILD_TOOLS_DIR}/cmake310/bin:${PATH}"
204 fi
205 fi
206
207 echo "LLVM_FORCE_HEAD_REVISION was set; using r${CLANG_REVISION}"
208 fi
209
210 if [[ -n "$if_needed" ]]; then
211 if [[ "${OS}" == "Darwin" ]]; then
212 # clang is always used on Mac.
213 true
214 elif [[ "${OS}" == "Linux" ]]; then
215 # clang is also aways used on Linux.
216 true
217 elif [[ "$GYP_DEFINES" =~ .*(clang|tsan|asan|lsan|msan)=1.* ]]; then
218 # clang requested via $GYP_DEFINES.
219 true
220 elif [[ -d "${LLVM_BUILD_DIR}" ]]; then
221 # clang previously downloaded, keep it up-to-date.
222 # If you don't want this, delete third_party/llvm-build on your machine.
223 true
224 else
225 # clang wasn't needed, not doing anything.
226 exit 0
227 fi
228 fi
229
230
231 # Check if there's anything to be done, exit early if not.
232 if [[ -f "${STAMP_FILE}" ]]; then
233 PREVIOUSLY_BUILT_REVISON=$(cat "${STAMP_FILE}")
234 if [[ -z "$force_local_build" ]] && \
235 [[ "${PREVIOUSLY_BUILT_REVISON}" = \
236 "${PACKAGE_VERSION}" ]]; then
237 echo "Clang already at ${PACKAGE_VERSION}"
238 exit 0
239 fi
240 fi
241 # To always force a new build if someone interrupts their build half way.
242 rm -f "${STAMP_FILE}"
243
244
245 if [[ -z "$force_local_build" ]]; then
246 # Check if there's a prebuilt binary and if so just fetch that. That's faster,
247 # and goma relies on having matching binary hashes on client and server too.
248 CDS_FILE="clang-${PACKAGE_VERSION}.tgz"
249 CDS_OUT_DIR=$(mktemp -d -t clang_download.XXXXXX)
250 CDS_OUTPUT="${CDS_OUT_DIR}/${CDS_FILE}"
251 if [ "${OS}" = "Linux" ]; then
252 CDS_FULL_URL="${CDS_URL}/Linux_x64/${CDS_FILE}"
253 elif [ "${OS}" = "Darwin" ]; then
254 CDS_FULL_URL="${CDS_URL}/Mac/${CDS_FILE}"
255 fi
256 echo Trying to download prebuilt clang
257 if which curl > /dev/null; then
258 curl -L --fail "${CDS_FULL_URL}" -o "${CDS_OUTPUT}" || \
259 rm -rf "${CDS_OUT_DIR}"
260 elif which wget > /dev/null; then
261 wget "${CDS_FULL_URL}" -O "${CDS_OUTPUT}" || rm -rf "${CDS_OUT_DIR}"
262 else
263 echo "Neither curl nor wget found. Please install one of these."
264 exit 1
265 fi
266 if [ -f "${CDS_OUTPUT}" ]; then
267 rm -rf "${LLVM_BUILD_DIR}"
268 mkdir -p "${LLVM_BUILD_DIR}"
269 tar -xzf "${CDS_OUTPUT}" -C "${LLVM_BUILD_DIR}"
270 echo clang "${PACKAGE_VERSION}" unpacked
271 echo "${PACKAGE_VERSION}" > "${STAMP_FILE}"
272 rm -rf "${CDS_OUT_DIR}"
273 # Download the gold plugin if requested to by an environment variable.
274 # This is used by the CFI ClusterFuzz bot.
275 if [[ -n "${LLVM_DOWNLOAD_GOLD_PLUGIN}" ]]; then
276 ${THIS_DIR}/../../../build/download_gold_plugin.py
277 fi
278 exit 0
279 else
280 echo Did not find prebuilt clang "${PACKAGE_VERSION}", building
281 fi
282 fi
283
284 if [[ -n "${with_android}" ]] && ! [[ -d "${ANDROID_NDK_DIR}" ]]; then
285 echo "Android NDK not found at ${ANDROID_NDK_DIR}"
286 echo "The Android NDK is needed to build a Clang whose -fsanitize=address"
287 echo "works on Android. See "
288 echo "http://code.google.com/p/chromium/wiki/AndroidBuildInstructions for how"
289 echo "to install the NDK, or pass --without-android."
290 exit 1
291 fi
292
293 # Check that cmake and ninja are available.
294 if ! which cmake > /dev/null; then
295 echo "CMake needed to build clang; please install"
296 exit 1
297 fi
298 if ! which ninja > /dev/null; then
299 echo "ninja needed to build clang, please install"
300 exit 1
301 fi
302
303 echo Reverting previously patched files
304 for i in \
305 "${CLANG_DIR}/test/Index/crash-recovery-modules.m" \
306 "${CLANG_DIR}/unittests/libclang/LibclangTest.cpp" \
307 "${COMPILER_RT_DIR}/lib/asan/asan_rtl.cc" \
308 "${COMPILER_RT_DIR}/test/asan/TestCases/Linux/new_array_cookie_test.cc" \
309 "${LLVM_DIR}/test/DebugInfo/gmlt.ll" \
310 "${LLVM_DIR}/lib/CodeGen/SpillPlacement.cpp" \
311 "${LLVM_DIR}/lib/CodeGen/SpillPlacement.h" \
312 "${LLVM_DIR}/lib/Transforms/Instrumentation/MemorySanitizer.cpp" \
313 "${CLANG_DIR}/test/Driver/env.c" \
314 "${CLANG_DIR}/lib/Frontend/InitPreprocessor.cpp" \
315 "${CLANG_DIR}/test/Frontend/exceptions.c" \
316 "${CLANG_DIR}/test/Preprocessor/predefined-exceptions.m" \
317 "${LLVM_DIR}/test/Bindings/Go/go.test" \
318 "${CLANG_DIR}/lib/Parse/ParseExpr.cpp" \
319 "${CLANG_DIR}/lib/Parse/ParseTemplate.cpp" \
320 "${CLANG_DIR}/lib/Sema/SemaDeclCXX.cpp" \
321 "${CLANG_DIR}/lib/Sema/SemaExprCXX.cpp" \
322 "${CLANG_DIR}/test/SemaCXX/default2.cpp" \
323 "${CLANG_DIR}/test/SemaCXX/typo-correction-delayed.cpp" \
324 "${COMPILER_RT_DIR}/lib/sanitizer_common/sanitizer_stoptheworld_linux_libc dep.cc" \
325 "${COMPILER_RT_DIR}/test/tsan/signal_segv_handler.cc" \
326 "${COMPILER_RT_DIR}/lib/sanitizer_common/sanitizer_coverage_libcdep.cc" \
327 "${COMPILER_RT_DIR}/cmake/config-ix.cmake" \
328 "${COMPILER_RT_DIR}/CMakeLists.txt" \
329 "${COMPILER_RT_DIR}/lib/ubsan/ubsan_platform.h" \
330 ; do
331 if [[ -e "${i}" ]]; then
332 rm -f "${i}" # For unversioned files.
333 svn revert "${i}"
334 fi;
335 done
336
337 echo Remove the Clang tools shim dir
338 CHROME_TOOLS_SHIM_DIR=${ABS_LLVM_DIR}/tools/chrometools
339 rm -rfv ${CHROME_TOOLS_SHIM_DIR}
340
341 echo Getting LLVM r"${CLANG_REVISION}" in "${LLVM_DIR}"
342 if ! svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" \
343 "${LLVM_DIR}"; then
344 echo Checkout failed, retrying
345 rm -rf "${LLVM_DIR}"
346 svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" "${LLVM_DIR}"
347 fi
348
349 echo Getting clang r"${CLANG_REVISION}" in "${CLANG_DIR}"
350 svn co --force "${LLVM_REPO_URL}/cfe/trunk@${CLANG_REVISION}" "${CLANG_DIR}"
351
352 # We have moved from building compiler-rt in the LLVM tree, to a separate
353 # directory. Nuke any previous checkout to avoid building it.
354 rm -rf "${LLVM_DIR}/projects/compiler-rt"
355
356 echo Getting compiler-rt r"${CLANG_REVISION}" in "${COMPILER_RT_DIR}"
357 svn co --force "${LLVM_REPO_URL}/compiler-rt/trunk@${CLANG_REVISION}" \
358 "${COMPILER_RT_DIR}"
359
360 # clang needs a libc++ checkout, else -stdlib=libc++ won't find includes
361 # (i.e. this is needed for bootstrap builds).
362 if [ "${OS}" = "Darwin" ]; then
363 echo Getting libc++ r"${CLANG_REVISION}" in "${LIBCXX_DIR}"
364 svn co --force "${LLVM_REPO_URL}/libcxx/trunk@${CLANG_REVISION}" \
365 "${LIBCXX_DIR}"
366 fi
367
368 # While we're bundling our own libc++ on OS X, we need to compile libc++abi
369 # into it too (since OS X 10.6 doesn't have libc++abi.dylib either).
370 if [ "${OS}" = "Darwin" ]; then
371 echo Getting libc++abi r"${CLANG_REVISION}" in "${LIBCXXABI_DIR}"
372 svn co --force "${LLVM_REPO_URL}/libcxxabi/trunk@${CLANG_REVISION}" \
373 "${LIBCXXABI_DIR}"
374 fi
375
376 if [[ -n "$with_patches" ]]; then
377
378 # Apply patch for tests failing with --disable-pthreads (llvm.org/PR11974)
379 pushd "${CLANG_DIR}"
380 cat << 'EOF' |
381 --- test/Index/crash-recovery-modules.m (revision 202554)
382 +++ test/Index/crash-recovery-modules.m (working copy)
383 @@ -12,6 +12,8 @@
384
385 // REQUIRES: crash-recovery
386 // REQUIRES: shell
387 +// XFAIL: *
388 +// (PR11974)
389
390 @import Crash;
391 EOF
392 patch -p0
393 popd
394
395 pushd "${CLANG_DIR}"
396 cat << 'EOF' |
397 --- unittests/libclang/LibclangTest.cpp (revision 215949)
398 +++ unittests/libclang/LibclangTest.cpp (working copy)
399 @@ -431,7 +431,7 @@
400 EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU));
401 }
402
403 -TEST_F(LibclangReparseTest, ReparseWithModule) {
404 +TEST_F(LibclangReparseTest, DISABLED_ReparseWithModule) {
405 const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;";
406 const char *HeaderBottom = "\n};\n#endif\n";
407 const char *MFile = "#include \"HeaderFile.h\"\nint main() {"
408 EOF
409 patch -p0
410 popd
411
412 # This Go bindings test doesn't work after the bootstrap build on Linux. (PR21 552)
413 pushd "${LLVM_DIR}"
414 cat << 'EOF' |
415 --- test/Bindings/Go/go.test (revision 223109)
416 +++ test/Bindings/Go/go.test (working copy)
417 @@ -1,3 +1,3 @@
418 -; RUN: llvm-go test llvm.org/llvm/bindings/go/llvm
419 +; RUN: true
420
421 ; REQUIRES: shell
422 EOF
423 patch -p0
424 popd
425
426 # The UBSan run-time, which is now bundled with the ASan run-time, doesn't wor k
427 # on Mac OS X 10.8 (PR23539).
428 pushd "${COMPILER_RT_DIR}"
429 cat << 'EOF' |
430 Index: CMakeLists.txt
431 ===================================================================
432 --- CMakeLists.txt (revision 241602)
433 +++ CMakeLists.txt (working copy)
434 @@ -305,6 +305,7 @@
435 list(APPEND SANITIZER_COMMON_SUPPORTED_OS iossim)
436 endif()
437 endif()
438 + set(SANITIZER_MIN_OSX_VERSION "10.7")
439 if(SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.7")
440 message(FATAL_ERROR "Too old OS X version: ${SANITIZER_MIN_OSX_VERSION}")
441 endif()
442 EOF
443 patch -p0
444 popd
445
446 fi
447
448 # Echo all commands.
449 set -x
450
451 # Set default values for CC and CXX if they're not set in the environment.
452 CC=${CC:-cc}
453 CXX=${CXX:-c++}
454
455 if [[ -n "${gcc_toolchain}" ]]; then
456 # Use the specified gcc installation for building.
457 CC="$gcc_toolchain/bin/gcc"
458 CXX="$gcc_toolchain/bin/g++"
459 # Set LD_LIBRARY_PATH to make auxiliary targets (tablegen, bootstrap compiler,
460 # etc.) find the .so.
461 export LD_LIBRARY_PATH="$(dirname $(${CXX} -print-file-name=libstdc++.so.6))"
462 fi
463
464 CFLAGS=""
465 CXXFLAGS=""
466 LDFLAGS=""
467
468 # LLVM uses C++11 starting in llvm 3.5. On Linux, this means libstdc++4.7+ is
469 # needed, on OS X it requires libc++. clang only automatically links to libc++
470 # when targeting OS X 10.9+, so add stdlib=libc++ explicitly so clang can run on
471 # OS X versions as old as 10.7.
472 # TODO(thakis): Some bots are still on 10.6 (nacl...), so for now bundle
473 # libc++.dylib. Remove this once all bots are on 10.7+, then use
474 # -DLLVM_ENABLE_LIBCXX=ON and change deployment_target to 10.7.
475 deployment_target=""
476
477 if [ "${OS}" = "Darwin" ]; then
478 # When building on 10.9, /usr/include usually doesn't exist, and while
479 # Xcode's clang automatically sets a sysroot, self-built clangs don't.
480 CFLAGS="-isysroot $(xcrun --show-sdk-path)"
481 CXXFLAGS="-stdlib=libc++ -nostdinc++ -I${ABS_LIBCXX_DIR}/include ${CFLAGS}"
482
483 if [[ -n "${bootstrap}" ]]; then
484 deployment_target=10.6
485 fi
486 fi
487
488 # Build bootstrap clang if requested.
489 if [[ -n "${bootstrap}" ]]; then
490 ABS_INSTALL_DIR="${PWD}/${LLVM_BOOTSTRAP_INSTALL_DIR}"
491 echo "Building bootstrap compiler"
492 mkdir -p "${LLVM_BOOTSTRAP_DIR}"
493 pushd "${LLVM_BOOTSTRAP_DIR}"
494
495 cmake -GNinja \
496 -DCMAKE_BUILD_TYPE=Release \
497 -DLLVM_ENABLE_ASSERTIONS=ON \
498 -DLLVM_TARGETS_TO_BUILD=host \
499 -DLLVM_ENABLE_THREADS=OFF \
500 -DCMAKE_INSTALL_PREFIX="${ABS_INSTALL_DIR}" \
501 -DCMAKE_C_COMPILER="${CC}" \
502 -DCMAKE_CXX_COMPILER="${CXX}" \
503 -DCMAKE_C_FLAGS="${CFLAGS}" \
504 -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
505 ../llvm
506
507 ninja
508 if [[ -n "${run_tests}" ]]; then
509 ninja check-all
510 fi
511
512 ninja install
513 if [[ -n "${gcc_toolchain}" ]]; then
514 # Copy that gcc's stdlibc++.so.6 to the build dir, so the bootstrap
515 # compiler can start.
516 cp -v "$(${CXX} -print-file-name=libstdc++.so.6)" \
517 "${ABS_INSTALL_DIR}/lib/"
518 fi
519
520 popd
521 CC="${ABS_INSTALL_DIR}/bin/clang"
522 CXX="${ABS_INSTALL_DIR}/bin/clang++"
523
524 if [[ -n "${gcc_toolchain}" ]]; then
525 # Tell the bootstrap compiler to use a specific gcc prefix to search
526 # for standard library headers and shared object file.
527 CFLAGS="--gcc-toolchain=${gcc_toolchain}"
528 CXXFLAGS="--gcc-toolchain=${gcc_toolchain}"
529 fi
530
531 echo "Building final compiler"
532 fi
533
534 # Build clang (in a separate directory).
535 # The clang bots have this path hardcoded in built/scripts/slave/compile.py,
536 # so if you change it you also need to change these links.
537 mkdir -p "${LLVM_BUILD_DIR}"
538 pushd "${LLVM_BUILD_DIR}"
539
540 # Build libc++.dylib while some bots are still on OS X 10.6.
541 if [ "${OS}" = "Darwin" ]; then
542 rm -rf libcxxbuild
543 LIBCXXFLAGS="-O3 -std=c++11 -fstrict-aliasing"
544
545 # libcxx and libcxxabi both have a file stdexcept.cpp, so put their .o files
546 # into different subdirectories.
547 mkdir -p libcxxbuild/libcxx
548 pushd libcxxbuild/libcxx
549 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXX_DIR}"/src/*.cpp
550 popd
551
552 mkdir -p libcxxbuild/libcxxabi
553 pushd libcxxbuild/libcxxabi
554 ${CXX:-c++} -c ${CXXFLAGS} ${LIBCXXFLAGS} "${ABS_LIBCXXABI_DIR}"/src/*.cpp -I" ${ABS_LIBCXXABI_DIR}/include"
555 popd
556
557 pushd libcxxbuild
558 ${CC:-cc} libcxx/*.o libcxxabi/*.o -o libc++.1.dylib -dynamiclib \
559 -nodefaultlibs -current_version 1 -compatibility_version 1 \
560 -lSystem -install_name @executable_path/libc++.dylib \
561 -Wl,-unexported_symbols_list,${ABS_LIBCXX_DIR}/lib/libc++unexp.exp \
562 -Wl,-force_symbols_not_weak_list,${ABS_LIBCXX_DIR}/lib/notweak.exp \
563 -Wl,-force_symbols_weak_list,${ABS_LIBCXX_DIR}/lib/weak.exp
564 ln -sf libc++.1.dylib libc++.dylib
565 popd
566 LDFLAGS+="-stdlib=libc++ -L${PWD}/libcxxbuild"
567
568 if [[ -n "${bootstrap}" ]]; then
569 # Now that the libc++ headers have been installed and libc++.dylib is built,
570 # delete the libc++ checkout again so that it's not part of the main
571 # build below -- the libc++(abi) tests don't pass on OS X in bootstrap
572 # builds (http://llvm.org/PR24068)
573 rm -rf "${ABS_LIBCXX_DIR}"
574 rm -rf "${ABS_LIBCXXABI_DIR}"
575 CXXFLAGS="-stdlib=libc++ -nostdinc++ -I${ABS_INSTALL_DIR}/include/c++/v1 ${C FLAGS}"
576 fi
577 fi
578
579 # Find the binutils include dir for the gold plugin.
580 BINUTILS_INCDIR=""
581 if [ "${OS}" = "Linux" ]; then
582 BINUTILS_INCDIR="${ABS_BINUTILS_DIR}/Linux_x64/Release/include"
583 fi
584
585
586 # If building at head, define a macro that plugins can use for #ifdefing
587 # out code that builds at head, but not at CLANG_REVISION or vice versa.
588 if [[ -n ${LLVM_FORCE_HEAD_REVISION:-''} ]]; then
589 CFLAGS="${CFLAGS} -DLLVM_FORCE_HEAD_REVISION"
590 CXXFLAGS="${CXXFLAGS} -DLLVM_FORCE_HEAD_REVISION"
591 fi
592
593 # Hook the Chromium tools into the LLVM build. Several Chromium tools have
594 # dependencies on LLVM/Clang libraries. The LLVM build detects implicit tools
595 # in the tools subdirectory, so install a shim CMakeLists.txt that forwards to
596 # the real directory for the Chromium tools.
597 # Note that the shim directory name intentionally has no _ or _. The implicit
598 # tool detection logic munges them in a weird way.
599 mkdir -v ${CHROME_TOOLS_SHIM_DIR}
600 cat > ${CHROME_TOOLS_SHIM_DIR}/CMakeLists.txt << EOF
601 # Since tools/clang isn't actually a subdirectory, use the two argument version
602 # to specify where build artifacts go. CMake doesn't allow reusing the same
603 # binary dir for multiple source dirs, so the build artifacts have to go into a
604 # subdirectory...
605 add_subdirectory(\${CHROMIUM_TOOLS_SRC} \${CMAKE_CURRENT_BINARY_DIR}/a)
606 EOF
607 rm -fv CMakeCache.txt
608 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
609 -DCMAKE_BUILD_TYPE=Release \
610 -DLLVM_ENABLE_ASSERTIONS=ON \
611 -DLLVM_ENABLE_THREADS=OFF \
612 -DLLVM_BINUTILS_INCDIR="${BINUTILS_INCDIR}" \
613 -DCMAKE_C_COMPILER="${CC}" \
614 -DCMAKE_CXX_COMPILER="${CXX}" \
615 -DCMAKE_C_FLAGS="${CFLAGS}" \
616 -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
617 -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}" \
618 -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \
619 -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" \
620 -DCMAKE_INSTALL_PREFIX="${ABS_LLVM_BUILD_DIR}" \
621 -DCHROMIUM_TOOLS_SRC="${ABS_CHROMIUM_TOOLS_DIR}" \
622 -DCHROMIUM_TOOLS="${chrome_tools}" \
623 "${ABS_LLVM_DIR}"
624 env
625
626 if [[ -n "${gcc_toolchain}" ]]; then
627 # Copy in the right stdlibc++.so.6 so clang can start.
628 mkdir -p lib
629 cp -v "$(${CXX} ${CXXFLAGS} -print-file-name=libstdc++.so.6)" lib/
630 fi
631
632 ninja
633 # If any Chromium tools were built, install those now.
634 if [[ -n "${chrome_tools}" ]]; then
635 ninja cr-install
636 fi
637
638 STRIP_FLAGS=
639 if [ "${OS}" = "Darwin" ]; then
640 # See http://crbug.com/256342
641 STRIP_FLAGS=-x
642
643 cp libcxxbuild/libc++.1.dylib bin/
644 fi
645 strip ${STRIP_FLAGS} bin/clang
646 popd
647
648 # Build compiler-rt out-of-tree.
649 mkdir -p "${COMPILER_RT_BUILD_DIR}"
650 pushd "${COMPILER_RT_BUILD_DIR}"
651
652 rm -fv CMakeCache.txt
653 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
654 -DCMAKE_BUILD_TYPE=Release \
655 -DLLVM_ENABLE_ASSERTIONS=ON \
656 -DLLVM_ENABLE_THREADS=OFF \
657 -DCMAKE_C_COMPILER="${CC}" \
658 -DCMAKE_CXX_COMPILER="${CXX}" \
659 -DLLVM_CONFIG_PATH="${ABS_LLVM_BUILD_DIR}/bin/llvm-config" \
660 "${ABS_COMPILER_RT_DIR}"
661
662 ninja
663
664 # Copy selected output to the main tree.
665 # Darwin doesn't support cp --parents, so pipe through tar instead.
666 CLANG_VERSION=$("${ABS_LLVM_BUILD_DIR}/bin/clang" --version | \
667 sed -ne 's/clang version \([0-9]\.[0-9]\.[0-9]\).*/\1/p')
668 ABS_LLVM_CLANG_LIB_DIR="${ABS_LLVM_BUILD_DIR}/lib/clang/${CLANG_VERSION}"
669 tar -c *blacklist.txt | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
670 tar -c include/sanitizer | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
671 if [[ "${OS}" = "Darwin" ]]; then
672 tar -c lib/darwin | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
673 else
674 tar -c lib/linux | tar -C ${ABS_LLVM_CLANG_LIB_DIR} -xv
675 fi
676
677 popd
678
679 if [[ -n "${with_android}" ]]; then
680 # Make a standalone Android toolchain.
681 ${ANDROID_NDK_DIR}/build/tools/make-standalone-toolchain.sh \
682 --platform=android-19 \
683 --install-dir="${LLVM_BUILD_DIR}/android-toolchain" \
684 --system=linux-x86_64 \
685 --stl=stlport \
686 --toolchain=arm-linux-androideabi-4.9
687
688 # Android NDK r9d copies a broken unwind.h into the toolchain, see
689 # http://crbug.com/357890
690 rm -v "${LLVM_BUILD_DIR}"/android-toolchain/include/c++/*/unwind.h
691
692 # Build ASan runtime for Android in a separate build tree.
693 mkdir -p ${LLVM_BUILD_DIR}/android
694 pushd ${LLVM_BUILD_DIR}/android
695 rm -fv CMakeCache.txt
696 MACOSX_DEPLOYMENT_TARGET=${deployment_target} cmake -GNinja \
697 -DCMAKE_BUILD_TYPE=Release \
698 -DLLVM_ENABLE_ASSERTIONS=ON \
699 -DLLVM_ENABLE_THREADS=OFF \
700 -DCMAKE_C_COMPILER=${PWD}/../bin/clang \
701 -DCMAKE_CXX_COMPILER=${PWD}/../bin/clang++ \
702 -DLLVM_CONFIG_PATH=${PWD}/../bin/llvm-config \
703 -DCMAKE_C_FLAGS="--target=arm-linux-androideabi --sysroot=${PWD}/../androi d-toolchain/sysroot -B${PWD}/../android-toolchain" \
704 -DCMAKE_CXX_FLAGS="--target=arm-linux-androideabi --sysroot=${PWD}/../andr oid-toolchain/sysroot -B${PWD}/../android-toolchain" \
705 -DANDROID=1 \
706 "${ABS_COMPILER_RT_DIR}"
707 ninja libclang_rt.asan-arm-android.so
708
709 # And copy it into the main build tree.
710 cp "$(find -name libclang_rt.asan-arm-android.so)" "${ABS_LLVM_CLANG_LIB_DIR}/ lib/linux/"
711 popd
712 fi
713
714 if [[ -n "$run_tests" || -n "${LLVM_FORCE_HEAD_REVISION:-''}" ]]; then
715 # Run Chrome tool tests.
716 ninja -C "${LLVM_BUILD_DIR}" cr-check-all
717 fi
718 if [[ -n "$run_tests" ]]; then
719 # Run the LLVM and Clang tests.
720 ninja -C "${LLVM_BUILD_DIR}" check-all
721 fi
722
723 # After everything is done, log success for this revision.
724 echo "${PACKAGE_VERSION}" > "${STAMP_FILE}"
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698