Bug 1467571 [wpt PR 11385] - Make manifest's parsers quicker, a=testonly
[gecko.git] / intl / update-tzdata.sh
blob34b753156c198720cac67f162c34f1d2c3e9f3c8
1 #!/bin/sh
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 set -e
8 # Usage: update-tzdata.sh <tzdata version>
9 # E.g., for tzdata2016f: update-tzdata.sh 2016f
11 # Ensure that $Date$ in the checked-out svn files expands timezone-agnostically,
12 # so that this script's behavior is consistent when run from any time zone.
13 export TZ=UTC
15 # Also ensure SVN-INFO is consistently English.
16 export LANG=en_US.UTF-8
17 export LANGUAGE=en_US
18 export LC_ALL=en_US.UTF-8
20 # Path to icupkg executable, typically located at $ICU_DIR/bin/icupkg.
21 icu_pkg=
22 # Force updates even when current tzdata is newer than the requested version.
23 force=false
24 # Dry run, doesn't run 'svn export' and 'icupkg'.
25 dry=false
26 # Compare ICU and local tzdata versions (used by update-icu.sh).
27 check_version=false
29 while getopts ce:fd opt
31 case "$opt" in
32 c) check_version=true;;
33 e) icu_pkg="$OPTARG";;
34 f) force=true;;
35 d) dry=true;;
36 \?)
37 echo >&2 "Usage: $0 [-e <path to icupkg>] [-f] [-d] <tzdata version>"
38 exit 1;;
39 esac
40 done
41 shift "$((OPTIND - 1))"
43 if [ $# -ne 1 -a $check_version = false ]; then
44 echo >&2 "Usage: $0 [-e <path to icupkg>] [-f] [-d] <tzdata version>"
45 exit 1
48 tzdata_version=$1
50 icudata_dir=`dirname "$0"`/../config/external/icu/data
51 icu_dir=`dirname "$0"`/icu
52 tzdata_dir=`dirname "$0"`/tzdata
53 tzdata_files="${tzdata_dir}"/files.txt
54 tzdata_url=https://ssl.icu-project.org/repos/icu/data/trunk/tzdata/icunew/${tzdata_version}/44/
55 icu_tzdata_version=`grep --only-matching --perl-regexp --regexp="tz version:\s+\K.*$" "${icu_dir}"/source/data/misc/zoneinfo64.txt`
56 local_tzdata_version=
57 if [ -f "${tzdata_dir}"/SVN-INFO ]; then
58 local_tzdata_version=`grep --only-matching --perl-regexp --regexp="^URL: .*tzdata/icunew/\K[0-9a-z]+" "${tzdata_dir}"/SVN-INFO`
61 # Check ICU and current local tzdata versions.
62 if [ $check_version = true ]; then
63 if [ ! -z ${local_tzdata_version} ]; then
64 if [ ${local_tzdata_version} \> ${icu_tzdata_version} ]; then
65 echo >&2 "WARN: Local tzdata (${local_tzdata_version}) is newer than ICU tzdata (${icu_tzdata_version}), please run '$0 ${local_tzdata_version}'"
66 else
67 echo "INFO: ICU tzdata ${icu_tzdata_version} is newer than local tzdata (${local_tzdata_version})"
69 else
70 echo "INFO: No local tzdata files found"
72 exit 0
75 # Find icu_pkg if not provided as an argument.
76 icu_pkg=${icu_pkg:-`which icupkg`}
78 # Test if we can execute icupkg.
79 if [ ! -x "${icu_pkg}" ]; then
80 echo >&2 "ERROR: icupkg is not an executable"
81 exit 1
84 # Check ICU tzdata version.
85 if [ ${icu_tzdata_version} \> ${tzdata_version} ]; then
86 if [ $force = false ]; then
87 echo >&2 "ERROR: ICU tzdata (${icu_tzdata_version}) is newer than requested version ${tzdata_version}, use -f to force replacing"
88 exit 1
92 # Check tzdata version from last checkout.
93 if [ -n ${local_tzdata_version} -a ${local_tzdata_version} \> ${tzdata_version} ]; then
94 if [ $force = false ]; then
95 echo >&2 "ERROR: Local tzdata (${local_tzdata_version}) is newer than requested version ${tzdata_version}, use -f to force replacing"
96 exit 1
100 echo "INFO: Updating tzdata from ${local_tzdata_version:-$icu_tzdata_version} to ${tzdata_version}"
102 # Search for ICU data files.
103 # Little endian data files.
104 icudata_file_le=`find "${icudata_dir}" -type f -name 'icudt*l.dat'`
105 if [ -f "${icudata_file_le}" ]; then
106 icudata_file_le=`cd "$(dirname "${icudata_file_le}")" && pwd -P`/`basename "${icudata_file_le}"`
107 echo "INFO: ICU data file (little endian): ${icudata_file_le}"
108 else
109 echo >&2 "ERROR: ICU data (little endian) file not found"
110 exit 1
113 # Big endian data files.
114 # Optional until https://bugzilla.mozilla.org/show_bug.cgi?id=1264836 is fixed.
115 icudata_file_be=`find "${icudata_dir}" -type f -name 'icudt*b.dat'`
116 if [ -f "${icudata_file_be}" ]; then
117 icudata_file_be=`cd "$(dirname "${icudata_file_be}")" && pwd -P`/`basename "${icudata_file_be}"`
118 echo "INFO: ICU data file (big endian): ${icudata_file_be}"
119 else
120 echo "INFO: ICU data file (big endian) not found, skipping..."
123 # Retrieve tzdata from svn.
124 if [ $dry = false ]; then
125 echo "INFO: Downloading tzdata${tzdata_version}"
127 # Remove intl/tzdata/source, then replace it with a clean export.
128 rm -r "${tzdata_dir}"/source
129 svn export "${tzdata_url}" "${tzdata_dir}"/source
132 # Record `svn info`, eliding the line that changes every time the entire ICU
133 # tzdata repository (not just the path within it we care about) receives a
134 # commit.
135 if [ $dry = false ]; then
136 svn info "${tzdata_url}" | grep --invert-match '^Revision: [[:digit:]]\+$' > "${tzdata_dir}"/SVN-INFO
139 # Update ICU data.
140 update_icu_data() {
141 set +e
143 local type="$1"
144 local file="$2"
145 local cmd="${icu_pkg} --add ${tzdata_files} --sourcedir ${tzdata_dir}/source/${type} ${file}"
146 eval "${cmd}"
148 local exit_status=$?
150 if [ $exit_status -ne 0 ]; then
151 echo >&2 "ERROR: Error updating tzdata"
152 echo >&2 "ERROR: If you see an error message like 'format version 03.00 not supported',\n"\
153 " ensure your icupkg version matches the current ICU version."
154 exit $exit_status
157 set -e
160 if [ $dry = false ]; then
161 update_icu_data "le" "${icudata_file_le}"
162 if [ -n "${icudata_file_be}" ]; then
163 update_icu_data "be" "${icudata_file_be}"
166 hg addremove "${tzdata_dir}/source" "${tzdata_dir}/SVN-INFO" "${icudata_file_le}"
167 if [ -n "${icudata_file_be}" ]; then
168 hg addremove "${icudata_file_be}"
171 echo "INFO: Successfully updated tzdata!"
172 echo "INFO: Please run js/src/builtin/make_intl_data.py to update additional time zone files for SpiderMonkey."