1#!/bin/bash
2# Copyright 2014 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, build a full package
7# with the latest plugin revisions and then repackage an existing
8# clang-package with the new plugin revisions.
9
10# The new package can be uploaded to replace the existing clang
11# package at the same clang revision.
12
13THIS_DIR="$(dirname "${0}")"
14LLVM_BUILD_DIR="${THIS_DIR}/../../../third_party/llvm-build"
15LLVM_TAR_DIR="${LLVM_BUILD_DIR}/Release+Asserts"
16LLVM_BIN_DIR="${LLVM_TAR_DIR}/bin"
17LLVM_LIB_DIR="${LLVM_TAR_DIR}/lib"
18
19set -eu
20
21if [ "$(uname -s)" = "Darwin" ]; then
22  PLATFORM=Mac
23  SO_EXT="dylib"
24else
25  PLATFORM=Linux_x64
26  SO_EXT="so"
27fi
28
29# Build clang with the new plugin revisions.
30"$THIS_DIR"/package.sh $@
31
32R=$("${LLVM_BIN_DIR}/clang" --version | \
33     sed -ne 's/clang version .*(\([0-9]*\))/\1/p')
34PDIR=clang-$R
35
36if [ ! -f "$PDIR.tgz" ]; then
37    echo "Could not find package archive $PDIR.tgz generated by package.sh"
38    exit 1
39fi
40
41# We don't want to change the clang binary, so fetch the current clang
42# package and add the plugin shared-libraries to the existing package.
43rm -rf $LLVM_BUILD_DIR
44"$THIS_DIR"/update.sh
45
46LIBNAME=\
47$(grep 'set(LIBRARYNAME' "$THIS_DIR"/../blink_gc_plugin/CMakeLists.txt \
48    | cut -d ' ' -f 2 | tr -d ')')
49LIBFILE=lib$LIBNAME.$SO_EXT
50
51# Check that we are actually creating the plugin at a new revision.
52if [ -f "$LLVM_LIB_DIR/$LIBFILE" ]; then
53    echo "The plugin revision $LIBNAME is already in the existing package."
54    exit 1
55fi
56
57cp $PDIR/lib/$LIBFILE "$LLVM_LIB_DIR/"
58if [ "$(uname -s)" = "Darwin" ]; then
59  tar zcf ${PDIR}_repack.tgz -C "$LLVM_TAR_DIR" bin include lib buildlog.txt
60else
61  tar zcf ${PDIR}_repack.tgz -C "$LLVM_TAR_DIR" bin lib buildlog.txt
62fi
63
64echo The clang package has been repackaged with $LIBNAME
65echo To upload, run:
66echo gsutil cp -a public-read ${PDIR}_repack.tgz \
67     gs://chromium-browser-clang/$PLATFORM/$PDIR.tgz
68