Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / tools / clang / scripts / package.sh
blob25cd6f0e0b4b9e44257a2d134e0125649f93868a
1 #!/bin/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, and then package the results up
7 # to a tgz file.
9 gcc_toolchain=
11 # Parse command line options.
12 while [[ $# > 0 ]]; do
13 case $1 in
14 --gcc-toolchain)
15 shift
16 if [[ $# == 0 ]]; then
17 echo "--gcc-toolchain requires an argument."
18 exit 1
20 if [[ -x "$1/bin/gcc" ]]; then
21 gcc_toolchain=$1
22 else
23 echo "Invalid --gcc-toolchain: '$1'."
24 echo "'$1/bin/gcc' does not appear to be valid."
25 exit 1
29 --help)
30 echo "usage: $0 [--gcc-toolchain <prefix>]"
31 echo
32 echo "--gcc-toolchain: Set the prefix for which GCC version should"
33 echo " be used for building. For example, to use gcc in"
34 echo " /opt/foo/bin/gcc, use '--gcc-toolchain '/opt/foo"
35 echo
36 exit 1
39 echo "Unknown argument: '$1'."
40 echo "Use --help for help."
41 exit 1
43 esac
44 shift
45 done
48 THIS_DIR="$(dirname "${0}")"
49 LLVM_DIR="${THIS_DIR}/../../../third_party/llvm"
50 LLVM_BOOTSTRAP_DIR="${THIS_DIR}/../../../third_party/llvm-bootstrap"
51 LLVM_BOOTSTRAP_INSTALL_DIR="${LLVM_DIR}/../llvm-bootstrap-install"
52 LLVM_BUILD_DIR="${THIS_DIR}/../../../third_party/llvm-build"
53 LLVM_BIN_DIR="${LLVM_BUILD_DIR}/Release+Asserts/bin"
54 LLVM_LIB_DIR="${LLVM_BUILD_DIR}/Release+Asserts/lib"
55 STAMP_FILE="${LLVM_DIR}/../llvm-build/cr_build_revision"
57 echo "Diff in llvm:" | tee buildlog.txt
58 svn stat "${LLVM_DIR}" 2>&1 | tee -a buildlog.txt
59 svn diff "${LLVM_DIR}" 2>&1 | tee -a buildlog.txt
60 echo "Diff in llvm/tools/clang:" | tee -a buildlog.txt
61 svn stat "${LLVM_DIR}/tools/clang" 2>&1 | tee -a buildlog.txt
62 svn diff "${LLVM_DIR}/tools/clang" 2>&1 | tee -a buildlog.txt
63 echo "Diff in llvm/compiler-rt:" | tee -a buildlog.txt
64 svn stat "${LLVM_DIR}/compiler-rt" 2>&1 | tee -a buildlog.txt
65 svn diff "${LLVM_DIR}/compiler-rt" 2>&1 | tee -a buildlog.txt
66 echo "Diff in llvm/projects/libcxx:" | tee -a buildlog.txt
67 svn stat "${LLVM_DIR}/projects/libcxx" 2>&1 | tee -a buildlog.txt
68 svn diff "${LLVM_DIR}/projects/libcxx" 2>&1 | tee -a buildlog.txt
69 echo "Diff in llvm/projects/libcxxabi:" | tee -a buildlog.txt
70 svn stat "${LLVM_DIR}/projects/libcxxabi" 2>&1 | tee -a buildlog.txt
71 svn diff "${LLVM_DIR}/projects/libcxxabi" 2>&1 | tee -a buildlog.txt
74 echo "Starting build" | tee -a buildlog.txt
76 set -exu
77 set -o pipefail
79 # Do a clobber build.
80 rm -rf "${LLVM_BOOTSTRAP_DIR}"
81 rm -rf "${LLVM_BOOTSTRAP_INSTALL_DIR}"
82 rm -rf "${LLVM_BUILD_DIR}"
83 extra_flags=
84 if [[ -n "${gcc_toolchain}" ]]; then
85 extra_flags="--gcc-toolchain ${gcc_toolchain}"
87 "${THIS_DIR}"/update.sh --bootstrap --force-local-build --run-tests \
88 ${extra_flags} 2>&1 | tee -a buildlog.txt
90 R=$(cat "${STAMP_FILE}")
92 PDIR=clang-$R
93 rm -rf $PDIR
94 mkdir $PDIR
95 mkdir $PDIR/bin
96 mkdir $PDIR/lib
98 GOLDDIR=llvmgold-$R
99 if [ "$(uname -s)" = "Linux" ]; then
100 mkdir -p $GOLDDIR/lib
103 if [ "$(uname -s)" = "Darwin" ]; then
104 SO_EXT="dylib"
105 else
106 SO_EXT="so"
109 # Copy buildlog over.
110 cp buildlog.txt $PDIR/
112 # Copy clang into pdir, symlink clang++ to it.
113 cp "${LLVM_BIN_DIR}/clang" $PDIR/bin/
114 (cd $PDIR/bin && ln -sf clang clang++)
115 cp "${LLVM_BIN_DIR}/llvm-symbolizer" $PDIR/bin/
116 if [ "$(uname -s)" = "Darwin" ]; then
117 cp "${LLVM_BIN_DIR}/libc++.1.${SO_EXT}" $PDIR/bin/
118 (cd $PDIR/bin && ln -sf libc++.1.dylib libc++.dylib)
121 # Copy libc++ headers.
122 if [ "$(uname -s)" = "Darwin" ]; then
123 mkdir $PDIR/include
124 cp -R "${LLVM_BOOTSTRAP_INSTALL_DIR}/include/c++" $PDIR/include
127 # Copy plugins. Some of the dylibs are pretty big, so copy only the ones we
128 # care about.
129 cp "${LLVM_LIB_DIR}/libFindBadConstructs.${SO_EXT}" $PDIR/lib
130 cp "${LLVM_LIB_DIR}/libBlinkGCPlugin.${SO_EXT}" $PDIR/lib
132 # Copy gold plugin on Linux.
133 if [ "$(uname -s)" = "Linux" ]; then
134 cp "${LLVM_LIB_DIR}/LLVMgold.${SO_EXT}" $GOLDDIR/lib
137 if [[ -n "${gcc_toolchain}" ]]; then
138 # Copy the stdlibc++.so.6 we linked Clang against so it can run.
139 cp "${LLVM_LIB_DIR}/libstdc++.so.6" $PDIR/lib
142 # Copy built-in headers (lib/clang/3.x.y/include).
143 # compiler-rt builds all kinds of libraries, but we want only some.
144 if [ "$(uname -s)" = "Darwin" ]; then
145 # Keep only the OSX (ASan and profile) and iossim (ASan) runtime libraries:
146 # Release+Asserts/lib/clang/*/lib/darwin/libclang_rt.{asan,profile}_*
147 find "${LLVM_LIB_DIR}/clang" -type f -path '*lib/darwin*' \
148 ! -name '*asan_osx*' ! -name '*asan_iossim*' ! -name '*profile_osx*' | \
149 xargs rm
150 # Fix LC_ID_DYLIB for the ASan dynamic libraries to be relative to
151 # @executable_path.
152 # TODO(glider): this is transitional. We'll need to fix the dylib name
153 # either in our build system, or in Clang. See also http://crbug.com/344836.
154 ASAN_DYLIB_NAMES="libclang_rt.asan_osx_dynamic.dylib
155 libclang_rt.asan_iossim_dynamic.dylib"
156 for ASAN_DYLIB_NAME in $ASAN_DYLIB_NAMES
158 ASAN_DYLIB=$(find "${LLVM_LIB_DIR}/clang" \
159 -type f -path "*${ASAN_DYLIB_NAME}")
160 install_name_tool -id @executable_path/${ASAN_DYLIB_NAME} "${ASAN_DYLIB}"
161 strip -x "${ASAN_DYLIB}"
162 done
163 else
164 # Keep only
165 # Release+Asserts/lib/clang/*/lib/linux/libclang_rt.{[atm]san,san,ubsan,profile}-*.a
166 # , but not dfsan.
167 find "${LLVM_LIB_DIR}/clang" -type f -path '*lib/linux*' \
168 ! -name '*[atm]san*' ! -name '*ubsan*' ! -name '*libclang_rt.san*' \
169 ! -name '*profile*' | xargs rm -v
170 # Strip the debug info from the runtime libraries.
171 find "${LLVM_LIB_DIR}/clang" -type f -path '*lib/linux*' ! -name '*.syms' | xargs strip -g
174 cp -vR "${LLVM_LIB_DIR}/clang" $PDIR/lib
176 if [ "$(uname -s)" = "Darwin" ]; then
177 tar zcf $PDIR.tgz -C $PDIR bin include lib buildlog.txt
178 else
179 tar zcf $PDIR.tgz -C $PDIR bin lib buildlog.txt
182 if [ "$(uname -s)" = "Linux" ]; then
183 tar zcf $GOLDDIR.tgz -C $GOLDDIR lib
186 if [ "$(uname -s)" = "Darwin" ]; then
187 PLATFORM=Mac
188 else
189 PLATFORM=Linux_x64
192 echo To upload, run:
193 echo gsutil cp -a public-read $PDIR.tgz \
194 gs://chromium-browser-clang/$PLATFORM/$PDIR.tgz
195 if [ "$(uname -s)" = "Linux" ]; then
196 echo gsutil cp -a public-read $GOLDDIR.tgz \
197 gs://chromium-browser-clang/$PLATFORM/$GOLDDIR.tgz
200 # FIXME: Warn if the file already exists on the server.