blob: 2f31c405990f94aaa74d125bc0a0e0d6a1b63436 [file] [log] [blame]
#!/bin/bash
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Download the newest version of Closure Compiler, build it and put into Chrome
# source tree. Also update externs/chrome_extensions.js.
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly TEMP_DIR=$(mktemp -d)
readonly EXTERNS_DIR="${SCRIPT_DIR}/externs"
readonly README="${SCRIPT_DIR}/README.chromium"
cleanup() {
rm -rf "${TEMP_DIR}"
}
get_sha1() {
sha1sum "$1" | cut -d" " -f1
}
trap cleanup SIGINT SIGHUP SIGTERM
old_head=$(egrep -o "^Revision: [0-9a-f]{5,40}$" "${README}" | cut -d" " -f2)
old_extensions_sha1=$(get_sha1 "${EXTERNS_DIR}/chrome_extensions.js")
old_polymer_sha1=$(get_sha1 "${EXTERNS_DIR}/polymer-1.0.js")
cd "${TEMP_DIR}"
echo "Cloning Closure Compiler repo"
git clone --depth 1 https://github.com/google/closure-compiler.git
cd closure-compiler
new_head=$(git rev-parse HEAD)
if [[ "${new_head}" == "${old_head}" ]]; then
echo "No closure-compiler changes since last roll. Nothing to do."
cleanup
exit 0
else
head_range=$(cat <<EOT
Change log:
https://github.com/google/closure-compiler/compare/${old_head}...${new_head}
EOT
)
fi
echo "Building Closure Compiler"
# TODO(dbeam): can we do less here? As in: build a more specific target.
mvn install -DskipTests=true
if [[ "$?" -ne 0 ]]; then
echo "Failed to build jar, copying nothing" >&2
cleanup
exit 1
fi
# TODO(dbeam): this .jar seems to be a bit bigger than the jar previously built
# by ant. I tried many other jars in target/, but none of them were able to
# build the runner.jar without issue.
cp target/closure-compiler-1.0-SNAPSHOT.jar "${SCRIPT_DIR}/compiler/compiler.jar"
echo "Re-building runner.jar"
"${SCRIPT_DIR}/runner/build_runner_jar.py"
if [[ "$?" -ne 0 ]]; then
echo "Failed to build runner.jar, roll unsuccessful"
cleanup
exit 1
fi
readonly WARNING="$(cat <<EOT
// SSSSSSSSSSSSSSS TTTTTTTTTTTTTTTTTTTTTTT OOOOOOOOO PPPPPPPPPPPPPPPPP
// SS:::::::::::::::ST:::::::::::::::::::::T OO:::::::::OO P::::::::::::::::P
// S:::::SSSSSS::::::ST:::::::::::::::::::::T OO:::::::::::::OO P::::::PPPPPP:::::P
// S:::::S SSSSSSST:::::TT:::::::TT:::::TO:::::::OOO:::::::OPP:::::P P:::::P
// S:::::S TTTTTT T:::::T TTTTTTO::::::O O::::::O P::::P P:::::P
// S:::::S T:::::T O:::::O O:::::O P::::P P:::::P
// S::::SSSS P::::PPPPPP:::::P
// SS::::::SSSSS This file is generated. To update it, P:::::::::::::PP
// SSS::::::::SS run roll_closure_compiler. P::::PPPPPPPPP
// SSSSSS::::S P::::P
// S:::::S T:::::T O:::::O O:::::O P::::P
// S:::::S T:::::T O::::::O O::::::O P::::P
// SSSSSSS S:::::S TT:::::::TT O:::::::OOO:::::::OPP::::::PP
// S::::::SSSSSS:::::S T:::::::::T OO:::::::::::::OO P::::::::P
// S:::::::::::::::SS T:::::::::T OO:::::::::OO P::::::::P
// SSSSSSSSSSSSSSS TTTTTTTTTTT OOOOOOOOO PPPPPPPPPP
EOT
)"
(echo "${WARNING}" && cat contrib/externs/chrome_extensions.js) > "${EXTERNS_DIR}/chrome_extensions.js"
(echo "${WARNING}" && cat contrib/externs/polymer-1.0.js) > "${EXTERNS_DIR}/polymer-1.0.js"
new_extensions_sha1=$(get_sha1 "${EXTERNS_DIR}/chrome_extensions.js")
if [[ "${new_extensions_sha1}" != "${old_extensions_sha1}" ]]; then
extensions_range="chrome_extensions.js: ${old_extensions_sha1} -> ${new_extensions_sha1}"
fi
new_polymer_sha1=$(get_sha1 "${EXTERNS_DIR}/polymer-1.0.js")
if [[ "${new_polymer_sha1}" != "${old_polymer_sha1}" ]]; then
polymer_range="polymer-1.0.js: ${old_polymer_sha1} -> ${new_polymer_sha1}"
fi
echo
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo "@"
echo "@ ROLL RESULTS:"
echo "@"
echo "@ closure-compiler.git HEAD:"
echo "@ Old: ${old_head}"
echo "@ New: ${new_head}"
echo "@"
echo "@ externs/chrome_extensions.js SHA1:"
echo "@ Old: ${old_extensions_sha1}"
echo "@ New: ${new_extensions_sha1}"
echo "@"
echo "@ externs/polymer-1.0.js SHA1:"
echo "@ Old: ${old_polymer_sha1}"
echo "@ New: ${new_polymer_sha1}"
echo "@"
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo
sed -i "s/^Revision: ${old_head}$/Revision: ${new_head}/" "${README}"
echo "git commit -a -m 'Roll closure compiler"
echo
echo "${head_range}"
if [[ ! -z "${extensions_range}" ]]; then echo "${extensions_range}"; fi
if [[ ! -z "${polymer_range}" ]]; then echo "${polymer_range}"; fi
echo
echo "TBR="
echo "BUG='"
echo
echo "git cl upload"
cleanup