summaryrefslogtreecommitdiffstats
path: root/third_party/closure_compiler/bump_compiler_version
blob: 45af0533d4efdee56d8b52bd28117649b0c227d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/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 COMPILER_PATH="${SCRIPT_DIR}/compiler/compiler.jar"
readonly EXTERNS_PATH="${SCRIPT_DIR}/externs/chrome_extensions.js"

cleanup() {
  rm -rf "${TEMP_DIR}"
}

get_compiler_version() {
  java -jar "${1}" --version | grep ^Version: | cut -d' ' -f2
}

get_externs_sha1() {
  sha1sum "${EXTERNS_PATH}" | cut -d' ' -f1
}

trap cleanup SIGINT SIGHUP SIGTERM

previous_compiler_version=$(get_compiler_version ${COMPILER_PATH})
previous_externs_sha1=$(get_externs_sha1)

cd "${TEMP_DIR}"
echo "Cloning Closure Compiler repo"
git clone https://github.com/google/closure-compiler.git

cd closure-compiler
echo "Building Closure Compiler"
ant jar

if [[ "$?" -ne 0 ]]; then
  echo "Failed to build jar, copying nothing" >&2
  cleanup
  exit 1
fi

new_compiler_version=$(get_compiler_version "build/compiler.jar")

if [[ "${new_compiler_version}" != "${previous_compiler_version}" ]]; then
  cp build/compiler.jar "${COMPILER_PATH}"

  echo "Compiler version changed; re-building runner.jar"
  "${SCRIPT_DIR}/runner/build_runner_jar.py"

  compiler_jar_range="compiler.jar: ${previous_compiler_version} -> ${new_compiler_version}"
fi

(cat <<EOT && cat contrib/externs/chrome_extensions.js) > "${EXTERNS_PATH}"
//    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 bump_compiler_version.          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

new_externs_sha1=$(get_externs_sha1)

if [[ "${new_externs_sha1}" != "${previous_externs_sha1}" ]]; then
  chrome_extensions_range="chrome_extensions.js: ${previous_externs_sha1} -> ${new_externs_sha1}"
fi

echo
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo "@"
echo "@  ROLL RESULTS:"
echo "@"
echo "@  Compiler version:"
echo "@    Previous: ${previous_compiler_version}"
echo "@    New: ${new_compiler_version}"
echo "@"
echo "@  Externs SHA1:"
echo "@    Previous: ${previous_externs_sha1}"
echo "@    New: ${new_externs_sha1}"
echo "@"
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo

if [[ -z "${compiler_jar_range}" ]] && [[ -z "${chrome_extensions_range}" ]]; then
  echo "Nothing to update"
else
  echo "git commit -a -m 'Bumping closure compiler:"
  echo
  if [[ ! -z "${compiler_jar_range}" ]]; then echo "${compiler_jar_range}"; fi
  if [[ ! -z "${chrome_extensions_range}" ]]; then echo "${chrome_extensions_range}"; fi
  echo "TBR="
  echo "BUG='"
  echo
  echo "git cl upload"
fi

cleanup