media/webrtc/trunk/tools/clang/scripts/update.sh

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/env bash
michael@0 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 3 # Use of this source code is governed by a BSD-style license that can be
michael@0 4 # found in the LICENSE file.
michael@0 5
michael@0 6 # This script will check out llvm and clang into third_party/llvm and build it.
michael@0 7
michael@0 8 # Do NOT CHANGE this if you don't know what you're doing -- see
michael@0 9 # https://code.google.com/p/chromium/wiki/UpdatingClang
michael@0 10 # Reverting problematic clang rolls is safe, though.
michael@0 11 CLANG_REVISION=163674
michael@0 12
michael@0 13 THIS_DIR="$(dirname "${0}")"
michael@0 14 LLVM_DIR="${THIS_DIR}/../../../third_party/llvm"
michael@0 15 LLVM_BUILD_DIR="${LLVM_DIR}/../llvm-build"
michael@0 16 LLVM_BOOTSTRAP_DIR="${LLVM_DIR}/../llvm-bootstrap"
michael@0 17 CLANG_DIR="${LLVM_DIR}/tools/clang"
michael@0 18 COMPILER_RT_DIR="${LLVM_DIR}/projects/compiler-rt"
michael@0 19 STAMP_FILE="${LLVM_BUILD_DIR}/cr_build_revision"
michael@0 20
michael@0 21 # ${A:-a} returns $A if it's set, a else.
michael@0 22 LLVM_REPO_URL=${LLVM_URL:-https://llvm.org/svn/llvm-project}
michael@0 23
michael@0 24 # Die if any command dies.
michael@0 25 set -e
michael@0 26
michael@0 27 OS="$(uname -s)"
michael@0 28
michael@0 29 # Parse command line options.
michael@0 30 force_local_build=
michael@0 31 mac_only=
michael@0 32 run_tests=
michael@0 33 bootstrap=
michael@0 34 while [[ $# > 0 ]]; do
michael@0 35 case $1 in
michael@0 36 --bootstrap)
michael@0 37 bootstrap=yes
michael@0 38 ;;
michael@0 39 --force-local-build)
michael@0 40 force_local_build=yes
michael@0 41 ;;
michael@0 42 --mac-only)
michael@0 43 mac_only=yes
michael@0 44 ;;
michael@0 45 --run-tests)
michael@0 46 run_tests=yes
michael@0 47 ;;
michael@0 48 --help)
michael@0 49 echo "usage: $0 [--force-local-build] [--mac-only] [--run-tests] "
michael@0 50 echo "--bootstrap: First build clang with CC, then with itself."
michael@0 51 echo "--force-local-build: Don't try to download prebuilt binaries."
michael@0 52 echo "--mac-only: Do initial download only on Mac systems."
michael@0 53 echo "--run-tests: Run tests after building. Only for local builds."
michael@0 54 exit 1
michael@0 55 ;;
michael@0 56 esac
michael@0 57 shift
michael@0 58 done
michael@0 59
michael@0 60 # --mac-only prevents the initial download on non-mac systems, but if clang has
michael@0 61 # already been downloaded in the past, this script keeps it up to date even if
michael@0 62 # --mac-only is passed in and the system isn't a mac. People who don't like this
michael@0 63 # can just delete their third_party/llvm-build directory.
michael@0 64 if [[ -n "$mac_only" ]] && [[ "${OS}" != "Darwin" ]] &&
michael@0 65 [[ "$GYP_DEFINES" != *clang=1* ]] && ! [[ -d "${LLVM_BUILD_DIR}" ]]; then
michael@0 66 exit 0
michael@0 67 fi
michael@0 68
michael@0 69 # Xcode and clang don't get along when predictive compilation is enabled.
michael@0 70 # http://crbug.com/96315
michael@0 71 if [[ "${OS}" = "Darwin" ]] && xcodebuild -version | grep -q 'Xcode 3.2' ; then
michael@0 72 XCONF=com.apple.Xcode
michael@0 73 if [[ "${GYP_GENERATORS}" != "make" ]] && \
michael@0 74 [ "$(defaults read "${XCONF}" EnablePredictiveCompilation)" != "0" ]; then
michael@0 75 echo
michael@0 76 echo " HEARKEN!"
michael@0 77 echo "You're using Xcode3 and you have 'Predictive Compilation' enabled."
michael@0 78 echo "This does not work well with clang (http://crbug.com/96315)."
michael@0 79 echo "Disable it in Preferences->Building (lower right), or run"
michael@0 80 echo " defaults write ${XCONF} EnablePredictiveCompilation -boolean NO"
michael@0 81 echo "while Xcode is not running."
michael@0 82 echo
michael@0 83 fi
michael@0 84
michael@0 85 SUB_VERSION=$(xcodebuild -version | sed -Ene 's/Xcode 3\.2\.([0-9]+)/\1/p')
michael@0 86 if [[ "${SUB_VERSION}" < 6 ]]; then
michael@0 87 echo
michael@0 88 echo " YOUR LD IS BUGGY!"
michael@0 89 echo "Please upgrade Xcode to at least 3.2.6."
michael@0 90 echo
michael@0 91 fi
michael@0 92 fi
michael@0 93
michael@0 94
michael@0 95 # Check if there's anything to be done, exit early if not.
michael@0 96 if [[ -f "${STAMP_FILE}" ]]; then
michael@0 97 PREVIOUSLY_BUILT_REVISON=$(cat "${STAMP_FILE}")
michael@0 98 if [[ -z "$force_local_build" ]] && \
michael@0 99 [[ "${PREVIOUSLY_BUILT_REVISON}" = "${CLANG_REVISION}" ]]; then
michael@0 100 echo "Clang already at ${CLANG_REVISION}"
michael@0 101 exit 0
michael@0 102 fi
michael@0 103 fi
michael@0 104 # To always force a new build if someone interrupts their build half way.
michael@0 105 rm -f "${STAMP_FILE}"
michael@0 106
michael@0 107 # Clobber pch files, since they only work with the compiler version that
michael@0 108 # created them. Also clobber .o files, to make sure everything will be built
michael@0 109 # with the new compiler.
michael@0 110 if [[ "${OS}" = "Darwin" ]]; then
michael@0 111 XCODEBUILD_DIR="${THIS_DIR}/../../../xcodebuild"
michael@0 112
michael@0 113 # Xcode groups .o files by project first, configuration second.
michael@0 114 if [[ -d "${XCODEBUILD_DIR}" ]]; then
michael@0 115 echo "Clobbering .o files for Xcode build"
michael@0 116 find "${XCODEBUILD_DIR}" -name '*.o' -exec rm {} +
michael@0 117 fi
michael@0 118 fi
michael@0 119
michael@0 120 if [ -f "${THIS_DIR}/../../../WebKit.gyp" ]; then
michael@0 121 # We're inside a WebKit checkout.
michael@0 122 # TODO(thakis): try to unify the directory layout of the xcode- and
michael@0 123 # make-based builds. http://crbug.com/110455
michael@0 124 MAKE_DIR="${THIS_DIR}/../../../../../../out"
michael@0 125 else
michael@0 126 # We're inside a Chromium checkout.
michael@0 127 MAKE_DIR="${THIS_DIR}/../../../out"
michael@0 128 fi
michael@0 129
michael@0 130 for CONFIG in Debug Release; do
michael@0 131 if [[ -d "${MAKE_DIR}/${CONFIG}/obj.target" ||
michael@0 132 -d "${MAKE_DIR}/${CONFIG}/obj.host" ]]; then
michael@0 133 echo "Clobbering ${CONFIG} PCH and .o files for make build"
michael@0 134 if [[ -d "${MAKE_DIR}/${CONFIG}/obj.target" ]]; then
michael@0 135 find "${MAKE_DIR}/${CONFIG}/obj.target" -name '*.gch' -exec rm {} +
michael@0 136 find "${MAKE_DIR}/${CONFIG}/obj.target" -name '*.o' -exec rm {} +
michael@0 137 fi
michael@0 138 if [[ -d "${MAKE_DIR}/${CONFIG}/obj.host" ]]; then
michael@0 139 find "${MAKE_DIR}/${CONFIG}/obj.host" -name '*.o' -exec rm {} +
michael@0 140 fi
michael@0 141 fi
michael@0 142
michael@0 143 # ninja puts its output below ${MAKE_DIR} as well.
michael@0 144 if [[ -d "${MAKE_DIR}/${CONFIG}/obj" ]]; then
michael@0 145 echo "Clobbering ${CONFIG} PCH and .o files for ninja build"
michael@0 146 find "${MAKE_DIR}/${CONFIG}/obj" -name '*.gch' -exec rm {} +
michael@0 147 find "${MAKE_DIR}/${CONFIG}/obj" -name '*.o' -exec rm {} +
michael@0 148 find "${MAKE_DIR}/${CONFIG}/obj" -name '*.o.d' -exec rm {} +
michael@0 149 fi
michael@0 150
michael@0 151 if [[ "${OS}" = "Darwin" ]]; then
michael@0 152 if [[ -d "${XCODEBUILD_DIR}/${CONFIG}/SharedPrecompiledHeaders" ]]; then
michael@0 153 echo "Clobbering ${CONFIG} PCH files for Xcode build"
michael@0 154 rm -rf "${XCODEBUILD_DIR}/${CONFIG}/SharedPrecompiledHeaders"
michael@0 155 fi
michael@0 156 fi
michael@0 157 done
michael@0 158
michael@0 159 if [[ -z "$force_local_build" ]]; then
michael@0 160 # Check if there's a prebuilt binary and if so just fetch that. That's faster,
michael@0 161 # and goma relies on having matching binary hashes on client and server too.
michael@0 162 CDS_URL=https://commondatastorage.googleapis.com/chromium-browser-clang
michael@0 163 CDS_FILE="clang-${CLANG_REVISION}.tgz"
michael@0 164 CDS_OUT_DIR=$(mktemp -d -t clang_download.XXXXXX)
michael@0 165 CDS_OUTPUT="${CDS_OUT_DIR}/${CDS_FILE}"
michael@0 166 if [ "${OS}" = "Linux" ]; then
michael@0 167 CDS_FULL_URL="${CDS_URL}/Linux_x64/${CDS_FILE}"
michael@0 168 elif [ "${OS}" = "Darwin" ]; then
michael@0 169 CDS_FULL_URL="${CDS_URL}/Mac/${CDS_FILE}"
michael@0 170 fi
michael@0 171 echo Trying to download prebuilt clang
michael@0 172 if which curl > /dev/null; then
michael@0 173 curl -L --fail "${CDS_FULL_URL}" -o "${CDS_OUTPUT}" || \
michael@0 174 rm -rf "${CDS_OUT_DIR}"
michael@0 175 elif which wget > /dev/null; then
michael@0 176 wget "${CDS_FULL_URL}" -O "${CDS_OUTPUT}" || rm -rf "${CDS_OUT_DIR}"
michael@0 177 else
michael@0 178 echo "Neither curl nor wget found. Please install one of these."
michael@0 179 exit 1
michael@0 180 fi
michael@0 181 if [ -f "${CDS_OUTPUT}" ]; then
michael@0 182 rm -rf "${LLVM_BUILD_DIR}/Release+Asserts"
michael@0 183 mkdir -p "${LLVM_BUILD_DIR}/Release+Asserts"
michael@0 184 tar -xzf "${CDS_OUTPUT}" -C "${LLVM_BUILD_DIR}/Release+Asserts"
michael@0 185 echo clang "${CLANG_REVISION}" unpacked
michael@0 186 echo "${CLANG_REVISION}" > "${STAMP_FILE}"
michael@0 187 rm -rf "${CDS_OUT_DIR}"
michael@0 188 exit 0
michael@0 189 else
michael@0 190 echo Did not find prebuilt clang at r"${CLANG_REVISION}", building
michael@0 191 fi
michael@0 192 fi
michael@0 193
michael@0 194 echo Getting LLVM r"${CLANG_REVISION}" in "${LLVM_DIR}"
michael@0 195 if ! svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" \
michael@0 196 "${LLVM_DIR}"; then
michael@0 197 echo Checkout failed, retrying
michael@0 198 rm -rf "${LLVM_DIR}"
michael@0 199 svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" "${LLVM_DIR}"
michael@0 200 fi
michael@0 201
michael@0 202 echo Getting clang r"${CLANG_REVISION}" in "${CLANG_DIR}"
michael@0 203 svn co --force "${LLVM_REPO_URL}/cfe/trunk@${CLANG_REVISION}" "${CLANG_DIR}"
michael@0 204
michael@0 205 echo Getting compiler-rt r"${CLANG_REVISION}" in "${COMPILER_RT_DIR}"
michael@0 206 svn co --force "${LLVM_REPO_URL}/compiler-rt/trunk@${CLANG_REVISION}" \
michael@0 207 "${COMPILER_RT_DIR}"
michael@0 208
michael@0 209 # Echo all commands.
michael@0 210 set -x
michael@0 211
michael@0 212 NUM_JOBS=3
michael@0 213 if [[ "${OS}" = "Linux" ]]; then
michael@0 214 NUM_JOBS="$(grep -c "^processor" /proc/cpuinfo)"
michael@0 215 elif [ "${OS}" = "Darwin" ]; then
michael@0 216 NUM_JOBS="$(sysctl -n hw.ncpu)"
michael@0 217 fi
michael@0 218
michael@0 219 # Build bootstrap clang if requested.
michael@0 220 if [[ -n "${bootstrap}" ]]; then
michael@0 221 echo "Building bootstrap compiler"
michael@0 222 mkdir -p "${LLVM_BOOTSTRAP_DIR}"
michael@0 223 cd "${LLVM_BOOTSTRAP_DIR}"
michael@0 224 if [[ ! -f ./config.status ]]; then
michael@0 225 # The bootstrap compiler only needs to be able to build the real compiler,
michael@0 226 # so it needs no cross-compiler output support. In general, the host
michael@0 227 # compiler should be as similar to the final compiler as possible, so do
michael@0 228 # keep --disable-threads & co.
michael@0 229 ../llvm/configure \
michael@0 230 --enable-optimized \
michael@0 231 --enable-targets=host-only \
michael@0 232 --disable-threads \
michael@0 233 --disable-pthreads \
michael@0 234 --without-llvmgcc \
michael@0 235 --without-llvmgxx
michael@0 236 MACOSX_DEPLOYMENT_TARGET=10.5 make -j"${NUM_JOBS}"
michael@0 237 fi
michael@0 238 if [[ -n "${run_tests}" ]]; then
michael@0 239 make check-all
michael@0 240 fi
michael@0 241 cd -
michael@0 242 export CC="${PWD}/${LLVM_BOOTSTRAP_DIR}/Release+Asserts/bin/clang"
michael@0 243 export CXX="${PWD}/${LLVM_BOOTSTRAP_DIR}/Release+Asserts/bin/clang++"
michael@0 244 echo "Building final compiler"
michael@0 245 fi
michael@0 246
michael@0 247 # Build clang (in a separate directory).
michael@0 248 # The clang bots have this path hardcoded in built/scripts/slave/compile.py,
michael@0 249 # so if you change it you also need to change these links.
michael@0 250 mkdir -p "${LLVM_BUILD_DIR}"
michael@0 251 cd "${LLVM_BUILD_DIR}"
michael@0 252 if [[ ! -f ./config.status ]]; then
michael@0 253 ../llvm/configure \
michael@0 254 --enable-optimized \
michael@0 255 --disable-threads \
michael@0 256 --disable-pthreads \
michael@0 257 --without-llvmgcc \
michael@0 258 --without-llvmgxx
michael@0 259 fi
michael@0 260
michael@0 261 MACOSX_DEPLOYMENT_TARGET=10.5 make -j"${NUM_JOBS}"
michael@0 262 cd -
michael@0 263
michael@0 264 # Build plugin.
michael@0 265 # Copy it into the clang tree and use clang's build system to compile the
michael@0 266 # plugin.
michael@0 267 PLUGIN_SRC_DIR="${THIS_DIR}/../plugins"
michael@0 268 PLUGIN_DST_DIR="${LLVM_DIR}/tools/clang/tools/chrome-plugin"
michael@0 269 PLUGIN_BUILD_DIR="${LLVM_BUILD_DIR}/tools/clang/tools/chrome-plugin"
michael@0 270 rm -rf "${PLUGIN_DST_DIR}"
michael@0 271 cp -R "${PLUGIN_SRC_DIR}" "${PLUGIN_DST_DIR}"
michael@0 272 rm -rf "${PLUGIN_BUILD_DIR}"
michael@0 273 mkdir -p "${PLUGIN_BUILD_DIR}"
michael@0 274 cp "${PLUGIN_SRC_DIR}/Makefile" "${PLUGIN_BUILD_DIR}"
michael@0 275 MACOSX_DEPLOYMENT_TARGET=10.5 make -j"${NUM_JOBS}" -C "${PLUGIN_BUILD_DIR}"
michael@0 276
michael@0 277 if [[ -n "$run_tests" ]]; then
michael@0 278 # Run a few tests.
michael@0 279 "${PLUGIN_SRC_DIR}/tests/test.sh" "${LLVM_BUILD_DIR}/Release+Asserts"
michael@0 280 cd "${LLVM_BUILD_DIR}"
michael@0 281 make check-all
michael@0 282 cd -
michael@0 283 fi
michael@0 284
michael@0 285 # After everything is done, log success for this revision.
michael@0 286 echo "${CLANG_REVISION}" > "${STAMP_FILE}"

mercurial