blob: d34e162c221029a8fb14917c0d68fdfc15bf1ec9 [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.
#
# TODO(dbeam): we don't really need to build the compiler any more. We used to
# need to because we built a custom runner. We could probably just curl
# https://dl.google.com/closure-compiler/compiler-latest.zip and unzip. And get
# the externs from rawgit.com.
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_chrome_sha1=$(get_sha1 "${EXTERNS_DIR}/chrome.js")
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
check_jdk_version() {
# Pretty contrived checks modeling how we write Maven XML files.
if [ ! -r "$2" ]; then
echo "Could not find $2" >&2
exit 1
elif ! fgrep -q '<jdk.version>'$1'</jdk.version>' "$2"; then
echo "JDK version $1 must be specified in $2" >&2
exit 1
elif ! fgrep -q '<source>${jdk.version}</source>' "$2"; then
echo "Java source must be specified to be \${jdk.version} in $2" >&2
exit 1
elif ! fgrep -q '<target>${jdk.version}</target>' "$2"; then
echo "Java target must be specified to be \${jdk.version} in $2" >&2
exit 1
fi
}
echo "Checking JDK Version Used to Build"
check_jdk_version 1.8 pom.xml
echo "Building Closure Compiler"
mvn clean install -DskipTests=true --projects com.google.javascript:closure-compiler,com.google.javascript:closure-compiler-externs
if [[ "$?" -ne 0 ]]; then
echo "Failed to build jar, copying nothing" >&2
cleanup
exit 1
fi
# TODO(dbeam): the Maven-built jar seems a little bigger than the ant version.
cp target/closure-compiler-1.0-SNAPSHOT.jar "${SCRIPT_DIR}/compiler/compiler.jar"
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.js) > "${EXTERNS_DIR}/chrome.js"
(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_chrome_sha1=$(get_sha1 "${EXTERNS_DIR}/chrome.js")
if [[ "${new_chrome_sha1}" != "${old_chrome_sha1}" ]]; then
chrome_range="chrome.js: ${old_chrome_sha1} -> ${new_chrome_sha1}"
fi
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.js SHA1:"
echo "@ Old: ${old_chrome_sha1}"
echo "@ New: ${new_chrome_sha1}"
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 "${chrome_range}" ]]; then echo "${chrome_range}"; fi
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