1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/tools/clang/scripts/update.sh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,286 @@ 1.4 +#!/usr/bin/env bash 1.5 +# Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.6 +# Use of this source code is governed by a BSD-style license that can be 1.7 +# found in the LICENSE file. 1.8 + 1.9 +# This script will check out llvm and clang into third_party/llvm and build it. 1.10 + 1.11 +# Do NOT CHANGE this if you don't know what you're doing -- see 1.12 +# https://code.google.com/p/chromium/wiki/UpdatingClang 1.13 +# Reverting problematic clang rolls is safe, though. 1.14 +CLANG_REVISION=163674 1.15 + 1.16 +THIS_DIR="$(dirname "${0}")" 1.17 +LLVM_DIR="${THIS_DIR}/../../../third_party/llvm" 1.18 +LLVM_BUILD_DIR="${LLVM_DIR}/../llvm-build" 1.19 +LLVM_BOOTSTRAP_DIR="${LLVM_DIR}/../llvm-bootstrap" 1.20 +CLANG_DIR="${LLVM_DIR}/tools/clang" 1.21 +COMPILER_RT_DIR="${LLVM_DIR}/projects/compiler-rt" 1.22 +STAMP_FILE="${LLVM_BUILD_DIR}/cr_build_revision" 1.23 + 1.24 +# ${A:-a} returns $A if it's set, a else. 1.25 +LLVM_REPO_URL=${LLVM_URL:-https://llvm.org/svn/llvm-project} 1.26 + 1.27 +# Die if any command dies. 1.28 +set -e 1.29 + 1.30 +OS="$(uname -s)" 1.31 + 1.32 +# Parse command line options. 1.33 +force_local_build= 1.34 +mac_only= 1.35 +run_tests= 1.36 +bootstrap= 1.37 +while [[ $# > 0 ]]; do 1.38 + case $1 in 1.39 + --bootstrap) 1.40 + bootstrap=yes 1.41 + ;; 1.42 + --force-local-build) 1.43 + force_local_build=yes 1.44 + ;; 1.45 + --mac-only) 1.46 + mac_only=yes 1.47 + ;; 1.48 + --run-tests) 1.49 + run_tests=yes 1.50 + ;; 1.51 + --help) 1.52 + echo "usage: $0 [--force-local-build] [--mac-only] [--run-tests] " 1.53 + echo "--bootstrap: First build clang with CC, then with itself." 1.54 + echo "--force-local-build: Don't try to download prebuilt binaries." 1.55 + echo "--mac-only: Do initial download only on Mac systems." 1.56 + echo "--run-tests: Run tests after building. Only for local builds." 1.57 + exit 1 1.58 + ;; 1.59 + esac 1.60 + shift 1.61 +done 1.62 + 1.63 +# --mac-only prevents the initial download on non-mac systems, but if clang has 1.64 +# already been downloaded in the past, this script keeps it up to date even if 1.65 +# --mac-only is passed in and the system isn't a mac. People who don't like this 1.66 +# can just delete their third_party/llvm-build directory. 1.67 +if [[ -n "$mac_only" ]] && [[ "${OS}" != "Darwin" ]] && 1.68 + [[ "$GYP_DEFINES" != *clang=1* ]] && ! [[ -d "${LLVM_BUILD_DIR}" ]]; then 1.69 + exit 0 1.70 +fi 1.71 + 1.72 +# Xcode and clang don't get along when predictive compilation is enabled. 1.73 +# http://crbug.com/96315 1.74 +if [[ "${OS}" = "Darwin" ]] && xcodebuild -version | grep -q 'Xcode 3.2' ; then 1.75 + XCONF=com.apple.Xcode 1.76 + if [[ "${GYP_GENERATORS}" != "make" ]] && \ 1.77 + [ "$(defaults read "${XCONF}" EnablePredictiveCompilation)" != "0" ]; then 1.78 + echo 1.79 + echo " HEARKEN!" 1.80 + echo "You're using Xcode3 and you have 'Predictive Compilation' enabled." 1.81 + echo "This does not work well with clang (http://crbug.com/96315)." 1.82 + echo "Disable it in Preferences->Building (lower right), or run" 1.83 + echo " defaults write ${XCONF} EnablePredictiveCompilation -boolean NO" 1.84 + echo "while Xcode is not running." 1.85 + echo 1.86 + fi 1.87 + 1.88 + SUB_VERSION=$(xcodebuild -version | sed -Ene 's/Xcode 3\.2\.([0-9]+)/\1/p') 1.89 + if [[ "${SUB_VERSION}" < 6 ]]; then 1.90 + echo 1.91 + echo " YOUR LD IS BUGGY!" 1.92 + echo "Please upgrade Xcode to at least 3.2.6." 1.93 + echo 1.94 + fi 1.95 +fi 1.96 + 1.97 + 1.98 +# Check if there's anything to be done, exit early if not. 1.99 +if [[ -f "${STAMP_FILE}" ]]; then 1.100 + PREVIOUSLY_BUILT_REVISON=$(cat "${STAMP_FILE}") 1.101 + if [[ -z "$force_local_build" ]] && \ 1.102 + [[ "${PREVIOUSLY_BUILT_REVISON}" = "${CLANG_REVISION}" ]]; then 1.103 + echo "Clang already at ${CLANG_REVISION}" 1.104 + exit 0 1.105 + fi 1.106 +fi 1.107 +# To always force a new build if someone interrupts their build half way. 1.108 +rm -f "${STAMP_FILE}" 1.109 + 1.110 +# Clobber pch files, since they only work with the compiler version that 1.111 +# created them. Also clobber .o files, to make sure everything will be built 1.112 +# with the new compiler. 1.113 +if [[ "${OS}" = "Darwin" ]]; then 1.114 + XCODEBUILD_DIR="${THIS_DIR}/../../../xcodebuild" 1.115 + 1.116 + # Xcode groups .o files by project first, configuration second. 1.117 + if [[ -d "${XCODEBUILD_DIR}" ]]; then 1.118 + echo "Clobbering .o files for Xcode build" 1.119 + find "${XCODEBUILD_DIR}" -name '*.o' -exec rm {} + 1.120 + fi 1.121 +fi 1.122 + 1.123 +if [ -f "${THIS_DIR}/../../../WebKit.gyp" ]; then 1.124 + # We're inside a WebKit checkout. 1.125 + # TODO(thakis): try to unify the directory layout of the xcode- and 1.126 + # make-based builds. http://crbug.com/110455 1.127 + MAKE_DIR="${THIS_DIR}/../../../../../../out" 1.128 +else 1.129 + # We're inside a Chromium checkout. 1.130 + MAKE_DIR="${THIS_DIR}/../../../out" 1.131 +fi 1.132 + 1.133 +for CONFIG in Debug Release; do 1.134 + if [[ -d "${MAKE_DIR}/${CONFIG}/obj.target" || 1.135 + -d "${MAKE_DIR}/${CONFIG}/obj.host" ]]; then 1.136 + echo "Clobbering ${CONFIG} PCH and .o files for make build" 1.137 + if [[ -d "${MAKE_DIR}/${CONFIG}/obj.target" ]]; then 1.138 + find "${MAKE_DIR}/${CONFIG}/obj.target" -name '*.gch' -exec rm {} + 1.139 + find "${MAKE_DIR}/${CONFIG}/obj.target" -name '*.o' -exec rm {} + 1.140 + fi 1.141 + if [[ -d "${MAKE_DIR}/${CONFIG}/obj.host" ]]; then 1.142 + find "${MAKE_DIR}/${CONFIG}/obj.host" -name '*.o' -exec rm {} + 1.143 + fi 1.144 + fi 1.145 + 1.146 + # ninja puts its output below ${MAKE_DIR} as well. 1.147 + if [[ -d "${MAKE_DIR}/${CONFIG}/obj" ]]; then 1.148 + echo "Clobbering ${CONFIG} PCH and .o files for ninja build" 1.149 + find "${MAKE_DIR}/${CONFIG}/obj" -name '*.gch' -exec rm {} + 1.150 + find "${MAKE_DIR}/${CONFIG}/obj" -name '*.o' -exec rm {} + 1.151 + find "${MAKE_DIR}/${CONFIG}/obj" -name '*.o.d' -exec rm {} + 1.152 + fi 1.153 + 1.154 + if [[ "${OS}" = "Darwin" ]]; then 1.155 + if [[ -d "${XCODEBUILD_DIR}/${CONFIG}/SharedPrecompiledHeaders" ]]; then 1.156 + echo "Clobbering ${CONFIG} PCH files for Xcode build" 1.157 + rm -rf "${XCODEBUILD_DIR}/${CONFIG}/SharedPrecompiledHeaders" 1.158 + fi 1.159 + fi 1.160 +done 1.161 + 1.162 +if [[ -z "$force_local_build" ]]; then 1.163 + # Check if there's a prebuilt binary and if so just fetch that. That's faster, 1.164 + # and goma relies on having matching binary hashes on client and server too. 1.165 + CDS_URL=https://commondatastorage.googleapis.com/chromium-browser-clang 1.166 + CDS_FILE="clang-${CLANG_REVISION}.tgz" 1.167 + CDS_OUT_DIR=$(mktemp -d -t clang_download.XXXXXX) 1.168 + CDS_OUTPUT="${CDS_OUT_DIR}/${CDS_FILE}" 1.169 + if [ "${OS}" = "Linux" ]; then 1.170 + CDS_FULL_URL="${CDS_URL}/Linux_x64/${CDS_FILE}" 1.171 + elif [ "${OS}" = "Darwin" ]; then 1.172 + CDS_FULL_URL="${CDS_URL}/Mac/${CDS_FILE}" 1.173 + fi 1.174 + echo Trying to download prebuilt clang 1.175 + if which curl > /dev/null; then 1.176 + curl -L --fail "${CDS_FULL_URL}" -o "${CDS_OUTPUT}" || \ 1.177 + rm -rf "${CDS_OUT_DIR}" 1.178 + elif which wget > /dev/null; then 1.179 + wget "${CDS_FULL_URL}" -O "${CDS_OUTPUT}" || rm -rf "${CDS_OUT_DIR}" 1.180 + else 1.181 + echo "Neither curl nor wget found. Please install one of these." 1.182 + exit 1 1.183 + fi 1.184 + if [ -f "${CDS_OUTPUT}" ]; then 1.185 + rm -rf "${LLVM_BUILD_DIR}/Release+Asserts" 1.186 + mkdir -p "${LLVM_BUILD_DIR}/Release+Asserts" 1.187 + tar -xzf "${CDS_OUTPUT}" -C "${LLVM_BUILD_DIR}/Release+Asserts" 1.188 + echo clang "${CLANG_REVISION}" unpacked 1.189 + echo "${CLANG_REVISION}" > "${STAMP_FILE}" 1.190 + rm -rf "${CDS_OUT_DIR}" 1.191 + exit 0 1.192 + else 1.193 + echo Did not find prebuilt clang at r"${CLANG_REVISION}", building 1.194 + fi 1.195 +fi 1.196 + 1.197 +echo Getting LLVM r"${CLANG_REVISION}" in "${LLVM_DIR}" 1.198 +if ! svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" \ 1.199 + "${LLVM_DIR}"; then 1.200 + echo Checkout failed, retrying 1.201 + rm -rf "${LLVM_DIR}" 1.202 + svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" "${LLVM_DIR}" 1.203 +fi 1.204 + 1.205 +echo Getting clang r"${CLANG_REVISION}" in "${CLANG_DIR}" 1.206 +svn co --force "${LLVM_REPO_URL}/cfe/trunk@${CLANG_REVISION}" "${CLANG_DIR}" 1.207 + 1.208 +echo Getting compiler-rt r"${CLANG_REVISION}" in "${COMPILER_RT_DIR}" 1.209 +svn co --force "${LLVM_REPO_URL}/compiler-rt/trunk@${CLANG_REVISION}" \ 1.210 + "${COMPILER_RT_DIR}" 1.211 + 1.212 +# Echo all commands. 1.213 +set -x 1.214 + 1.215 +NUM_JOBS=3 1.216 +if [[ "${OS}" = "Linux" ]]; then 1.217 + NUM_JOBS="$(grep -c "^processor" /proc/cpuinfo)" 1.218 +elif [ "${OS}" = "Darwin" ]; then 1.219 + NUM_JOBS="$(sysctl -n hw.ncpu)" 1.220 +fi 1.221 + 1.222 +# Build bootstrap clang if requested. 1.223 +if [[ -n "${bootstrap}" ]]; then 1.224 + echo "Building bootstrap compiler" 1.225 + mkdir -p "${LLVM_BOOTSTRAP_DIR}" 1.226 + cd "${LLVM_BOOTSTRAP_DIR}" 1.227 + if [[ ! -f ./config.status ]]; then 1.228 + # The bootstrap compiler only needs to be able to build the real compiler, 1.229 + # so it needs no cross-compiler output support. In general, the host 1.230 + # compiler should be as similar to the final compiler as possible, so do 1.231 + # keep --disable-threads & co. 1.232 + ../llvm/configure \ 1.233 + --enable-optimized \ 1.234 + --enable-targets=host-only \ 1.235 + --disable-threads \ 1.236 + --disable-pthreads \ 1.237 + --without-llvmgcc \ 1.238 + --without-llvmgxx 1.239 + MACOSX_DEPLOYMENT_TARGET=10.5 make -j"${NUM_JOBS}" 1.240 + fi 1.241 + if [[ -n "${run_tests}" ]]; then 1.242 + make check-all 1.243 + fi 1.244 + cd - 1.245 + export CC="${PWD}/${LLVM_BOOTSTRAP_DIR}/Release+Asserts/bin/clang" 1.246 + export CXX="${PWD}/${LLVM_BOOTSTRAP_DIR}/Release+Asserts/bin/clang++" 1.247 + echo "Building final compiler" 1.248 +fi 1.249 + 1.250 +# Build clang (in a separate directory). 1.251 +# The clang bots have this path hardcoded in built/scripts/slave/compile.py, 1.252 +# so if you change it you also need to change these links. 1.253 +mkdir -p "${LLVM_BUILD_DIR}" 1.254 +cd "${LLVM_BUILD_DIR}" 1.255 +if [[ ! -f ./config.status ]]; then 1.256 + ../llvm/configure \ 1.257 + --enable-optimized \ 1.258 + --disable-threads \ 1.259 + --disable-pthreads \ 1.260 + --without-llvmgcc \ 1.261 + --without-llvmgxx 1.262 +fi 1.263 + 1.264 +MACOSX_DEPLOYMENT_TARGET=10.5 make -j"${NUM_JOBS}" 1.265 +cd - 1.266 + 1.267 +# Build plugin. 1.268 +# Copy it into the clang tree and use clang's build system to compile the 1.269 +# plugin. 1.270 +PLUGIN_SRC_DIR="${THIS_DIR}/../plugins" 1.271 +PLUGIN_DST_DIR="${LLVM_DIR}/tools/clang/tools/chrome-plugin" 1.272 +PLUGIN_BUILD_DIR="${LLVM_BUILD_DIR}/tools/clang/tools/chrome-plugin" 1.273 +rm -rf "${PLUGIN_DST_DIR}" 1.274 +cp -R "${PLUGIN_SRC_DIR}" "${PLUGIN_DST_DIR}" 1.275 +rm -rf "${PLUGIN_BUILD_DIR}" 1.276 +mkdir -p "${PLUGIN_BUILD_DIR}" 1.277 +cp "${PLUGIN_SRC_DIR}/Makefile" "${PLUGIN_BUILD_DIR}" 1.278 +MACOSX_DEPLOYMENT_TARGET=10.5 make -j"${NUM_JOBS}" -C "${PLUGIN_BUILD_DIR}" 1.279 + 1.280 +if [[ -n "$run_tests" ]]; then 1.281 + # Run a few tests. 1.282 + "${PLUGIN_SRC_DIR}/tests/test.sh" "${LLVM_BUILD_DIR}/Release+Asserts" 1.283 + cd "${LLVM_BUILD_DIR}" 1.284 + make check-all 1.285 + cd - 1.286 +fi 1.287 + 1.288 +# After everything is done, log success for this revision. 1.289 +echo "${CLANG_REVISION}" > "${STAMP_FILE}"