Merge pull request #8668 from electron/fix-mas
[platform/framework/web/crosswalk-tizen.git] / script / update-clang.sh
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=284979
12
13 # This is incremented when pushing a new build of Clang at the same revision.
14 CLANG_SUB_REVISION=1
15
16 PACKAGE_VERSION="${CLANG_REVISION}-${CLANG_SUB_REVISION}"
17
18 THIS_DIR="$(dirname "${0}")"
19 LLVM_DIR="${THIS_DIR}/../vendor/llvm"
20 LLVM_BUILD_DIR="${LLVM_DIR}/../llvm-build/Release+Asserts"
21 STAMP_FILE="${LLVM_DIR}/../llvm-build/cr_build_revision"
22
23 # ${A:-a} returns $A if it's set, a else.
24 LLVM_REPO_URL=${LLVM_URL:-https://llvm.org/svn/llvm-project}
25
26 CDS_URL=https://commondatastorage.googleapis.com/chromium-browser-clang
27
28
29 # Die if any command dies, error on undefined variable expansions.
30 set -eu
31
32
33 OS="$(uname -s)"
34
35 # Check if there's anything to be done, exit early if not.
36 if [[ -f "${STAMP_FILE}" ]]; then
37   PREVIOUSLY_BUILT_REVISON=$(cat "${STAMP_FILE}")
38   if [[ "${PREVIOUSLY_BUILT_REVISON}" = "${PACKAGE_VERSION}" ]]; then
39     echo "Clang already at ${PACKAGE_VERSION}"
40     exit 0
41   fi
42 fi
43 # To always force a new build if someone interrupts their build half way.
44 rm -f "${STAMP_FILE}"
45
46 # Check if there's a prebuilt binary and if so just fetch that. That's faster,
47 # and goma relies on having matching binary hashes on client and server too.
48 CDS_FILE="clang-${PACKAGE_VERSION}.tgz"
49 CDS_OUT_DIR=$(mktemp -d -t clang_download.XXXXXX)
50 CDS_OUTPUT="${CDS_OUT_DIR}/${CDS_FILE}"
51 if [ "${OS}" = "Linux" ]; then
52   CDS_FULL_URL="${CDS_URL}/Linux_x64/${CDS_FILE}"
53 elif [ "${OS}" = "Darwin" ]; then
54   CDS_FULL_URL="${CDS_URL}/Mac/${CDS_FILE}"
55 fi
56 echo Trying to download prebuilt clang
57 if which curl > /dev/null; then
58   curl -L --fail "${CDS_FULL_URL}" -o "${CDS_OUTPUT}" || \
59       rm -rf "${CDS_OUT_DIR}"
60 elif which wget > /dev/null; then
61   wget "${CDS_FULL_URL}" -O "${CDS_OUTPUT}" || rm -rf "${CDS_OUT_DIR}"
62 else
63   echo "Neither curl nor wget found. Please install one of these."
64   exit 1
65 fi
66 if [ -f "${CDS_OUTPUT}" ]; then
67   rm -rf "${LLVM_BUILD_DIR}"
68   mkdir -p "${LLVM_BUILD_DIR}"
69   tar -xzf "${CDS_OUTPUT}" -C "${LLVM_BUILD_DIR}"
70   echo clang "${PACKAGE_VERSION}" unpacked
71   echo "${PACKAGE_VERSION}" > "${STAMP_FILE}"
72   rm -rf "${CDS_OUT_DIR}"
73   exit 0
74 else
75   echo Did not find prebuilt clang "${PACKAGE_VERSION}", building
76 fi