Bug 1919083 - [ci] Enable os-integration variant for more suites, r=jmaher
[gecko.git] / intl / update-tzdata.sh
blob62a6cbcae2b05819085571c485a9ed929a74688f
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 git 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 GIT-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 'git clone' 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://github.com/unicode-org/icu-data.git
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}"/VERSION ]; then
58 local_tzdata_version=`grep --only-matching --perl-regexp --regexp="^\K[0-9a-z]+" "${tzdata_dir}"/VERSION`
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 git.
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 git clone --depth 1 "${tzdata_url}" "${tzdata_dir}"/source
130 git -C "${tzdata_dir}"/source filter-branch --prune-empty --subdirectory-filter tzdata/icunew/${tzdata_version}/44 HEAD
132 # Record `git log` and the tzdata version.
133 git -C "${tzdata_dir}"/source log -1 > "${tzdata_dir}"/GIT-INFO
134 echo "${tzdata_version}" > "${tzdata_dir}"/VERSION
136 # Remove the .git directory.
137 rm -rf "${tzdata_dir}"/source/.git
140 # Update ICU data.
141 update_icu_data() {
142 set +e
144 local type="$1"
145 local file="$2"
146 local cmd="${icu_pkg} --add ${tzdata_files} --sourcedir ${tzdata_dir}/source/${type} ${file}"
147 eval "${cmd}"
149 local exit_status=$?
151 if [ $exit_status -ne 0 ]; then
152 echo >&2 "ERROR: Error updating tzdata"
153 echo >&2 "ERROR: If you see an error message like 'format version 03.00 not supported',\n"\
154 " ensure your icupkg version matches the current ICU version."
155 exit $exit_status
158 set -e
161 if [ $dry = false ]; then
162 update_icu_data "le" "${icudata_file_le}"
163 if [ -n "${icudata_file_be}" ]; then
164 update_icu_data "be" "${icudata_file_be}"
167 hg addremove "${tzdata_dir}/source" "${tzdata_dir}/GIT-INFO" "${tzdata_dir}/VERSION" "${icudata_file_le}"
168 if [ -n "${icudata_file_be}" ]; then
169 hg addremove "${icudata_file_be}"
172 echo "INFO: Successfully updated tzdata!"
173 echo "INFO: Please run js/src/builtin/intl/make_intl_data.py to update additional time zone files for SpiderMonkey."